So you want to lookup the field number given the field name? Hashes are usually great as lookup tables. You can use $. to determine whether this is the first line of the file or not (or you could create a flag).
use strict; use warnings; my %col_idx; open(my $result_fh, '<', 'file') # 3-arg safer or die("Unable to open input file: $!\n"); # $! meaningful while (<$result_fh>) { chomp(); # chomp safer my @fields = split(/;/, $_); if ($. == 1) { @col_idx{@fields} = 0..$#fields; } else { # Do what you want here. print "$fields[$col_idx{name}], "; print "$fields[$col_idx{postcode}]\n"; } }
In reply to Re: get array number
by ikegami
in thread get array number
by darrengan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |