Tony1 has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, Can any one define the following regular expression. 1) m/ bar /x 2) difference between tr/// and y///. Thanks in advance by Tony1
  • Comment on Meaning for the following regular expression

Replies are listed 'Best First'.
Re: Meaning for the following regular expression
by Joost (Canon) on Feb 02, 2008 at 19:54 UTC
Re: Meaning for the following regular expression
by hipowls (Curate) on Feb 02, 2008 at 19:56 UTC

    If a regular expression has a /x modifier then white space is not significant and it may contain comments.

    m/foor # this is not a comment/
    does not contain a comment while
    m/foo # this is a comment bar/x
    does and matches 'foobar'. See perlre and perlreref for more details.

    There is no difference between tr/// and y/// except that old awk sed hackers feel more at home;-)

      I think you mean old sed hackers like me.

      But I'm an old shell hacker, too, so I use tr///, not y///.

      Cheers!

      Jim

        Blushes with shame, you are absolutely right. It's been so long since I've used either that my memory is failing me;)

Re: Meaning for the following regular expression
by kyle (Abbot) on Feb 02, 2008 at 19:57 UTC

    Well, y is a synonym for tr (see perlop under "Quote-like operators").

    The regular expression m/ bar /x matches the literal string "bar" anywhere in the text.

Re: Meaning for the following regular expression
by Skeeve (Parson) on Feb 02, 2008 at 20:05 UTC
    Homework? Do I smell homework?

    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e