Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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; }

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://436252]
[erix]: Look what I found! :P
[Corion]: Hmm - actually, I don't need them, even though they'd be nice. I just want the (say) 10 latest images, and that's easily done with a limit 10 offset 0 clause, as I don't need all top 10 images for all users.
[Corion]: erix: Sure, but this is for a really-lightweight application and I'm replacing a CSV file / JSON file for user configuration with SQLite (and optionally, Pg) :)
[erix]: isn't a texty format handier for configs?
[Corion]: So far, I've avoided having even a user database by storing the user information in a (signed) cookie that the browser keeps for me, but as I want to be able to lock users, I need a second storage option :)
[Corion]: erix: It's needed for keeping the list of users and the list of tags associated with an image, and for keeping the images with users. I want an easy way to know if an image can be deleted, which means that it can't be referenced by any tag anymore. ...
[Corion]: SQL feels like a natural choice here :)

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (12)
As of 2018-03-20 14:02 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (253 votes). Check out past polls.