don@zippy.eecs.umich.edu (Don Winsor) (06/05/89)
Does anyone know if there is any way to make "perl" read from a file whose name begins with a ">" character? This question arose from a discussion I was had about whether a perl script could replace a C program for some simple operations on arbitrarily named files. At first, I though it could, but then this issue of files with names beginnning with characters in the set [<>|+] came up. I know this is a strange and rare situation, but I'd like to be able to handle it should it arise. The "perl" manual says: If the filename begins with <" or nothing, the file is opened for input. If the filename begins with ">", the file is opened for output. If the filename begins with ">>", the file is opened for appending. This seems to preclude any nice way to access files whose names may contain arbitrary characters. Is there any way around this? Don Winsor, Systems Programmer, University of Michigan Department of Electrical Engineering and Computer Science, don@dip.eecs.umich.edu
cosell@bbn.com (Bernie Cosell) (06/05/89)
In article <123@zip.eecs.umich.edu> don@zippy.eecs.umich.edu (Don Winsor) writes: }Does anyone know if there is any way to make "perl" read from a }file whose name begins with a ">" character? How about the standard unix tricks for dealing with that sort of problem: either reference the file as "./>myfile" or as "/usr/home/me/dir/>myfile"? } If the filename begins with <" or nothing, the file } is opened for input. If the filename begins with } ">", the file is opened for output. If the filename } begins with ">>", the file is opened for appending. I would bet that this really means "the filename string", not the filename-itself (if you were thinking of that string as being "device" . "directorypath" . "filename" even though the above decomposition is the actual reality for most operating systems.) /Bernie\
dik@cwi.nl (Dik T. Winter) (06/05/89)
In article <40899@bbn.COM> cosell@BBN.COM (Bernie Cosell) writes: > In article <123@zip.eecs.umich.edu> don@zippy.eecs.umich.edu (Don Winsor) writes: > }Does anyone know if there is any way to make "perl" read from a > }file whose name begins with a ">" character? > > How about the standard unix tricks for dealing with that sort of problem: > either reference the file as "./>myfile" or as "/usr/home/me/dir/>myfile"? > Except that those do not work. Not with the Bourne shell nor with the Korn shell. With the shells you have to quote. -- dik t. winter, cwi, amsterdam, nederland INTERNET : dik@cwi.nl BITNET/EARN: dik@mcvax
david@kailand.kai.com (06/05/89)
/* Written 2:36 pm Jun 4, 1989 by don@zippy.eecs.umich.edu in kailand:comp.sources.d */ /* ---------- "perl question about > in file name" ---------- */ >Does anyone know if there is any way to make "perl" read from a >file whose name begins with a ">" character? Even more fun is trying to remove a couple files named -r and -f. One simple answer is to prepend './' to files that do not start with a slash. David Nelson UUCP: ...!uunet!uiucuxc!kailand!dnelson Kuck and Associates, Inc. Internet: dnelson@kai.com 1906 Fox Drive Arpanet: dnelson%kai.com@uxc.cso.uiuc.edu Champaign, Ill. 61820 Optimizing software for supercomputers
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (06/06/89)
In article <123@zip.eecs.umich.edu> don@zippy.eecs.umich.edu (Don Winsor) writes:
: Does anyone know if there is any way to make "perl" read from a
: file whose name begins with a ">" character? This question arose
: from a discussion I was had about whether a perl script could
: replace a C program for some simple operations on arbitrarily
: named files. At first, I though it could, but then this issue of
: files with names beginnning with characters in the set [<>|+] came
: up. I know this is a strange and rare situation, but I'd like to
: be able to handle it should it arise. The "perl" manual says:
:
: If the filename begins with <" or nothing, the file
: is opened for input. If the filename begins with
: ">", the file is opened for output. If the filename
: begins with ">>", the file is opened for appending.
:
: This seems to preclude any nice way to access files whose names
: may contain arbitrary characters. Is there any way around this?
Yes, simply put an explict < on the front of the string.
open(FOO, "<$filename");
Larry Wall
lwall@jpl-devvax.jpl.nasa.gov
frankel@corona.megatek.uucp (Allan Frankel) (06/06/89)
perl is quite happy to work with a file named "<a": open(A,"><a"); print A "Heigh, Their!\n"; close(A); open(B,"<<a"); $line = <B>; print $line; To write to ">a" it would presumably be necessary to delete (or truncate) it first and then open ">>>a". Allan Frankel, frankel@megatek or: (619) 455-5590 x2541 ucsd! Megatek Corp. hplabs!hp-sdd!megatek!frankel 9645 Scranton Rd. ames|scubed! San Diego, CA 92121
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (06/07/89)
In article <568@megatek.UUCP> frankel@corona.UUCP (Allan Frankel) writes:
: To write to ">a" it would presumably be necessary to delete (or truncate)
: it first and then open ">>>a".
Actually, it suffices to put a space after the first >, as in "> >a".
Of course, this means you can't easily create a filename starting with spaces,
but why would you want to do that anyway?
Larry Wall
lwall@jpl-devvax.jpl.nasa.gov
allbery@ncoast.ORG (Brandon S. Allbery) (06/09/89)
As quoted from <123@zip.eecs.umich.edu> by don@zippy.eecs.umich.edu (Don Winsor): +--------------- | begins with ">>", the file is opened for appending. | | This seems to preclude any nice way to access files whose names | may contain arbitrary characters. Is there any way around this? +--------------- Use backslashes to escape them, probably. Before you flame this as not being transparent enough: even C has to escape the \ and " characters. ++Brandon -- Brandon S. Allbery, moderator of comp.sources.misc allbery@ncoast.org uunet!hal.cwru.edu!ncoast!allbery ncoast!allbery@hal.cwru.edu Send comp.sources.misc submissions to comp-sources-misc@<backbone> NCoast Public Access UN*X - (216) 781-6201, 300/1200/2400 baud, login: makeuser
batie@agora.UUCP (Alan Batie) (06/09/89)
From article <5058@jpl-devvax.JPL.NASA.GOV>, by lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall): > Actually, it suffices to put a space after the first >, as in "> >a". > Of course, this means you can't easily create a filename starting with spaces, > but why would you want to do that anyway? Although I agree with Larry in this case, the question "Why would you want to do that anyway?" is usually followed by someone finding a good reason to do so, and I consider it a very dangerous question. -- Alan Batie +1 503 640-4013 1221 N.E. 51st, #227 batie@agora.hf.intel.com Hillsboro, OR 97124 tektronix!tessi!agora!batie