How to make this case insenstive

Discussion in 'Perl Misc' started by Daniel, Aug 27, 2007.

  1. Daniel

    Daniel Guest

    I am checking to see if the name is the same name as in $row[1] but
    should be case insensitive.

    my $line = DBI::neat_list(\@row, 70, ',');
    if ($name ne $row[1])
    do
    error message

    ....
    ..

    Is this possible?

    Thank you!
     
    Daniel, Aug 27, 2007
    #1
    1. Advertising

  2. Daniel

    Tony Curtis Guest

    Daniel wrote:
    > I am checking to see if the name is the same name as in $row[1] but
    > should be case insensitive.
    >
    > my $line = DBI::neat_list(\@row, 70, ',');
    > if ($name ne $row[1])
    > do
    > error message


    That's easy, canonicalize both of them: e.g. lc() or uc(), q.v.

    hth
    t
     
    Tony Curtis, Aug 27, 2007
    #2
    1. Advertising

  3. Daniel

    Sisyphus Guest

    "Daniel" <> wrote in message
    news:...
    >I am checking to see if the name is the same name as in $row[1] but
    > should be case insensitive.
    >
    > my $line = DBI::neat_list(\@row, 70, ',');
    > if ($name ne $row[1])
    > do
    > error message


    my $line = DBI::neat_list(\@row, 70, ',');
    if (lc($name) ne lc($row[1]))
    do
    error message

    Cheers,
    Rob
     
    Sisyphus, Aug 27, 2007
    #3
  4. On Aug 27, 9:44 am, Daniel <> wrote:
    > I am checking to see if the name is the same name as in $row[1] but
    > should be case insensitive.
    >
    > my $line = DBI::neat_list(\@row, 70, ',');
    > if ($name ne $row[1])
    > do
    > error message
    >
    > ...
    > .
    >


    an alternative to the lc() or uc() solution is to use a regex
    (although this is probably less efficient).

    if ( $name =~ m/$row[1]/i ) {
    do {
    blah
     
    it_says_BALLS_on_your forehead, Aug 27, 2007
    #4
  5. Daniel wrote:
    > I am checking to see if the name is the same name as in $row[1] but
    > should be case insensitive.
    >
    > my $line = DBI::neat_list(\@row, 70, ',');
    > if ($name ne $row[1])


    > Is this possible?


    Use normal forms, i.e. convert both to all lower or all upper case:
    if (lc($name) ne lc($row[1])) {
    If you loop through @row again and again it might be faster to store the
    text in normal form.

    Or you can use pattern matching with the /i option, but you need to be
    careful to anchor the pattern at both ends and to block RE special
    characters from being interpreted as such.

    jue
     
    Jürgen Exner, Aug 27, 2007
    #5
  6. On Aug 27, 11:42 am, "Jürgen Exner" <> wrote:
    > Daniel wrote:
    > > I am checking to see if the name is the same name as in $row[1] but
    > > should be case insensitive.

    >
    > > my $line = DBI::neat_list(\@row, 70, ',');
    > > if ($name ne $row[1])
    > > Is this possible?

    >
    > Use normal forms, i.e. convert both to all lower or all upper case:
    > if (lc($name) ne lc($row[1])) {
    > If you loop through @row again and again it might be faster to store the
    > text in normal form.
    >
    > Or you can use pattern matching with the /i option, but you need to be
    > careful to anchor the pattern at both ends and to block RE special
    > characters from being interpreted as such.


    gah! i was thinking about anchoring, but completely forgot to include
    them in my post. thanks jue. i forgot about the escapes too, so double
    thanks.
     
    it_says_BALLS_on_your forehead, Aug 27, 2007
    #6
  7. Daniel

    Dr.Ruud Guest

    it_says_BALLS_on_your forehead schreef:
    > Daniel:


    >> I am checking to see if the name is the same name as in $row[1] but
    >> should be case insensitive.
    >>
    >> my $line = DBI::neat_list(\@row, 70, ',');
    >> if ($name ne $row[1])
    >> do
    >> error message

    >
    > an alternative to the lc() or uc() solution is to use a regex
    > (although this is probably less efficient).
    >
    > if ( $name =~ m/$row[1]/i ) {
    > do {
    > blah


    Missing: quotemeta.

    --
    Affijn, Ruud

    "Gewoon is een tijger."
     
    Dr.Ruud, Aug 27, 2007
    #7
  8. it_says_BALLS_on_your forehead wrote:
    > On Aug 27, 9:44 am, Daniel <> wrote:
    >
    >>I am checking to see if the name is the same name as in $row[1] but
    >>should be case insensitive.
    >>
    >>my $line = DBI::neat_list(\@row, 70, ',');
    >> if ($name ne $row[1])
    >> do
    >> error message
    >>
    >>...
    >>.
    >>

    >
    >
    > an alternative to the lc() or uc() solution is to use a regex
    > (although this is probably less efficient).
    >
    > if ( $name =~ m/$row[1]/i ) {
    > do {
    > blah


    $name = "ThisIsALongFilename";
    would match
    $row[1] = "Filename";

    You should anchor your pattern:

    $name =~ m/^$row[1]$/i;

    --
    These are my personal views and not those of Fujitsu Siemens Computers!
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize (T. Pratchett)
    Company Details: http://www.fujitsu-siemens.com/imprint.html
     
    Josef Moellers, Aug 28, 2007
    #8
  9. Daniel

    Uri Guttman Guest

    >>>>> "R" == Ruud <> writes:

    R> it_says_BALLS_on_your forehead schreef:
    >> Daniel:


    >>> I am checking to see if the name is the same name as in $row[1] but
    >>> should be case insensitive.
    >>>
    >>> my $line = DBI::neat_list(\@row, 70, ',');
    >>> if ($name ne $row[1])
    >>> do
    >>> error message

    >>
    >> an alternative to the lc() or uc() solution is to use a regex
    >> (although this is probably less efficient).
    >>
    >> if ( $name =~ m/$row[1]/i ) {
    >> do {
    >> blah


    R> Missing: quotemeta.

    also missing regex anchors which are needed since he did 'ne'.

    uri

    --
    Uri Guttman ------ -------- http://www.stemsystems.com
    --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
    Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
     
    Uri Guttman, Aug 28, 2007
    #9
  10. Daniel

    Dr.Ruud Guest

    Uri Guttman schreef:
    > Ruud:
    >> it_says_BALLS_on_your forehead:
    >>> Daniel:


    >>>> I am checking to see if the name is the same name as in $row[1]
    >>>> but should be case insensitive.
    >>>>
    >>>> my $line = DBI::neat_list(\@row, 70, ',');
    >>>> if ($name ne $row[1])
    >>>> do
    >>>> error message
    >>>
    >>> an alternative to the lc() or uc() solution is to use a regex
    >>> (although this is probably less efficient).
    >>>
    >>> if ( $name =~ m/$row[1]/i ) {
    >>> do {
    >>> blah

    >>
    >> Missing: quotemeta.

    >
    > also missing regex anchors which are needed since he did 'ne'.


    ACK.

    He did mention "the name in $var" though, which can be read as that $var
    can contain more than just the name.

    --
    Affijn, Ruud

    "Gewoon is een tijger."
     
    Dr.Ruud, Aug 30, 2007
    #10
    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. Steve Franks
    Replies:
    2
    Views:
    1,285
    Steve Franks
    Jun 10, 2004
  2. Tee
    Replies:
    3
    Views:
    7,913
    Herfried K. Wagner [MVP]
    Jun 23, 2004
  3. Janice

    lower case to upper case

    Janice, Dec 10, 2004, in forum: C Programming
    Replies:
    17
    Views:
    1,227
    Richard Bos
    Dec 14, 2004
  4. Replies:
    1
    Views:
    2,556
    Mark P
    Apr 6, 2007
  5. darrel

    'case' vs. 'case is'

    darrel, Aug 14, 2008, in forum: ASP .Net
    Replies:
    3
    Views:
    295
    Rory Becker
    Aug 14, 2008
Loading...

Share This Page