#!/usr/bin/perl -w

#######################################################
# class2_09_pop_etc
#
# playing with pop, push, shift, unshift
#
# modified by Sharon Tuttle from "Learning Perl",
#    by Schartz and Phoenix
#
# last modified: 4-11-03
#######################################################


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

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";

# pops from END of array
print "\npopping from \@wordlist: \n";
while ($grabbed = pop(@wordlist))
{
    print "$grabbed\n";
}


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

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 class2_09_pop_etc
