Phonebuff
asked on
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..
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"; }
ASKER
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"; }
}
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"
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"
ASKER
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,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
---------
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.
---------
ASKER
Changing from == to eq fixed the issue for me, without the need to do the isNumeric check in the string..
Thank you --
Thank you --
if( $param($p) !~ /\d/ ){