Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Improving dismal performance - Part 1

by rir (Vicar)
on May 12, 2009 at 20:59 UTC ( #763599=note: print w/ replies, xml ) Need Help??


in reply to Improving dismal performance - Part 1

This isn't complete, but shows a common approach.

Be well
rir

# XXX lots of possibly magic string literals $| = 1; local $_; while (<DATA>) { # find next record next unless /^\s*Record /; # read a record $_ = ''; my @record; do { s/^ *//; push @record, $_ if $_ && $_ !~ /^\s*End of Sub/ && $_ !~ /^\ +s*Sub/; $_ = <DATA>; }while ( $_ !~ /^\s*End of Record/ ); # massage the raw data in @record # XXX incomplete for my $item ( @record ) { $item =~ s/" = "/ /; $item =~ s/"//g; $item = "F " . $item; } @record = sort @record; # output preamble print STDOUT "RECORD\n"; print STDOUT "#addkey\n"; print STDOUT "#filename FF\n"; # XXX more? # output @record print STDOUT @record; # output trailer print STDOUT ".\n"; }


Comment on Re: Improving dismal performance - Part 1
Download Code
Re^2: Improving dismal performance - Part 1
by PoorLuzer (Beadle) on May 12, 2009 at 21:18 UTC
    Yes, the script before this one (using Tie) looked exactly like this, and that is still what I use now after the new version failed to do anything useful in reasonable time, but I was hoping that maybe I could optimize this code somehow - using Tie makes things so easy - just like looping through an array!

    Well, I am not totally out of luck, as I am reading line by line anyways, and not much change would be required to translate it into a direct file IO .. but in case someone comes across a light bulb in their vicinity, keep this node updated!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2014-07-29 08:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (212 votes), past polls