On Wednesday, May 1, 2002, at 04:35 , Teresa Raymond wrote:
> I'm trying to test @inlocation to make sure it is not null or filled in
> with a space but although I input via ckbox a value, the error msg is
> returned. I am not comfortable using the while or the $_.
>
> while (length @inlocation)
> {if ($_ eq "" || $_ eq " ")
> {
> print "Error location is required\n";
> }
> }
what I have found is that one should in general avoid
randomly using the $_ - since it is the default
input and pattern-searching space. ( perldoc perlvar )
I tend to do the sorts of things like
while(<STDIN>) {
next if (/^\s*$/); # throw away empty lines
chomp; # run against $_ - why not
my $line = $_ ; # set $line because we want multiple matches
if ( $line =~ /$pat/ or $line =~ /$pat2/) {
# we have our pattern.
}
}
also you might want to check:
perldoc -f length
since you do not want to use it on an @arracy or a %hash.
note:
my @list_shrugged = qw/joe bob brigs/;
my $val = scalar(@list_shrugged);
print "$val for :@list_shrugged:" . length(@list_shrugged) . ": \n";
generates:
3 for :joe bob brigs:1:
which is not what I think you were expecting....
hence what you would want is something like:
my $val = scalar(@list_shrugged);
if ( $val == 1 ) { # possible empty list
my $tmp = pop(@list_shrugged); #funky way to get 'it' off...
$tmp =~ s/\s*//g;
unless( $tmp ){
print "Error must have value";
return;
}
}
# what ever is in @list_shrugged has something in it...
ciao
drieux
---
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]