Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Context tutorial

by kyle (Abbot)
on Jan 23, 2009 at 19:20 UTC ( [id://738558]=perltutorial: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perltutorial [id://738558]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 13:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found