identifying and separating directories from files

I have the contents of a directory in an array (@contents).

I want to push all files present in @contents to @files and all directories present in @contents to @dir

Yelp

Anant
LVL 1
anant99Asked:
Who is Participating?
 
monasConnect With a Mentor Commented:
if this is perl, then

push @files,map {-f $_? $_: ()} @contents;
push @dir,map {-d $_? $_: ()} @contents;
0
 
marecsCommented:
push @files, grep {-f } @contents;
push @dir, grep {-d } @contents;
0
 
anant99Author Commented:
i am testing them out. i shall accept one of them soon.

Anant
0
 
shirjeelCommented:
hey man use this code
$i = 0;
foreach $file((@contents)
{
if(-e $file)
{
@dir[$i] = $file;
$i++;
}
}

0
All Courses

From novice to tech pro — start learning today.