in reply to parsing lists

use strict; use File::Slurp; my $filename = shift; my @lines = read_file($filename); my $counter; for( @lines ){ ++$counter > 200 and last; s/\r?\n//; write_file("$counter-$_.cvs"); }


Replies are listed 'Best First'.
Re^2: parsing lists
by dmorelli (Scribe) on Mar 03, 2005 at 22:07 UTC
    If you don't want to, or are unable to install File::Slurp, it's still pretty small and painless:

    open FH, "<$filename" or die "Cannot open $filename: $!"; my @lines = <FH>; close FH;
Re^2: parsing lists
by tphyahoo (Vicar) on Mar 04, 2005 at 09:38 UTC
    This creates a file for every line of input.
    write_file("$counter-$_.cvs");
    Careful!

    Also, sh1tn, I don't understand

    ++$counter > 200 and last;
    but I've seen it around... this is some kind of perl idiom right? What were you trying to do?
      Also, sh1tn, I don't understand
      ++$counter > 200 and last;
      ++$counter # increments the value of $counter and returns # the values after the increment and # logical and operator last # immediately exits the loop
      You may want to see perlop and last command.