B::Deparse shows this: eval "sub func $ret". But this doesn't work.
Either nothing happans or I get a failor, that the sub is not predeclared :-/
Am I doing s.th. wrong?#! /usr/bin/perl # write-read-execute code my %hash = (); # btw, all of a sudden there is a syntax error near: $hash{ # I have no idea why (can't test this, while simular code works?) $hash{'code'} = sub { print "Hi Guy - Hello Fellow!\n" }; &$hash{'code'}(); my $string = toStr($hash{'code'}; $hash{'code'} = toCode( split(/\n/, $string) ); # this should work (as before saved): &$hash{'code'}(); # the two subs sub toStr { use B::Deparse; my $ret .= $deparse->coderef2text( shift )."\n"; $ret .= B::Deparse->new("-p", "-sC")->coderef2text( shift )."\n"; return $ret; } sub toCode { my $ret; while ( @_ ) { $ret .= (shift)."\n"; # "\n" was eliminated by split } # NOW MAKE $ret been executed: # This is the examlpe of B:Deparse: eval "sub func $ret"; # but nothing happens # this causes this mistake: # Undefined subroutine &sub &{$ret}; # this should be given back: return $ret; }
In reply to Re: Re: save to file: $h{'sub'}=sub{..};
by Anonymous Monk
in thread save to file: $h{'sub'}=sub{..};
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |