I am having problems wherein I can't seem to get it work if my sub has any quoted arguments, so I am assuming I am just not escaping or interpolating the "" right?
My XML contains a sub as follows: sub mySub() { # stuff }
My call mySub() to the sub works fine. However, if I try mySub("Hello World"), it does not return anything upon evaluation. If I hard code the direct calls in my Perl script it works either ways.
Also in the code the line below will cause an error to be thrown saying "Useless use of string in void context at test.pl line XX."
#eval { eval { "$config->{client}->{1}->{file}->{1}->{executeInternal} +" } };
However, if I replace the "{}" with "()" it doesn't throw that error. Could someone please explain why using the block form does this?
eval ( eval { "$config->{client}->{1}->{file}->{1}->{executeInternal} +" } );
Below is the code (Perl and XML) that I am attempting to use:
Perl code:
#!/usr/bin/perl -w use warnings; use strict; use XML::Simple; # Getting the ref using XMLIn my $config = XMLin("test.xml", forceArray=>[qw(config client file)], s +uppressEmpty=>undef); # Print the actual subroutine and call from XML print "The actual code in the XML is:\n"; print $config->{client}->{1}->{file}->{1}->{subroutines}->{callInterna +lSub},"\n"; # Eval the sub - works fine - contains a mySub() call without argument +s print "EVALing the actual code in the XML. Works fine if my call is si +mply mySub() without arguments. \n"; eval (qq"{" . $config->{client}->{1}->{file}->{1}->{subroutines}->{cal +lInternalSub} . "}"); print "\n"; #Direct call to EVALed sub - works fine print "Direct call to the EVALed sub without arguments works fine. \n" +; mySub("hello world"); print "\n"; # Print a bunch of stuff print "Print a bunch of stuff:\n"; print "$config->{client}->{1}->{file}->{1}->{executeInternal}\n"; print eval { "$config->{client}->{1}->{file}->{1}->{executeInternal}" +},"\n"; print eval qq{"$config->{client}->{1}->{file}->{1}->{executeInternal}" +}; print "\n\nNow trying the actual eval:\n"; eval (qq"{" . $config->{client}->{1}->{file}->{1}->{executeInternal} . + "}"); # As expected, the line below works too (not because of the EVAL) - #eval (qq"{" . mySub("hello world") . "}"); # Do I have to escape my "" in my XML file? If I simple call mySub() i +n the XML, it works fine. # I tried a few things (\,\\) to no avail. # The line below will cause an error to be thrown saying "Useless use +of string in void context at test.pl line XX." #eval { eval { "$config->{client}->{1}->{file}->{1}->{executeInternal} +" } }; # However, if I replace the "{}" with "()" it doesn't throw that error +. Could someone please explain why using the # block form does this? #eval ( eval { "$config->{client}->{1}->{file}->{1}->{executeInternal} +" } );
XML code:
I apologize if the comments in the code are excessive. Thank you for your help.<config> <client name="1"> <file name="1"> <executeInternal>mySub(\"Hello World\")</executeInternal> <executeInternalWORKS>mySub()</executeInternalWORKS> <subroutines> <callInternalSub> sub mySub() { my $message = "blah"; my $message = shift; #broken version print "Message- $message\n"; print "Caller-> ",caller,"\n"; } mySub(); </callInternalSub> </subroutines> </file> </client> </config>
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |