in reply to Re^2: How do I get rid of the cr/lf
in thread How do I get rid of the cr/lf
(Please use <code> tags to display code, not <pre>tags)
Do you have "use warnings" in your code? I ask because the important piece of your code seems to be if($fieldName eq $ourstring) and according to the extract you've shown us, $fieldName is undefined at that point.
But assuming that it's set somewhere outside of this extract, I still think that you can simplify a lot of this code. I'd consider setting up a hash where the keys are the column names and the associated values are the column numbers. Something like:
my %columns; @columns{@split_first_line} = 0 .. $#split_first_line;
You can then get the column number associated with a given field name with a simple:
if (defined (my $field_num = $columns{$field_name})) { # field exists }
Also, the best place to deal with chomping the input data is probably as soon as you've read it in, when a simple chomp(@f) would suffice.
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
|
|---|