jeanluca has asked for the wisdom of the Perl Monks concerning the following question:
Output#! /usr/bin/perl -lw use strict ; my %r = ( 'a' => 1, 'b' => 2, 'c' => 3) ; my $keys = keys(%r) ; print "keys = $keys" ; printf "keys=%d\n", keys(%r) ;
So, the second time keys(%r) is not used in scalar context. I tried everything I could think of to get it into scalar context, but onlykeys = 3 Argument "c" isn't numeric in printf at ./t12.pl line 12. keys=0
seems to work, which doesn't look like the best solution :)printf "keys=%d\n", (my $sc = keys(%r)) ;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: keys(%hash) not in scalar context in printf
by Joost (Canon) on Apr 18, 2007 at 11:59 UTC | |
|
Re: keys(%hash) not in scalar context in printf
by Herkum (Parson) on Apr 18, 2007 at 12:05 UTC | |
|
Re: keys(%hash) not in scalar context in printf
by roboticus (Chancellor) on Apr 18, 2007 at 12:03 UTC | |
|
Re: keys(%hash) not in scalar context in printf
by cdarke (Prior) on Apr 18, 2007 at 12:13 UTC | |
|
Re: keys(%hash) not in scalar context in printf
by jeanluca (Deacon) on Apr 18, 2007 at 12:31 UTC | |
|
Re: keys(%hash) not in scalar context in printf
by liverpole (Monsignor) on Apr 18, 2007 at 13:19 UTC | |
by Obidan (Initiate) on Apr 18, 2007 at 18:04 UTC | |
by tye (Sage) on Apr 18, 2007 at 18:29 UTC |