Post a reply

Write your message and submit

Options

Click in the dark area of the image to send your post.

Go back

Topic review (newest first)

David Weber
2007-05-30 17:16:25

Thanks for your help. I got the job to work!

plegall
2007-05-30 10:01:38

My routine file has the following content:

Code:

use Exporter;

use vars qw(@EXPORT @ISA);

@ISA = qw(Exporter);
@EXPORT = qw(
    testIssueDate
);


sub testIssueDate {
    my $datestring = $_[0];
    
    if ((split('/', $datestring))[2] > 1950) {
        return $datestring;
    }
    else {
        return '1950/01/01';
    }
}

1;

The output of my job is:

Code:

Starting job topic792 at 09:58 30/05/2007.
.-------------------------.
|        tLogRow_1        |
+------------+------------+
| old_date   | new_date   |
+------------+------------+
| 9/29/1988  | 9/29/1988  |
| 10/29/1944 | 1950/01/01 |
| 9/29/1945  | 1950/01/01 |
| 9/29/1988  | 9/29/1988  |
| 9/29/1988  | 9/29/1988  |
'------------+------------'
Job topic792 ended at 09:58 30/05/2007. [exit code=0]
rbillerey
2007-05-30 10:00:10

Hi David,

c0utta is right and the recipe from the Perl cookbook is one way to do it. Another way is to use Date::Manip cpan module : http://cpan.uwinnipeg.ca/htdocs/DateMan … anip.html.

Code:

use Date::Manip ;
# French summer time zone
$ENV{TZ} = 'FST' ;

# dateA cmp dateB : 
# -1 if dateA < dateB
#  0 if dateA = dateB
#  1 if dateA > dateB
# perl cmp operator works when dates are in the same time zone

print ParseDate("1950/01/01") cmp ParseDate("10/02/1988"), "\n";

# use Date_Cmp with dates from different timezone

print Date_Cmp( ParseDate("1950/01/01") , ParseDate("10/02/1988") ), "\n";

Hope this helps.

c0utta
2007-05-30 01:45:12

Hi David,

I'm an absolute amateur when it comes to Perl, but date values are handled as Epoch Seconds, not as character strings or dates.  I had to spend some time to get my head around this, but now it's second nature.  You're always returning $BondEdge_Raw[Issue_Date] because the gt comparison is irrelevant.

Have a look at http://www.unix.org.ua/orelly/perl/cookbook/ch03_03.htm if you want to use Epoch Seconds.  I assume you're interested in local time, so you'll need to do:

      my $date1950 = timelocal(0, 0, 0, 1, 0, 50);

You'll then need to convert your incoming date using timelocal as well.  Then you can easily do comparisons because you're dealing with numbers.

My disclaimer is that I'm no Perl programmer, so I tend to do things the long way, whereas a real Perl programmer would be able to this in one line of code!

Cheers,

c0utta

David Weber
2007-05-29 22:07:26

I am looking to come up with a routine to return a date of < 1950/01/01 >  if the date is less than < 1950/01/01 > or Blank   So far I have to the routine below.   


sub testIssueDate {
      if ( $BondEdge_Raw[Issue_Date] gt "1950/01/01" )
            { return '$BondEdge_Raw[Issue_Date]'; }
       else
           { return '1950/01/01'; }
}


Below is my input:

9/29/1988
10/29/1944
9/29/1945

9/29/1988
9/29/1988

This is my output after the job is run:

9/29/1988
10/29/1944
9/29/1945
   0/00/00
9/29/1988
9/29/1988


Can anyone help me out with this?
Thanks,
David

Board footer

Powered by FluxBB