| [reply] [d/l] |
perl -pi.bak -e '$_="PREFIX $_"' filename.csv
perl -pi.bak -e 's/^/PREFIX /' filename.csv
| [reply] [d/l] |
use strict;
use warnings;
local @ARGV = ('file.csv');
local $^I = '.bak';
while (<>)
{
print "prepended stuff - $_";
}
DWIM is Perl's answer to Gödel
| [reply] [d/l] |
perl -pi.bak -e 's/^/PREFIX/' filename.csv
| [reply] [d/l] |
Loading 20MB in the memory will speed up the things, but there are some problems related with that:
- Do you have that much of memory available to your application?
- Do you need this speed improvement?
- Do your application runs in batch mode? Or it's used thru user interaction?
Anyway, do not use REGEX to prepend the variable there. REGEX is a cool thing, but is a mistake to use REGEX as the solution for everything. In your case, a very simple print will do, so I using REGEX?
As a hint, try to use print like this:
print $prepend_value, $line_from_file, "\n";
Instead of:
print "$prepend_value$line_from_file\n";
Usually using print with multiple arguments is faster them concatenating strings and print after that. Use Benchmark to test the speed of different methods.
Alceu Rodrigues de Freitas Junior
---------------------------------
"You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill
| [reply] [d/l] [select] |