View Single Post
Old April 25th, 2007, 02:20 PM
ZORCH ZORCH is offline
Authorized User
Join Date: Apr 2007
Location: Toronto, ontario, .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Define:Push and pop

How doe's push and pop work? I have been reading alot about perl but I don't understand how this script Works.I have been trying to break it down one by one but i still don't get it Can some help.

# stacks.plx
use warnings;
use strict;

my $hand;
my @pileofpaper = ("letter", "newspaper", "gas bill", "notepad");

print "Here's what's on the desk: @pileofpaper\n";

print "You pick up something off the top of the pile.\n";
$hand = pop @pileofpaper;
print "You have now a $hand in your hand.\n";

print "You put the $hand away, and pick up something else.\n";
$hand = pop @pileofpaper;
print "You picked up a $hand.\n";

print "Left on the desk is: @pileofpaper\n";

print "You pick up the next thing, and throw it away.\n";
pop @pileofpaper;

print "You put the $hand back on the pile.\n";
push @pileofpaper, $hand;

print "You also put a leaflet and a bank statement on the pile.\n";
push @pileofpaper, "leaflet", "bank statement";

print "Left on the desk is: @pileofpaper\n";