[comp.lang.perl] '~' in file names

worley@compass.com (Dale Worley) (02/28/91)

   From: jas@ISI.EDU (Jeff Sullivan)

   The problem is, when I say;

   require "~/.perlLib/random.pl";

   I get the error:

   Can't locate ~/.perlLib/random.pl in @INC at roll line 3.

The problem is that '~' is not recognized by the file system.  You can
use it in commands because the shell translates '~/' at the beginning
of an argument into '$HOME/', etc.  For instance, if you say "ls ~"
you get a listing of your home directory, but if you say "ls '~'" the
quoting inhibits the expansion of the '~', and you get "~ not found".

Dale

Dale Worley		Compass, Inc.			worley@compass.com
--
But Calvin is not a kind and loving god!  He's one of the _old_ gods!
He demands sacrifice!
-- "Calvin and Hobbes"

rrr@u02.svl.cdc.com (Rich Ragan) (03/01/91)

In <1991Feb28.151019.22944@uvaarpa.Virginia.EDU> worley@compass.com (Dale Worley) writes:

>The problem is that '~' is not recognized by the file system.  You can
>use it in commands because the shell translates '~/' at the beginning
>of an argument into '$HOME/', etc.  For instance, if you say "ls ~"
>you get a listing of your home directory, but if you say "ls '~'" the
>quoting inhibits the expansion of the '~', and you get "~ not found".

Agreed, the shell does this and it is very useful. Because we
sometimes move users from one file system to another to balance
disk usage, we strongly encourage users to employ ~ to avoid
having to change absolute paths if they get moved. I have been
meaning to ask why perl can't support this convention for file
names too. It would allow me to make my perl scripts more "portable".
Any chance of getting perl to support this?
--
Richard R. Ragan   rrr@svl.cdc.com    (408) 496-4340 
Control Data Corporation - Silicon Valley Operations
5101 Patrick Henry Drive, Santa Clara, CA 95054-1111

tchrist@convex.COM (Tom Christiansen) (03/01/91)

From the keyboard of rrr@svl.cdc.com:
:Any chance of getting perl to support this [tilde-expansion]?

If you mean

    open(FILE, '~john/bar');

then you would also be expecting perl to "know" to do the right
thing with:

    unlink '~john/bar';
and
    unlink '~john/bar*';

which is getting way out of hand.  That's what globbing is for.
These work if you have csh on your system (or have linked sh to ksh):

    open(FILE, <~john/bar>);
    unlink <~john/bar>;
    unlink <~john/bar*>;

If not, you could use my glob package, which does the right 
thing here.

--tom
--
"UNIX was not designed to stop you from doing stupid things, because
 that would also stop you from doing clever things." -- Doug Gwyn

 Tom Christiansen                tchrist@convex.com      convex!tchrist

alan@frey.newcastle.edu.au (Alan Hargreaves) (03/01/91)

rrr@u02.svl.cdc.com (Rich Ragan) writes:

>Agreed, the shell does this and it is very useful. Because we
>sometimes move users from one file system to another to balance
>disk usage, we strongly encourage users to employ ~ to avoid
>having to change absolute paths if they get moved. I have been

so why not get them to use $HOME? For starters there are a few Standard
shells around that don't map ~ to $HOME. $HOME is much safer.

alan.
-- 
Alan Hargreaves (VK2MGL) alan@frey.newcastle.edu.au, Uni of Newcastle, UCS.
Ph: +61 49 215 512 Fax: +61 49 602 118 ICBM: 32 53 44.6 S / 151 41 52.6 E
Yes one usually thinks to oneself. If one thinks to others, it is called ESP.
							Me.

meissner@osf.org (Michael Meissner) (03/02/91)

In article <1991Mar1.000018.15048@frey.newcastle.edu.au> alan@frey.newcastle.edu.au (Alan Hargreaves) writes:

