- or download this
# Example 1.
# @now will be (40, 51, 20, 9, 0, 109, 5, 8, 0)
...
# Example 2.
# $now will be "Fri Jan 9 20:51:40 2009"
$now = localtime();
- or download this
perl -e "@now = localtime(); for $now(@now) {print $now;}"
432351301092120
perl -e "$now = localtime(); print $now;"
Tue Jan 13 05:26:30 2009
- or download this
# Example 3.
# $sec will be 40, $min will be 51, $hr will be 20
($sec,$min,$hr) = localtime();
- or download this
my ($x) = localtime(); # Example 4
- or download this
my $x = localtime(); # Example 5
- or download this
# BAD! [Example 6]
my %h = ( now => localtime() );
- or download this
# GOOD [Example 7]
my %h = ( now => scalar localtime() );
- or download this
# GOOD [Example 8]
my %h = ( now => [ localtime() ] );
- or download this
# Example 9
sub print_time {
...
# prints "The time is now Tue Jan 13 05:26:30 2009"
print_time( scalar localtime() );
- or download this
# Example 10
my @loc = ($offset, $length);
my $part = substr( $string, @loc );
- or download this
print clock(); # Example 11
sub clock {
return localtime();
}
- or download this
print scalar localtime(); # Example 12
- or download this
my $match_count = ()= /x/g; # Example 13
- or download this
# Example 14
while (<>) {
ponder( $_ ); # void context
}
- or download this
# Example 15
...
void
list
scalar
- or download this
# Example 16
...
__END__
how much beer? 99 bottles
how much beer? 98
- or download this
# Example 17
...
my $stringified = ''. $n; # "31337"
my $numified = 0+ $s; # 12
my $boolean = !! $n; # 1
- or download this
# Example 18
...
# does the same thing:
#my @listy = ('snake');
- or download this
# Example 19
...
my $r = ( 'larry', 'moe', @t ); # 2
my $f = ( 'old', 'man', localtime() ); # "Fri Jan 9 20:51:40 2009"
- or download this
# Example 20
my $friend = 'Perl';
my $literal = '$friend'; # literally, '$friend'
my $expanded = "$friend"; # literally, 'Perl'