I have a file which has list of files with some other info too.. say..
1/1/2008./to/path/filename1.:
...
...
something like that.. can anyone tell me how can i just open the file and read the contents and then cut just the filename1 and write it to an @array..
when i read the name of the file from this filename list .. i need to check the directory and see if all the files are present or not... how is this possible??
thanks,
oops... I forgot you just wanted the filename. Try this instead of all previous suggestions:
my @array;
open (FH, 'yourfile') or die "$!";
while(<FH>){
chomp;
tr/://d;
if (m#/(\S+)\s*\d*$#) {
push @array, $1;
}
}
close FH;
print "$_\n" for @array;
tr/://d; <-- removes all colons from the lines
(split(/s\s+/))[-2] <-- splits the line on spaces and returns the second to last field. It is called an array slice.