Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2017-03-26 00:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (313 votes). Check out past polls.