Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re:x2 Ordering hash replacements to avoid clobbering things

by grinder (Bishop)
on Feb 26, 2003 at 16:17 UTC ( #238813=note: print w/ replies, xml ) Need Help??


in reply to Re: Ordering hash replacements to avoid clobbering things
in thread Ordering hash replacements to avoid clobbering things (update chaining)

I'm not interested in regexps as I'm not working with strings. This is being used to update database fields, so unless you're doing some really fancy tie-ing, regexps aren't gonna fly :)

For reference, the heart of the code that uses this snippet looks like this:

my $db = DBI->connect( $DSN, 'user', 'sekret', {AutoCommit => 0}) or die "Couldn't connect to database $DSN: ${\DBI->errstr}\n"; END { $db and $db->disconnect } my $ss = $db->prepare( q{update t set department = ? where department += ?}); die unless $ss; my $ok = 1; REPLACE: for my $r( @order ) { for my $key( keys %$r ) { print "$key -> $r->{$key}\n"; if( !$ss->execute( $r->{$key}, $key )) { warn "cannot update $key to $r->{$key}\n${\$ss->errstr}\n" +; $ok = 0; last REPLACE; } } } $ok ? $db->commit : $db->rollback;

NB: The above code is condensed from production code. I have excised things that have no relevance to the example, so it just may or may not compile :)


print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'


Comment on Re:x2 Ordering hash replacements to avoid clobbering things
Download Code
Re: Re:x2 Ordering hash replacements to avoid clobbering things
by xmath (Hermit) on Feb 26, 2003 at 16:33 UTC
    •Update: ok, I missed the line "The above example represents the fields in database records to be updated to reflect the change." -- my apologies

Log In?
Username:
Password:

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

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

    How do you remember the number of days in each month?











    Results (45 votes), past polls