Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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
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 perusing the Monastery: (7)
As of 2019-11-14 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (77 votes). Check out past polls.

    Notices?