Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: This code snippet causes Perl to SEGV

by Marshall (Abbot)
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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2018-06-25 03:18 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.