Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

(crazyinsomniac) Re: What is the difference between a list and an array?

by crazyinsomniac (Prior)
on Dec 11, 2001 at 10:49 UTC ( [id://130879]=note: print w/replies, xml ) Need Help??


in reply to What is the difference between a list and an array?

A list is, well, just that, a list, a bunch of values separated by commas. An array is a data structure -- a "variable".

Consider this:

for my $thing("this","Is","aA","List") { print "$thing\n"; } print "\---------\n"; my @things = ("this","Is","aA","List","being","assigned","to","an","ar +ray"); for my $thing(@things) { print "$thing\n"; } print "\---------\n"; my %things = ("this", "Is", "aA", "List", "being", "assigned", "to", "a", "hash", "and", "as", "such", "it", "must", "be", "EVEN!", ,); for my $thing(@things) { print "$thing\n"; }
Furthermore, the distinction between a list and an array goes to context. There are two context's in perl, list, and scalar. The scalar function forces scalar context. The for (@something) "construct" implies list construct, as do functions and other things. To get a better grip on context in perl, please read japhys excellent article from perlmonth.com Issue 9: "List" is a Four-Letter Word (local) (remote).

 
___crazyinsomniac_______________________________________
Disclaimer: Don't blame. It came from inside the void

perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

  • Comment on (crazyinsomniac) Re: What is the difference between a list and an array?
  • Download Code

Replies are listed 'Best First'.
Re(2) (crazyinsomniac): What is the difference between a list and an array?
by dmmiller2k (Chaplain) on Dec 12, 2001 at 00:38 UTC
    A list is, well, just that, a list, a bunch of values separated by commas.

    You may be failing to address the confusion between what a list is with its literal representation in a program. After all a "bunch of values separated by commas" is considered a list literal, where the commas are mere notational conveniences. To the program itself, a list is a series of values, nevermind how they got there.

    This is NOT a flame! It goes more to highlighting the difference between what a thing is (e.g., list), and what you have to write in a program to get one.

    This particular distinction (or more precisely, the failure to understand it) caused more problems for me early on than maybe anything else (one exception: learning that my means local--in the C/C++ sense of the word--and that local really means localized global, or having a temporary local value for one But I digress).

    Fortunately for me, Perl's forgiving nature (combined with its uncanny "do what I mean" quality) saved my skin more than once. But when I later went back to examine some of my old code, I could see evidence of my then-incomplete understanding of these concepts.

    dmm

    You can give a man a fish and feed him for a day ...
    Or, you can
    teach him to fish and feed him for a lifetime
Re(2): (crazyinsomniac): What is the difference between a list and an array?
by dmmiller2k (Chaplain) on Dec 13, 2001 at 00:02 UTC

    crazyinsomniac:

    Truly, I meant no harm, in "Re(2) (crazyinsomniac): What is the difference between a list and an array?," above. Please consider it an (apparently unsuccessful) attempt at constructive criticism.

    I was hoping to articulate how your explanation might have perhaps obfuscated more than illuminated the subject for me, given my own understanding (or lack thereof) back when I was struggling with this concept myself, and in so doing, perhaps assist sierrathedog04 (et al) in that endeavor.

    dmm

    You can give a man a fish and feed him for a day ...
    Or, you can
    teach him to fish and feed him for a lifetime

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-24 18:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found