Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Using an array element as a loop iterator

by Laurent_R (Canon)
on Nov 07, 2013 at 18:14 UTC ( [id://1061608]=note: print w/replies, xml ) Need Help??


in reply to Using an array element as a loop iterator

Maybe you should not ignore strict and the other things. You might have got some indication on your mistakes (although I can't check that now, having no environment right now).

[1,2,3] is not an array but a reference to an array. So you may want

my $a = [1, 2, 3];
or
my @a = (1, 2, 3);
This also does not work:
foreach $a[1](@b)
Maybe you want something this:
foreach @$a[1][@b]
but I am really not sure, because the inner array has not been initialized. Finally,
$a[1]
is also probably wrong, since @a is a reference to an array. Please explain what you are really trying to do, I can't really figure out.

Replies are listed 'Best First'.
Re^2: Using an array element as a loop iterator
by gurpreetsingh13 (Scribe) on Nov 08, 2013 at 03:52 UTC
    Sorry, that was a mistake in copy-paste or something. I have updated the same. I don't want a reference, I am mentioning an array there.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-03-29 10:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found