Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Mini-Tutorial: Scalar vs List Assignment Operator

by ikegami (Pope)
on Aug 20, 2009 at 16:05 UTC ( #790129=perlmeditation: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download

  1. or download this
    # Array evaluated in scalar context.
    my $count = @array;
  2. or download this
    # The s/// operates on $copy.
    (my $copy = $str) =~ s/\\/\\\\/g;
  3. or download this
    # Prints $x.
    print($x = $y);
  4. or download this
    # Array evaluated in list context.
    my @copy = @array;
  5. or download this
    # Only dies if f() returns an empty list.
    # This does not die if f() returns a
    # false scalar like zero or undef.
    my ($x) = f() or die;
  6. or download this
    my $count = () = f();
  7. or download this
    # Prints @x.
    print(@x = @y);

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://790129]
Front-paged by Arunbear
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2015-11-25 13:49 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (676 votes), past polls