Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: /ee -> Use of uninitialized value in substitution iterator (without back references)

by haukex (Bishop)
on Apr 29, 2021 at 18:11 UTC ( #11131888=note: print w/replies, xml ) Need Help??


in reply to Re^2: /ee -> Use of uninitialized value in substitution iterator (without back references)
in thread /ee -> Use of uninitialized value in substitution iterator (without back references)

If you require the $rhs to always be a Perl expression, then /ee works fine for me with these two examples. The $rhs in your example from the root node just needs to be adjusted to '"qqq"' so it's a valid Perl expression.

use warnings; use strict; use Test::More tests=>2; { my $lhs = '\\{(.*?)\\}'; my $rhs = '$1'; my $str = '{abc}'; $str =~ s{$lhs}{$rhs}ee; is $str, 'abc'; } { my $lhs = 'xyz'; my $rhs = '"qqq"'; my $str = 'AxyzB'; $str =~ s{$lhs}{$rhs}ee; is $str, 'AqqqB'; }
P.S. I see now that I should also be checking $@ inside the eval, to see if there were errors from the /ee.

Note Bug in eval in pre-5.14 - if I wanted to play it really safe, I might do use warnings FATAL => 'uninitialized'; just before the s///ee to make certain errors in the eval propagate.

(BTW, please use <code> tags to format your code)

  • Comment on Re^3: /ee -> Use of uninitialized value in substitution iterator (without back references)
  • Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2021-09-28 05:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?