Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Joining arrays from filehandles 2

Status
Not open for further replies.

artisst

Programmer
Apr 24, 2004
18
US
Code:
sub normal_search
{

### PERFORM SEARCH

$search_line = $fields{'keywords'};
$icnt = 0;
$toadk = "";

open (SIDX, "$data_dir/search.idx");
open (SIDX2, "$data_dir/search2.idx");
I need to join both files here into @skeyw
Code:
my @sidx = <SIDX>;
my @sidx2 = <SIDX2>;

@sidx = grep {$_ ne ""} @sidx;
@sidx2 = grep {$_ ne ""} @sidx2;

@skeyw = (\@sidx, \@sidx2);

## How do I join @sidx, @sidx2 into @skeyw ##

#my $line = join('|', @sidx, @sidx2);
#$line = qr/$line/;

(@skeyw) = split(/ /,$search_line);

$nrkeywords = 0;
foreach $item (@skeyw){$nrkeywords++;}

Then return the results from both files
Code:
	{
	$sline = $line;
	
	}
		{
	foreach $kwr (@skeyw)
		{

		if (($sline =~ /$kwr/i) and ($kwr ne ""))
			{
			
			$toadk = "true";
			}
			
		}

		if ($toadk eq "true")
			{
			$resultline[$icnt] = $line;
			$toadk = false;
			$icnt++;
			}

	}
	
	
	
	
 #if ($file_locking ne "No"){flock (CIT, LOCK_UN);}
close (SIDX);
close (SIDX2);

}
 
Hi artisst,

if you have @sidx, @sidx2 then you can add these to the @skeyw array with a simple push command ...

i.e.

push (@skeyw,@sidx,@sidy)

Thanks,
SP
 
For some reason, this following not working:

Code:
sub normal_search
{

### PERFORM SEARCH

$search_line = $fields{'keywords'};
$icnt = 0;
$toadk = "";

open (SIDX, "$data_dir/search.idx");
open (SIDX2, "$data_dir/search2.idx");

### I need to join both files here into @skeyw ###

#my @sidx = <SIDX>;
@sidx2 = <SIDX2>;

#@sidx = grep {$_ ne ""} @sidx;
#@sidx2 = grep {$_ ne ""} @sidx2;

#@skeyw = (\@sidx, \@sidx2);

push (@skeyw,@sidx2);


(@skeyw) = split(/ /,$search_line);

$nrkeywords = 0;
foreach $item (@skeyw){$nrkeywords++;}







# if ($file_locking ne "No"){flock (SIDX, LOCK_SH) or die "Can't set lock for file: $data_dir/search.idx, $data_dir/search2.idx $!\n";}
	while ($line=<SIDX>)
	
	{
	$sline = $line;

		
	foreach $kwr (@skeyw)
		{

		if (($sline =~ /$kwr/i) and ($kwr ne ""))
			{

		$toadk = "true";
			}
			
		}
		

		if ($toadk eq "true")
			{
			$resultline[$icnt] = $line;
			$toadk = false;
			$icnt++;
			}

	}
	
	
	
	
 #if ($file_locking ne "No"){flock (CIT, LOCK_UN);}
close (SIDX);
close (SIDX2);

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top