in reply to recognizing OS

Although $^O is the literal answer to your question the answer for portability is to use perls internal functions only rather than system calls. That way the port of Perl takes care of the port of you script for you. This could be a lot more terse if desired:

use Cwd; opendir my $dir, cwd() or die "Can't read ".cwd().": $!\n"; my @contents = readdir $dir; closedir $dir; my @dirs = grep{ -d and $_ ne '.' and $_ ne '..' } @contents; print "DIR $_\n" for @dirs; #my @files= grep{ -f } @contents; #print "FILE $_\n" for @files;

Replies are listed 'Best First'.
Re^2: recognizing OS
by ikegami (Patriarch) on May 03, 2008 at 06:18 UTC

    cwd() can be changed to just '.'

    opendir my $dir, '.' or die "Can't read current directory (".cwd()."): $!\n";

    That applies to the OP too. He could drop $dirname from the command line both simplifying the code and removing his bug.

      use File::Spec; die File::Spec->curdir;