Hi Rob,

Thanks for that. I have spent 30 mins on it and was pulling out my hair. The 
end of the heredoc had a tab in front. I didn't know this mattered. I had the 
"tag" included and removed for the heredoc. But I got an error when compiled 
without the quotes around the Heredoc tag. Now I know why. This is the first 
time I ever have used heredocs.

Far better then other ways I have done it.


It all works now.

Sean 
On 25/02/2012, at 11:51 AM, Rob Dixon wrote:

> On 25/02/2012 00:41, Sean Murphy wrote:
>> 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.
> 
> Hi Sean
> 
> I don't fully understand what you are trying to do, but the form of your
> here doc is wrong. You must remove the quotes or Perl will see as code
> what you intend as the contents of the string. Write
> 
> print <<TEXT;
>    $s () if(\$k =~ m/$k/);
>    sub $s () {
>    } # end sub
> TEXT
> 
> where the string TEXT *must* be at the beginning of the line.
> 
> I hope this solves your problem.
> 
> Rob
> 


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to