in reply to split, manipulate, join
It's hard to give specific advice without seeing a sample of your input data, but it may be hard for you to show us a sample if your lines are 550 columns wide. Short answer: yes, it's quite likely that there is a faster solution using split and/or regex than what you're doing now with multiple index and substr commands.
One example to get you started: If you want the six columns numbered 10, 20, 30, 32, 34, and 38 (with the first column numbered 0), and your columns are separated by whitespace, you could do this to get them in an array:
while(my $line = <$file>){ chomp $line; # split the line on whitespace, then take certain indexed columns my @columns = (split /\s+/, $line)[10,20,30,32,34,38]; do_stuff_with_those_columns(@columns); }
On the other hand, if you know what you want out of each column, you may be able to skip the step of splitting into an array and go straight to extracting what you need. It just depends on the data. Give us at least a couple lines if you can.
Aaron B.
Available for small or large Perl jobs and *nix system administration; see my home node.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: split, manipulate, join
by jc.smith3 (Initiate) on Apr 10, 2015 at 22:55 UTC | |
by LanX (Saint) on Apr 10, 2015 at 23:07 UTC | |
by SuicideJunkie (Vicar) on Apr 10, 2015 at 23:09 UTC | |
by AnomalousMonk (Archbishop) on Apr 11, 2015 at 00:38 UTC | |
by jc.smith3 (Initiate) on Apr 11, 2015 at 01:32 UTC | |
by aaron_baugher (Curate) on Apr 10, 2015 at 23:26 UTC |