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 6087643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:53:37+00:00 2026-05-23T11:53:37+00:00

Okay, so there is an input form, with 4 text boxes. I get the

  • 0

Okay, so there is an input form, with 4 text boxes. I get the input using CGI.pm:

my $exc0 = param('exclude0') || 'a'; 
my $exc1 = param('exclude1') || 'a';
my $exc2 = param('exclude2') || 'a';
my $exc3 = param('exclude3') || 'a';

The reason I had to include the || 'a' is to allow it to work if there was no input. Is there a safer way to do this?

It gets called later on in a regex:

next if ($totalmatch->[2] =~ /\b$exc0\b/i);
next if ($totalmatch->[2] =~ /\b$exc1\b/i);
next if ($totalmatch->[2] =~ /\b$exc2\b/i);
next if ($totalmatch->[2] =~ /\b$exc3\b/i);

Where $totalmatch->[2] is a sentence. If I don’t check for no input, when there isn’t an input no matches come up (a.k.a. it includes $exc in every case). I’d guess this is because there is an undef or space in every sentence?

What I’ve tried is || '' and I suppose I could use a if ($exc0) or a if defined() or eq '' but just looking for help.

Thanks a lot for your time.

  • 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-05-23T11:53:38+00:00Added an answer on May 23, 2026 at 11:53 am

    If you don’t do use warnings and don’t do the || 'a' you should get a warnings: Use of uninitialized value at ...

    It’s best practice in perl (or any language, for that matter) to check for the existence of a variable before you use it in a function, or in this case, a regular expression, unless there is a specific reasons of it being null being a desirable possibility.

    Your should really get rid of the || 'a' and do this:

    next if (length($exc0) and $totalmatch->[2] =~ /\b$exc0\b/i);
    next if (length($exc1) and $totalmatch->[2] =~ /\b$exc1\b/i);
    next if (length($exc2) and $totalmatch->[2] =~ /\b$exc2\b/i);
    next if (length($exc3) and $totalmatch->[2] =~ /\b$exc3\b/i);
    

    You don’t want to use defined() here because '' is defined, and you’ll still have the problem of it matching.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to DRY this jQuery up? <script type=text/javascript> $('form input#search').watermark('search...'); </script>
I'm writing an ASP.NET 3.5 web application. There is a rather complex input form
Okay, I have been studying text input in SDL (how to turn the keystrokes
Okay, There seems to be a lot of discussion on here about how terribly
Well, okay. There's Visual Studio 2008 and Embarcadero Delphi/Studio that are both able to
Okay, I've looked all over the internet for a good solution to get PHP
Okay, so ultimately I want a program where the user can input simple data
I am attempting to post form data to my app using Facebook. My form
REVISED: Okay, thanks to all of your input, I figured out what I was
Okay so I have this website where I have a form on the sidebar

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.