in reply to Re: search for exact word only
in thread search for exact word only

Please let me a little bit modify my problem.
There is a number of names which consist of 2 or 3 words.

For example:

'Ministry Of Sound' or
'Oliver Shanti & Friends'
The user has remembered exactly only the first word ('Ministry'),the other words he has written incorrectly/with mistake.
I want that this first 'exact' word was enough to find the full name - 'Ministry Of Sound'. Even if there will be shown additionally some other items than the user searched, the user can choose the right item.
The main thing is to prevent code display of words just containing a required word as a syllable, like 'nistry' or 'inis'..

I have no access to Perl modules, i use shared hosting. Its not clear for me where was meant to insert lines:
use strict;
use warnings;
use CGI::Carp::FatalsToBrowser();

Replies are listed 'Best First'.
Re^3: search for exact word only
by Roy Johnson (Monsignor) on Sep 27, 2004 at 17:01 UTC
    The solution I provided solves the problem you describe here. It matches on word boundaries, it does not require the entire string to match. My solution did not include strict, warnings, or Carp, but strict and warnings are pragmas, and do not require external modules. Warnings is not supported in some versions of Perl, so you should rely on the -w option, in that case.

    Caution: Contents may have been coded under pressure.
      Could you put the lines you provided inside my code? I got '500 Internal Server Error'. I suspect, that probably I have incorrectly closed braces or not in the right place.

      Thanks
      tenerif

        You can just use your original code, and where you did have the pattern
        /\Q$key/
        replace it with
        /\b\Q$key\E\b/

        Caution: Contents may have been coded under pressure.
Re^3: search for exact word only
by muntfish (Chaplain) on Sep 28, 2004 at 08:20 UTC
    I have no access to Perl modules, i use shared hosting.

    I have used various web hosting providers, but I've always had the CGI module. I'm pretty sure it comes as standard with all Perl distributions, so it would be very unlikely that you don't already have it. If you genuinely don't have it, you should give your hosting provider a good kicking.

    By the way - the monk who advised using CGI::Carp made a small typo, which would give you an error. The line should be:

    use CGI::Carp qw(fatalsToBrowser);

    and this (along with use strict) should go straight after the #! line at the start of your file:

    #!/usr/bin/perl -w use strict; use CGI; use CGI::Carp qw(fatalsToBrowser);

    Hope this helps.


    s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&
      I done this, but now the script refuses to work at all. It just shows vaste q-ty of various instructions. That is, this even has worsened script work.
      Probably there are something wrong or erroneous in initial approach to creation of this script.

      Global symbol "$qs" requires explicit package name at csvsearch.pl line 36.
      Global symbol "$base_length" requires explicit package name at csvsearch.pl line 41.
      Global symbol "$base_length" requires explicit package name at csvsearch.pl line 43.
      Global symbol "$qs" requires explicit package name at csvsearch.pl line 45.
      Global symbol "@header" requires explicit package name at csvsearch.pl line 45.
      Global symbol "$qs" requires explicit package name at csvsearch.pl line 47.
      Global symbol "@conditions" requires explicit package name at csvsearch.pl line 51.
      Global symbol "$qs" requires explicit package name at csvsearch.pl line 51.
      Global symbol "@conditions" requires explicit package name at csvsearch.pl line 53.
      Global symbol "$name" requires explicit package name at csvsearch.pl line 54.
      Global symbol "$value" requires explicit package name at csvsearch.pl line 54.
      Global symbol "$name" requires explicit package name at csvsearch.pl line 55.
      Global symbol "%FORM" requires explicit package name at csvsearch.pl line 56.
      Global symbol "$value" requires explicit package name at csvsearch.pl line 56.
      Global symbol "$value" requires explicit package name at csvsearch.pl line 57.
      Global symbol "@header" requires explicit package name at csvsearch.pl line 57.
      Global symbol "$name" requires explicit package name at csvsearch.pl line 59.
      Global symbol "$value" requires explicit package name at csvsearch.pl line 60.
      Global symbol "$value" requires explicit package name at csvsearch.pl line 61.
      Global symbol "@line" requires explicit package name at csvsearch.pl line 69.
      Global symbol "%INSERT" requires explicit package name at csvsearch.pl line 70.
      Global symbol "%INSERT" requires explicit package name at csvsearch.pl line 71.
      Global symbol "@line" requires explicit package name at csvsearch.pl line 71.
      Global symbol "%INSERT" requires explicit package name at csvsearch.pl line 74.
      Global symbol "%INSERT" requires explicit package name at csvsearch.pl line 75.
      Global symbol "%INSERT" requires explicit package name at csvsearch.pl line 76.
      Global symbol "$base_length" requires explicit package name at csvsearch.pl line 76.
      Global symbol "$key" requires explicit package name at csvsearch.pl line 104.
      Global symbol "$record" requires explicit package name at csvsearch.pl line 106.
      Global symbol "@line" requires explicit package name at csvsearch.pl line 107.
      Global symbol "$record" requires explicit package name at csvsearch.pl line 107.
      Global symbol "@line" requires explicit package name at csvsearch.pl line 110.
      Global symbol "$key" requires explicit package name at csvsearch.pl line 110.
      Global symbol "@line" requires explicit package name at csvsearch.pl line 112.
      Global symbol "$key" requires explicit package name at csvsearch.pl line 112.
      Global symbol "@line" requires explicit package name at csvsearch.pl line 115.
      Global symbol "$key" requires explicit package name at csvsearch.pl line 115.
      Global symbol "%INSERT" requires explicit package name at csvsearch.pl line 132.
      Global symbol "%INSERT" requires explicit package name at csvsearch.pl line 132.
      Global symbol "$style" requires explicit package name at csvsearch.pl line 150.
      Execution of csvsearch.pl aborted due to compilation errors.

        That's right, just adding use strict to the start of your program won't magically make it work. That wasn't what I (or the person who originally mentioned strict) was suggesting. It is a debugging aid, not a magic bullet. In your case it is telling you that certain variables have not been declared properly.


        s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&