Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^4: the basic datatypes, three

by davorg (Chancellor)
on May 09, 2006 at 13:25 UTC ( [id://548203]=note: print w/replies, xml ) Need Help??


in reply to Re^3: the basic datatypes, three
in thread the basic datatypes, three

assigning a list to a scalar variable returns the result as a total number of elements in a list

No. That's not right. Evaluating a list in a scalar context (by, for example, assigning it to a scalar) returns the last item in the list. Evaluating an array in scalar context returns the number of items in the array.

There is an important difference between a list and an array.

# Assign a list to a scalar my $scalar = ('A', 'B', 'C'); print "$scalar\n"; # $scalar is C # Assign an array to a scalar my @array = ('A', 'B', 'C'); $scalar = @array; print "$scalar\n"; # $scalar is 3
Update: Stupid typo fixed.
--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2025-03-24 22:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (65 votes). Check out past polls.

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.