On Wed, May 30, 2001 at 04:00:53PM -0700, Steve Best wrote:
> But when I went to go print the elements of the array:
> 
> sub print_array {
>    my($count) = 0;
>    print "Printing array...\n";
>    while (@files) {
>         print "$count\t$files[$count]\n";
>         $count++;
>    };
> };
>
> It got stuck in an infinite loop.

That's because you're waiting for the number of elements in @files to be
zero, but doing nothing to remove elements.  It looks like you were trying
to do some iteration (with $count), but aren't checking $count.

You probably wanted:

    while ($count < @files) {
        print ...
        $count++;
    }

or perhaps

    for (my $count = 0; $count < @files; $count++) {
        print ...
    }

or maybe

    for (my $count = 0; @files; $count++) {
        my $file = shift(@files);
        print "$count\t$file\n";
    }


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

Reply via email to