• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 505
  • Last Modified:

How to identify a character string from a numeric string in a perl CGI script.

I am having issues with some code.  I want to check the Argument coming from an HTML file for a certain value and can't get it to work.  I have tried a number of recommendations from google searchs with no luck.

Last test was NOT isDigit which errors out as an undefined subroutine, as do a number of other things I have tried. ..  

Trying to clear this error message / condition which makes the code not work with just a simple if condition and no check for the field type..


[Sun Oct 30 22:11:33 2011] postOrder.cgi: Argument "xyz@zyxcorp.org" isn't numeric in int at /web/mfa/cgi-bin/postOrder.cgi line 387.

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

 .....................

            if ( [b]!isDIGIT([/b]param($p)) ) {
                   if ( param($p) == "B1" ) { print MAIL "Order Date = ", $invdate, "\n"; }
            }

      Verse what generates the error above.. 
 
             if ( param($p) == "B1" ) { print MAIL "Order Date = ", $invdate, "\n"; }

Open in new window

0
Phonebuff
Asked:
Phonebuff
  • 4
  • 3
1 Solution
 
ozoCommented:
Do you mean
if( $param($p) !~ /\d/ ){
0
 
PhonebuffAuthor Commented:
Nope that does not work --

   
syntax error at /web/mfa/cgi-bin/postOrder.cgi line 339, near "$param("

   
      foreach my $p (param()) {
              if ( (param($p) !~ "B1") && ($p !~ "B1") ) { print MAIL "$p = ", param($p), "\n"; }
              if (  $param($p) !~ /\d/ ) {     # This is Line 339 ....
                if ( param($p) == "B1" ) { print MAIL "Order Date = ", $invdate, "\n"; }
              }

Open in new window

0
 
ozoCommented:
Sorry, param($p) !~ /\d/  
Or param($p) =~ /\D/ may be closer to what you want, depending on what you are doing on line 387

But  param($p) == "B1" should probably be param($p) eq "B1" or param($p) =~ "B1", not param($p) !~ "B1"
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
PhonebuffAuthor Commented:

My goal is to execute the resulting print statement only when the value of param($p) is "B1" otherwise I don;t want to print that in place of the contents of the array.  The problem is comparing the contents which is sometime numeric to the character string B1 results in errors occurring..

Isn't the ^ Start of String and \d a numeric character ?  How does this check that an address is not a numeric field when it might start with a couple of numeric characters but contains a string of alpha numeric.characters .  

It's late East Coast and I have had a short weekend, so I am going to park this till tomorrow morning.

Thanks for your assistance,
0
 
ozoCommented:
I didn't mention ^, but strings matching /^\d/ can be interpreted as a number in some contexts.
param($p) !~ /\d/ means does not contain a digit, and was an attempt to interpret what you meant by !isDIGIT
== is a numeric comparison, so you'd want  eq "B1" for a string comparison
a numeric comparison would treat "B1" as 0, and generate a warning if -w is set
0
 
PhonebuffAuthor Commented:
Good Morning,

     Thank you for the reply and sorry.  My tired eyes saw a ^  when in fact it's the /\ characters back to back.  Also, your explanation of the difference between == and eq is probably the correct solution for this.  I have some things that HAVE to be done first, but let me try that when I get a few minutes and get back with you.

      ---------
0
 
PhonebuffAuthor Commented:
Changing from == to eq fixed the issue for me, without the need to do the isNumeric check in the string..  

Thank you --
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now