#!/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)], suppressEmpty=>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}->{callInternalSub},"\n"; # Eval the sub - works fine - contains a mySub() call without arguments print "EVALing the actual code in the XML. Works fine if my call is simply mySub() without arguments. \n"; eval (qq"{" . $config->{client}->{1}->{file}->{1}->{subroutines}->{callInternalSub} . "}"); 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() in 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}" } );