CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
what is correct syntax?

 



digioleg54
User

Mar 6, 2017, 6:44 AM

Post #1 of 5 (2435 views)
what is correct syntax? Can't Post

Sorry for such stupid question, but I found different syntax. Some write if (! defined), some - if ( not defined). Which is correct?
Also, if I get a variable value from %ENV, should I check if it is defined or not?


FishMonger
Veteran / Moderator

Mar 6, 2017, 7:58 AM

Post #2 of 5 (2429 views)
Re: [digioleg54] what is correct syntax? [In reply to] Can't Post


Quote
Some write if (! defined), some - if ( not defined). Which is correct?

Both


Quote
Also, if I get a variable value from %ENV, should I check if it is defined or not?

Maybe or maybe not, but it never hurts to check.


BillKSmith
Veteran

Mar 6, 2017, 8:33 AM

Post #3 of 5 (2423 views)
Re: [digioleg54] what is correct syntax? [In reply to] Can't Post

The reason either operator is correct is that the only difference between them is precedence. (refer to section "Symbolic Unary Operators" in perldoc perlop) In your case that does not make any difference.
Good Luck,
Bill


digioleg54
User

Mar 6, 2017, 8:40 AM

Post #4 of 5 (2422 views)
Re: [BillKSmith] what is correct syntax? [In reply to] Can't Post

thank you


Laurent_R
Veteran / Moderator

Mar 7, 2017, 9:32 AM

Post #5 of 5 (2414 views)
Re: [digioleg54] what is correct syntax? [In reply to] Can't Post


In Reply To
Also, if I get a variable value from %ENV, should I check if it is defined or not?


Well, it's not mandatory to check, but you should probably check if you're going to use that variable for anything important. Then it also depends on which environment variable you're using: some will be almost guaranteed to exist, other are more likely to be undef. And then, there is always the possibility that it will not be defined just because to made a typo in the name.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives