in reply to Best way to search content of an array
I don't think @names = $new_gecos; is doing what you want it to do. After that the @names array has only one entry, which makes the for loop after that a bit useless
And the regex might not do what you want it to do even if @names had more than one entry:
use Data::Dumper; @names=('de lowen','doe','de la mancha'); for $name (@names) { @comps = $name =~ m{(?:von|de la|de|van|der|le|el|la).*|\w+}g; } print Dumper(@comps);
prints out
$VAR1 = 'de la mancha';
If you want to add values to an array in a loop, use push . If you have many values in a scalar variable and want to split them to an array, use split.
And the most important thing: Test your code. Use Data::Dumper or simple print statements to show you what values are in your variables at different places in your program. You will be surprised how easy it is to find the bugs in your program.
|
|---|