in reply to Re^2: Why split function treats single quotes literals as regex, instead of a special case?
in thread Why split function treats single quotes literals as regex, instead of a special case?
The regular expression // works differently in split then elsewhere:
$ perl -le' my $x = "1234 abcd 5678"; print $& if $x =~ /[a-z]+/; print $& if $x =~ //; print map qq[ "$_"], split /[a-z]+/, $x; print map qq[ "$_"], split //, $x; ' abcd abcd "1234 " " 5678" "1" "2" "3" "4" " " "a" "b" "c" "d" " " "5" "6" "7" "8"
Also, the line anchors /^/ and /$/ don't require the /m option to match lines in a string.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Why split function treats single quotes literals as regex, instead of a special case?
by AnomalousMonk (Archbishop) on Aug 14, 2020 at 18:17 UTC | |
|
Re^4: Why split function treats single quotes literals as regex, instead of a special case?
by jcb (Parson) on Aug 14, 2020 at 23:07 UTC |