Keep It Simple, Stupid | |
PerlMonks |
do [...], @INC subs, 3-args open to heredoc refs (oh my)by ForgotPasswordAgain (Priest) |
on May 01, 2006 at 16:17 UTC ( [id://546684]=perlquestion: print w/replies, xml ) | Need Help?? |
ForgotPasswordAgain has asked for the wisdom of the Perl Monks concerning the following question: Someone (Maddingue) in #perlfr mentioned that they couldn't understand the following test code in bleadperl/t/op/incfilter.t:
After looking at it, I gave up, so I was wondering if someone could explain it in gory detail. Thanks. I'll explain what I figured out. First, what does do [...] do? Does it use something like "ARRAY(0x814bc28)" as the filename to open? If you look at the test file, at the top is:
If you look in perldoc perlvar for the docs on @INC, you'll find that it says You can also insert hooks into the file inclusion system by putting Perl code directly into @INC. Those hooks may be subroutine references, array references or blessed objects. See "require" in perlfunc for details. So look also in perldoc perlfunc, grep for require VERSION followed by hooks. By this point my head is already spinning, but then note that before the do comes a 3-arg open of a reference to a heredoc:
The docs for that are in perldoc -f open:
Then note that \"foo" makes a reference to a string, so \<<'EOC';... is just a funny reference to a string that happens to've been made by a heredoc. Now's where I get lost. Anyone fill in the details? (What's the $fh doing in do [$fh, sub {...}], for example?)
Back to
Seekers of Perl Wisdom
|
|