home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / perl / 5411 < prev    next >
Encoding:
Internet Message Format  |  1992-08-21  |  1.4 KB

  1. Path: sparky!uunet!ogicse!reed!romulus!merlyn
  2. From: merlyn@romulus.reed.edu (Randal L. Schwartz)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: Filename expansion ("~user")
  5. Message-ID: <MERLYN.92Aug21092257@romulus.reed.edu>
  6. Date: 21 Aug 92 16:23:01 GMT
  7. Article-I.D.: romulus.MERLYN.92Aug21092257
  8. References: <1992Aug20.153727.167@cbnews.cb.att.com>
  9. Sender: news@reed.edu (USENET News System)
  10. Distribution: usa
  11. Organization: Reed College
  12. Lines: 22
  13. In-Reply-To: daleske@cbnews.cb.att.com's message of 20 Aug 92 15:37:27 GMT
  14.  
  15. In article <1992Aug20.153727.167@cbnews.cb.att.com> daleske@cbnews.cb.att.com (John D. Daleske) writes:
  16.    If I set $tst1 to the full pathname it works fine.  I'd like to use the common
  17.    facility of ~user to avoid needing to know the full path name.  (User home
  18.    directories do get moved around.)
  19.  
  20. There's nothing in the Unix kernel that understands the tilde hack
  21. (introduced by the C-shell, and copied to half a dozen other bezerkley
  22. utilities).
  23.  
  24. Fetching the home directory is easy enough though:
  25.  
  26.     $file = "~merlyn/.newsrc";
  27.     $file =~ s#^~([a-z0-9]+)(/.*)?$#(getpwnam($1))[7].$2#e;
  28.  
  29.  
  30. (If you mess with $[, you deserve what you get. :-)
  31.  
  32. for('a'..'z','A'..'Z'){*XX=$_;$XX=$_;}print"$J$u$s$t $a$n$o$t$h$e$r $P$e$r$l $h$a$c$k$e$r,"
  33. --
  34. Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
  35. merlyn@reed.edu (guest account) merlyn@ora.com (better for permanent record)
  36. cute quote: "Welcome to Portland, Oregon -- home of the California Raisins!"
  37.