Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: need an explanation

by choroba (Bishop)
on Sep 22, 2013 at 21:55 UTC ( #1055203=note: print w/replies, xml ) Need Help??


in reply to need an explanation

The first line is equivalent to
@a = ('a', 'b', 'c', 'd', 'e');

qw just "quotes words".

The second line is usually written as

$b = @a;

or, for more clarity,

$b = scalar @a;

Perl is sensitive to context. By assigning to a scalar value, you impose the scalar context on the right hand side of the assignment. Arrays return their size (number of elements) in scalar context. Using = () = here has no effect and is only confusing. Update: It is usually used to force list context, for example

$x = () = "abcdABCabA" =~ /a/ig; # Count A's regardless of case.
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1055203]
help
Chatterbox?
[RonW]: Happy Thanksgiving Eve
[RonW]: and no panic, here. We're staying home, safe from the frenzy in the stores
[AnomalousMonk]: choroba: It even has Rama's (relatively) high rate of spin, although I don't know if it's axial spin.
[LanX]: Rama spins?
LanX probably in my stomach

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (12)
As of 2017-11-22 16:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (327 votes). Check out past polls.

    Notices?