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

Re^2: Reading (the same) data in different ways & memory usage

by Neighbour (Friar)
on Apr 21, 2011 at 08:07 UTC ( [id://900490]=note: print w/replies, xml ) Need Help??


in reply to Re: Reading (the same) data in different ways & memory usage
in thread Reading (the same) data in different ways & memory usage

And so I'm learning new things every day :)

I have experienced difficulties with the @ and % prototypes, as I read in the link you provided, and stopped using those. The scalar prototypes are now purely used to enforce the right amount of arguments (as an added bonus, perl implicitly coerces any arguments supplied to scalars...this will definitely mess things up, but if you were supplying non-scalars to this function, that was bound to happen anyway, so I'm not worried about that much).

It seems that open accepts one thing besides strings as the EXPR-argument (2nd or 3rd if a MODE is supplied), and that is a reference to a scalar to be used as an in-memory file. Even though this is not the case here, I've removed the stat-check, since open will give an error anyway if the file doesn't exist. Also $! has been included in the errormessage, should open fail.

How does one substitution with capture compare to doing 2 substitutions without capture? I would have to benchmark this to figure out which is faster.

The sprintf seems out of place, though, as with all user-supplied data, it's not certain that the default-values (looks like I missed one when translating "standaard" to "default") for (VAR)CHAR fields actually contains a string-value. However, this can also be done just using ""'s.

  • Comment on Re^2: Reading (the same) data in different ways & memory usage

Replies are listed 'Best First'.
Re^3: Reading (the same) data in different ways & memory usage
by jwkrahn (Abbot) on Apr 21, 2011 at 10:59 UTC
    How does one substitution with capture compare to doing 2 substitutions without capture?

    In your example:

    $hr_returnvalue->{$CurrentColumnName} =~ s/^\s*(.*?)\s*$/$1/; + # Trim whitespace

    The regular expression /^\s*(.*?)\s*$/ will always match, regardless if there is or is not whitespace present, so the substitution will always be done.

    In my example:

    s/^\s+//, s/\s+$// for $hr_returnvalue->{$CurrentColumnName}; + # Trim whitespace

    The regular expressions /^\s+/ and /\s+$/ will only match if there is whitespace present and so the substitution will only be done on the occurrence of whitespace.

    Running a benchmark would be good start, and you should try to use data similar to, or the actual data that your program uses.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2025-07-11 03:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.