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:

$VAR1 = [ 1, 2, 3, 4, 5, 6, 7 ]; $VAR2 = [ 7, 6, 5, 4, 3, 2, 1 ];
which certainly lookedlike it had worked! It was only after seeing this that I went back and added a couple of labels

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.


In reply to Re: Re: Re: Producing 2 lists from a grep call by BrowserUk
in thread Producing 2 lists from a grep call by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.