Stupid Perl Tricks: Difference between revisions
From Federal Burro of Information
Jump to navigationJump to search
No edit summary |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 22: | Line 22: | ||
print "yday: $my_time[7]\n"; | print "yday: $my_time[7]\n"; | ||
print "isdst: $my_time[8]\n"; | print "isdst: $my_time[8]\n"; | ||
my @month; | |||
$month[0] = 'Jan'; | |||
$month[1] = 'Feb'; | |||
$month[2] = 'Mar'; | |||
$month[3] = 'Apr'; | |||
$month[4] = 'May'; | |||
$month[5] = 'Jun'; | |||
$month[6] = 'Jul'; | |||
$month[7] = 'Aug'; | |||
$month[8] = 'Sep'; | |||
$month[9] = 'Oct'; | |||
$month[10] = 'Nov'; | |||
$month[11] = 'Dec'; | |||
my %month; | |||
$month{'Jan'} = 0 ; | |||
$month{'Feb'} = 1 ; | |||
$month{'Mar'} = 2 ; | |||
$month{'Apr'} = 3 ; | |||
$month{'May'} = 4 ; | |||
$month{'Jun'} = 5 ; | |||
$month{'Jul'} = 6 ; | |||
$month{'Aug'} = 7 ; | |||
$month{'Sep'} = 8 ; | |||
$month{'Oct'} = 10 ; | |||
$month{'Nov'} = 11 ; | |||
$month{'Dec'} = 12 ; | |||
# ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) | # ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) |
Latest revision as of 03:26, 12 November 2013
#foreach my $part ( @dateparts ) { # print "Part: ".$part."\n"; #} #while (my ( $key, $value) = values %data) { # print $key." = ".$value."\n"; #} #!/usr/bin/perl @my_time = localtime(time()); print "sec: $my_time[0]\n"; print "min: $my_time[1]\n"; print "hour: $my_time[2]\n"; print "mday: $my_time[3]\n"; print "mon: $my_time[4]\n"; print "year: $my_time[5]\n"; print "real year: ".($my_time[5]+1900)."\n"; print "wday: $my_time[6]\n"; print "yday: $my_time[7]\n"; print "isdst: $my_time[8]\n"; my @month; $month[0] = 'Jan'; $month[1] = 'Feb'; $month[2] = 'Mar'; $month[3] = 'Apr'; $month[4] = 'May'; $month[5] = 'Jun'; $month[6] = 'Jul'; $month[7] = 'Aug'; $month[8] = 'Sep'; $month[9] = 'Oct'; $month[10] = 'Nov'; $month[11] = 'Dec'; my %month; $month{'Jan'} = 0 ; $month{'Feb'} = 1 ; $month{'Mar'} = 2 ; $month{'Apr'} = 3 ; $month{'May'} = 4 ; $month{'Jun'} = 5 ; $month{'Jul'} = 6 ; $month{'Aug'} = 7 ; $month{'Sep'} = 8 ; $month{'Oct'} = 10 ; $month{'Nov'} = 11 ; $month{'Dec'} = 12 ; # ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) # for Good perl. #!/usr/bin/perl -w use strict; use warnings; use diagnostics;
need to learn more: Moose ? vat ees eet?
20120127230040 yyyymmddhhmmss if ( /(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/ ) { $dt = DateTime->new( year => $1, month => $2, day => $3, hour => $4, minute => $5, second => $6 ); }