Re: Filehandles
- From: "Tassilo v. Parseval" <tassilo.von.parseval@xxxxxxxxxxxxxx>
- Date: Thu, 29 Sep 2005 10:41:43 +0200
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);
.
- Follow-Ups:
- Re: Filehandles
- From: Brian McCauley
- Re: Filehandles
- References:
- Filehandles
- From: Guenther Sohler
- Filehandles
- Prev by Date: Re: oo newbie question
- Next by Date: Re: Filehandles
- Previous by thread: Filehandles
- Next by thread: Re: Filehandles
- Index(es):
Relevant Pages
|
|