Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: A TRUE-once variable

by George_Sherston (Vicar)
on Dec 05, 2001 at 22:49 UTC ( #129704=note: print w/replies, xml ) Need Help??

in reply to A TRUE-once variable

To answer the question you asked, I like the ugly but effective:
my $do = 1; for (0...9) { stuff_to_do_always(); if ($do) { stuff_to_do_first_time(); } else { stuff_to_do_other_times(); } $do = 0; }
I know this isn't too subtle, but I find I can look at it and know what it does.

To answer the question you didn't ask, I think the problem wd go away if you used Then you could use placeholders, which put the commas in for you (and also handle the quoting issues which you do with quotrim).

This does what (I think) you want:
use DBI; my $dbh = DBI->connect("DBI:mysql:database=chess", "usr", "pwd"); # o +r whatever my @line; my $sth; while (<DATA>) { # your parsing: chomp; next if /^\s*$/; @line = split /;/; # these lines deal with the only variation in # your data I can see - there may be others: if (@line == 3) { push @line, $line[2]; $line[2] = 'NULL'; } # and finally, DBI takes the strain: $sth = $dbh->prepare("INSERT INTO eco_class (eco_id,eco,opening,va +riation,moves) VALUES (NULL,?,?,?,?)") or die $dbh->errstr; $sth->execute(@line) or die $dbh->errstr; }

George Sherston

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2020-05-27 10:31 GMT
Find Nodes?
    Voting Booth?
    If programming languages were movie genres, Perl would be:

    Results (154 votes). Check out past polls.