Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: unitialized value in subroutine entry

by reneeb (Chaplain)
on Jun 27, 2006 at 07:06 UTC ( #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? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2022-05-23 00:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (81 votes). Check out past polls.

    Notices?