home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / perl / 7683 < prev    next >
Encoding:
Internet Message Format  |  1993-01-06  |  2.2 KB

  1. Path: sparky!uunet!noc.near.net!bigboote.WPI.EDU!bigboote.wpi.edu!john
  2. From: john@sekrit.WPI.EDU (John Stoffel)
  3. Newsgroups: comp.lang.perl
  4. Subject: Re: stat problem
  5. Date: 6 Jan 93 11:48:43
  6. Organization: Worcester Polytechnic Institute
  7. Lines: 50
  8. Message-ID: <JOHN.93Jan6114843@sekrit.WPI.EDU>
  9. References: <jwh2.4.0@cornell.edu>
  10. NNTP-Posting-Host: sekrit.wpi.edu
  11. In-reply-to: jwh2@cornell.edu's message of Wed, 6 Jan 1993 15:10:16 GMT
  12.  
  13. >>>>> On Wed, 6 Jan 1993 15:10:16 GMT, jwh2@cornell.edu (James W. Howell) said:
  14. James> Nntp-Posting-User: @cornell.edu
  15.  
  16. James> Using the below perl script the stat routine doesn't return
  17. James> anything, has anyone seen this type of behavior before???  Jim
  18. James> Howell
  19.  
  20. I played around with this for a bit before i figured out that stat()
  21. wants the FULL path to the file before it will work.  All you have to
  22. do is make two simple changes to your program.
  23.  
  24. James> #!/usr/bin/perl
  25. James> $usr_spool_dir = "/usr/include/";
  26.                                      ^
  27. Add the trailing slash to make it easier later on...
  28.  
  29. James> # $usr_spool_dir = "/usr/spool/mail/jwhtest";
  30. James> # $usr_spool_dir = "./";
  31. James> opendir(SDIR,$usr_spool_dir);
  32. James> @dir_files = readdir(SDIR);
  33. James> closedir(SDIR);
  34.        ^^^^^^^^^^^^^^^
  35.  
  36. Moved this up here because it is 'safer' and makes more logical sense
  37. to have it here, right after you have finished reading in all the
  38. directory entries.
  39.  
  40. James> $ct = 0;
  41. James> foreach $file (@dir_files)   {
  42. James>     if( -d $file) { next; }
  43. James>     if( -B $file) { next; }
  44. James>     $one_file[$ct] = $file;
  45.  
  46. James>     ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size) =
  47.         stat($usr_spool_dir . $one_file[$ct]);
  48.                      ^^^^^^^^^^^^^^^^^
  49.  
  50. This is the major change, adding in the full path to the file you want
  51. to stat.
  52.  
  53. This should do the trick.  Oh yeah, this was with Perl 4.035 running
  54. on a DECstation 3100 running Ultrix 4.3
  55.  
  56.                     John
  57.  
  58. --
  59. Youth of today!  Join me in a mass rally for traditional mental attitudes!
  60. -------------------------------------------------------------------------------
  61. john@wpi.wpi.edu | Work Station Specialist | Worcester Polytechnic Institute
  62. John Stoffel     | 508-831-5512 (work)     | Worcester, MA  01609
  63.