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

incorrect output

by Anonymous Monk
on Feb 05, 2005 at 12:53 UTC ( [id://428309]=note: print w/replies, xml ) Need Help??


in reply to foreach loops

@a={1,2,3,4,5};
foreach $no (@a)
{
print "$no,";
}
OUTPUT :HASH(0x92efd28),

Replies are listed 'Best First'.
Re: incorrect output
by merlyn (Sage) on Feb 05, 2005 at 13:02 UTC
    That's the correct output. You may be misunderstanding this line:
    @a = {1, 2, 3, 4, 5};
    This line creates an anonymous hash by taking pairs of elements to create individual hash elements. With warnings enabled, you'd have also have been notified that the element "5" has no pair to take with it, so the hash is also improperly specified. Then the reference to this new anonymous hash becomes the sole element of the array @a.

    Perhaps you wanted:

    @a = (1, 2, 3, 4, 5);

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Re: incorrect output
by Anonymous Monk on Feb 18, 2005 at 17:43 UTC
    u have to initialize as
    @a=(1,2,3,4,5)
    or each element within double quotes

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2024-03-28 23:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found