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: Re: [cosmokramer] how to pattern match and fish out a entry from a hash: Edit Log



BillKSmith
Veteran

Jul 2, 2012, 12:07 PM


Views: 1334
Re: [cosmokramer] how to pattern match and fish out a entry from a hash

I can accomplish your objective in a different way. Convert your $var into a regular expression and then use it to grep the keys of %data.


Code
   

use strict;
use warnings;
my %data = (
b_slash_car_bit_slash_tebla_bit => 'b/car[10]/tebla[9]',
b_slash_car_bit_slash_tesla_bit => 'b/car[10]/tesla[0] b/car[9].tesla[1]',
);

my $var = "b/car[*]/te*a";
$var =~ s/\//_slash_/g;
$var =~ s/(?<! \[ ) \* (?! \])/.*/xg;
$var =~ s/ \[ [*] \] /.*/xg;

print +(grep {/$var/} keys %data) ? 'Yes' : 'No', "\n";

Good Luck,
Bill

(This post was edited by BillKSmith on Jul 2, 2012, 12:10 PM)


Edit Log:
Post edited by BillKSmith (Veteran) on Jul 2, 2012, 12:10 PM


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

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