Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^4: Listing of files using glob

by AG87 (Acolyte)
on Jan 05, 2012 at 11:46 UTC ( #946375=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Listing of files using glob
in thread Listing of files using glob

A separate code does work for me as well. But in the full fledge code its not working. The file names ">1elwA" etc etc are stored in a hash as a key. In a loop it has to retrieve the key value, tr it, and then print the output with .fasta extension. In the embedded code it is not printing the complete file name. Maybe there is some problem in storing the file in hash. Is there some other way to capture the output of the regular expression into the key of the hash other than the way used in my code in the first sub with the name of "StoreInHash"????


Comment on Re^4: Listing of files using glob
Re^5: Listing of files using glob
by choroba (Abbot) on Jan 05, 2012 at 11:48 UTC
    Please, be careful to what post you are replying to.

      Have I replied to wrong post?? I am replying in the same thread I think

Re^5: Listing of files using glob
by choroba (Abbot) on Jan 05, 2012 at 11:50 UTC
    Are you chomping lines when storing names into the hash?

      No I am not. Here is the code used to store the file into hash

      open(FILE, "$path_to_fastaSeqs") or die("cannot open file"); { while(<FILE>) { my $line = $_; if ($line =~ />.*/) { #print "$&\n"; } else { #print "$line\n"; } $seqInfo{$&} = $line; } close(FILE); }

      Any errors or wrong approach??

        Can you show the input, too?

        > Any errors or wrong approach??

        Yep. You never chomp the data read from the filehandle FILE. Since you are building the file name directly from the line read, it most likely contains a newline. If you print your value for $line with a delimiter surrounding it (print "'$line'\n";) you will see what I mean. See chomp (as has been previously mentioned) for a solution.

        Update: Since the OP is using $& to populate the hash, and the processing loop uses the keys of the hash as the name of the file, the newline from the file should not be included in the hash key. Nice catch choroba

        I wonder what the line endings are in the data file. Is it possible that the file is in DOS line ending format? In which case, the chomp (and $&?) would not do the right thing.

        --MidLifeXis

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://946375]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2014-07-26 13:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (176 votes), past polls