Reputation: 757
This is a subroutine which is used to get the past participle of a word. The verb is passed in, split into characters, and then depending on the final letters, an ending is chosen:
##Past Participle
sub getPPForBase(){ ##$verb passed in
my $verb = shift;
my @verbChars = split(//,$verb); ##Split into characters
my $verbLen = @verbChars; ##Length of @verbchars, as a number
###PROBLEM HERE:: trying to say last letter is e, second last is i
if(($verbChars[$verbLen -1] eq "e") && ($verbChars[$verLen -2] eq "i")){
return substr($verb,0,$verbLen-2)."ying";
}
if($verbChars[$verbLen -1] eq "e"){
return substr($verb,0,$verbLen-1)."ing";
}
return $verb."ing";
}
The error:
[Thu Jun 23 13:47:51 2011] [error] [client ::1] Use of uninitialized value $verLen in subtraction (-) at /Users/jon/Desktop/stanford-postagger-full-2011-04-20/verbTenseChanger.pl line 59.
Can someone help me figure out what this means, and how to fix it? (The code runs fine, but I'm afraid there is a hidden problem).
Let me know if you need more information.
Thanks a lot.
Upvotes: 0
Views: 74
Reputation: 67900
As others have pointed out, you have a typo that is causing your problem. This would not have been a problem if you had used:
use strict;
use warnings;
Which one always should. So do that.
Also, this is an alternative to your current sub:
sub getPPForBase {
my $verb = shift;
return $verb . "ying" if $verb =~ s/ie$//;
return $verb . "ing" if $verb =~ s/e$//;
return $verb . "ing";
}
Using a regex is in this case, I think, a much preferred solution, as it is much easier to read. Also, when put this way, it is easier to add or remove conditions when needed, rather than trying to sort out all the if-clauses.
Upvotes: 3
Reputation: 13612
my $verbLen
...
$verbChars[$verLen -2]
One of these things is not like the other...
Upvotes: 2