M
Michael Goerz
Hi,
what is the difference between this excerpt from my code (where in this
instance $visit->{$field} is set to integer 1, and $pattern was set as
qr/1/), which doesn't work, as the debugging output shows, and the
example code underneath it, which is supposed to do the same thing, and
works just like I expect!
The excerpt from my code:
# checks if visit has to be filtered out
sub is_filtered{
my $self = shift;
my $visit = shift;
while ( my ($field, $pattern) =
each %{ $self->{_excludepatterns} } ){
print "$visit->{$field} =~ $pattern\n"; # DEBUG
if ( $visit->{$field} =~ $pattern){
print "match\n"; # DEBUG
return 1;
} else { print "no match\n";} # DEBUG
}
return 0;
}
Debugging output:
[...]
0 =~ /1/
no match
1 =~ /1/
no match
1 =~ /1/
no match
[...]
The example code:
my $hashr = {};
my $field = 'foo';
$hashr->{$field} = 1;
my $pattern = qr/1/;
if ($hashr->{$field} =~ $pattern){
print "match\n";
} else {
print "no match\n";
}
Why is the behavior not the same???
Thank you,
Michael Goerz
what is the difference between this excerpt from my code (where in this
instance $visit->{$field} is set to integer 1, and $pattern was set as
qr/1/), which doesn't work, as the debugging output shows, and the
example code underneath it, which is supposed to do the same thing, and
works just like I expect!
The excerpt from my code:
# checks if visit has to be filtered out
sub is_filtered{
my $self = shift;
my $visit = shift;
while ( my ($field, $pattern) =
each %{ $self->{_excludepatterns} } ){
print "$visit->{$field} =~ $pattern\n"; # DEBUG
if ( $visit->{$field} =~ $pattern){
print "match\n"; # DEBUG
return 1;
} else { print "no match\n";} # DEBUG
}
return 0;
}
Debugging output:
[...]
0 =~ /1/
no match
1 =~ /1/
no match
1 =~ /1/
no match
[...]
The example code:
my $hashr = {};
my $field = 'foo';
$hashr->{$field} = 1;
my $pattern = qr/1/;
if ($hashr->{$field} =~ $pattern){
print "match\n";
} else {
print "no match\n";
}
Why is the behavior not the same???
Thank you,
Michael Goerz