I have a string of many zeroes and '1' but I just want the value of zeroes from the string. So, I use split function to split the '1' but it seems like it will produce the undef or empty string in the array. So, I try to scan through each array element using foreach and compare if there is empty string that i thought was "undef" will be ignored. In return, those in the not empty string will not be ignored and will be placed into another variable. The problems seem like it does not recognized my "undef" variable.
OR there is another better method to scan the string in order to pull off the number of '0' in the string?
Please help out on this matters. This the coding:
#!/usr/bin/perl
use strict;
use warnings;
my $data = '111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000000000000011111
';
my @values = split('1', $data);
my $zero = "0";
foreach my $val (@values)
{
if (!defined$val)
{
$zero= $val;
}
}
print "$zero\n";
exit 0;
Thanks a lot.
Regards, Nicky