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

#######################################################
# lect02_foreach1
#
# playing with foreach - part 1
#
# modified by Sharon Tuttle from "Learning Perl",
#    by Schartz and Phoenix
#
# last modified: 8-31-04
#######################################################


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 $val ( @myArr )
{
    print "$val\n";
}

# print each value in a literal list on its own line
print "\nSome names: \n";
foreach $val ( qw/ George Harold Jerome /)
{
    print "$val\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 $file ( `ls` )
{
    print "$file";  # guess what? ls returns LINES of results...
}


# end of lect02_foreach1