Skip to main content.
home | support | download

Back to List Archive

Re: Older scripts working with swish dev ?

From: Bill Moseley <moseley(at)not-real.hank.org>
Date: Fri Jun 28 2002 - 20:03:04 GMT
At 11:47 AM 06/28/02 -0700, Andrew Lord wrote:
>On Saturday 29 June 2002 03:17 am, you wrote:
>
>> I realize I wasn't very clear:
>> >    open( $fh, "$swish -k $letter|" ) or
>> >        die "Failed to run '$swish -k $letter': $!";
>>
>> You would have to pass in an array of index files then, after validating
>> them carefully,
>>
>>   my $index_files = join ' ', @index_file_list;
>>
>>   open( $fh, "$swish -k $letter -f $index_files|" ) or
>>       die "Failed to run '$swish -k $letter': $!";
>
>Thanks Bill,
>
>That has helped some, though I still feel like I'm swimming through a fog.  
>Probably something to do with it being nearly 4:15am here.  Mmm.  Must be 
>crazy or something.

I've be *up* since 1am, so I'm in the same boat.


>Obviously I haven't got it right yet . . . I'm getting an error message "-f 
>requires list of index files".  Would you mind pointing me to an example of 
>how one should pass an array to a sub program such as makewordlist ?  

Here's one way:

my @indexes = qw/ index1 index2 index3 index4 /;
makewordlist( @indexes );

sub makewordlist {
   my @index_file_list = @_;
   ...

>I think I understand that when you refer to carefully validating the
indexes, 
>you're referring to the line you previously provided: 
> my @valid_indexes =qw/ index1 index2 index3 index4 /;
>so that only those indexes called from the web page which are also listed in 
>that line, are able to be used.   A good idea.

Yes, you do not want to use any data passed in from a CGI form directly in
a call that passes through the shell.  Someone might pass in an index file
name of "; rm -rf /".


>A question on the format of 
>listing the indexes in that line though. . . . should the indexes be listed 
>as the actual 'indexfile (ie.  index.swish anotherindex.swish) or as the 
>indexname (ie. such as MyIndex HisIndex) ?  I would assume the former.

Not sure what you are asking, but the -f parameter takes a list of index
file names (or paths).  If you are asking about what to pass in from the
form you can pick anything you like -- you can pass in the actual index
file names, or some index.  I would not use the IndexName as there's
nothing that says that they must be unique.  Therefore, I'd create a map:

    my %index_map = (
        1    => 'index1',
        2    => 'index2',
        3    => 'index3',
   );

and then you have your drop-down list use the values 1, 2, 3,....

   my @requested_indexes = $cgi->param('index_select');

   my $index_files = join ' ', 
       map { $index_map{$_} } grep { exists $index_map{$_} )
          @requested_indexes;

grep filters out any submissions that are not 1,2, or 3, and then map
converts from the number to the real index file name, and then finally
join's them into a single space-separated string.

$cgi->param() is a better way to access your parameters.  See:

     perldoc CGI

>With regards to some of those other bits and pieces you mentioned, I'm not 
>sure what they're about either; I'm not the author and haven't got to the 
>point of fully understanding that script.

Me either.  What's it suppose to do?  A rewrite might be in order.


-- 
Bill Moseley
mailto:moseley@hank.org
Received on Fri Jun 28 20:06:39 2002