in reply to split to get the dir name

Other monks have given you some good answers here. If you really have no alternative to parsing the output from ls -l then have a peek at File::Listing. I've had to parse the output from ls -l over an FTP connection and File::Listing was perfect for that.

-- vek --

Replies are listed 'Best First'.
Re: Re: split to get the dir name
by Grygonos (Chaplain) on Sep 29, 2003 at 17:49 UTC
    If you were looking for just the files and not any directories, then try this,
    #!/perl -w use strict; ##Code is tested on winxp with perl 5.8## my $path = "c:\\"; my @files; #Open the directory opendir(AMHANDLE,$path); #iterate over the file handle while(my $file = readdir(AMHANDLE)) { #print $file ."\n"; #If the file is a folder then just echo it if(-d $path.$file) { print "$file is a folder\n"; } else { #Else push it onto the files array push @files,$file; } } #Close the handle closedir(AMHANDLE); #Echo the contents of the @files array foreach my $item(@files) { print $item . "\n"; }

    Yes I know that in *NIX that directories are just special case files, but I didn't know if the poster meant files or simply the contents. Please understand that I'm not trying to sound like a know-it-all because everyone probably knows by now that I'm not. I just wanted to offer a few other tidbits of knowledge to AM.

      thanks all