TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TCLUG:16442] stupid perl question



Yes, but for hash elements you may want exists.

%foo;
...
$foo{'bar'} = baz($quux);
if(defined $foo{'bar'}) { 
	# is true if $foo{'bar'} has a value, baz didn't return undef to us
	...
}
elsif(exists $foo{'quuux'}) { 
	# executed if the key is in the hash, whether defined or not
	...
} 
else {
	# only executed if $foo{'quuux'} has never been mentioned
	...
}



On Wed, 19 Apr 2000, Troy Johnson wrote:

> I think 'defined' is what you want to use.
> 
> Luke Francl wrote:
> > 
> > Sorry for the off-topicness of this, but is there a way to find out if a
> > variable exists in perl? Like isset() in PHP, for example.
> > 
> > Context: I'm taking input from the command line and using GetOptions to
> > retrieve it. I want to set defaults for variables the user didn't input.
> > 
> > Thanks
> > 
> > Luke
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tclug-list-unsubscribe@mn-linux.org
> > For additional commands, e-mail: tclug-list-help@mn-linux.org
> 
> -- 
> 	<a href="http://umn.edu/~john1536">Troy Johnson</a>
> 
> I went to a general store.  They  wouldn't  let  me  buy  anything
> specifically.
> 						-- Stephen Wright
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tclug-list-unsubscribe@mn-linux.org
> For additional commands, e-mail: tclug-list-help@mn-linux.org
>