The first error means the value against which you are matching is undef. The value against which you are matching is data_verify's first argument. That situation is not possible in the code you posted.
There are numerous places where undefined could be passed to data_verify in the code on your scratchpad.
The second error is caused by your use of the $/ in your pattern while that variable is undefined. m{s/\s*$//}xms means
Obviously not what you wanted. For starters, you wanted to do a substitution rather than a match. m{s/\s*$//}xms should be just s/\s*$//.
sub data_verify { my @data = shift; my $loop_count = 0; while (@data) { $data[$loop_count] =~ s/^\s*//; $data[$loop_count] =~ s/\s*$//; $loop_count++; } return @data; }
By the way,
is equivalent tosub data_verify { my @data = shift; my $loop_count = 0; while (@data) { $data[$loop_count] =~ s/^\s*//; $data[$loop_count] =~ s/\s*$//; $loop_count++; } return @data; }
sub data_verify { my $data = shift; $data =~ s/^\s*//; $data =~ s/\s*$//; return $data; }
Based on the code in your scratchpad, you want to process multiple values per call. What you really want is
sub data_verify { my @data = @_; for (@data) { s/^\s*//; s/\s*$//; } return @data; }
In reply to Re: Returning and passing data to and from subroutines
by ikegami
in thread Returning and passing data to and from subroutines
by vendion
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |