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

#######################################################
# lect02_array2
#
# showing how you can fill any array element you want ---
# array will be set up automatically from there...
# 
# BUT now taking advantage of $# notation (giving index
# of last element in array); playing with negative indices
# a little, too.
#
# modified by Sharon Tuttle from "Learning Perl",
#    by Schartz and Phoenix
#
# last modified: 8-30-04
#######################################################

# @myArray will have 7 elements after this, those with indices 0-5
# undefined:

$myArray[6] = 27;
$ct = 0;

print "\nDo indices go from 0 to 6?:\n";
while ($ct <= $#myArray)
{
    print "\$myArray[$ct]: ";
    if (defined($myArray[$ct]))
    {
        print "$myArray[$ct]\n";
    }
    else
    {
        print "undef\n";

    }

    $ct++;
}

print "\n\$myArray[-1]: $myArray[-1]\n";

# now @myArray will have 14 items

$myArray[13] = George;

print "\nDo indices go from 0 to 13?:\n";
$ct = 0;
while ($ct <= $#myArray)
{
    print "\$myArray[$ct]: ";
    if (defined($myArray[$ct]))
    {
        print "$myArray[$ct]\n";
    }
    else
    {
        print "undef\n";
    }

    $ct++;
}

print "\n\$myArray[-1]: $myArray[-1]\n";

print "\n\$myArray[-100]: $myArray[-100]\n";

print "\nTHE END\n";


# end of lect02_array2