Sunday, 15 July 2012

extracting filename and getting " GLOB in perl -



extracting filename and getting " GLOB<0x486a8> in perl -

i trying extract file name maintain getting glob<0x486a8> file name? i've looked @ multiple answers questions answering similar questions still can't seem solve issue. files i'm opening standard fasta files next format first line contains sequence info , lines follow sequences.

here code

#!/usr/bin/perl utilize strict; utilize warnings; #open files info directory opendir $data_dir, "data" or die "unable open directory!"; @files = readdir $data_dir; #reading files array #taking files .fa extention @fa_files = grep /[\.][f][a]$/, @files; @sorted_fa_files = sort @fa_files; #taking each .fa , reading description line foreach (@sorted_fa_files) { open $filehandle, "<", "data/$_" or die "unable open file!"; while (<$filehandle>) { print "filename: $filehandle\n"; } }

thoughts anyone?

the filename "data/$_" (at to the lowest degree before while loop; overwriting $_ in while). $filehandle filehandle, not filename.

you should avoid using $_ 2 different purposes this; utilize lexical variables instead:

foreach $filename (@sorted_fa_files){ open $filehandle,"<","data/$filename" or die "unable open file!"; while ( $line = <$filehandle> ){ print "filename: data/$filename";

perl filenames glob

No comments:

Post a Comment