in reply to sprintf minor problem
print (sprintf "%5.5d", 1) . "hello\n";
print is seeing the parenthesis as containing the parameters of the print statement, and the . "hello\n" as concatenating "hello\n" to the return value of print.
The easiest workaround is probably just to use printf in the first place, since that seems to be the behavior you seek. Barring that you can either encapsulate the entire expression to be printed in parenthesis, or put a plus sign just before the (sprintf... so that print understands that to be a portion of an expression, not the parameter list.
print ( ( sprintf "%5.5d", 1 ) . "hello\n" ); # or print + ( sprintf "%5.5d", 1 ) . "hello\n";
I like the first solution for clarity, and the second for not having to count opening and closing parenthesis.
Dave
"If I had my life to do over again, I'd be a plumber." -- Albert Einstein
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: sprintf minor problem
by Melly (Chaplain) on Sep 04, 2003 at 14:45 UTC |