Basic perl code- Date format

Hi friends,

Please see the below code carefully.

=======================================================

# Get batch date and Ord range
open OR,$ARGV[2];
while (<OR>) { # find the batch date
next if length $_ < 3; # BLANK LINE
# last if $. > 120; # sample should be good enough
(undef,undef,undef,undef,$batch_date,$oId,undef)=split(/,/,$_,);
   $dates{$batch_date}++;

$firstOrder ||= $ordId;
}
close OR;
@maxdates = sort{$dates{$b} <=> $dates{$a}} keys %dates;
$batch_date = shift @maxdates;
undef @maxdates;

=======================================================

so whatever i am catching batch_date from $ARGV[2];

that is interms of date+time
eg:2011-05-20 07:38:28

i want that batch date should be only contain date 2011-05-20
I cant change the file so plz tell me how can i do this, so that in next step i can use maxdate (@maxdates = sort{$dates{$b} <=> $dates{$a}} keys %dates;)

so plz help me to do so

Regards,
priyanka

use the result of command ls -l in linux ,, use its 4rth entry to sort or copy whatever u want..

Your problem boils down to converting a string like this -

2011-05-20 07:38:28

to this -

2011-05-20

After you capture the value of $batch_date and before you add it as a hash key, you may want to perform a trimming operation like the following -

$
$ perl -le '$batch_date = "2011-05-20 07:38:28"; $batch_date =~ s/ .*$//; print $batch_date'
2011-05-20
$
$

tyler_durden

1 Like