Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I ran this code on my Windows machine and also got a seg fault. When I first saw this "format" thing in Perl, I thought that it would be way cool. That initial idea turned out to be very, very wrong - there are limitations and weirdness with this idea. Something is wrong with the "format" statement, and I don't know exactly what.

My advice and what I do is to steer clear of this "format" statement and instead use standard printf style formatting specs. printf ("some data: %4d\n", $foo); or whatever. There are modules to help with complex textual tables, but in my experience they are seldom needed.

Summary: Use the extremely well debugged standard 'C' style family of formatting specs.

Update:
One of the issues here is that this "format" gizmo speaks to a different era in programming (punched cards and fixed field widths with no "column" separator characters). With the printf() format specs you can specify a minimum width for the field. If the data takes more characters than the print spec says, then it will put more characters in. This is almost always what is wanted. Use an explicit space character between fields like (%4d %4d) so that if the first int overflows, there will be a space between that and the next field, this better than say (%5d%5d) because that does not guarantee a space between fields. Perl is designed to parse space separated tokens very, very well.

use format if you will, the last time I used it was in Perl 5.6. Perl 5.10 may have a bug. I'm just saying that since Perl 5.6, I have found other ways to do what I want.


In reply to Re: This code snippet causes Perl to SEGV by Marshall
in thread This code snippet causes Perl to SEGV by worenklein

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 chilling in the Monastery: (4)
As of 2024-04-25 20:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found