Help for this page

Select Code to Download


  1. 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();
    
  2. or download this
    # Example 3.
    # $sec will be 40, $min will be 51, $hr will be 20
    ($sec,$min,$hr) = localtime();
    
  3. or download this
    my ($x) = localtime();
    
  4. or download this
    my $x = localtime();
    
  5. or download this
    print clock();
    
    sub clock {
        return localtime();
    }
    
  6. or download this
    print scalar localtime();
    
  7. or download this
    my $match_count = ()= /x/g;
    
  8. or download this
    while (<>) {
        ponder( $_ );   # void context
    }
    
  9. or download this
    sub print_context {
        if ( wantarray() ) {
    ...
    void
    list
    scalar
    
  10. or download this
    my $beer_inventory = '99 bottles';
    print "how much beer?  $beer_inventory\n";
    ...
    __END__
    how much beer?  99 bottles
    how much beer?  98
    
  11. or download this
    my $s = "12 monkeys";
    my $n = 31337;
    ...
    my $stringified = ''. $n;  # "31337"
    my $numified    = 0+  $s;  # 12
    my $bool        = !!  $n;  # 1
    
  12. or download this
    my $scaley = 'snake';
    my @listy = $scaley;
    
    # does the same thing:
    #my @listy = ('snake');
    
  13. or download this
    my @t = ( 'one', 'two' );
    my $x = ( 'one', 'two' );               # 'two'
    my $y = ( 'larry', 'moe', @t );         # 2
    my $z = ( 'old', 'man', localtime() );  # "Fri Jan  9 20:51:40 2009"
    
  14. or download this
    my $friend   = 'Perl';
    my $literal  = '$friend';   # literally, '$friend'
    my $expanded = "$friend";   # literally, 'Perl'