Hi Monks,
my Google-Fu so far didn't produce any results for my question so I'm trying to obtain the answer here. :)
To keep it simple I creates a small test script. I'm creating a new array and give a reference of it to a function which simply prints the array elements.
Now I want to do the same for a reverse sorted array (basially reverse @array) without having to save the reverse output into a second array but so far I'm struggling to do that.
use strict;
use warnings;
sub blubb($)
{
my $array_ref = shift;
for(my $i = 0; $i <= $#$array_ref; ++$i)
{
print "$i $array_ref->[$i]\n";
}
}
my @array = (1, 2, 3);
blubb(\@array);
Now I could simply do:
my @array2 = reverse @array;
blubb(\@array2);
My question is: Is there a way to do this without @array2 ?
Can I use blubb() directly with the reverse sorted @array ?
So far I haven't been able to come up with the syntax for this. :(
Thanks a lot in advance.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.