diff options
author | Perl 5 Porters <perl5-porters@africa.nicoh.com> | 1997-04-23 00:00:00 +1200 |
---|---|---|
committer | Chip Salzenberg <chip@atlantic.net> | 1997-04-23 00:00:00 +1200 |
commit | 46fc3d4c69a0adf236bfcba70daee7fd597cf30d (patch) | |
tree | 3b70f4a42d2ccd034756c9786032a1e531569e62 /pod/perlfaq5.pod | |
parent | 10a676f83f541430b63a3192b246bf6f86d3b189 (diff) | |
download | perl-46fc3d4c69a0adf236bfcba70daee7fd597cf30d.tar.gz |
[inseparable changes from match from perl-5.003_97g to perl-5.003_97h]
BUILD PROCESS
Subject: Fix up Linux hints for tcsh, and Configure patch
Date: Tue, 22 Apr 1997 11:02:27 -0400 (EDT)
From: Andy Dougherty <doughera@lafcol.lafayette.edu>
Files: Configure hints/linux.sh
Msg-ID: Pine.SOL.3.95q.970422101051.2506C-100000@fractal.lafayette.e
(applied based on p5p patch as commit 1eb1b1cb9647b817d039bb17afa3e74940b5ef92)
Subject: There is no standard answer to 'Use suidperl?'
From: Chip Salzenberg <chip@perl.com>
Files: hints/bsdos.sh hints/freebsd.sh hints/linux.sh hints/machten_2.sh
CORE LANGUAGE CHANGES
Subject: Support PRINTF for tied handles
Date: Sun, 20 Apr 1997 18:26:13 -0400
From: Doug MacEachern <dougm@opengroup.org>
Files: pod/perldelta.pod pod/perltie.pod pp_sys.c t/op/misc.t
Msg-ID: 199704202226.SAA08032@postman.osf.org
(applied based on p5p patch as commit e7c5525577c16ee25e3521e86aca2b5105dba394)
CORE PORTABILITY
Subject: Fix bitwise shifts and pack('w') on Crays
From: Chip Salzenberg <chip@perl.com>
Files: pp.c
DOCUMENTATION
Subject: FAQ udpate (23-apr-97)
Date: Wed, 23 Apr 1997 12:22:55 -0600 (MDT)
From: Nathan Torkington <gnat@prometheus.frii.com>
Files: pod/perlfaq*.pod
private-msgid: 199704231822.MAA05074@prometheus.frii.com
OTHER CORE CHANGES
Subject: Mondo Cool patch for buffer safety and convenience
From: Chip Salzenberg <chip@perl.com>
Files: XSUB.h doop.c dump.c ext/DynaLoader/dl_dlopen.xs ext/DynaLoader/dl_hpux.xs ext/DynaLoader/dl_next.xs ext/DynaLoader/dlutils.c ext/ODBM_File/ODBM_File.xs global.sym gv.c interp.sym mg.c op.c perl.c perl.h pod/perlguts.pod pp.c pp_ctl.c pp_hot.c pp_sys.c proto.h regcomp.c regexec.c sv.c toke.c util.c
Subject: Problems with glob
Date: Sun, 20 Apr 1997 02:44:32 -0400 (EDT)
From: Ilya Zakharevich <ilya@math.ohio-state.edu>
Files: op.c
Msg-ID: 1997Apr20.024432.1941365@hmivax.humgen.upenn.edu
(applied based on p5p patch as commit a1230b335277820e65b8a9454ab751341204cf4f)
Subject: Fix scalar leak in closures
From: Chip Salzenberg <chip@perl.com>
Files: op.c scope.c
Subject: Refine error messages re: anon subs' prototypes
From: Chip Salzenberg <chip@perl.com>
Files: op.c
Subject: Outermost scope is void, not scalar
From: Chip Salzenberg <chip@perl.com>
Files: pp_ctl.c
Diffstat (limited to 'pod/perlfaq5.pod')
-rw-r--r-- | pod/perlfaq5.pod | 69 |
1 files changed, 56 insertions, 13 deletions
diff --git a/pod/perlfaq5.pod b/pod/perlfaq5.pod index 1c694f0347..898864b51a 100644 --- a/pod/perlfaq5.pod +++ b/pod/perlfaq5.pod @@ -1,6 +1,6 @@ =head1 NAME -perlfaq5 - Files and Formats ($Revision: 1.20 $, $Date: 1997/03/19 17:24:51 $) +perlfaq5 - Files and Formats ($Revision: 1.21 $, $Date: 1997/04/23 18:05:19 $) =head1 DESCRIPTION @@ -106,7 +106,7 @@ the changes you want, then copy that over the original. rename($new, $old) or die "can't rename $new to $old: $!"; Perl can do this sort of thing for you automatically with the C<-i> -command line switch or the closely-related C<$^I> variable (see +command-line switch or the closely-related C<$^I> variable (see L<perlrun> for more details). Note that C<-i> may require a suffix on some non-Unix systems; see the platform-specific documentation that came with your port. @@ -231,6 +231,36 @@ Internally, Perl believes filehandles to be of class IO::Handle. You may use that module directly if you'd like (see L<IO::Handle>), or one of its more specific derived classes. +Once you have IO::File or FileHandle objects, you can pass them +between subroutines or store them in hashes as you would any other +scalar values: + + use FileHandle; + + # Storing filehandles in a hash and array + foreach $filename (@names) { + my $fh = new FileHandle($filename) or die; + $file{$filename} = $fh; + push(@files, $fh); + } + + # Using the filehandles in the array + foreach $file (@files) { + print $file "Testing\n"; + } + + # You have to do the { } ugliness when you're specifying the + # filehandle by anything other than a simple scalar variable. + print { $files[2] } "Testing\n"; + + # Passing filehandles to subroutines + sub debug { + my $filehandle = shift; + printf $filehandle "DEBUG: ", @_; + } + + debug($fh, "Testing\n"); + =head2 How can I set up a footer format to be used with write()? There's no builtin way to do this, but L<perlform> has a couple of @@ -262,6 +292,18 @@ You can't just: because you have to put the comma in and then recalculate your position. +Alternatively, this commifies all numbers in a line regardless of +whether they have decimal portions, are preceded by + or -, or +whatever: + + # from Andrew Johnson <ajohnson@gpu.srv.ualberta.ca> + sub commify { + my $input = shift; + $input = reverse $input; + $input =~ s<(\d\d\d)(?=\d)(?!\d*\.)><$1,>g; + return reverse $input; + } + =head2 How can I translate tildes (~) in a filename? Use the E<lt>E<gt> (glob()) operator, documented in L<perlfunc>. This @@ -406,13 +448,13 @@ atomic test-and-set instruction. In theory, this "ought" to work: except that lamentably, file creation (and deletion) is not atomic over NFS, so this won't work (at least, not every time) over the net. -Various schemes involving link() have been suggested, but these tend -to involve busy-wait, which is also subdesirable. +Various schemes involving involving link() have been suggested, but +these tend to involve busy-wait, which is also subdesirable. =head2 I still don't get locking. I just want to increment the number in the file. How can I do this? -Didn't anyone ever tell you web page hit counters were useless? +Didn't anyone ever tell you web-page hit counters were useless? Anyway, this is what to do: @@ -426,7 +468,7 @@ Anyway, this is what to do: # DO NOT UNLOCK THIS UNTIL YOU CLOSE close FH or die "can't close numfile: $!"; -Here's a much better web page hit counter: +Here's a much better web-page hit counter: $hits = int( (time() - 850_000_000) / rand(1_000) ); @@ -455,14 +497,14 @@ like this: Locking and error checking are left as an exercise for the reader. Don't forget them, or you'll be quite sorry. -Don't forget to set binmode() under MS-DOS-like platforms when operating +Don't forget to set binmode() under DOS-like platforms when operating on files that have anything other than straight text in them. See the docs on open() and on binmode() for more details. =head2 How do I get a file's timestamp in perl? If you want to retrieve the time at which the file was last read, -written, or had its metadata (owner, etc) changed, you use the B<-M>, +written, or had its meta-data (owner, etc) changed, you use the B<-M>, B<-A>, or B<-C> filetest operations as documented in L<perlfunc>. These retrieve the age of the file (measured against the start-time of your program) in days as a floating point number. To retrieve the "raw" @@ -602,7 +644,7 @@ The Term::ReadKey module from CPAN may be easier to use: printf "\nYou said %s, char number %03d\n", $key, ord $key; -For MS-DOS systems, Dan Carson <dbc@tc.fluke.COM> reports the following: +For DOS systems, Dan Carson <dbc@tc.fluke.COM> reports the following: To put the PC in "raw" mode, use ioctl with some magic numbers gleaned from msdos.c (Perl source file) and Ralf Brown's interrupt list (comes @@ -737,17 +779,17 @@ to, you may be able to do this: $rc = syscall(&SYS_close, $fd + 0); # must force numeric die "can't sysclose $fd: $!" unless $rc == -1; -=head2 Why can't I use "C:\temp\foo" in MS-DOS paths? What doesn't `C:\temp\foo.exe` work? +=head2 Why can't I use "C:\temp\foo" in DOS paths? What doesn't `C:\temp\foo.exe` work? Whoops! You just put a tab and a formfeed into that filename! Remember that within double quoted strings ("like\this"), the backslash is an escape character. The full list of these is in L<perlop/Quote and Quote-like Operators>. Unsurprisingly, you don't have a file called "c:(tab)emp(formfeed)oo" or -"c:(tab)emp(formfeed)oo.exe" on your MS-DOS filesystem. +"c:(tab)emp(formfeed)oo.exe" on your DOS filesystem. Either single-quote your strings, or (preferably) use forward slashes. -Since all MS-DOS and Windows versions since something like MS-DOS 2.0 or so +Since all DOS and Windows versions since something like MS-DOS 2.0 or so have treated C</> and C<\> the same in a path, you might as well use the one that doesn't clash with Perl -- or the POSIX shell, ANSI C and C++, awk, Tcl, Java, or Python, just to mention a few. @@ -755,7 +797,7 @@ awk, Tcl, Java, or Python, just to mention a few. =head2 Why doesn't glob("*.*") get all the files? Because even on non-Unix ports, Perl's glob function follows standard -Unix globbing semantics. You'll need C<glob("*")> to get all (nonhidden) +Unix globbing semantics. You'll need C<glob("*")> to get all (non-hidden) files. =head2 Why does Perl let me delete read-only files? Why does C<-i> clobber protected files? Isn't this a bug in Perl? @@ -786,3 +828,4 @@ file in. Copyright (c) 1997 Tom Christiansen and Nathan Torkington. All rights reserved. See L<perlfaq> for distribution information. + |