Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7901837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:20:11+00:00 2026-06-03T09:20:11+00:00

When I write out a HTML::Table I want to skip certain rows. This should

  • 0

When I write out a HTML::Table I want to skip certain rows. This should be done according to a few user parameters which I get from the web page and compile them as regex.

The Parameters are the upper case NOT_* with values such as cc08 or a post code or whatever.

my $nameRegex =    ($NOT_NAME)  ? qr/$NOT_NAME/  : '';
my $rackRegex =    ($NOT_RACK)  ? qr/$NOT_RACK/  : '';
my $unitRegex =    ($NOT_UNIT)  ? qr/$NOT_UNIT/  : '';
my $addressRegex = ($NOT_ADDR)  ? qr/$NOT_ADDR/  : ''; 
my $townRegex  =   ($NOT_TOWN)  ? qr/$NOT_TOWN/  : '';
my $pcodeRegex =   ($NOT_PCODE) ? qr/$NOT_PCODE/ : '';

In the while loop (for a SQL query elsewhere) I get the data, and what I think im doing is “unless you match any of these” add this row of results.

while ((my $id, my $name, my $rack, my $unit, my $town, my $address, my $pcode, my $lat, my $lon) = $select_sites->fetchrow_array()) {
        my $checkbox = "<input type='checkbox' name='FILTER_SITE' value='$id' $checked{$id} />";

        unless ($name =~ $nameRegex
            || $rack =~ $rackRegex
            || $unit =~ $unitRegex
            || $address =~ $addressRegex
            || $town =~ $townRegex 
            || $pcode =~ $pcodeRegex) {

            $rows++;
            $sitesResultSection->addRow($checkbox, $name, $rack, $unit, $town, $address, $pcode, $lat, $lon);
        }

Spitting the Regexs would look something like this for $NOT_RACK = "cc08"

  = qr//;
 (?-xism:cc08) = qr/cc08/;
  = qr//;
  = qr//; 
   = qr//;
  = qr//;

However the problem is no rows are added at all, while only one result in the query must be omitted for “cc08”, and all others must be shown.

The reason I’m doing this in HTML is because there are already other filters in the SQL query (limiting the result set significantly) and making those filters dynamic according to user input would be a nightmare.

Answer accepted, however I had a further issue:

This is how I initialised those NOT_s, in the same fashion I used for my query’s REGEXP conditions. Thusly when a user enters “City rackname” it’ll display racks in City

my $NOT_NAME = &useOrs(&trim($cgi->param('NOT_NAME')));
my $NOT_RACK = &useOrs(&trim($cgi->param('NOT_RACK')));
my $NOT_UNIT = &useOrs(&trim($cgi->param('NOT_UNIT')));
my $NOT_ADDR = &useOrs(&trim($cgi->param('NOT_ADDR')));
my $NOT_TOWN = &useOrs(&trim($cgi->param('NOT_TOWN')));
my $NOT_PCODE= &useOrs(&trim($cgi->param('NOT_PCODE')));

my $QUICK_SEARCH_SITES = &trim($cgi->param('QUICK_SEARCH_SITES'));
my $searchRegexp = ($QUICK_SEARCH_SITES) ? &useOrs($QUICK_SEARCH_SITES) : '.*';

sub useOrs {
    my $tmp = $_[0];
    $tmp =~ s/\s+/|/g;
    return $tmp;
}

Here’s an excerpt from the SQL query WHERE name REGEXP ? OR rack-id REGEXP ? OR [..]
So with these hacks some reasonable flexibility is achieved without having to train the monkeys that will use the tool.
However using merely $var =~ /$NOT_VAR/ will apparently match only exactly that, case sensitive etc.
To achieve the looseness of the SQL filter Instead of using &useOrs I use

sub useAny {
    my $tmp = $_[0];
    $tmp =~ s/\s/./g;
    return $tmp;
}

And most importantly $var =~ /.*$NOT_VAR.*/i

I was under the impression that one is supposed to hack away with Perl so there.. 🙂 Suggestions still welcome.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:20:12+00:00Added an answer on June 3, 2026 at 9:20 am

    Update:

    As Sinan Ünür has pointed out, there is a hidden functionality, described in perlop in that any empty regex // will instead use the last successfully matched regex. A very strange feature, IMO, and in this case will cause subtle errors.

    That makes it a bad idea to use variables inside regexes, unless they are checked for content first.

    Solution:

    What you should do, IMO, is exchange this for a subroutine, e.g.:

    sub check_var {
        my ($var, $NOT_VAR) = @_;
        return 0 unless $NOT_VAR;
        return ($var =~ /$NOT_VAR/);
    }
    

    And then use it as such:

    unless ( check_var($name, $NOT_NAME) 
          || check_var($rack, $NOT_RACK)
          ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In plain html, when I want to point-out a table row, I just write:
I want to write reusable code that takes an HTML table from a JSP
In google app engine certain html tags are stripped out like tr, table an
I want to write out a text file. Instead of the default UTF-8, I
I'm using Java and OpenXLS to write out an Excel spreadsheet. I want to
I have a simple working PHP script to write an HTML table from a
client.html how can I write this json data retrieval in client end in order
I'm trying to write out a Byte[] array representing a complete file to a
Grails tends to write out the URL for everything that uses its tags as
Trying to write out syslog entries containing strings but they don't register. // person.name

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.