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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Search a Hash



Apr 18, 2001, 4:47 PM

Post #1 of 2 (281 views)
Search a Hash Can't Post

How do you search a hash using a regular expression?

I have a module that is passed a regular expression and I need to use that regular expression to search through an associative array and return another associative array with all matching entries in it. How do I do that?


Apr 19, 2001, 9:18 AM

Post #2 of 2 (271 views)
Re: Search a Hash [In reply to] Can't Post

Just so you know, you can pass compiled regular expressions (in 5.005) with the qr// quoting operator:

$regex = qr/:-\)/;  # makes a regex like (?-ismx::-\)) 

if ($text =~ /$regex/) { ... }

As far as searching a hash with a regex, you probably want to grep() the keys (or values) of the hash.

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


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

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