develooper Front page | perl.beginners | Postings from February 2012

Including () and {} in strings.

Thread Next
From:
Sean Murphy
Date:
February 24, 2012 16:41
Subject:
Including () and {} in strings.
Message ID:
18729EB1-DCD3-4E30-9D20-44562FB13E9C@gmail.com
Hi All.

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.

Sean 
Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About