Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

-- == null ??????

Posted on 1998-09-15
4
Medium Priority
?
146 Views
Last Modified: 2010-03-05
I have this simple logic code for perl

if ( ($rev==undef) || ($rev=="new") ) {
    $rev = "new"; }
else {
    $rev = "rev" . $rev;
}

now this works fine when I pass in normal characters to $rev
but when I set $rev = "--" or "-"
it assumes $rev is undef and sets it to "new".
Is - a special character in perl?
why is this code not working properly and how to I get it to do what I want it to do?
0
Comment
Question by:ueihp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1204871
perl -we '$rev = "--"; if( ($rev=="new") ){ $rev = "new"; }'
Argument "new" isn't numeric in eq at -e line 1.
Argument "--" isn't numeric in eq at -e line 1.
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1204872
ozo's right

You'd be better off with

if ( !defined($rev) ) {
   $rev = 'new';
} elsif ($rev ne 'new') {
   $rev  = 'rev' . $rev;
}



0
 
LVL 1

Accepted Solution

by:
stormerider earned 0 total points
ID: 1204873
Or, closer to the original code,

if ( ($rev == undef) || ($rev eq "new") ) {
   $rev = "new";
} else {
   $rev = "rev" . $rev;
}


0
 
LVL 84

Expert Comment

by:ozo
ID: 1204874
But since == will evaluate undef to be ==0, anything numerically ==0 will be ==undef
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question