Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: Regex in json: escaping forward slash

by Mr. Muskrat (Abbot)
on Aug 22, 2012 at 21:37 UTC ( #989154=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Regex in json: escaping forward slash
in thread Regex in json: escaping forward slash

That code doesn't exhibit the problem you are trying to solve. (It isn't trying to do anything that requires escaping the slashes.)

Output:

$VAR1 = { 'regex' => { '.*/home/members/index.htm.*' => { '404' => { ' +reporting' => '1000', ' +paging' => '2000' } } } };

Even when I use that key as a regex, it works for me.

#!/usr/bin/env perl use strict; use warnings; use JSON; use Data::Dumper; my $contents = `cat progconfig.json`; my $config = JSON->new->decode($contents); my $re = (keys %{$config->{regex}})[0]; print "re: $re\n"; my $path = '/some/fake/path/home/members/index.html'; if ( $path =~ /$re/ ) { print "$path matched regex\n"; }

Output:

re: .*/home/members/index.htm.* /some/fake/path/home/members/index.html matched regex


Comment on Re^3: Regex in json: escaping forward slash
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2015-07-01 21:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (22 votes), past polls