in reply to Using eval to s/// with a pattern supplied on the command-line
Checking if the eval succeeded finds the cause I suspected:
use strict; use warnings; my $op = shift; for (qw(your hand is too cold to hold)) { eval $op; print $@ if $@; print $_, "\n"; } __END__ Modification of a read-only value attempted at (eval 1) line 1. your Modification of a read-only value attempted at (eval 2) line 1. hand Modification of a read-only value attempted at (eval 3) line 1. is Modification of a read-only value attempted at (eval 4) line 1. too Modification of a read-only value attempted at (eval 5) line 1. cold Modification of a read-only value attempted at (eval 6) line 1. to Modification of a read-only value attempted at (eval 7) line 1. hold
Fix:
use strict; use warnings; my $op = shift; for (qw(your hand is too cold to hold)) { local $_ = $_; eval $op; print $_, "\n"; } __END__ your hand is too cnew to hnew
|
|---|