in reply to Re: arrays of arrays
in thread arrays of arrays
my @words; my @parts_of_speech; while(my $sentence = <DATA>) { @words = (); @parts_of_speech = (); while ($sentence =~ /(\w+)\/(\w+)/g ) { push(@words, $1) if $1; push(@parts_of_speech, $2) if $2; } print $_, " " for @words; print $_, " " for @parts_of_speech; print "\n"; }
The arrays @words and @parts_of_speech don't need to be in file scope, you should declare them inside the loop.
The pattern \w+ will always match at least one character so the only way it can be false is if that one character is '0' so the tests for $1 and $2 are superfluous.
Your print statements are overly complicated, they could be simplified to:
print "@words @parts_of_speech\n";
|
|---|