Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Use of uninitialized value in substitution iterator in variable expansion

by jaco (Pilgrim)
on Apr 07, 2005 at 16:30 UTC ( [id://445767]=note: print w/replies, xml ) Need Help??


in reply to Re: Use of uninitialized value in substitution iterator in variable expansion
in thread Use of uninitialized value in substitution iterator in variable expansion

This gives me the same warning. I thought it should work as well, though i wrote it like this with and without parans around the defined statement as mentioned above. Curious

for my $line (@cfile){ $line =~ s/(\$\w+->{\w+})/defined $1 ? $1 : ''/eeg; $line =~ s/(\$\w+)/defined $1 ? $1 : ''/eeg; $text .= $line; }
  • Comment on Re^2: Use of uninitialized value in substitution iterator in variable expansion
  • Download Code

Replies are listed 'Best First'.
Re^3: Use of uninitialized value in substitution iterator in variable expansion
by Roy Johnson (Monsignor) on Apr 07, 2005 at 16:44 UTC
    Quotation marks. I was suggesting you use quotation marks.
    #!perl use strict; use warnings; my $foo = undef; # No warning my $line = 'substitute for $foo in here'; $line =~ s/(\$\w+)/"defined $1 ? $1 : ''"/eeg; print $line, "\n"; # Warning $line = 'substitute for $foo in here'; $line =~ s/(\$\w+)/defined $1 ? $1 : ''/eeg; print $line, "\n";

    Caution: Contents may have been coded under pressure.

      I understood what you meant, i should have been more clear in my reply. I think i may have discovered part of the problem though. I'll look into it and get back to you

      It looks like i had a scope problem a little further up in the code. the only reason i noticed it was because i attempted to run your code with the addition on an undelcared var. i.e.

      #!/usr/bin/perl use strict; use warnings; my $foo = undef; # No warning my $line = 'substitute for $foo in $bar here'; $line =~ s/(\$\w+)/"defined $1 ? $1 : ''"/eeg; print $line, "\n";
      hairbear% ./test2.pl Use of uninitialized value in substitution iterator at ./test2.pl line + 11. substitute for in here

      Edit by tye: remove PRE tags around long lines

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://445767]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-20 07:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found