Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with some simple Perl code

Status
Not open for further replies.

BigDoug

IS-IT--Management
Feb 20, 2002
49
US
Help please! I am working on modifying a script I use, and I am a dummy. Plain and simple. But I know many here are not. So here is my question. I have this code:


BigDougCode::error(&quot;You must leave the open date empty in your file in row <B>$theline</B>.&quot;) unless $nine


Basically what I want is to tell the error module that if they enter anything in $nine, they are in error. So what can I add after the error statement to insure this?

Could I do this:

BigDougCode::error(&quot;You must leave the open date empty in your file in row <B>$theline</B>.&quot;) unless $nine =>$_

I don't know. Anybody want to answer this neophyte question?



 
Doug,

I'm sorry to be thick about this, but you seem to be contradicting yourself. Could you ask your question a different way please? Mike
&quot;Experience is the comb that Nature gives us after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
I'm sorry. I thought I was pretty clear. Let me re-word.

Here is the situation. I want to add the below statement to my BigDougCode.pm file as an error handler in case someone enters data into the file in the designated field of $nine. Below is what I have so far. What can I add after the statement ( after the &quot;); ) to check for this? I thought about this &quot;) unless $nine ne 'something';

Problem is, what do I put in the unless part??

BigDougCode::error(&quot;You must leave the open date empty in your file in row <B>$theline</B>.&quot;)

I want to add to the code so that if a user enters anything in the open date field designated as $nine, they are in error and my script spits that error out to them from the BigDougCode.pm file. This is a small snippet out of a larger script. I thought it would be simple to do.

I hope this is clearer, although it seems more complicated now.
 
Ok, thanks.

The code:

BigDougCode::error(&quot;You must leave the open date empty in your file in row <B>$theline</B>.&quot;) if $nine;

will call BigDougCode::error if $nine is defined at all, if it has a value in other words.

The code:

BigDougCode::error(&quot;You must leave the open date empty in your file in row <B>$theline</B>.&quot;) unless $nine;

will call BigDougCode::error *UNLESS* $nine has a value, in other words &quot;If $nine is blank then tell the user&quot;.

Looks to me like you were 99% of the way there, you just had the check the wrong way around...
Mike
&quot;Experience is the comb that Nature gives us after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
Okay, good. Problem lies in the fact that I need $nine to always be blank or if it is not, then throw the error.
 
Thank you for your help. I just need to figure out now how to do the opposite of your example. I need $nine to always be blank or then throw the error. Also, $nine is not numeric, it is alphabetic, but I need to know how to throw the error for both a numeric value and a non-numeric value.
 
Okay, I answered my own question. In case anybody wants to know I had to use this:

unless $nine == (0);# This is for a numeric value

and:

unless $ten eq &quot;&quot;;# This is for a string Do me justice, O God, and fight my fight against a faithless people; from the deceitful and impious man rescue me.

Psalm 43:1

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top