Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: array confusion

by hotshot (Prior)
on Aug 21, 2003 at 06:10 UTC ( #285364=note: print w/ replies, xml ) Need Help??


in reply to array confusion

Your two examples are not the same try doing:

foreach my $item (($name,$nerd,$noodle,$froodle,)) { # another brack +ets $item =~ s/$i_seek/ /g; }
and you'll see it doesn't work either

Hotshot


Comment on Re: array confusion
Download Code
Re: Re: array confusion
by Anonymous Monk on Aug 21, 2003 at 06:22 UTC

    Indeed it doesn't!

    I am at a loss to see how I should define the array so that it behaves in the same way as the initial example in the loop. If you could show me this I would be very grateful.

    Phil

Re: Re: array confusion
by esh (Pilgrim) on Aug 21, 2003 at 06:25 UTC
    (Please see Update below. I'm not editing out my mistakes, but I don't want to confuse readers.)

    I'm going to have to disagree with this statement. As far as I can see from the provided code, they are very close to the same.

    Furthermore, I believe that the extra set of parens in your example makes no difference in the functionality. Try this for yourself:

    perl -e 'foreach my $i ((1,2,3,4)) { print "$i\n" }'
    Update: I'm now going to correct myself. I misread the original code thinking that the loop variable was being used to select the strings that were being replaced. However, the loopvariable is being used to select the strings that are being modified.

    Yes! These are different. and I'll expand further, but wanted to get this correction out quickly.

    -- Eric Hammond

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2014-12-26 15:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls