Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Pattern matching with hash keys

by tej (Scribe)
on Oct 04, 2010 at 06:24 UTC ( [id://863264]=note: print w/replies, xml ) Need Help??


in reply to Re: Pattern matching with hash keys
in thread Pattern matching with hash keys

All rite i will change the syntax as it is wrong, However, What i want is to match key value with input string.

Like If $str contains "Rabbit" or "rabbit" i want it to be replaced with "pap". I am tring to use hash as there are n number values that i want to match and replace

Replies are listed 'Best First'.
Re^3: Pattern matching with hash keys
by eyepopslikeamosquito (Archbishop) on Oct 04, 2010 at 06:49 UTC

    If $str contains "Rabbit" or "rabbit" i want it to be replaced with "pap".
    Hashes, by default, are case sensitive. However, if you take care to create the hash with all lower case keys, you could then simply lower case each input string, for example:
    use strict; use warnings; my %hash = ( "rabbit" => "pap", "triangle" => "tri" ); my $key = "rabbit"; print $hash{ lc($key) }, "\n"; # prints "pap" $key = "Rabbit"; print $hash{ lc($key) }, "\n"; # also prints "pap"

Re^3: Pattern matching with hash keys
by prasadbabu (Prior) on Oct 04, 2010 at 06:37 UTC

    You can do that with regex with 'i' option modifier which stands for ignore case. Refer perlre. For example,

    $str =~ /rabbit/i
    But TIMTOWTDI, you can do that with functions also.

    Prasad

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://863264]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-26 04:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found