#!/usr/bin/perl -w use strict; use Getopt::Long; #usage example: perl GetbackIDs.pl -p /path_to_files -e [table file extension] #requires a table file and a "IDs database" in ".txt" format that share their name my ($path, $ext); GetOptions( 'path=s' => \$path, 'extension=s' => \$ext, ); print "$path\n"; chdir $path or die "ERROR: Unable to enter $path: $!\n"; opendir (TEMP , "."); my @files = readdir (TEMP); closedir TEMP; print "@files\n"; my $name; my @db; for my $file (@files) { if($file=~/(\w+).$ext/){ $name = "$1"; print"This is the Filename: $file\n"; open (INFILE, "$file") || die ("cannot open input file"); chomp(my @data = ); my$file2= "$name.bd"; print"This is the DBname:$file2\n"; open (DB, "$file2") || die ("cannot open input file"); chomp(@db = ); } #Edition "on the fly" via One-Liner for(@db){ my ($dbid,$firstid) = split(/\t/, $_); chomp $firstid; print"This is my $dbid and its $firstid\n"; ##ONELINER #if id matches, replace id my$susti=`perl -pi -e 's/$dbid/$firstid/g' $name.$ext`; } }