in reply to Elegant way to parse an optional prefix with default?

You've hit a non-DWIMism. $@ is getting expanded into the value of that scalar. If you escape the $ then you can do:    my( $sigil )= ( $name =~ /^([\$@%&<*])/, '&' );

        - tye (just ignore this answer to the wrong question)

Replies are listed 'Best First'.
Re: (tye)Re: Elegant way to parse an optional prefix with default?
by John M. Dlugosz (Monsignor) on Nov 08, 2002 at 17:04 UTC
    Yow! I didn't know it did that in character classes.

    Interesting... this relies on undef being dropped in list catenation, so '&' becomes the first element?

      Whether to treat $ and @ as literals or not inside a regular expression is the single most complicated case of DWIM in Perl. It calculates weights to make this decision. I hate that it results in /[$]/ being a syntax error.

      And it is good that character classes are not exempted as $anagram !~ /[^\Q$word\E]/ is actually useful code.

      Yes, if you turn on warnings you'll get "Use of uninitialized value in pattern match (m//)".

              - tye