calling grep from perl

Toshiba / P30
February 25, 2010 at 12:49:28
Specs: MS Win XP, Intel 8600 2.40ghz/3.0GB
I have a perl script where I looping through a file. For each entry I want to look in another file to see if it exist. To do this I am using system("grep", $srchstrg, "exlude.lst"). The problem I am having is the commands return 0 whether the entry is found or not. How can I test to see if the grep actually finds the entry in the exclude.lst file?

See More: calling grep from perl

Report •

#1
February 25, 2010 at 14:13:20
Please post a sample of the lines from each file and show what you need to match.

It would also be helpful if you post your script.


Report •

#2
February 25, 2010 at 15:13:22
exclude.lst contains only 1 record right now
030406m.jpg050526m.jpg

the file I am looping through looks like this
DUPS
; --- Duplicates Info -- recording stops at 1000 pairs --
; 02/24/10 15:29:28
; Match total: 86
; --- Compared: Images all within Primary datafile
; Total image files: 7256
; Source: C:\rguest\multimed\X\bod\all\all1
; Consider a duplicate if match is between 95.0% and 100.0%
; Match restrictions: None
; Match method: Color (euclidean)
; No mean difference adjustment when matching
-- Matches --
; Match no: 6
Image 1 path: C:\rguest\multimed\X\bod\all\all1\030315b.jpg
Image 2 path: C:\rguest\multimed\X\bod\all\all1\051017b.jpg
; % matching: 95.2
; -------
; Match no: 7
Image 1 path: C:\rguest\multimed\X\bod\all\all1\030406m.jpg
Image 2 path: C:\rguest\multimed\X\bod\all\all1\050526m.jpg
; % matching: 95.0
; -------

here is my script;

open(infile1, 'dups.log') || die("Error - unable to open file(1)\n");
@data1 = <infile1>;
close(infile1);

$count1=0;
$count2=1;

foreach $line1 (@data1)
{
$count1++;

if ($count1 <= 12)
{
printf("%s", $line1);
next;
}

if ($count2 == 1)
{
$outline1=$line1;
$count2++;
next;
}

if ($count2 == 2)
{
$outline2 = $line1;
$jpg1 = substr($line1, length($line) - 11, 11);
chomp($jpg1);
$count2++;
next;
}

if ($count2 == 3)
{
$outline2 = $line1;
$jpg2 = substr($line1, length($line) - 11, 11);
chomp($jpg2);
$count2++;
next;
}

if ($count2 == 4)
{
$outline4 = $line1;
$count2++;
$jpgstring = $jpg1 . $jpg2;
next;
}

if ($count2 == 5)
{
$outline5 = $line1;
$count2 = 1;
system("grep", $jpgstring, "bodexcl.lst");
printf("return value is %d\n", $?);
printf("return value is %d\n", $? >> 8);
printf("%s\n", $jpgstring);
next;
}
}


Report •
Related Solutions


Ask Question