in reply to change files names bug
How about undoing some of those loops. If your file names are as consistent as they look from your example, this is a simpler way to do it
#!/usr/bin/perl use strict; use warnings; # Read barcodes, and look for coresponding files to rename my $dir = "/samplesA"; my $bcf = "/ID.txt"; open my $barcodelist, "<", $bcf or die "Can not open barcode file $bcf +: $!\n"; while (my $line = <$barcodelist>) { chomp; my ($id, $barcode) = split(/\t/,$line); # I like validating inputs warn "bad line at $.\n" unless $barcode =~/^[ACGT]+$/; my $file = "$dir/sample_$barcode.fq"; if (-e $file) { my $new = "$dir/$id.fq"; rename $file, $new or die "Can't change $file to $new, $!\n"; } } close $barcodelist;
Cheers,
R.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: change files names bug
by Yuma248 (Initiate) on Nov 01, 2013 at 04:01 UTC |