[Israel.pm] mangled $_

Levenglick Dov-RM07994 DovL at freescale.com
Thu Dec 23 07:27:09 PST 2004

In YAPC::2004 a short presentation titled "A $_ gotcha" (http://www.perl.org.il/YAPC/2004/talk.html?id=20) has the answer (I think).
The presentation demonstrated that while for loops maintain scoping of $_, while loops don't. 
The code is as follows:

sub capitalize_title {
 while ( $string =~ /$sentence_rule/g ) {
    for ($i ; ; ) {
       $_ = $word;   # following operations act on the current word

I believe that this setting of $_ inside the while loop is the cause for your problem. If so - no, there is no way around it :(

Best Regards,
Dov Levenglick
The information contained in this email is classified as:
[ ] General Business Information
[ ] Freescale Internal Use Only
[ ] Freescale Confidential Propriety
[x] Personal Memorandum

-----Original Message-----
From: perl-bounces at perl.org.il [mailto:perl-bounces at perl.org.il] On Behalf Of Jason Friedman
Sent: Thursday, December 23, 2004 4:59 PM
To: perl at perl.org.il
Subject: [Israel.pm] mangled $_

Hi all,

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?

(I already use: use warning and use strict).



Perl mailing list
Perl at perl.org.il

More information about the Perl mailing list