Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
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;

Replies are listed 'Best First'.
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?
[1nickt]: thezip use Path::Tiny. @paths = path("/foo")-> children; (Excludes "." and ".." automatically.)
[1nickt]: (Also takes a compiled regexp as an arg to filter the list)
[1nickt]: For multiple dirs use iterator(): $it = path("/foo")-> iterator; while ( my $path = $it->() ) {...}
[1nickt]: (also skips . and .. automatically, and follows subdirs if you set <c\>recurse => 1</c>
[1nickt]: $it = path("/foo")-> iterator(recurse => 1 );

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (12)
As of 2017-03-28 18:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (339 votes). Check out past polls.