CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Pattern matching with hash values

 



tej.87g
Novice

Oct 3, 2010, 10:51 PM

Post #1 of 3 (352 views)
Pattern matching with hash values Can't Post

I am creating a hash like

Code
 my %hash= (  

"rabbit" = "pap",

"triangle" = "tri",

and so on..

);

I want to match key in input and replace it with its value.

How can i do it?

Thank you


7stud
Enthusiast

Oct 4, 2010, 7:16 PM

Post #2 of 3 (334 views)
Re: [tej.87g] Pattern matching with hash values [In reply to] Can't Post

You'll have to provide more details, and examples are always better than wordy descriptions that are subject to various interpretations.


AnkurMundhada
Novice

Oct 7, 2010, 10:31 PM

Post #3 of 3 (321 views)
Re: [7stud] Pattern matching with hash values [In reply to] Can't Post

We can use perl regx. to do the task as,


In the example below we can "triangle" will be replaced by "tri"

my %hash= ( "rabbit" = "pap", "triangle" = "tri", and so on.. );

my $str = "A triangle has three side";
foreach my $keys (keys %hash){
$str =~ s/$keys/$hash{$keys}/;
}
Thanks
Ankur M.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives