Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: parsing lists

by tphyahoo (Vicar)
on Mar 03, 2005 at 15:42 UTC ( #436252=note: print w/ replies, xml ) Need Help??


in reply to parsing lists

1) put

use warnings; use strict;
at the top of your file.

2) I think you are missing a semicolon at the end of -the "open" line.

UPDATE: Here's some untested code...

use warnings; use strict; $count = 0; open (DISTLISTS, " < rdy.csv") || die "Unable host file for splitting: + $!."; while (<DISTLISTS>) { chomp $dist_split; if ($. % 200 == 0) { # modular arithmetic $count ++; } my $filename = "file$count.csv"; open (OUTPUT1, " >>$filename") print OUTPUT1 "$dist_split\n"; close OUTPUT1; }


Comment on Re: parsing lists
Select or Download Code
Re^2: parsing lists
by Roy Johnson (Monsignor) on Mar 03, 2005 at 19:00 UTC
    put the open inside the if block and the close outside the while block.

    Caution: Contents may have been coded under pressure.
      Yep. Ok this is tested and works.
      use warnings; use strict; my $count = 0; my $filename = "file0.csv"; open (DISTLISTS, " < rdy.csv") || die "Unable host file for splitting: + $!."; while (<DISTLISTS>) { chomp $_; if ( ($. - 1) % 200 == 0) { # modular arithmetic $count ++; my $filename = "file$count.csv"; open (OUTPUT1, " >$filename") } print OUTPUT1 "$_\n"; if ($. % 200 == 0) { # modular arithmetic close OUTPUT1; } }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (16)
As of 2014-09-02 14:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (24 votes), past polls