| rrr@u02.svl.cdc.com (Rich Ragan) writes:
| 
| >Agreed, the shell does this and it is very useful. Because we
| >sometimes move users from one file system to another to balance
| >disk usage, we strongly encourage users to employ ~ to avoid
| >having to change absolute paths if they get moved. I have been
| 
| so why not get them to use $HOME? For starters there are a few Standard
| shells around that don't map ~ to $HOME. $HOME is much safer.

But ~otheruser/foo does not work.  I don't think it's unreasonable
that perl do the ~ translation for all names in file contexts.....

(as long as it's all places filenames are handled).
--
Michael Meissner	email: meissner@osf.org		phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142

Considering the flames and intolerance, shouldn't USENET be spelled ABUSENET?

jv@mh.nl (Johan Vromans) (03/03/91)

In article <MEISSNER.91Mar1183220@curley.osf.org> meissner@osf.org (Michael Meissner) writes:

> But ~otheruser/foo does not work.  I don't think it's unreasonable
> that perl do the ~ translation for all names in file contexts.....

Long ago, we have adopted the habit of having a common place where all
user directories can be found, using symlinks. "/users/foo" will
allways point to the real (actual, current) login directory for foo.

This solves this problem.

	Johan
-- 
Johan Vromans				       jv@mh.nl via internet backbones
Multihouse Automatisering bv		       uucp: ..!{uunet,hp4nl}!mh.nl!jv
Doesburgweg 7, 2803 PL Gouda, The Netherlands  phone/fax: +31 1820 62911/62500
------------------------ "Arms are made for hugging" -------------------------

vixie@decwrl.dec.com (Paul A Vixie) (03/04/91)

(warning: this is an os-wars flame, not relevant to perl.)

>> Long ago, we have adopted the habit of having a common place where all
>> user directories can be found, using symlinks. "/users/foo" will
>> allways point to the real (actual, current) login directory for foo.

We do that here, too (using "/udir" but the idea is the same).  However,
many people use AT&T UNIX SYSTEM V.3 ("CONSIDER IT STANDARD"), and they
can't do this simple thing.  (V.4 can, in 1990; 4.2bsd could, in 1980.)

Uh, cheers,
--
Paul Vixie
DEC Western Research Lab	<vixie@pa.dec.com>	<paul@vixie.sf.ca.us>
Palo Alto, California, USA	...!decwrl!vixie	...!vixie!paul

meissner@osf.org (Michael Meissner) (03/05/91)

In article <1991Mar3.100859.4383@pronto.mh.nl> jv@mh.nl (Johan Vromans) writes:

| 
| In article <MEISSNER.91Mar1183220@curley.osf.org> meissner@osf.org (Michael Meissner) writes:
| 
| > But ~otheruser/foo does not work.  I don't think it's unreasonable
| > that perl do the ~ translation for all names in file contexts.....
| 
| Long ago, we have adopted the habit of having a common place where all
| user directories can be found, using symlinks. "/users/foo" will
| allways point to the real (actual, current) login directory for foo.
| 
| This solves this problem.

Actually no, it does not solve the problem if you have System V.3
systems which do not support symlinks.
--
Michael Meissner	email: meissner@osf.org		phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142

Considering the flames and intolerance, shouldn't USENET be spelled ABUSENET?

ronald@robobar.co.uk (Ronald S H Khoo) (03/06/91)

meissner@osf.org (Michael Meissner) writes:

> In article <1991Mar3.100859.4383@pronto.mh.nl> jv@mh.nl (Johan Vromans) writes:
> | Long ago, we have adopted the habit of having a common place where all
> | user directories can be found, using symlinks.
...
> | This solves this problem.
> 
> Actually no, it does not solve the problem if you have System V.3
> systems which do not support symlinks.

Note the similarity to perl in the current timeframe: "Fixed in Release 4".  :-)
-- 
Ronald Khoo <ronald@robobar.co.uk> +44 81 991 1142 (O) +44 71 229 7741 (H)