Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Why study a SCALAR?

by clintp (Curate)
on Dec 26, 2001 at 08:59 UTC ( #134346=note: print w/replies, xml ) Need Help??

in reply to Why study SCALAR?

To be perfectly honest, study was one of the very few places in the Perl Developer's Dictionary where I copped out and didn't include an example of the syntax in an actual program. Why?

Following the guidelines in the Camel, online docs, and what I could grok of the source code, I kept coming up with seriously contrived uses. Okay, I did find a few uses that seemed to apply and didn't look so bad. So like any "optimization" scheme, I set up some benchmarks so that I could recommend it or at least further specify *exactly* where study benefits.

By the time that I had a broad list of examples where studywas beneficial, and a list where it didn't help (or even hurt) performance it would have taken several pages to explain *why* it works this way -- and along the way dancing around implementation details of the language that I really didn't care to explain. Very, very small changes in the input data would cause large swings in the benchmark timings. I didn't want a huge checklist of cases and exceptions with disclaimers making the whole thing moot anyway.

So I documented what I found (which is essentially what the Camel 3ed and the docs say) but with even broader warnings and more vigorous handwaving.

Replies are listed 'Best First'.
Re: Re: Why study a SCALAR?
by melora (Scribe) on Nov 14, 2003 at 02:55 UTC
    One area where I'm currently using regexes is a 'simulator' that I've written in Perl, which basically interprets another language (a process control language). The syntax is different, this other language allows for arbitrarily complex expressions (really hairy 2-page messes with plenty of parentheses nesting, etc... nothing I'd want to maintain, and I'm glad I don't have to), and it also provides for an IF statement which tests whether an expression's value has gone from 0 to 1 (an edge-triggered device, to a hardware person). So it's not a trivial one-for-one translation. Bear in mind that I'm using some of the regexes to *alter* the original line; in essence, I translate it into the Perl equivalent and then use eval() to 'execute' it. Is this a candidate for the use of study($line), given that the $line is changing along the way? (If so, I will attempt to see if there's a speedup; right now, it's executing tens of thousands of lines in a little over a minute and I've got timestamping which could tell if there's anything to be gained.)

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2020-11-23 20:23 GMT
Find Nodes?
    Voting Booth?

    No recent polls found