in reply to Re^3: loop iterator in a string
in thread loop iterator in a string
DB<53> $EVIL= ',@{[say "kill all kitties!"]}' DB<54> $str = "2,4..9" DB<55> p $str =~ m/[^0-9,.]/ # OK DB<56> $str .= $EVIL DB<57> p $str =~ m/[^0-9,.]/ # NOT OK 1 DB<58> eval $str kill all kitties!
in order to avoid syntax error you need to check $@ to see if the eval was successful. NB line 82, not all errors are caught tho
DB<80> @list = eval ",1..3"; unless($@){say for @list } DB<81> @list = eval "1..3"; unless($@){say for @list } 1 2 3 DB<82> @list = eval "1.3"; unless($@){say for @list } 1.3
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: loop iterator in a string
by haukex (Archbishop) on Sep 28, 2021 at 10:23 UTC | |
by LanX (Saint) on Sep 28, 2021 at 10:53 UTC | |
by haukex (Archbishop) on Sep 28, 2021 at 11:07 UTC | |
by LanX (Saint) on Sep 28, 2021 at 11:11 UTC | |
by LanX (Saint) on Sep 28, 2021 at 15:42 UTC |