dark314 has asked for the wisdom of the Perl Monks concerning the following question:
I only get 13 characters... the test file is simply a file with letters a - z, it should print all characters backwardsdark314@somebox:~/Perl$ ./tac.pl test zyxwvutsrqpon
#!/usr/bin/perl use strict; #perl excercise, reverse cat... my @file; while (<>) { chomp; push @file, $_; } foreach (@file) { my $test = pop (@file); print $test; } print "\n";
Thanks. I am aware of reverse() lol. The idea was to use push() and pop(). I guess I understand now my problem, using a foreach there evaluates the size of @file each time I think, and by the time it gets halfway thru it believes that it has gone thru the entire set? ?? how confusing. I will use while from now on
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using Push and Pop.
by ikegami (Patriarch) on Aug 23, 2006 at 19:31 UTC | |
|
Re: Using Push and Pop.
by Joost (Canon) on Aug 23, 2006 at 19:33 UTC | |
|
Re: Using Push and Pop. - response to update
by imp (Priest) on Aug 23, 2006 at 22:07 UTC | |
by ikegami (Patriarch) on Aug 23, 2006 at 22:28 UTC | |
|
Re: Using Push and Pop.
by imp (Priest) on Aug 23, 2006 at 19:32 UTC | |
|
Re: Using Push and Pop.
by chromatic (Archbishop) on Aug 24, 2006 at 05:20 UTC |