Perl file IO sucks?

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
pthomas
Forum Commoner
Posts: 68
Joined: Wed Jan 19, 2005 11:28 am
Location: Cincinnati, OH

Perl file IO sucks?

Post by pthomas »

I've been trying to find different IO functions for opening files, listing directories, getting file stats and such and have come up quite sort so far. Anyone know of a good perl module or some built-in stuff that does file and directory stuff with quite a few options?

Paul
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what "options" are you looking for? Perl is built alot around file handling..
User avatar
pthomas
Forum Commoner
Posts: 68
Joined: Wed Jan 19, 2005 11:28 am
Location: Cincinnati, OH

Post by pthomas »

Mainly file and directory stats: size, names...

Paul
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It's been a while since I've used Perl last, so I looked it up:

Code: Select all

#!/usr/bin/perl

opendir(MYDIR, '/path/to/folder') or die(&quote;Unable to open directory.\n&quote;);

while( $file = readdir( MYDIR ) )
{
  if( -d $file )
  {
    print( $file . &quote; directory.\n&quote; );
  }
  else
  {
    ($device, $inode, $fileinfo, $links, $userID, $groupID, $deviceID, $size, $access, $modify, $inodeChange, $prefIO, $IO) = stat($file);
    print( $file . ' ' . $size . &quote;\n&quote; );
  }
}
Post Reply