Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Mini-Tutorial: Scalar vs List Assignment Operator

by ikegami (Patriarch)
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
    # @array evaluated in list context.
    my ($first) = @array;
  6. 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;
  7. or download this
    my $count = () = f();
  8. or download this
    # Prints @x.
    print(@x = @y);

Log In?

What's my password?
Create A New User
Domain Nodelet?
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 perusing the Monastery: (3)
As of 2023-03-23 18:11 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (60 votes). Check out past polls.