Hi all,
Hope someone can help, i get the date in the format of 12/12/2008
i 'd like to find out what day this is on, either a weekday/weekend. so output would be:
12/12/2008
midweek: fri 12 december
I'm also trying to do it the hard way, without the use of any modules .. i feel this will help my perl skills.
after the user has entered a date, i use the back tick operator to ask the shell a cal command and then put it all into an array.
I then try to see if i can change all single digits to double digits,i.e.
1 -> 01, 2 ->02...
but can't do it for the very last number for any month... whereas the other ones i can :(
Here is my attempt:
[CODE=perl]
#!/usr/bin/perl -w
use strict;
system('clear') ;
my %days = (
Sun => 'Sunday',
Mon => 'Monday',
Tue => 'Tuesday',
Wed => 'Wednesday',
Thu => 'Thursday',
Fri => 'Friday',
Sat => 'Saturday',
);
my %months = (
'01' => 'January',
'02' => 'February',
'03' => 'March',
'04' => 'April',
'05' => 'May',
'06' => 'June',
'07' => 'July',
'08' => 'August',
'09' => 'September',
'10' => 'October',
'11' => 'November',
'12' => 'December',
);
print "Enter a date dd/mm/yyyy\n";
chomp (my $ans = <>);
my @tmp = split(/\//,$ans);
print "day - $tmp[0], month = $tmp[1] year = $tmp[2]\n";
print "month is $months{$tmp[1]} \n";
my @caldata = `cal -m $tmp[1] $tmp[2]`;
foreach my $line (@caldata){
if ($line =~ /[a-zA-Z]+/){
$line = "";
next;
}
else{
chomp($line);
$line =~ s/ (\d[^\d]| \d$)/0$1/g;
#$line =~ s/ (\d)[^\d]/0$1 /g;
my @line = split(/ /,$line);
print "$line\t element count - ", scalar @line, "\n";
}
}
[/CODE]
the very last date on any line is giving me probs, the single digit remains single, like:
01 02 03 04 05 06 7
Any help would b very much appreciated.
thanks
g0uki
Hope someone can help, i get the date in the format of 12/12/2008
i 'd like to find out what day this is on, either a weekday/weekend. so output would be:
12/12/2008
midweek: fri 12 december
I'm also trying to do it the hard way, without the use of any modules .. i feel this will help my perl skills.
after the user has entered a date, i use the back tick operator to ask the shell a cal command and then put it all into an array.
I then try to see if i can change all single digits to double digits,i.e.
1 -> 01, 2 ->02...
but can't do it for the very last number for any month... whereas the other ones i can :(
Here is my attempt:
[CODE=perl]
#!/usr/bin/perl -w
use strict;
system('clear') ;
my %days = (
Sun => 'Sunday',
Mon => 'Monday',
Tue => 'Tuesday',
Wed => 'Wednesday',
Thu => 'Thursday',
Fri => 'Friday',
Sat => 'Saturday',
);
my %months = (
'01' => 'January',
'02' => 'February',
'03' => 'March',
'04' => 'April',
'05' => 'May',
'06' => 'June',
'07' => 'July',
'08' => 'August',
'09' => 'September',
'10' => 'October',
'11' => 'November',
'12' => 'December',
);
print "Enter a date dd/mm/yyyy\n";
chomp (my $ans = <>);
my @tmp = split(/\//,$ans);
print "day - $tmp[0], month = $tmp[1] year = $tmp[2]\n";
print "month is $months{$tmp[1]} \n";
my @caldata = `cal -m $tmp[1] $tmp[2]`;
foreach my $line (@caldata){
if ($line =~ /[a-zA-Z]+/){
$line = "";
next;
}
else{
chomp($line);
$line =~ s/ (\d[^\d]| \d$)/0$1/g;
#$line =~ s/ (\d)[^\d]/0$1 /g;
my @line = split(/ /,$line);
print "$line\t element count - ", scalar @line, "\n";
}
}
[/CODE]
the very last date on any line is giving me probs, the single digit remains single, like:
01 02 03 04 05 06 7
Any help would b very much appreciated.
thanks
g0uki
Comment