[Omaha.pm] Passing arguments to "sprintf"...

Andy Lester andy at petdance.com
Wed Feb 9 12:11:37 PST 2005


On Wed, Feb 09, 2005 at 01:27:45PM -0600, Daniel Linder (dan at linder.org) wrote:
>     # This section prints "2" for the
>     my $myline = sprintf (@LogString);

sprintf's prototype is ($;@), meaning it demands the first parm be a
scalar.  Because it wants a scalar first, it coerces @LogString into a
scalar, in this case "2" since that's the number of elements in
@LogString;

Do it as:

my $mask = shift @LogString;
my $line = sprintf( $mask, @LogString );

xoxo,
Andy

-- 
Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance


More information about the Omaha-pm mailing list