How can I use Linux to copy binary files to a new directory
Hi,
I am new to Linux and Perl as well. I wrote a Perl script that compares two files (one is a text file and the other has images (.gif) in it. If an image in file 2 has an ID that's found in file one, I want to copy the image in a new directory with this textfile name. I am not being successful in copying and if anybody can help, I would appreciate it. When I try to print the output, images are printed as strings instead of binary. I am sure that there must an easy way to do this with Linx commands but I am not there yet. Here is my code:
#!/usr/bin/perl
use warnings;
use Getopt::Long;
use File::Copy;
my $output= "/data/Outputfile";
$filewith_images ="/data/Images/";
$textfile="/data/121test";
opendir (OUT, $output)or die " Can't open the output file";
open (FC,$txtfile) || die "Can't open the text file";
@image_desc = <FC>;
foreach $code(@image_codes)
{
opendir (FI, $filewith_images) or die " Can't open the file with images";
@images=grep(~/\_GIF$/i,readdir(FI)) or die " Can't ready directory";
foreach $item (@images)
{
$code++;
my $code1= substr($item, 0, -4);
if ($code1 eq $code){
print OUT "$item\n" ;
}
}
}
|