Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
More experienced programmers are shaking their heads right now, they know it would be much more efficient to ...

The truly experienced programmer doesn't conflate efficiency with effectiveness, but that's worth a separate discussion.

Using a regex to parse fixed-width fields does indeed sound like overkill, but using substr isn't necessarily the most effective alternative. Splitting a record with multiple fixed-width fields requires multiple calls to substr, along with cascading math to make sure that the substr's start at the right places. Contrast that with a regexp-based solution, which requires a single invocation of a regexp, and no additional bookeeping. And then there's the oft-overlooked unpack.

The psgrep example in The Perl Cookbook demonstrates a method for separating fixed-width fields by constructing a format string for unpack. It also demonstrates an elegant way of documenting how the format string is assembled.


In reply to Re: Regex Misuse by dws
in thread Regex Misuse by srawls

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 browsing the Monastery: (6)
As of 2024-04-19 09:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found