Where are lexical Filehandles documented?

G

Greg Snow

I have noticed several references to lexically scoped filehandles in
this group recently, code like:

{
open my $fh, "path/to/file" or die "couldn't open file: $!";
...
}

I want to read up some more on how this works, but have not found
anything in the standard docs about lexical filehandles. I greped all
the docs I have
(tcgrep.pl -p -r -i -l "(?s)lexical.{1,50}file\s*hand" in my perl
directory (activestate v5.6.1)) and that only pointed to perlopentut
and perlfaq5 which both only refer to using a non-lexical scalars as
the handle.

So, where are lexically scoped filehandles documented?

Thanks,
 
B

Ben Morrow

Greg Snow said:
I have noticed several references to lexically scoped filehandles in
this group recently, code like:

{
open my $fh, "path/to/file" or die "couldn't open file: $!";
...
}

I want to read up some more on how this works, but have not found
anything in the standard docs about lexical filehandles.
So, where are lexically scoped filehandles documented?

perlopentut, "Indirect Filehandles".

Ben
 
T

Tad McClellan

Greg Snow said:
I have noticed several references to lexically scoped filehandles in
this group recently, code like:

{
open my $fh, "path/to/file" or die "couldn't open file: $!";
...
}

I want to read up some more on how this works, but have not found
anything in the standard docs about lexical filehandles.


Try the third paragraph of:

perldoc -f open

:)

I greped all
the docs I have
(tcgrep.pl -p -r -i -l "(?s)lexical.{1,50}file\s*hand"


What if "filehandle" comes first and "lexical" comes second?

As in:

If FILEHANDLE is an undefined lexical ("my") variable the
variable is assigned a reference to a new anonymous filehandle
 
E

Eric Amick

I have noticed several references to lexically scoped filehandles in
this group recently, code like:

{
open my $fh, "path/to/file" or die "couldn't open file: $!";
...
}

I want to read up some more on how this works, but have not found
anything in the standard docs about lexical filehandles. I greped all
the docs I have
(tcgrep.pl -p -r -i -l "(?s)lexical.{1,50}file\s*hand" in my perl
directory (activestate v5.6.1)) and that only pointed to perlopentut
and perlfaq5 which both only refer to using a non-lexical scalars as
the handle.

So, where are lexically scoped filehandles documented?

The only place I've seen it in the 5.6.1 docs is in perldelta, and only
obliquely at that; look for "file and directory handles can be
autovivified". As other posters have pointed out, the 5.8.x docs do a
better job of documenting it.
 
G

Greg Snow

Tad McClellan said:
Try the third paragraph of:

perldoc -f open

:)

Didn't help on my local computer (this change did not make it into the
v5.6.1 perlfunc doc apparently), but I did find it at
http://www.perldoc.org/. My quick test shows that it does work on my
copy.

Thanks,
What if "filehandle" comes first and "lexical" comes second?

Good point, but still didn't help since I don't have a local copy of
the v5.8 docs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top