|Perl Monk, Perl Meditation|
Determine if sub is called from control block.by shotgunefx (Parson)
|on Feb 26, 2002 at 22:35 UTC||Need Help??|
shotgunefx has asked for the
wisdom of the Perl Monks concerning the following question:
Is there a way to determine what type of block a sub is called from?
I was working on a greplike operator called findone.
It needs to keep track of where it was called from to keep it's position in the @array in question.
This work find and dandy until I realized a subtle bug.
Because it keeps track of where and what it's called with, it will never match past the first match which means it will fail on the second block. (Unless there are multiple matches in @tokens. Then it will fail on the N+1 iteration.)
If I move my @tokens into the while block, it will work ok because the ref is different which it will see.
I knowning about this could just take care not to do this, or I could make a version that doesn't keep track and call it find or findfirst / findany whatever, but in the spirit of DWIM and learning, is there a way to tell if it's being called from a control block? I realize this wouldn't help calls within bare blocks.
I have a feeling I could coke up something with a source filter but would like to avoid it if possible.
"To be civilized is to deny one's nature."