You will get good advice if you provide more information, such as:
- How many even columns do you have?
- How many odd columns do you have?
- Are you just comparing items on the same line? If so, there may be no need to read all lines of your large input file into memory at once.
- Or, do you need to compare an item on one line to items on all other lines?
- Are you comparing strings or numbers?
- What are you using the 1st column for?
- Show a small sample of your input (fewer than 10 lines, fewer than 10 columns). Creating a small sample for yourself will make it easier for you to debug your own code, so the extra effort should pay off.
See also
perldsc.
Update: here is some example code to read the whole file into a data structure (HoHoA):
use warnings;
use strict;
use Data::Dumper;
my %data;
while (<DATA>) {
my ($id, @cols) = split;
for my $i (0 .. $#cols) {
my $type = ($i % 2) ? 'odd' : 'even';
push @{ $data{$id}{$type} } , $cols[$i];
}
}
print Dumper(\%data);
__DATA__
a 1 2 3 4 5 6
b 9 8 7 6 5 4
prints:
$VAR1 = {
'a' => {
'even' => [
'1',
'3',
'5'
],
'odd' => [
'2',
'4',
'6'
]
},
'b' => {
'even' => [
'9',
'7',
'5'
],
'odd' => [
'8',
'6',
'4'
]
}
};
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.