On 19/09/2007, Dintelmann, Peter <Peter.Dintelmann dresdner-bank.com> wrote:
> I want to use state vars for file iterators like
> in
>
> use strict;
> use feature qw(state);
>
> sub lister {
> open state $fh, "<",
"file" or die $!;
> print scalar <$fh>;
> eof $fh and close $fh;
> }
>
> lister(), lister();
>
> The open() call seems to be executed twice contrary
> to my expectations and the first line of
"file" is
> printed twice instead of the first and second line.
>
> Are my expectations wrong?
Yes. The only special one-time initialisation occurs with
the syntax
C<state $x = "foo">. You'll need something
like the untested (but
should work):
state $fh // open $fh, "<", "file" or
die $!;
|