Please send questions to st10@humboldt.edu .
#!/usr/bin/perl -w

#######################################################
# lect02_pop_etc
#
# playing with pop, push, shift, unshift
#
# modified by Sharon Tuttle from "Learning Perl",
#    by Schartz and Phoenix
#
# last modified: 8-31-04
#######################################################


print "enter a word (or q to quit): ";
chomp($word = <STDIN>);

# push words into list until user asks to quit

while ($word ne "q")
{
    # pushes onto END of array
    push (@wordlist, $word);

    print "enter a word (or q to quit): ";
    chomp($word = <STDIN>);
}

print "\n\@wordlist: @wordlist\n";

print "\npopping from \@wordlist: \n";
while ($grabbed = pop(@wordlist))
{
    print "$grabbed\n";
}

print "\nenter a word (or q to quit): ";
chomp($word = <STDIN>);

# put words onto BEGINNING of array until user asks to quit

while ($word ne "q")
{
    # puts onto BEGINNING of array
    unshift (@wordlist, $word);

    print "enter a word (or q to quit): ";
    chomp($word = <STDIN>);
}

print "\n\@wordlist: @wordlist\n";

# takes from BEGINNING of array

print "\nshifting from \@wordlist: \n";

while ($grabbed = shift(@wordlist))
{
    print "$grabbed\n";
}

# end of lect02_pop_etc