in reply to Scope of RegEx vars like $_
I suspect $_ is being reset by __exhibit_verb_function.
...very likely, as there isn't much else happening in between $_ being valid (in /(\{exhibit\})/) and it having become undefined in pos($_). But unless we get a chance to look at __exhibit_verb_function(), it's hard to tell what exactly is causing it...
Note that many variables like $_ are global unless you localize them, i.e.
!/usr/bin/perl -l use strict; use warnings; sub foo { # ... $_ = undef; } while (<DATA>) { chomp; if (/^FOO/) { foo(); print "found $_"; } if (/^BAR/) { # ... print "found $_"; } # ... } __DATA__ FOO BAR
prints
Use of uninitialized value in concatenation (.) or string at ./828268. +pl line 14, <DATA> line 1. found Use of uninitialized value in pattern match (m//) at ./828268.pl line +16, <DATA> line 1. found BAR
While if you write
sub foo { # ... local $_ = "whatever"; $_ = undef; }
you'll get
found FOO found BAR
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Scope of RegEx vars like $_
by Steve_BZ (Chaplain) on Mar 12, 2010 at 17:33 UTC | |
|
Re^2: Scope of RegEx vars like $_
by Steve_BZ (Chaplain) on Mar 13, 2010 at 00:28 UTC |