Find the answer to your Linux question:
Results 1 to 5 of 5
Are there functions in perl to access the the directories in linux. for example is there a find function in perl that will both work in windows and linux. thanx ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux User
    Join Date
    Apr 2003
    Location
    TEXAS
    Posts
    314

    Functions in perl


    Are there functions in perl to access the the directories in linux.

    for example is there a find function in perl that will both work in windows and linux.

    thanx for reading
    The computer made me do it!! Slackware and SUSE too Gig\'em WHOOOOP!!
    \"God put me on this earth to accomplish a certain amount of tasks, At the rate I\'m going I will never die.\" (I don\'t know)

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    I'm not sure what you mean by a "find function", but it's very easy to retrieve the contents of a directory:
    Code:
    print("Directory contents:\n");
    while&#40;<*>&#41;
    &#123;
        print&#40;$_ . "\n"&#41;;
    &#125;

  3. #3
    Linux User
    Join Date
    Apr 2003
    Location
    TEXAS
    Posts
    314
    ok but i also need all of the info for example the size of each file in the directory. Number of subdirecttories and so on.

    in linux i just use the find function.

    Code:
    find /certain/directory/ -type d
    is their a way to do this in perl so this will work also in windows.
    The computer made me do it!! Slackware and SUSE too Gig\'em WHOOOOP!!
    \"God put me on this earth to accomplish a certain amount of tasks, At the rate I\'m going I will never die.\" (I don\'t know)

  4. #4
    Linux Engineer
    Join Date
    Jan 2003
    Location
    Lebanon, pa
    Posts
    994
    For find, you could do something like this:
    Code:
    while&#40;`find / -type d`&#41; &#123;
      chomp&#40;$_&#41;;
      print $_;
    &#125;
    There are many ways to work with the filesystem. I suggest you read up on these subs:
    open(), close(), select(), eof(), seek(), tell(), read(), sysread(), syswrite(), mkdir(), opendir(), closedir(), readdir(), chdir(), telldir(), seekdir(), rewinddir(), rmdir(), rename(), unlink(), link(), symlink(), readlink(), chmod(), chown(), umask(), truncate(), stat(), lstat(), fileno(), and flock().
    You can also run the shell commands by putting them in system() or using `command`. As for windows, I have never coded perl on that platform so I do not know how you can work with the filesystem there.

  5. #5
    Linux Newbie
    Join Date
    Aug 2001
    Location
    USA, Texas
    Posts
    217
    You can use File::Find (CPAN page). I haven't found it to be the easiest thing in the world to use, but it works really well.
    [ [ SykkN alloc ] initWithThePowerTo: destroyYouAll ];
    /* Don\'t make me use it! */

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •