I have this example:
my $numbers = [ 1, 2, 3, 4, 5, 6 ];
my $newarray = [ reverse @$numbers ];
This example contains some synthetic code to make the $numbers arrayref appropriate for the reverse function. I would like to remove that code and do something more like this:
my $newarray = reverse $numbers;
I know this doesn’t work, it returns:
)8936f22x0(YARRA
Is there a better way to reverse an arrayref in Perl without changing the first line?
UPDATE:
my $mails = [ reverse @{$mail_api->GetLogSendMail({ customer_id => $id })} ];
The idea is to make the above line of code better.
If you are ok to use array instead of arrayref, then try this:
Code
my $newarray = reverse $numbersdidn’t work becausereverseis called in scalar context, which make it return a string with charactes in reversed order. Fromreversemanual:If you declare $newarray variable somewhere above you can write it in following way:
Update
May be you would like to create your own function: