LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How can I use Linux to copy binary files to a new directory (https://www.linuxquestions.org/questions/linux-newbie-8/how-can-i-use-linux-to-copy-binary-files-to-a-new-directory-611541/)

lnx_learner 01-06-2008 01:24 PM

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" ;
}
}
}

Poetics 01-07-2008 11:37 AM

I believe it's the way 'print' handles data, and how you're requesting it be sent to the screen. I don't know if perldoc print has any further information on the subject, but I bet it'd be a good place to start -- are you just trying to print to the screen? It may be better to call a program to print them instead of relying on 'print' which may be much more limited. If you don't need to wait for output, perhaps an exec() instead of system()


All times are GMT -5. The time now is 10:34 AM.