Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Array qw difference

by davido (Cardinal)
on Nov 30, 2021 at 16:21 UTC ( [id://11139273]=note: print w/replies, xml ) Need Help??


in reply to Array qw difference

The qw// operator is discussed in perlop. The semantics are essentially that within a qw quote-like operator, whitespace separates elements. So: qw{ABCGE ABCGE} represents two elements, not one. This is different behavior from q// or qq//, which would return a single element:

my @list = qw{ABCDE DEFGH}; # @list has two elements. my @list = qq{ABCDE DEFGH}; # @list has one element. my @list = q{ABCDE DEFGH}; # @list has one element.

Therefore, these two things ARE equivalent:

my @list = qw{ABCDE DEFGH}; # Two elements. my @list = ('ABCDE', 'DEFGH'); # Two elements.

And these are equivalent:

my @list = ([qw{ABCDE DEFGH}], [qw{IJKLM NOPQR}]); # Two array-refs w +ith two elements in each. my @list = (['ABCDE, 'DEFGH'], ['IJKLM', 'NOPQR']); # Two array-refs w +ith two elements in each.

And the following produces four elements:

my @list = ('ABCDE', qw{DEFGH IJKLM}, 'NOPQR');  # Four elements.

Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11139273]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2026-01-19 07:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (122 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.