yunfei has asked for the wisdom of the Perl Monks concerning the following question:

Hello! I got a weird print output for the line of code: print "******processing <<<<${file}>>>\n\n"; One output is ******processing <<<</home/user/projects/database/bwa/index_bwa_human_b36_both.fasta.tar.gz>>> Another output is actually the following which is weird >>>***processing <<<</home/user/projects/database/bwa/index_bwa_human_b36_both.fasta.index.tar.gz.md5 The input file where I got the file name has the following line:
[13:06 yunfei@bcl code]$ cat -T -E ../src/db_names | grep "hg18ibwa" $g18ibwa^Iindex_bwa_human_b36_both.fasta.tar.gz^Iindex_bwa_human_b36_b +oth.fasta.index.tar.gz.md5
The code for reading file names is (file path is added thereafter by $file="$dir/$file";)
102 while(<DBNAME>) { 103 next if /^#/; 104 1 while (chomp); 105 s/ +/\t/g; 106 s/\t+/\t/g; 107 my @tmp=split('\t',$_); 108 my $item=shift @tmp; 109 $down_name{$item}=\@tmp; 110 }
Also when I try
130 if ($file =~/(zip$)|(gz$)|(tar$)|(bz$)|(bz +2$)/i) { 131 $untar{$file}=$untar_dir; 132 print STDERR "Got $file another ta +r file\n"; 133 } elsif ($file =~/md5$/i) { 134 my ($source_file)= $file=~/(.*)\.m +d5$/i; 135 print STDERR "Source file $source_ +file\n"; 136 }
I only got output from line 132 but never from line 135. Any idea what's wrong here? Thank you very much! I'm new to this place, hope I'm asking the question at the right place.

Replies are listed 'Best First'.
Re: weird print output
by kcott (Archbishop) on Sep 30, 2012 at 21:07 UTC

    G'day yunfei,

    Welcome to the monastery.

    Please provide a self-contained piece of code which reproduces your problem. (Guidelines for doing this can be found in: How do I post a question effectively?)

    The following code simulates what you're describing but does not reproduce the problem.

    #!/usr/bin/env perl use strict; use warnings; while (my $file = <DATA>) { print '-' x 60, "\n"; chomp $file; print "******processing <<<<${file}>>>\n\n"; if ($file =~/(zip$)|(gz$)|(tar$)|(bz$)|(bz2$)/i) { print "IF: $file\n"; } elsif ($file =~/md5$/i) { print "ELSIF: $file\n"; } print '-' x 60, "\n"; } __DATA__ /home/user/projects/database/bwa/index_bwa_human_b36_both.fasta.tar.gz /home/user/projects/database/bwa/index_bwa_human_b36_both.fasta.index. +tar.gz.md5

    Output:

    $ pm_weird_print.pl ------------------------------------------------------------ ******processing <<<</home/user/projects/database/bwa/index_bwa_human_ +b36_both.fasta.tar.gz>>> IF: /home/user/projects/database/bwa/index_bwa_human_b36_both.fasta.ta +r.gz ------------------------------------------------------------ ------------------------------------------------------------ ******processing <<<</home/user/projects/database/bwa/index_bwa_human_ +b36_both.fasta.index.tar.gz.md5>>> ELSIF: /home/user/projects/database/bwa/index_bwa_human_b36_both.fasta +.index.tar.gz.md5 ------------------------------------------------------------

    In your while(<DBNAME>) {...} loop, it would be useful to show the raw data before and after modification as well as how that ties in with $file="$dir/$file";.

    Also, please correct the typo in the title: s/wired/weird/

    -- Ken

Re: weird print output
by jwkrahn (Abbot) on Oct 01, 2012 at 00:32 UTC

    In your second example you have a "\r" (carriage return) at the end of the file name.