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.
In reply to Prototyping functions used in here-docs by Sprad
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |