in reply to Null in Array

The code you have works properly on undef values:
#!/usr/bin/perl use vars qw(@day); $day[5] = ''; printday(); $day[5]="\n"; printday(); $day[5]=undef; printday(); sub printday { my $len = length($day[5]); if ($len =~ /8/) { print "$day[5]"; } else { print "00:00:00"; } print "\n"; }
outputs:
00:00:00
00:00:00
00:00:00
as expected. So there error is likely to be elsewhere in your code.

Using $len =~ /8/ to see if the length is 8 is very strange. It says "if the string representation of the length contains the digit 8", so will match 8, 18, 3008, 8000000, etc. You probably just want $len == 8.

Replies are listed 'Best First'.
Re: Re: Null in Array
by Pyramid (Initiate) on Jul 29, 2003 at 22:18 UTC
    Thank you for your suggestion to check for errors elsewhere in my code. I did that and now it works!