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


in reply to Corrupt Data?

The reason you're getting garbage at the end of your loop is because you're pushing stuff onto @array, then shifting stuff off the front, but looping over @array sequentially. You can't alter the thing you're looping over and expect sane results.

BTW, you don't need to use a C-style for loop to iterate over an array, it's much easier to write it this way:

my @results; foreach my $addr( @array ) { my $element = lc $addr; # mess with $element here push @results, $element; } return @results;
You also don't need to reset @hold each time through the loop if you declare it with my, since it will be lexically scoped to the enclosing block. You'll catch a number of other problems if you turn on strict and warnings; put this at the top of your script:
use strict; use warnings;
and fix stuff until it stops yelling at you. Finally, the print @array statement at the end of your sub will never get executed because you return on the previous line!

I think that should be enough to get you well on your way. Good luck!