my $file = 'file.txt'; # open for input is default and now our die tells us which # file we were trying to open open (DATA, $file) or die "Can't open $file $!\n"; # assuming you aren't using @DATA for something else later # there is no need to slurp it all into memory now while (<DATA>) { next unless $. > 21; chomp; my @temp=(); foreach (split /,/){ s/"//g; # strip the quotes first if you want s/\s+$//; # to remove trailing whitespace push @temp, $_; } $compHash{$temp[0]} = $temp[1]; $aliasHash{$temp[2]} = $temp[3]; # you did mean $var4? } close (DATA);
I am sure it could be reduced further with a judicious use of map but I can't get my head around it this morning :(
Since you are parsing quoted CSV data you may want to look at Text::CSV which is a standard module or tilly's Text::xSV which is also available from CPAN.
--
my $chainsaw = 'Perl';
In reply to Re: Re: Skip 21 Lines
by greenFox
in thread Skip 21 Lines
by qball
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |