tamaguchi has asked for the wisdom of the Perl Monks concerning the following question:
If the hash is defined the running of the program doesn´t couse any problems, but if the hash is undefied I get the error message: "Use of uniintialised value in hash element". The the whole purpose of the code in a larger concept is to look if the hash is defined, if it is so do A if it is not do B. It should therefore not print error messages if the hash is not defined, becouse it may very well be undefined. Do you have any solution to this small problem?#!/usr/bin/perl -w my (%hash); my (@keyarr)=(keys (%hash)); if (defined ($hash{$keyarr[0]}})) {print "hash is defined\n";} else {print "hash is undefined\n";}
2006-02-11 Retitled by planetscape, as per Monastery guidelines
Original title: 'Defied vs. undefined'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Defined vs. undefined
by xdg (Monsignor) on Feb 10, 2006 at 12:15 UTC | |
by misterb101 (Sexton) on Feb 10, 2006 at 15:57 UTC | |
by xdg (Monsignor) on Feb 10, 2006 at 17:27 UTC | |
|
Re: Defined vs. undefined
by monarch (Priest) on Feb 10, 2006 at 11:39 UTC | |
by muntfish (Chaplain) on Feb 10, 2006 at 11:50 UTC | |
|
Re: Defined vs. undefined
by kwaping (Priest) on Feb 10, 2006 at 16:17 UTC | |
|
Re: Defined vs. undefined
by swampyankee (Parson) on Feb 10, 2006 at 19:08 UTC |