Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

RE (2): pack / unpack woes

by agoth (Chaplain)
on Aug 24, 2000 at 18:00 UTC ( #29418=note: print w/replies, xml ) Need Help??

in reply to RE: pack / unpack woes
in thread pack / unpack woes

Davorg is right above!, but i should have explained my intentions with the data set.
In @d, I want to pad items that are too short with spaces and crudely truncate items that are too long, and end up with a fixed width record.

the lc(format) was the only way i could think of to turn all the A's to a's to preserve the spacing
I just felt there must be a clearer way, looking into sprintf at the moment

Replies are listed 'Best First'.
RE: RE (2): pack / unpack woes
by davorg (Chancellor) on Aug 24, 2000 at 18:05 UTC

    Something like this perhaps:

    my @list = (1, 2, 3); my $tmpl = '%-3s|%-4s|%-5s'; @list = split/\|/, sprintf $tmpl, @list; $" = '='; print "=@list=\n";

    ...although that won't truncate elements that are too big :(


    European Perl Conference - Sept 22/24 2000, ICA, London
      ...although that won't truncate elements that are too big :(
      It will if you use
      my $tmpl = "%-3.3s|%-4.4s|%-5.5s";
      The value after the dot gives a "maximum width".

      -- Randal L. Schwartz, Perl hacker

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2022-05-19 15:56 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (71 votes). Check out past polls.