1 #!/usr/bin/perl
 2 
 3 use strict;
 4 use warnings;
 5 
 6 #
 7 # Initialize the list
 8 my @queue = qw( bob sue mary );
 9 
10 
11 print "Queue Operations\n";
12 #
13 # Add tom to the queue
14 push @queue, 'tom';
15 show_line(@queue);
16 
17 #
18 # tim cuts into the front of the line!
19 unshift @queue, 'tim';
20 show_line(@queue);
21 
22 #
23 # get the first in line
24 my $first = shift @queue;
25 print "$first made it into the store!\n";
26 show_line(@queue);
27 
28 print "Stack Operations\n";
29 
30 #
31 # Copy the list
32 my @stack = @queue;
33 #
34 # get the "top" item on the stack
35 my $top = pop @stack;
36 print "$top got tired of waiting and left!\n";
37 show_line(@stack);
38 
39 sub show_line {
40 	my @line = @_;
41 	print "In Line: ", join(", ", @line), "\n";
42 }


syntax highlighted by Code2HTML, v. 0.9.1