[vienna.pm] Warnings...

Peter J. Holzer hjp at wsr.ac.at
Fri Apr 14 05:17:23 CDT 2000


On 2000-04-14 11:18:17 +0200, Florian Helmberger wrote:
> Abgesehen von dem eh standardmäßigen use strict benutze ich zum Debuggen 
> auch use diagnostics. Das Teil liefert mir eine ganze Menge von
> 
> Use of uninitialized value at
>          <script> line <zeile> (#1)
[...]
> if($cmlib->{in}->{'action'} eq "addform")
> 	{
> 	}
> 
> eine Warnung kommt, wenn action eben nicht von der Funktion gesetzt wurde.

Ja, das ist lästig. Ich hätte gerne, daß undef schlicht und einfach ne
zu jedem beliebigen String ist. 

Du kannst Dir aber behelfen indem Du schreibst:

  if($cmlib->{in}->{'action'} &&
     $cmlib->{in}->{'action'} eq "addform")
	{
	}

oder 

  if(defined($cmlib->{in}->{'action'}) &&
     $cmlib->{in}->{'action'} eq "addform")
	{
	}

In dem Fall sind beide äquivalent, aber wenn Du eventuell mit 0 oder ""
vergleichen willst, mußt Du defined() verwenden.

Am besten schreibst Du gleich eine Funktion:

    sub fteq {
	my ($var, $val) = (@_); 

	return (defined ($var) && $var eq $val);
    }

    if(fteq($cmlib->{in}->{'action'}, "addform")
	{
	}


	hp

-- 
   _  | Peter J. Holzer      | The best way to make sure something is
|_|_) | Sysadmin WSR / LUGA  |  "standard" today is to get an O'Reilly
| |   | hjp at wsr.ac.at        | book written on the topic.
__/   | http://www.hjp.at/   |   -- Casey Schaufler <casey at sgi.com>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 371 bytes
Desc: not available
Url : http://mail.pm.org/archives/vienna-pm/attachments/20000414/746579a0/attachment.bin


More information about the Vienna-pm mailing list