Sean Murphy wrote:
Hi All.
Hello,
I have a real issue with strings. I want to build a sub routine
skeleton plus some test code. If I use () or {} etc. The string comes
out completely messed up. The code below is for a heredoc and
complains that I am trying to define a function. If I use the skeleton
within a string. It places the () at() at the beginning. In other
words it messes up the formatting.
Both code examples below:
foreach my $k (keys %commands ) {
my $s;
$k =~ s/show //;
$s = $k;
$s =~ s/ |\-/_/g;
print "<<TEXT";
$s () if(\$k =~ m/$k/);
sub $s () {
} # end sub
String example:
foreach my $k (keys %commands ) {
my $s;
$k =~ s/show //;
$s = $k;
$s =~ s/ |\-/_/g;
print ""$s () if(\$k =~ m/$k/);\n";
print "sub $s () {\} # end sub\n\n";
} # end foreach
Note, I have escaped with the '\' the above () and {}, and other
punctuation characters with no success. I have even used the \q \e
escape sequences with no success. Tried to build the string up with
using single quotes and double quotes with no success. Any help would
be really welcomed.
Why? I have about 100 different commands from a router which I am
converting the command into a sub routine to process the output. Each
output is unique to the command.
It sounds like you want to use a dispatch table.
Could you please provide a few examples of commands and the subroutines
associated with those commands?
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/