Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: unitialized value in subroutine entry

by reneeb (Chaplain)
on Jun 27, 2006 at 07:06 UTC ( [id://557719]=note: print w/replies, xml ) Need Help??


in reply to unitialized value in subroutine entry

The variable $formatThis is not known as a "package-variable", because it just a variable for the subroutine. You can do it this way:
#!/usr/bin/perl use strict; use warnings; my $OBJ = {test => 3}; my $p = 'test'; A(); sub A { my $formatThis = sub { my ($x) = @_; my $y = sprintf ( "%.2f", $x); return $y; }; if ( exists $OBJ->{$p} ) { my $q = $OBJ->{$p}; $q = $formatThis->($q); print "$p=$q "; } $formatThis; }

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://557719]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-03-29 09:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found