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

I seem to remember some time back seeing a way to get perl to always ignore case when pattern matching within a script but can not find how to do it? As I recall, it was someting you could set at the begining of the script so that you don't have to use /i for each regex.

Does anyone know what I am thinking of?

Replies are listed 'Best First'.
•Re: Regex Ignore Case
by merlyn (Sage) on Sep 24, 2002 at 19:09 UTC
    There's never been a setting like that that I can recall. Maybe you're confusing it with setting $* (now deprecated). Or maybe some other language that (falsely1) claims to have Perl-compatible regular expressions.

    -- Randal L. Schwartz, Perl hacker

    1 Unless there's an embedded Perl interpreter, it can't be completely compatible, because of the use of variable interpolation and embedded Perl code in a regex.

Re: Regex Ignore Case
by insensate (Hermit) on Sep 24, 2002 at 19:20 UTC
    You may be thinking of the -i switch for unix grep/egrep... There isn't a perl equivilant that I can think of.
Re: Regex Ignore Case
by fglock (Vicar) on Sep 24, 2002 at 19:32 UTC

    Can't believe the things there are in CPAN...

    IO::Filter::uc - Convert all characters in input to uppercase

Re: Regex Ignore Case
by Anonymous Monk on Sep 24, 2002 at 23:55 UTC

    I'm not really sure why you'd want to do this. Things like this make code difficult to maintain. If you came back to the code in say 6 months and added a regular expression you might wonder why it wasn't matching properly. All for saving yourself 1 keystroke per regexp.

    Also, case insensitive regexps make the regular expression do more work. That said, you could probably use Filter::Simple to impliment something like this:

    Untested, possibly broken, almost certainly stupid code follows:

    package rxMatchAnyCase; use strict; use Filter::Simple; FILTER_ONLY( regex => sub { $_ = "(?i:$_)" } ); 1;
    Then you'd just "use rxMatchAnyCase" in your script.
Re: Regex Ignore Case
by Elgon (Curate) on Sep 24, 2002 at 23:02 UTC

    If I've read the question right, a sensible way to do this is to use the i modifier, dependent upon a command-line parameter.

    if ($case == 0) { $foo =~ s/INSERTREGEXHERE/i; } else { $foo =~ s/INSERTREGEXHERE/; }

    In the case where we have stored our command line switch from @ARGV in $case as a binary flag - 0 for case-insensitive and 1 for case sensitive.

    Is this what your looking for?

    Elgon

    UPDATE: Updated after incorrectly reading question for the first time. D'oh.

    "What this book tells me is that goose-stepping morons, such as yourself, should read books instead of burning them."
           - Dr. Jones Snr, Indiana Jones and the Last Crusade