Re: Filehandles



Also sprach Guenther Sohler:

> I am writing a small parser in perl, which should also be able to
> include files.
> if a include statement happens,
> the prg shall put the current FH onto the stack and open a new file with
> the same FH.
>
> How can I do this as filehandles are special in perl ?

Just pretend that they aren't special. Filehandles no longer need to be
barewords:

open my $fh, "<", $file or die "$file: $!";
push @stack, $fh;

...

# and then later
my $element = pop @stack;
if (ref($element) eq 'GLOB') { # is it a filehandle?
while (<$element>) { # then: read file
...
}
}

Note that your terminology is a bit sloppy: If it's a filehandle then
the underlying file has already been opened and you cannot really "open
a new file with the same FH".

Tassilo
--
use bigint;
$n=71423350343770280161397026330337371139054411854220053437565440;
$m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);
.



Relevant Pages

  • Re: Why does Windows allow Worms?
    ... The difference, AISI, is the decision to execute code. ... Take a stack overflow: On the Solaris system, ... Perl has a mechanism to tag data that came from non-trusted ... Human error is, ...
    (comp.security.misc)
  • Re: Why does Windows allow Worms?
    ... The difference, AISI, is the decision to execute code. ... Take a stack overflow: On the Solaris system, ... Perl has a mechanism to tag data that came from non-trusted ... Human error is, ...
    (comp.security.misc)
  • Re: a good TeX parser for use by software that needs to read TeX?
    ... : read TeX? ... In particular, has anyone used the perl Text::TeX parser, ... In addition, push $found into a list @commands, ...
    (comp.text.tex)
  • Re: Syntax checker wtf?
    ... the parser has no means to detect the error ... I'll note that perl has a similarly flexible syntax, ... example, if you get a runaway unclosed string or regexp operator, ...
    (comp.lang.ruby)
  • Re: Need workaround for regex bug in 5.8.6
    ... > I found a weird bug in Perl 5.8.6: If a variable in a CGI script ... This is a very old limitation of the Perl REx engine: it uses C stack ... and running out of stack is a catastrophic process (as ...
    (comp.lang.perl.misc)