"John W. Krahn" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Jeff 'japhy' Pinyan wrote:
> > On Sep 8, Christopher Spears said:
> >
> >> I want to catch the various parts of the output of the
> >> date command.  Here is my script:
> >>
> >> my $date = system("date");
> >
<snip />
> >
> > You really just want to do this:
> >
> >   my @days = qw( Sun Mon Tue Wed Thu Fri Sat Sun );
> >   my $d = (localtime)[3];
> >   print "Today is $days[$d].\n";
>
> Or:
>
> my ( $day ) = localtime =~ /(\S+)/;
> print "Today is $day.\n";
>

Or if you like code that is easier to extend:

use Time::Piece;
my $date = Time::Piece->new;
print( $date->day, "\n" ); # prints "Fri" today

Now pretend the boss said to use full day names instead of abbreviations.
The code would just change to:

use Time::Piece;
my $date = Time::Piece->new;
print( $date->fullday, "\n" ); # prints "Friday" today

Todd W.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to