Greets all<br><br>So I have a interesting issue that I need some assistance with.<br><br>I found a here doc "formatting" function on-line (at CPAN) that claims to "expect input from a here doc".<br>I've made one little change to preserve "blank lines" (i.e, changed a couple "\s" to "[\t ]"), hence the <br>
function name.<br><br>Now I want to offload it into a require file. however "perl -c" fails when doing so.<br><br>--------[ code #1: file1.pl ]-------------<br>sub dequote_blank_lines<br>{<br> local $_ = shift;<br>
my ($white, $leader); # common white space and common leading string<br> if (/^[\t ]*(?:([^\w\s]+)(\s*).*\n)(?:\s*\1\2?.*\n)+$/) {<br> ($white, $leader) = ($2, quotemeta($1));<br> } else {<br> ($white, $leader) = (/^([\t ]+)/, '');<br>
}<br> s/^[\t ]*?$leader(?:$white)?//gm;<br> return $_;<br>}<br><br> $cde_script = dequote_blank_lines <<_EOF_;<br> #!/bin/sh<br> <br> #real code removed for brevity<br> /usr/bin/echo "Hello World"<br>
<br>_EOF_<br><br> print $cde_script<br><br>In this first snippet everything works fine. and a "perl -c" returns OK. <br>Now lets offload to a require file:<br><br><br>--------[ code #2: file2.pl ]-------------<br>
sub dequote_blank_lines<br>
{<br>
local $_ = shift;<br>
my ($white, $leader); # common white space and common leading string<br>
if (/^[\t ]*(?:([^\w\s]+)(\s*).*\n)(?:\s*\1\2?.*\n)+$/) {<br>
($white, $leader) = ($2, quotemeta($1));<br>
} else {<br>
($white, $leader) = (/^([\t ]+)/, '');<br>
}<br>
s/^[\t ]*?$leader(?:$white)?//gm;<br>
return $_;<br>
}<br>
<br>1;<br><br>--------[ code #2: file3.pl ]-------------<br><br> require "file2.pl";<br><br>
$cde_script = dequote_blank_lines <<_EOF_;<br>
#!/bin/sh<br>
<br>
#real code removed for brevity<br>
/usr/bin/echo "Hello World"<br>
<br>
_EOF_<br>
<br>
print $cde_script<br><br>In this case, file3.pl fails syntax check in every way imaginable.<br><br>I have tried prototyping the function: sub dequote_blank_lines ($), but this fails too.<br>I am not opposed to making this routine work like a real function and change it to:<br>
<br><div style="margin-left: 40px;">$cde_script = HERE_DOC; # for brevity<br>$cde_script = &dequote_blank_lines($cde_script);<br></div><br>But, I am one who likes flexibility and I think it should work either way. And I am trying <br>
to maintain the original intent of the subroutine, expecting a here doc<br><br><br><br clear="all">Chad, CISSP<br><a href="http://www.brainyquote.com/quotes/authors/j/jack_benny.html" target="_blank">Jack Benny</a> - "I don't deserve this award, but I have arthritis and I don't deserve that either."