Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
These discussion typically start with "only I run the script", and that's just a lack of imagination. You know better than that.

Um no. Read the thread again. This was not 'advice' to a petitioner, but a response to a request for "Small examples of string eval".

Your telling the world it's a good idea to follow your example.

No I am not. I am describing one useful example use I make of string eval.

Your 'nanny state' attitude reminds of sit-com mothers spelling out "bad words" letter by letter so their children won't understand.

"Yes. I too find occasions when S-T-R-I-N-G E-V-A-L is U-S-E-F-U-L; but don't tell the K-I-D-S!".

As for your code example. You had to extend it to deal with exponentiation. How about &, |? How about shift-left (<<) and shift-right(>>)? Or string increment ($n++)? Bitwise operators on strings ($a ^ $b)? Ranges ('a'..'z'; 1..10)? Hash and array variables? sqrt()? The list goes on. And on... And on.

Perl has a very well designed, tried, and tested expresson parser built in. For the purpose I described, it is illogical to try and recreate it. Talk about re-inventing the wheel and passing up oppertunities for code reuse.

There are all sorts of other things you can do to harden your code, but you have to want to do that. At the very least, turn on taint checking and scrub the input.

If you are obtaining input from unknown persons via (say) the web, then these measures are appropriate. If you are obtaining input from a person sat at the keyboard with the ability to run perl(.exe), they are simply pointless.

Do you put your seatbelt on to drive your car from the drive into your garage?

There are times when such hardening is appropriate. There are times when it is not. The trick is recognising the difference. I know the difference and I am sure you do too; but unlike you, I do not operate under the premise that other people are not smart enough to understand. Nor do I feel the need to preach about it.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^5: Small examples of string eval by BrowserUk
in thread Small examples of string eval by spurperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-19 12:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found