http://www.perlmonks.org?node_id=557719


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.