Anonymous user
Undefined values: Difference between revisions
→Tcl: Added implementation
m (Correct omit from use) |
(→Tcl: Added implementation) |
||
Line 2:
=={{header|Perl}}==
<lang perl>#!/usr/bin/perl -w
use strict;
Line 47 ⟶ 46:
=={{header|PHP}}==
<lang php><?php
// Check to see whether it is defined
Line 90 ⟶ 88:
=={{header|Python}}==
<lang python># Check to see whether it is defined▼
▲# Check to see whether it is defined
try: var
except NameError: print "var is undefined at first check"
Line 122 ⟶ 118:
# Because most of the output is conditional, this serves as
# a clear indicator that the program has run to completion.
print "Done"</lang>
</lang>▼
Results in:
Line 133 ⟶ 128:
=={{header|Ruby}}==
<lang ruby># Check to see whether it is defined▼
▲# Check to see whether it is defined
puts "var is undefined at first check" unless defined? var
Line 149 ⟶ 142:
# Because most of the output is conditional, this serves as
# a clear indicator that the program has run to completion.
puts "Done"</lang>
Results in:
<pre>var is undefined at first check
Done
=={{header|Tcl}}==
Tcl does not have undefined ''values'', but ''variables'' may be undefined by being not set.
<lang tcl># Variables are undefined by default and do not need explicit declaration
# Check to see whether it is defined
if {![info exists var]} {puts "var is undefind at first check"}
# Give it a value
set var "Screwy Squirrel"
# Check to see whether it is defined
if {![info exists var]} {puts "var is undefind at second check"}
# Remove its value
unset var
# Check to see whether it is defined
if {![info exists var]} {puts "var is undefind at third check"}
# Give it a value again
set var 12345
# Check to see whether it is defined
if {![info exists var]} {puts "var is undefind at fourth check"}
puts "Done"</lang>
Yields this output:
<pre>
var is undefind at first check
var is undefind at third check
Done
</pre>
|