Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Alternative to substr on unknown length of scalar

by periapt (Hermit)
on Oct 19, 2004 at 13:04 UTC ( #400499=note: print w/ replies, xml ) Need Help??


in reply to Re: Alternative to substr on unknown length of scalar
in thread Alternative to substr on unknown length of scalar

This never works for me. In the event that len($line) > 6, sprintf will print the entire string as follows: (Win32/ActiveState 5.6.1)

use strict; use warnings; use diagnostics; my $line = 'a'x 8; my $prnline = sprintf("len(line) > 6: [%-6s]\n",$line); $line = 'b' x 6; $prnline .= sprintf("len(line) = 6: [%-6s]\n",$line); $line = 'c' x 3; $prnline .=sprintf("len(line) n 6: [%-6s]\n",$line); print $prnline; __END__ len(line) > 6: [aaaaaaaa] len(line) = 6: [bbbbbb] len(line) n 6: [ccc ]

I usually go with ikegami's option

PJ
use strict; use warnings; use diagnostics;


Comment on Re^2: Alternative to substr on unknown length of scalar
Download Code
Re^3: Alternative to substr on unknown length of scalar
by thospel (Hermit) on Oct 19, 2004 at 15:04 UTC
    It's a . (maximum length) before the 6, not a - (justify left)

    And it should work everywhere, otherwise you found a bug.

      Well, what do you know. Learn something new everyday here at the monestary. I've always overlooked the maximal modifier for strings. Thanks :o)

      PJ
      use strict; use warnings; use diagnostics;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2015-07-07 03:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (87 votes), past polls