Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Open Source > Perl
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Perl section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 25th, 2007, 02:20 PM
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";

Reply With Quote
  #2 (permalink)  
Old April 27th, 2007, 10:17 AM
Friend of Wrox
Points: 1,515, Level: 15
Points: 1,515, Level: 15 Points: 1,515, Level: 15 Points: 1,515, Level: 15
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Dec 2003
Location: Oxford, , United Kingdom.
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts

Imagine your stack goes from left to right like this:

1 2 3 4

pop($stack) removes the 1 from the left of the stack and you're left with

2 3 4

push($stack, 5) pushes 5 on to the left of the stack so you're left with

5 2 3 4

Normally people think of stacks vertically with what I've called the left at the top.


Charlie Harvey's website - linux, perl, java, anarchism and punk rock: http://charlieharvey.org.uk
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
push to multi dimensional harpua PHP How-To 0 December 4th, 2006 01:47 AM
push to users dfeuerborn VB Databases Basics 2 August 29th, 2005 10:18 AM
push to users dfeuerborn Access VBA 3 August 22nd, 2005 03:10 AM
Pull or Push? sureshvb Crystal Reports 0 August 23rd, 2004 01:13 AM
how far to push Access DB ? seanUK Access 2 July 31st, 2004 05:41 PM

All times are GMT -4. The time now is 12:05 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.