Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: This code snippet causes Perl to SEGV

by Marshall (Prior)
on Aug 21, 2012 at 20:29 UTC ( #988851=note: print w/ replies, xml ) Need Help??

in reply to This code snippet causes Perl to SEGV

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.

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.

Comment on Re: This code snippet causes Perl to SEGV

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2014-09-22 23:13 GMT
Find Nodes?
    Voting Booth?

    How do you remember the number of days in each month?

    Results (208 votes), past polls