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
|
|