http://www.perlmonks.org?node_id=946341


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

storeInHash seems problematic. I have seen a .fasta file, and it looks like  >gi|21040368|ref| ... , and on my platform there is no way to create a file/directory with a | character in the name, so what Platform/Filesystem are you on?

Replies are listed 'Best First'.
Re^4: Listing of files using glob
by tobyink (Canon) on Jan 05, 2012 at 09:27 UTC

    I can't speak for AG87, but on Linux it's pretty easy to create a file with a pipe symbol in it.

    touch 'foo|bar' && ls -l foo* && rm -i 'foo|bar'
    

    If I recall correctly, the only character disallowed in Linux filenames is the slash.

      You also can't create a file with \0 in its name :).

        There are many characters, though, that you can use in file names, but you never should :-)
Re^4: Listing of files using glob
by AG87 (Acolyte) on Jan 05, 2012 at 10:25 UTC

    I am working on linux and it has no issues in creating a filename with "|" sign in it. I have figured out the problem. In actual the file created in sub createFoldersAndFiles automatically inserts a space before the extension .fasta due to which the complete file name is not being grabbed by glob. Can anyone suggest how to overcome this problem coz its very strange. Normally the FILEOUT handle does not add a space before extension. Any thoughts??? :(

      The handle does not create the filename. Your program does.
      open(FILEOUT, ">$dir/$nameWithoutFastaSign/$nameWithoutFastaSign.fasta +");
      Remove the space from $nameWithoutFastaSign.
Re^4: Listing of files using glob
by AG87 (Acolyte) on Jan 05, 2012 at 11:02 UTC

    I cant see any space though

    Even the code (part of the previous complete code) below does not print the complete filename. It only prints the extension

    $nameWithoutFastaSign =~ tr/>//d; print "$nameWithoutFastaSign.fasta\n";

    Any more thoughts?? :(

      What is in $nameWithoutFastaSign before tr?
Re^4: Listing of files using glob
by AG87 (Acolyte) on Jan 05, 2012 at 11:14 UTC

    Before tr it has ">1elwA". and tr is used to omit the ">" sign

      Strange. Works for me:
      perl -e '$nameWithoutFastaSign = ">1elwA"; print "before: $nameWithoutFastaSign\n"; $nameWithoutFastaSign =~ tr/>//d; print "after: $nameWithoutFastaSign\n";'
      Output:
      before: >1elwA after: 1elwA
Re^4: Listing of files using glob
by AG87 (Acolyte) on Jan 05, 2012 at 11:46 UTC

    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"????

      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??

      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