Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Context tutorial

by kyle (Abbot)
on Jan 23, 2009 at 19:20 UTC ( #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
Node Status?
node history
Node Type: perltutorial [id://738558]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2014-12-26 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (167 votes), past polls