FAQ 5.17 How can I open a file with a leading ">" or trailing blanks?
- From: PerlFAQ Server <brian@xxxxxxxxxxxxxx>
- Date: Sat, 30 Dec 2006 00:03:02 -0800
This is an excerpt from the latest version perlfaq5.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
5.17: How can I open a file with a leading ">" or trailing blanks?
(contributed by Brian McCauley)
The special two argument form of Perl's open() function ignores trailing
blanks in filenames and infers the mode from certain leading characters
(or a trailing "|"). In older versions of Perl this was the only version
of open() and so it is prevalent in old code and books.
Unless you have a particular reason to use the two argument form you
should use the three argument form of open() which does not treat any
charcters in the filename as special.
open FILE, "<", " file "; # filename is " file "
open FILE, ">", ">file"; # filename is ">file"
--------------------------------------------------------------------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
--
Posted via a free Usenet account from http://www.teranews.com
.
- Prev by Date: FAQ 5.8 How can I make a filehandle local to a subroutine? How do I pass filehandles between subroutines? How do I make an array of filehandles?
- Next by Date: Re: Superformula with Perl?
- Previous by thread: FAQ 5.8 How can I make a filehandle local to a subroutine? How do I pass filehandles between subroutines? How do I make an array of filehandles?
- Next by thread: Assigning pattern matches to an array
- Index(es):
Relevant Pages
|