in reply to Re^2: Producing 2 lists from a grep call
in thread Producing 2 lists from a grep call
I quite like that one. I came close to that but missed (actually, simply wasn't aware of) the @{\@array) 'trick'.
However (you knew that was coming right?), as I can do:
my (@a1,@a2) = ([1,2,3],[3,2,1]);
Update: the above line doesn't work after all
I had tried:
my (@a1,@a2) = ([1,2,3,4,5,6,7],[7,6,5,4,3,2,1]); print Dumper(@a1), Dumper(@a2);
which gave:
which certainly lookedlike it had worked! It was only after seeing this that I went back and added a couple of labels$VAR1 = [ 1, 2, 3, 4, 5, 6, 7 ]; $VAR2 = [ 7, 6, 5, 4, 3, 2, 1 ];
print "a1\n", Dumper(@a1), "a2\n", Dumper(@a2);
That I saw what tstock meant below.
Thanks tstock, I'll be more careful in future with my quick tests. (I agree about the loop/if being better too.)
end of update
Which personally I find a very clear yet concise way of declaring and initialising two arrays. It still seems as if something close to:
my ( @dirs, @files)= ( @{-d}, @{-f} ) for (readdir DIR);
could be possible if I could only get the syntactic sugar right!
This is only an exercise in my trying to understand arrays and list contexts etc. ie. Its essentially a purely academic excercise for late (for me) on a Sunday evening, and so not worthy of anyone's time unless they are also in play mode.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: Producing 2 lists from a grep call
by tstock (Curate) on Jun 16, 2002 at 23:40 UTC | |
by Aristotle (Chancellor) on Jun 17, 2002 at 12:28 UTC |