in reply to sub that sets $_

...by changeing the while into for?

One world, one people

Replies are listed 'Best First'.
Re^2: sub that sets $_
by Joost (Canon) on Jun 28, 2005 at 14:06 UTC
Re^2: sub that sets $_
by holli (Abbot) on Jun 28, 2005 at 12:31 UTC
    That would mean I have to read the whole file into memory, and return a list of chunks. Depending on the filesize this might turn out as a bad idea ;-)
      No - each iteration returns a chunk into $_ in the for or foreach loop.

      One world, one people

        definitly not.
        use FTest; my $test = new FTest (); print foreach $test->foo; print for $test->foo;
        Meanwhile in a module
        package FTest; sub new { return bless {}, shift; } sub foo { return 1; } 1;
        That code prints "11". I you were correct that would be an endless loop.
Re^2: sub that sets $_
by Jaap (Curate) on Jun 28, 2005 at 11:55 UTC
    or foreach.