diff options
author | Gabor Szabo <szabgab@gmail.com> | 2007-12-26 08:03:29 +0200 |
---|---|---|
committer | Steve Peters <steve@fisharerojo.org> | 2007-12-26 14:55:03 +0000 |
commit | 460b70c2ae94a254c087c06a9e5a5c4c3d88a0b5 (patch) | |
tree | 5cf780d367d8eee1503107032e6428c6771cbd79 /pod | |
parent | d374f9c73e6118631558f80521fa3b0f1c61fb3a (diff) | |
download | perl-460b70c2ae94a254c087c06a9e5a5c4c3d88a0b5.tar.gz |
docs: replace FH by my $fh in open
From: "Gabor Szabo" <szabgab@gmail.com>
Message-ID: <d8a74af10712252003m2d3244fbv2955fe17e683063d@mail.gmail.com>
p4raw-id: //depot/perl@32729
Diffstat (limited to 'pod')
-rw-r--r-- | pod/perlfunc.pod | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 0f4c4a8fd8..dc340f10bd 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -3057,6 +3057,14 @@ X<open> X<pipe> X<file, open> X<fopen> Opens the file whose filename is given by EXPR, and associates it with FILEHANDLE. +Simple examples to open a file for reading: + + open(my $fh, '<', "input.txt") or die $!; + +and for writing: + + open(my $fh, '>', "output.txt") or die $!; + (The following is a comprehensive reference to open(): for a gentler introduction you may consider L<perlopentut>.) @@ -3128,7 +3136,7 @@ You may use the three-argument form of open to specify IO "layers" that affect how the input and output are processed (see L<open> and L<PerlIO> for more details). For example - open(FH, "<:encoding(UTF-8)", "file") + open(my $fh, "<:encoding(UTF-8)", "file") will open the UTF-8 encoded file containing Unicode characters, see L<perluniintro>. Note that if layers are specified in the @@ -3158,7 +3166,7 @@ working with an unopened filehandle is actually what you want to do. As a special case the 3-arg form with a read/write mode and the third argument being C<undef>: - open(TMP, "+>", undef) or die ... + open(my $tmp, "+>", undef) or die ... opens a filehandle to an anonymous temporary file. Also using "+<" works for symmetry, but you really should consider writing something @@ -3186,10 +3194,10 @@ Examples: open(LOG, '>>/usr/spool/news/twitlog'); # (log is reserved) # if the open fails, output is discarded - open(DBASE, '+<', 'dbase.mine') # open for update + open(my $dbase, '+<', 'dbase.mine') # open for update or die "Can't open 'dbase.mine' for update: $!"; - open(DBASE, '+<dbase.mine') # ditto + open(my $dbase, '+<dbase.mine') # ditto or die "Can't open 'dbase.mine' for update: $!"; open(ARTICLE, '-|', "caesar <$article") # decrypt article |