http://qs321.pair.com?node_id=677973


in reply to **HomeWork** Printing the found input from an array

Your issue is scoping.

foreach my $city ( @myCities ) { # $city is local to this loop only! } print "$city"; #there's no $city in scope!

You've declared $city within the scope of the foreach loop. Once you leave that loop, $city goes out of scope. If you'd used strict and warnings you would have gotten a warning on that print "main::city used only once", which would have been a good clue that you might have scope issues.

Simple fix? Move $city into a wider scope:

my $city; # now is scoped to the whole package! foreach $city ( @myCities ) { # do your stuff } print "$city"; # works as expected!

Make sense?

<radiant.matrix>
Ramblings and references
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet