[Omaha.pm] here doc help

Chad Homan choman at gmail.com
Fri Jul 10 10:24:59 PDT 2009


Greets all

So I have a interesting issue that I need some assistance with.

I found a here doc "formatting" function on-line (at CPAN) that claims to
"expect input from a here doc".
I've made one little change to preserve "blank lines" (i.e, changed a couple
"\s" to "[\t ]"), hence the
function name.

Now I want to offload it into a require file.  however "perl -c" fails when
doing so.

--------[ code #1: file1.pl ]-------------
sub dequote_blank_lines
{
    local $_ = shift;
    my ($white, $leader);  # common white space and common leading string
    if (/^[\t ]*(?:([^\w\s]+)(\s*).*\n)(?:\s*\1\2?.*\n)+$/) {
        ($white, $leader) = ($2, quotemeta($1));
    } else {
        ($white, $leader) = (/^([\t ]+)/, '');
    }
    s/^[\t ]*?$leader(?:$white)?//gm;
    return $_;
}

   $cde_script = dequote_blank_lines <<_EOF_;
           #!/bin/sh

           #real code removed for brevity
           /usr/bin/echo "Hello World"

_EOF_

   print $cde_script

In this first snippet everything works fine.  and a "perl -c" returns OK.
Now lets offload to a require file:


--------[ code #2: file2.pl ]-------------
sub dequote_blank_lines
{
    local $_ = shift;
    my ($white, $leader);  # common white space and common leading string
    if (/^[\t ]*(?:([^\w\s]+)(\s*).*\n)(?:\s*\1\2?.*\n)+$/) {
        ($white, $leader) = ($2, quotemeta($1));
    } else {
        ($white, $leader) = (/^([\t ]+)/, '');
    }
    s/^[\t ]*?$leader(?:$white)?//gm;
    return $_;
}

1;

--------[ code #2: file3.pl ]-------------

   require "file2.pl";

   $cde_script = dequote_blank_lines <<_EOF_;
           #!/bin/sh

           #real code removed for brevity
           /usr/bin/echo "Hello World"

_EOF_

   print $cde_script

In this case, file3.pl fails syntax check in every way imaginable.

I have tried prototyping the function: sub dequote_blank_lines ($), but this
fails too.
I am not opposed to making this routine work like a real function and change
it to:

$cde_script = HERE_DOC; # for brevity
$cde_script = &dequote_blank_lines($cde_script);

But, I am one who likes flexibility and I think it should work either way.
And I am trying
to maintain the original intent of the subroutine, expecting a here doc



Chad, CISSP
Jack Benny <http://www.brainyquote.com/quotes/authors/j/jack_benny.html>  -
"I don't deserve this award, but I have arthritis and I don't deserve that
either."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/omaha-pm/attachments/20090710/e12b3b02/attachment.html>


More information about the Omaha-pm mailing list