/[+-]?\d+/
/[+-]?(\d+(\.\d*)?|\.\d+)/
$time = localtime; print "$time";
Output:
Fri May 28 10:06:09 2004
$epochTime = time(); print "$epochTime";
Output:
1085710785
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime; $year = int($year); $mon = int($mon) + 1; $mday = int($mday); $sec = int($sec); $min = int($min); $hour = int($hour); $year += 1900 if $year < 1900;
# assume the epoch time is stored at $epochTime my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime ($epochTime); $year = int($year); $mon = int($mon) + 1; $mday = int($mday); $sec = int($sec); $min = int($min); $hour = int($hour); $year += 1900 if $year < 1900;
my %conf; open CONFIG, $configFile or die "couldn't open $configFile for reading"; foreach my $line (){ chop $line; # remove CR $line =~ s/#.*$//; # remove comment line next if $line eq ""; # skip empty line next if $line !~ m/[^=]+=.+/; # check format of key=value my ($key, $value) = $line =~ /^([^=]+)=(.+)$/; $key = &trim($key); # trim leading and trailing white space $value = &trim($value); $conf{$key} = $value; # store in associative array } close CONFIG;
Sample configuration file to read
key1=value1 key2=value2 key3=value3
@filenames;
$dir = "c:\\ht\\project\\studyPerl";
opendir DIR, $dir or die "cannot open directory";
while (my $file = readdir(DIR)) {
push @filenames, $file;
}
close DIR;
@args = ("one", "two", "three");
$line = join ("-", @args);
print "$line \n";
Output:
one-two-three