Sprad has asked for the wisdom of the Perl Monks concerning the following question:
my $tempscript = dequote<<' END'; !!! some text END sub dequote { local $_ = shift; my ($white, $leader); if (/^\s*(?:([^\w\s]+)(\s*).*\n)(?:\s*\1\2?.*\n)+$/) { ($white, $leader) = ($2, quotemeta($1)); } else { ($white, $leader) = (/^(\s+)/, ''); } s/^\s*?$leader(?:$white)?//gm; return $_; }
This code results in a syntax error at the end of the here-doc. The problem is that Perl doesn't know about dequote yet. Making the dequote usage more explicit (&dequote, dequote()) doesn't help in this case. Two things work: putting the dequote function before its first usage, or using a prototype.
But then things get a little more complicated. In the real code, dequote is in a utility script, separate from where it's used. I'm exporting it and useing the utilities script before trying to call the function, but I still get the syntax error. The only thing that works is if I explicitly specify the package before each call to dequote. I'd rather not do this.
I don't have problems with any other functions in my utilities script. Do functions behave differently when used in here-docs?
---
A fair fight is a sign of poor planning.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Prototyping functions used in here-docs
by borisz (Canon) on Jan 09, 2004 at 18:55 UTC | |
|
Re: Prototyping functions used in here-docs
by Anonymous Monk on Jan 09, 2004 at 18:59 UTC | |
|
Re: Prototyping functions used in here-docs
by PodMaster (Abbot) on Jan 10, 2004 at 11:08 UTC |