[Israel.pm] mangled $_

Gaal Yahas gaal at forum2.org
Thu Dec 23 08:16:02 PST 2004


Jason Friedman wrote:

>I am using a CPAN module, Text::Capitalize (it properly capitilizes
>titles), but it "mangles" my $_. To get around it, I am doing:
>
>  my $underscore = $_; 
>  my $cap_title = capitalize_title($1,PRESERVE_ALLCAPS => 1); 
>  $_ = $underscore;
>
>Is there a better way of doing this or at least being warned?
>
Taking a peek at the source code here:

     http://search.cpan.org/src/DOOM/Text-Capitalize-0.3/Capitalize.pm

There are a few palaces where $_ is being written to without being 
localized. I'd call
this a bug (it's definitely not documented behavior). Consider looking 
up the authors and
sending a patch. As for what you can do to protect yourself from this 
kind of thing in
general, unfortunately there isn't much. You could localize $_ yourself 
around calls to
code you don't trust; that's effectively what you're doing above, but a 
scoped local $_
should achieve the same thing with possibly less fussy syntax.

Gaal

-- 
Gaal Yahas <gaal at forum2.org>
http://gaal.livejournal.org/




More information about the Perl mailing list