Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: getting wrong value

by AnomalousMonk (Chancellor)
on Jan 15, 2013 at 22:54 UTC ( #1013465=note: print w/replies, xml ) Need Help??

in reply to getting wrong value

printf returns 1 for a successful print, which is what you say happens. You probably want sprintf (note leading 's'), which returns a string.


>perl -wMstrict -le "my $line = 55473; my $line2 = sprintf '%#x', $line; printf qq{\$line is '%#x' \n}, $line; print qq{\$line2 is '$line2'}; " $line is '0xd8b1' $line2 is '0xd8b1'

Replies are listed 'Best First'.
Re^2: getting wrong value
by ggrise (Initiate) on Jan 15, 2013 at 23:01 UTC
    Thanks, that works. however if printf will print to STDOUT, why can't I get it to print to $line2 ?

      You can (since 5.8; see open, search for 'scalar'):

      >perl -wMstrict -le "my $scalar_as_file; ;; open my $fh_scalar, '>', \$scalar_as_file or die qq{opening: $!}; printf $fh_scalar q{xxx :%#x: yyy}, 55473; close $fh_scalar; ;; print qq{scalar as file: '$scalar_as_file'}; " scalar as file: 'xxx :0xd8b1: yyy'

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1013465]
[erix]: yes, very handy that. I always use the one-page html version (dumped a local copy of it)
[erix]: (easier for searching)
choroba tries to grep -i choroba absg.html
[erix]: I count 3 (+1 in the list)-- wel done :)
[choroba]: I've read it body to /body and experimented a lot...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2017-11-24 11:57 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (348 votes). Check out past polls.