#!/usr/bin/perl -w

#######################################################
# class2_11_foreach2
#
# playing with foreach - part 2
# using $_ to hold current value of array/list being
#    worked through, instead of an explicit loop
#    control variable
#
# modified by Sharon Tuttle from "Learning Perl",
#    by Schartz and Phoenix
#
# last modified: 4-11-03
#######################################################

# count to 10...
foreach (1..10)
{
    print "$_ ";
}
print "\n\n";

print "give beginning of range: ";
chomp($left_val = <STDIN>);

print "give ending of range: ";
chomp($right_val = <STDIN>);

# swap range ends if user got 'em backwards!
if ($left_val > $right_val)
{
    ($right_val, $left_val) = ($left_val, $right_val);
}

@myArr = ($left_val..$right_val);

# print each value in @myArr on its own line
print "\@myArr contains:\n";
foreach ( @myArr )
{
    print "$_\n";
}

# print each value in a literal list on its own line
print "\nSome names: \n";
foreach ( qw/ George Harold Jerome /)
{
    print "$_\n";
}

# use UNIX command ls to generate the files in the
# current working directory --- and print THEM
# one per line

print "\nMan! Look at all this junk:\n";
foreach ( `ls` )
  {
    print "$_";  # guess what? ls returns LINES of results...
  }

# end of class2_11_foreach2
