Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: Perl Idioms Explained - my $count = () = /.../g

by santonegro (Scribe)
on Feb 05, 2006 at 20:31 UTC ( #528095=note: print w/replies, xml ) Need Help??

in reply to Perl Idioms Explained - my $count = () = /.../g

a list assignment in scalar context returns the number of elements on the right-hand side of the list assignment
I don't agree with that. An array assignment does this. A list assignment returns the last element. To wit:
@A = (1,3,5); $scalar_array = @A; $scalar_list = (1,3,5); $scalar_weird = (1..5); print "SA: ", $scalar_array, $/; print "SL: ", $scalar_list, $/; print "SW: ", $scalar_weird, $/; =for shell metaperl@pool-71-109-151-76:~/tmp$ perl SA: 3 SL: 5 SW: =cut

Replies are listed 'Best First'.
Re^2: Perl Idioms Explained - my $count = () = /.../g
by japhy (Canon) on Feb 05, 2006 at 21:23 UTC
    You misunderstood me. A list assignment in scalar context returns the number of elements.
    my $count = (LIST1) = (LIST2);
    The chunk in bold is the list assignment. That is put in scalar context by the my $count = ... part.

    Please see Re: Longest repeated string... for further clarification.

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
Re^2: Perl Idioms Explained - my $count = () = /.../g
by MrCricket (Sexton) on Dec 17, 2015 at 15:18 UTC
    About the
    $scalar_weird = (1..5); print "SW: ", $scalar_weird, $/; SW:
    -it's not a 'range' operator but a 'flip-flop', returns false in your case,

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://528095]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2018-07-20 16:58 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (438 votes). Check out past polls.