Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

JanneVee's scratchpad

by JanneVee (Friar)
on Jun 02, 2004 at 12:23 UTC ( #359378=scratchpad: print w/replies, xml ) Need Help??

I must admit that I'm a little rusty with Perl, I dug up an ancient script. I'm not proud of it... but hey it is from year 2000.

while (<FIL>) { $row = $_; ($pnr, $enamn, $fnamn, $adress, $stad, $telnr, $ar, $lon, $timmar, +$anr) = split("\t", $row); for ($i = 0; $i < $cnt; $i++) { if($pnr_array[$i] eq $pnr) { $duplicate++; $unique = 0; print "\n$pnr is not unique!\n"; } } if ($unique != 0) { $pnr_array[$cnt] = $pnr; $cnt++; # file write code omitted.. } $unique = 1; }

Now this code is terribly inefficient, it almost takes 30 minutes to run with the data set to remove the rows with non unique $pnr :s.

Today I looked up my old script, to do some serious optimization on it, and the resulting code

while (<FIL>) { $rad = $_; ($pnr, $enamn, $fnamn, $adress, $stad, $telnr, $ar, $lon, $timmar, +$anr) = split("\t", $rad); # print "$pnr"; if(exists $pnr_array{$pnr}) { $duplicate++; $unique = 0; print "\n$pnr är inte unikt!\n"; } if ($unique != 0) { $pnr_array{$pnr} = 0; } $unique = 1; }
Now this code uses a nasty construct that I don't find beatiful... $pnr_array{$pnr} = 0; is there a better way to do a set in perl?
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2023-12-05 09:44 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (26 votes). Check out past polls.