Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Re: Skip 21 Lines

by greenFox (Vicar)
on Apr 25, 2001 at 04:22 UTC ( [id://75327]=note: print w/replies, xml ) Need Help??


in reply to Re: Skip 21 Lines
in thread Skip 21 Lines

You are repeating quite a bit of code there :) Try this (partially tested)-
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';

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://75327]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (5)
As of 2024-04-23 11:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found