Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange y/[^e]//d behaviour. 2

Status
Not open for further replies.
Jun 22, 2000
6,317
AU
Hi,

Could someone please explain why the ^ in the second below expression doesn't do as I would expect?

[tt]$ echo hereditary | perl -n -e 'y/[e]//d;print'
hrditary
$ echo hereditary | perl -n -e 'y/[^e]//d;print'
hrditary
$[/tt]

I would expect it to delete all characters except "e" from the input in the second example.

I have a workaround (below), but would like to understand why the above isn't working.

[tt]$ echo hereditary | perl -n -e 's/[^e]//g;print;print "\n"'
ee
$[/tt]

Any wisdom gratefully received...

Annihilannic.
 
Why not use the complement modifier instead like this?

echo hereditary | perl -n -e 'y/e//cd;print'
 
That sounds perfectly sensible.

Should my method have worked though? Is it a bug or misunderstanding on my part?

Annihilannic.
 
It was a misunderstanding on your part. The transliteration operator is not regex related, just LOOKS like it is. Alls is does, is take a list of characters on the left, and a list of characters on the right. Then transliterates, or in this case "transobliterates". The camel is comical as well as helpful ;)

No regex magic allowed.

--jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top