# This prints the arguments in the same way as args4, but it re-constructs
# the list. (Of course, if you really needed the list again, you probably
# wouldn't print it this way, but it demonstrates the push operator.)
while($item = shift @ARGV) {
print "$item\n";
push @newargs, $item;
}
print "[@newargs]\n";
The
push
operator adds an item to the end of the array,
just as
removes one from the front.
The array
@newargs
, like all perl arrays, is initially
empty. So,
if the script is run as
perl args5.pl How are you perl
this is how the arrays change:
@newargs | | @ARGV
|
|
| How are you perl |
| Before the loop starts.
|
How |
| are you perl |
| After the first iteration.
|
How are |
| you perl |
| After the second iteration.
|
How are you |
| perl |
| After the third iteration.
|
How are you perl |
|
|
| After the fourth iteration.
|