Forum Moderators: coopster & phranque

Message Too Old, No Replies

An array of reg expressions is causing hash problems

using qr isn't helping

         

AWildman

2:04 pm on Apr 28, 2005 (gmt 0)

10+ Year Member



I have a hash that is like so:
%BLAH::BLAHBLAH::BLAHDEBLAH::sites = (

'webabbrev' => {
'unwanted_directories'=> (qr/images/, qr/control/, qr/correlations\/.*?pdf.*/),
'mappage' => qq¦$BLAH::BLAHBLAH::BLAHDEBLAH::somedir/www.domain.com/map/map.thtml¦,
'base_address'=> "/some/path/to/www.domain.com/",
},
'anotherwebabbrev' => {
'unwanted_directories'=> (qr/images/, qr/control/),
'mappage' => qq¦$BLAH::BLAHBLAH::BLAHDEBLAH::somedir/store.domain.com/map/map.thtml¦,'base_address'=> "/some/path/to/store.domain.com/",
},

);

As you can see, the two keys and values are pretty much the same, one difference being: qr/correlations\/.*?pdf.*/. If I keep this in the array, then, I can't access the 'base_address' value of the first key; it returns empty. If I remove that from the array, then I can. I don't understand why this is an issue since I'm using qr. I've also tried adding the expressions as quoted ("images") strings and that didn't work either. Why can't I do this?
<added>So, I just discovered that I can't add another element to the array at ALL or else I can't retrieve the base_address. What gives?</added>

sitz

1:48 am on Apr 29, 2005 (gmt 0)

10+ Year Member



Data::Dumper is your friend:


use Data::Dumper;

(your variable here)

print Dumper \%BLAH::BLAHBLAH::BLAHDEBLAH::sites;

Output:


$VAR1 = {
'webabbrev' => {
'mappage' => '/www.domain.com/map/map.thtml',
'unwanted_directories' => qr/(?-xism:images)/,
'(?-xism:control)' => qr/(?-xism:correlations\/.*?pdf.*)/,
'base_address' => '/some/path/to/www.domain.com/'
},
'anotherwebabbrev' => {
'/some/path/to/store.domain.com/' => undef,
'unwanted_directories' => qr/(?-xism:images)/,
'(?-xism:control)' => 'mappage',
'/store.domain.com/map/map.thtml' => 'base_address'
}
};

Hrm; looks like Unpleasant Things(tm) are happening to your array. Let's try changing those to array references:


use Data::Dumper;

%foo = (

'webabbrev' => {
'unwanted_directories'=> [qr/images/, qr/control/, qr/correlations\/.*?pdf.*/],
'mappage' => qq¦$foo::somedir/www.domain.com/map/map.thtml¦,
'base_address'=> "/some/path/to/www.domain.com/",
},

'anotherwebabbrev' => {
'unwanted_directories'=> [qr/images/, qr/control/],
'mappage' => qq¦$foo::somedir/store.domain.com/map/map.thtml¦,
'base_address'=> "/some/path/to/store.domain.com/",
},

);

print Dumper \%foo;

Output:


$VAR1 = {
'webabbrev' => {
'mappage' => '/www.domain.com/map/map.thtml',
'unwanted_directories' => [
qr/(?-xism:images)/,
qr/(?-xism:control)/,
qr/(?-xism:correlations\/.*?pdf.*)/
],
'base_address' => '/some/path/to/www.domain.com/'
},
'anotherwebabbrev' => {
'mappage' => '/store.domain.com/map/map.thtml',
'unwanted_directories' => [
qr/(?-xism:images)/,
qr/(?-xism:control)/
],
'base_address' => '/some/path/to/store.domain.com/'
}
};

Mmm....tasty....

That work better? Note that you'll (obviously) need to dereference your array when pulling out the regex you're interested in; something like:


$your_variable{'webabbrev'}->{'unwanted_directories'}->[0]

Make sense?

AWildman

11:53 am on Apr 29, 2005 (gmt 0)

10+ Year Member



Thank you very much! It was indeed that I was using parens instead of brackets! I feel like such a boob! Now everything is working just fine and I can put this bad boy to rest.