searching lines case-insensitive

Discussion in 'Perl' started by James Hunt, Jun 4, 2004.

  1. James Hunt

    James Hunt Guest

    Is there a way to do a case-insensitive search? This is what I have so far
    ....
    I know that what I currently have is case-sensitive.
    if($paramAction eq "SEARCH") {
    open(SEARCH,"$csvfile");
    @lines = <SEARCH>;
    close(SEARCH);

    foreach $line_entry (@lines) {
    if($line_entry =~ /$searchkey/) {
    print "$line_entry <br>\n";
    }
    }
    }

    James
    James Hunt, Jun 4, 2004
    #1
    1. Advertising

  2. James Hunt wrote:
    > Is there a way to do a case-insensitive search?


    You seem to be talking about a case-insensitive pattern match, and if
    so, the answer is yes.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Jun 5, 2004
    #2
    1. Advertising

  3. James Hunt wrote:
    > Is there a way to do a case-insensitive search?


    Please define "search"? Exact match of whole line? RE? Text::Approx? ...

    > This is what I have
    > so far ...

    [...]
    > if($line_entry =~ /$searchkey/) {


    Ah, REs. Did you check the fine manual?
    The very first modifier that is mentioned in "perldoc perlre" talks about
    Do case-insensitive pattern matching.

    Jue
    Jürgen Exner, Jun 5, 2004
    #3
  4. James Hunt

    raymond Guest

    $line_entry =~ /$searchkey/i

    this do search for case-insensitive

    more deatils about perl regular expression try "perldoc
    perlrequick,"perldoc perlre" "perldoc -t perlretut"

    Raymond Raj X



    "James Hunt" <> wrote in message news:<>...
    > Is there a way to do a case-insensitive search? This is what I have so far
    > ...
    > I know that what I currently have is case-sensitive.
    > if($paramAction eq "SEARCH") {
    > open(SEARCH,"$csvfile");
    > @lines = <SEARCH>;
    > close(SEARCH);
    >
    > foreach $line_entry (@lines) {
    > if($line_entry =~ /$searchkey/) {
    > print "$line_entry <br>\n";
    > }
    > }
    > }
    >
    > James
    raymond, Jun 5, 2004
    #4
  5. James Hunt

    James Hunt Guest

    [snip]
    > Ah, REs. Did you check the fine manual?
    > The very first modifier that is mentioned in "perldoc perlre" talks about
    > Do case-insensitive pattern matching.
    >
    > Jue




    Perfect that's exactly what I needed.

    --
    JAMES HUNT
    James Hunt, Jun 5, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tee
    Replies:
    3
    Views:
    7,771
    Herfried K. Wagner [MVP]
    Jun 23, 2004
  2. Guoqi Zheng

    string.indexof case insensitive

    Guoqi Zheng, Jul 9, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    12,885
    bentangle
    Jan 25, 2009
  3. Jan Nielsen
    Replies:
    7
    Views:
    502
    Jan Nielsen
    Feb 8, 2005
  4. Replies:
    1
    Views:
    2,457
    Mark P
    Apr 6, 2007
  5. Xah Lee
    Replies:
    4
    Views:
    936
Loading...

Share This Page