use warnings;
use strict;
my @array = (1,2,3,4,5);
@array = map { qq("${_}a") } @array;
print "@array\n";
__END__
"1a" "2a" "3a" "4a" "5a"
| [reply] [d/l] |
use strict;
use warnings;
my @array = qw(1 2 3 4 5 );
my @new_array = map { $_."a"} @array;
print join("\t", @new_array);
| [reply] [d/l] |
Something along these lines will do the trick:
my @modified_array = map {
$_ . "a"
} (1,2,3,4,5);
s;;5776?12321=10609$d=9409:12100$xx;;s;(\d*);push @_,$1;eg;map{print chr(sqrt($_))."\n"} @_;
| [reply] [d/l] |
One thought that flips through my head is that, unless you know that you really are going to “touch” every single one of those elements, you’re going to pay a terrible price in virtual-memory “thrashing” as you churn through all of those elements. (Think “hundreds of thousands of page-faults, each one requiring milliseconds to complete.” Suddenly, your CPU has been driven to a rate of performance that is entirely dictated by a physical device. Ouch!!)
Perhaps you could write a sub that returns the correct answer. This would, of course, perform the concatenation “on the fly,” and therefore perhaps millions of times, but it would only be invoked when the value was actually needed. This would avoid the virtual-memory “churn.” And if you know that you are walking through an array stem-to-stern, a function like each() might be much more advantageous than an index-variable.
(P.S. If you do write a sub, don’t get fancy. Don’t update the value in the array-element so that you don’t have to calculate the value again, because when you do that, you have just dirtied the page and obliged it to eventually be paged-out. You don’t want to impose an expensive I/O operation, which takes milliseconds, to avoid a cheap CPU operation, which takes nanoseconds.)
Edit: Oops! Nevermind!! You’re writing to a file, a row at a time. So what I just said doesn’t apply in your case. (Unless you can avoid creating that file.)
| |