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:
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:my @results; foreach my $addr( @array ) { my $element = lc $addr; # mess with $element here push @results, $element; } return @results;
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!use strict; use warnings;
I think that should be enough to get you well on your way. Good luck!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Corrupt Data?
by ikegami (Patriarch) on Jul 14, 2008 at 20:32 UTC | |
by friedo (Prior) on Jul 14, 2008 at 20:36 UTC | |
by ikegami (Patriarch) on Jul 14, 2008 at 20:49 UTC | |
Re^2: Corrupt Data?
by spickles (Scribe) on Jul 14, 2008 at 19:46 UTC | |
by almut (Canon) on Jul 14, 2008 at 20:13 UTC | |
by ikegami (Patriarch) on Jul 14, 2008 at 20:22 UTC |
In Section
Seekers of Perl Wisdom