Where are lexical Filehandles documented?

Discussion in 'Perl Misc' started by Greg Snow, Jan 22, 2004.

  1. Greg Snow

    Greg Snow Guest

    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,

    --
    Greg Snow, PhD Office: 223A TMCB
    Department of Statistics Phone: (801) 378-7049
    Brigham Young University Dept.: (801) 378-4505
    Provo, UT 84602 email:
    Greg Snow, Jan 22, 2004
    #1
    1. Advertising

  2. Greg Snow

    Ben Morrow Guest

    Greg Snow <> wrote:
    >
    > 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.

    <snip>
    > So, where are lexically scoped filehandles documented?


    perlopentut, "Indirect Filehandles".

    Ben

    --
    For the last month, a large number of PSNs in the Arpa[Inter-]net have been
    reporting symptoms of congestion ... These reports have been accompanied by an
    increasing number of user complaints ... As of June,... the Arpanet contained
    47 nodes and 63 links. [ftp://rtfm.mit.edu/pub/arpaprob.txt] *
    Ben Morrow, Jan 22, 2004
    #2
    1. Advertising

  3. Greg Snow <> wrote:
    >
    > 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


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jan 22, 2004
    #3
  4. Greg Snow

    Eric Amick Guest

    On 22 Jan 2004 13:30:47 -0700, Greg Snow <> wrote:

    >
    >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.

    --
    Eric Amick
    Columbia, MD
    Eric Amick, Jan 23, 2004
    #4
  5. Greg Snow

    Greg Snow Guest

    Tad McClellan <> writes:

    > Greg Snow <> wrote:
    > >
    > > 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
    >
    > :)


    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,

    > > 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?


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

    --
    Greg Snow, PhD Office: 223A TMCB
    Department of Statistics Phone: (801) 378-7049
    Brigham Young University Dept.: (801) 378-4505
    Provo, UT 84602 email:
    Greg Snow, Jan 23, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeremy Phillips

    newbie - Output to multiple Filehandles

    Jeremy Phillips, May 24, 2004, in forum: Perl
    Replies:
    1
    Views:
    2,137
    Jürgen Exner
    May 25, 2004
  2. Andrew

    FileHandles to string

    Andrew, Jul 10, 2004, in forum: Perl
    Replies:
    1
    Views:
    637
    Jürgen Exner
    Jul 10, 2004
  3. Richard Gration
    Replies:
    3
    Views:
    68
    Todd W
    Jan 11, 2005
  4. Paul Lalli

    convention regarding lexical filehandles

    Paul Lalli, Jan 13, 2005, in forum: Perl Misc
    Replies:
    14
    Views:
    177
    Michele Dondi
    Jan 16, 2005
  5. Veli-Pekka Tätilä

    Tie and Lexical Filehandles or IO::File?

    Veli-Pekka Tätilä, Aug 28, 2006, in forum: Perl Misc
    Replies:
    2
    Views:
    179
    Veli-Pekka Tätilä
    Aug 28, 2006
Loading...

Share This Page