Aha, things begin to fall in place here! I never thought of the space in
format. I relly didn't think it made a diffefence using "%6d %5d %5d"
instead of "%6d%5d%5d".

Thanx a lot, I think I got it now!!!

(The "non-ascii" from my name is the Scandinavian "a" with a circle on
top of it. If you set your keyboard to Norwegian, you will find it to
the right of the "p" on your keyboard. The substitute for it is actually
"aa" so my name can be written "Kaare".)

K. Edvardsen

On Thu, 2006-11-23 at 11:05 -0500, Chris Marshall wrote:

> On a cygwin PC running PDL-2.4.3, I get:
> 
> perldl> p $year = pdl(1997..1999)                                             
>                                                              
> [1997 1998 1999]
> 
> perldl> wcols "%5d", $year, "| od -t a -A d"                                  
>                                                              
> 00  sp   1   9   9   7  sp  nl  sp   1   9   9   8  sp  nl  sp   1
> 16   9   9   9  sp  nl
> 
>     This has the formatted field output as 5 chars.  The
> trailing space is the default column separator.  I only
> get 6 chars, not 7, all accounted for.
> 
> perldl> wcols "%6d %5d %5d", $year, $year, $year, '| od -t a -A d'            
>                                                              
> 00  sp  sp   1   9   9   7  sp  sp   1   9   9   7  sp  sp   1   9
> 16   9   7  sp  nl  sp  sp   1   9   9   8  sp  sp   1   9   9   8
> 32  sp  sp   1   9   9   8  sp  nl  sp  sp   1   9   9   9  sp  sp
> 48   1   9   9   9  sp  sp   1   9   9   9  sp  nl
> 
>      My wcols output gets a total of 19 chars: 6 from field#1,
> 1 from space in format, 5 from field#2, 1 from space in format,
> 5 from field#3, and 1 more column separator space.
> 
> perldl> wcols "%6d%5d%5d", $year, $year, $year, '| od -t a -A d'              
>                                                              
> 00  sp  sp   1   9   9   7  sp   1   9   9   7  sp   1   9   9   7
> 16  sp  nl  sp  sp   1   9   9   8  sp   1   9   9   8  sp   1   9
> 32   9   8  sp  nl  sp  sp   1   9   9   9  sp   1   9   9   9  sp
> 48   1   9   9   9  sp  nl
> 
>      This format is the same as above but without the spaces
> between the format specifications.  We get the expected
> 19 - 2 = 17 chars for the output width.  These results agree
> with those reported by Doug.
> 
> The remaining discrepancy between our results and yours
> may be your character encoding.  I'm using ascii here but
> noticed when I cut-n-pasted your e-mail to respond that
> there was a non-ascii character in your name.  Perhaps
> that accounts for your count being off by one from mine
> above (you do have to include the column separator to
> make the totals right).
> 
> Regards,
> Chris
> 
> 
> 
> > K Edvardsen writes:
> >
> > Another thing, "%6d %5d %5d" behaves different
> > from "%6d"."%5d" x 2. The last one is more
> > correct (gives less extra spaces)....hmmm....???
> >
> > Kare
> >
> > On Wed, 2006-11-22 at 10:10 -0700, Doug Hunt wrote:
> >
> > > PDL 2.4.2 (which is all I've got installed
> > > right now) gives a correct 5 character wide
> > > field for me.
> > >
> > > --Doug
> > >
> > > On Wed, 22 Nov 2006, KreEdvardsen wrote:
> > > >
> > > > Why does the output end up 2 character wider
> > > > than specified by the format code?
> > > >
> > > > wcols "%5d", $year, 'test.dat'
> > > >
> > > > gives a 7 character field width instead of a
> > > > width of 5 characters.
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to