Home > Archive > PERL Miscellaneous > March 2005 > regexp compilation
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
regexp compilation
|
|
| alythh@netscape.net 2005-03-30, 8:59 am |
|
hi all - I'm having some troubles, that seem related to regexp
compilation.
Trying to use the WordNet::SenseRelate module, I get a lot of errors
like the following:
Use of uninitialized value in regexp compilation at
/usr/lib/perl5/site_perl/5.6.1/WordNet/SenseRelate.pm line 1109, <SFH>
line 1.
....
the incriminated line is:
sub _loadStoplist
{
my $self = shift;
my $file = shift;
open SFH, '<', $file or die "Cannot open stoplist $file: $!";
$stoplist{$self} = [];
while (my $line = <SFH> ) {
chomp $line;
$line =~ m|/(.*)/|;
push @{$stoplist{$self}}, qr/$1/; # <<<<< LINE1109
}
close SFH;
}
.... so $1 comes from a previous pattern match on lines read from a file
at runtime.
I'm not at all an expert in quote-like operators, so I'm not able to
debug this problem - anybody can help ?
thanks1
Alessandro Magni
| |
| Arndt Jonasson 2005-03-30, 8:59 am |
|
alythh@netscape.net writes:
> hi all - I'm having some troubles, that seem related to regexp
> compilation.
>
> Trying to use the WordNet::SenseRelate module, I get a lot of errors
> like the following:
>
> Use of uninitialized value in regexp compilation at
> /usr/lib/perl5/site_perl/5.6.1/WordNet/SenseRelate.pm line 1109, <SFH>
> line 1.
> ...
>
> the incriminated line is:
> sub _loadStoplist
> {
> my $self = shift;
> my $file = shift;
> open SFH, '<', $file or die "Cannot open stoplist $file: $!";
> $stoplist{$self} = [];
> while (my $line = <SFH> ) {
> chomp $line;
> $line =~ m|/(.*)/|;
> push @{$stoplist{$self}}, qr/$1/; # <<<<< LINE1109
> }
> close SFH;
> }
>
> ... so $1 comes from a previous pattern match on lines read from a file
> at runtime.
> I'm not at all an expert in quote-like operators, so I'm not able to
> debug this problem - anybody can help ?
The first thing to try when there is some indication that the value of
a variable is not what you expect is to find out what its value really is.
Here, this would probably show that $1 is undef after the line
$line =~ m|/(.*)/|;
and you can analyse that, disregarding the regexp compilation.
Perhaps the line doesn't contain two slashes. Then the match will fail
and $1 not be set. You need to be prepared for that case.
Or what you really mean is
$line =~ m/(.*)/;
or
$line =~ m|(.*)|;
but then just using $line instead of $1 would be more straightforward,
so that's probably not it.
| |
| Tad McClellan 2005-03-30, 3:57 pm |
| alythh@netscape.net <alythh@netscape.net> wrote:
> Use of uninitialized value in regexp compilation at
> $line =~ m|/(.*)/|;
> push @{$stoplist{$self}}, qr/$1/; # <<<<< LINE1109
You should never use the dollar-digit variables unless you
have first ensured that the pattern match *succeeded*.
if ( $line =~ m|/(.*)/| )
{ push @{$stoplist{$self}}, qr/$1/ }
else
{ die "'$line' does not contain 2 slashes\n" }
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
| |
| Fabian Pilkowski 2005-03-30, 3:57 pm |
| * alythh@netscape.net schrieb:
>
> Trying to use the WordNet::SenseRelate module, I get a lot of errors
> like the following:
>
> Use of uninitialized value in regexp compilation at
> /usr/lib/perl5/site_perl/5.6.1/WordNet/SenseRelate.pm line 1109, <SFH>
> line 1.
Have you read the doc shipped with this module? Have a look at
http://search.cpan.org/~tpederse/Wo.../SenseRelate.pm
There you can see, that
Note: the methods below will die() on certain errors (actually, they
will Carp::croak()). Wrap calls to the methods in an eval BLOCK to
catch the exceptions. See 'perldoc -f eval' for more information.
Are you doing an eval() and looking into the special var »$@«?
>
> the incriminated line is:
> sub _loadStoplist
> {
> my $self = shift;
> my $file = shift;
> open SFH, '<', $file or die "Cannot open stoplist $file: $!";
> $stoplist{$self} = [];
> while (my $line = <SFH> ) {
> chomp $line;
> $line =~ m|/(.*)/|;
> push @{$stoplist{$self}}, qr/$1/; # <<<<< LINE1109
> }
> close SFH;
> }
>
> ... so $1 comes from a previous pattern match on lines read from a file
> at runtime.
> I'm not at all an expert in quote-like operators, so I'm not able to
> debug this problem - anybody can help ?
I assume that your input file is corrupt. This module presupposed that
*you* have to garantee a correct syntax in your files.
Nevertheless the module's author should check if the regex above matchs
and $1 is defined. Perhaps you send him an email to fix this for other
users. Line 1109 could be written as
push @{$stoplist{$self}}, qr/$1/ if defined $1;
regards,
fabian
|
|
|
|
|