I will incorporate the for -> while change you suggest.With regard to parse methods, I was intending to use the parse_csv subroutine suggested in Perl Cookbook for parsing actual data. I have tested this out and it seems to work just fine (having previously been caught out splitting CSV files).
I am really looking to tighten up old scripts so that modifications to files they use on will be spotted. Thank you both. Steve "Rob Dixon" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > "Jenda Krynicky" <[EMAIL PROTECTED]> wrote in message > 3E01E02F.17624.1ED52A1C@localhost">news:3E01E02F.17624.1ED52A1C@localhost... > > From: "Perl" <[EMAIL PROTECTED]> > > > This should work (but beware - it is untested :) > > > > > > Rob > > > > > > my @required = qw(head1 head6 head8); > > > my $line; > > > > > > for (<DATA>) > > > > It's much better to use > > while (<DATA>) > > > > This "for (<DATA>)" forces Perl to read the whole file into an array > > in memory. (Well ... unless the optimizer is bright enough to change > > the command to "while (<DATA>)". Not sure it is. You should not > > depend on the optimizer.) > > I agree completely. Also the optimiser shouldn't translate this to a while() > as optimisers aren't supposed to change code semantics at all. > > > > { > > > chomp; > > > my @field = split /,/; > > > > While this may be fine for column headers I would not recommend doing > > this with actual data. What if some of the fields are quoted and what > > if they contain commas? use Text::CSV_XS instead. > > > > Also true, but the problem was vaguely defined and I was coding for the > simplest case. > > [snip code] > > > > P.S.: Rob, could you change the comment part of your mail address? > > It's kinda strange to see a post comming from "Perl". :-) > > Yes, my apologies for this. I used to receive and send the newsgroup posts > as emails and just today set up the perl.org NNTP server - wrongly! Things > should be correct now. > > Cheers, > > Rob > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]