Interesting Error - Can't use string ("1909") as an ARRAY ref while "strict refs" in use

Rick Cooper rcooper at dwford.com
Sat Mar 7 19:58:19 GMT 2009


 

 > -----Original Message-----
 > From: mailscanner-bounces at lists.mailscanner.info 
 > [mailto:mailscanner-bounces at lists.mailscanner.info] On 
 > Behalf Of Julian Field
 > Sent: Saturday, March 07, 2009 1:08 PM
 > To: MailScanner discussion
 > Subject: Re: Interesting Error - Can't use string ("1909") 
 > as an ARRAY ref while "strict refs" in use
 > 
 > 
 > 
 > On 3/7/09 5:07 PM, Drew Marshall wrote:
 > > Rick
 > >
 > > On 7 Mar 2009, at 16:30, Rick Cooper wrote:
 > >
 > >> Been looking at this and really have no way to test 
 > because I don't use
 > >> postfix but try changing
 > >>
 > >>    while (${@{$body}}[scalar(@{$body})-1] !~ /^\s*$/) {
 > Doesn't scalar(@{$body})-1 need to be $#{@{$body}} or 
 > something like that?
 > As it needs to de-reference $body into an array, and then 
 > take $# of it?
 > $#body won't work as @body is not an array, @{$body} is the array.
 > >>      print "Line is ****" . 
 > ${@{$body}}[scalar(@{$body})-1] . "****\n";
 > >>      pop @{$body};
 > >>      #print STDERR ".";
 > >>    }
 > >>

This is what I get for not tracking everything from the beginning |-(

If I am ready the calls through correctly (now) the ReadyBody function is
call as

	ReadBody(\@original, MailScanner::Config::Value.....

So   my($body, $max) = @_;

Is akin to my $body = \@orignal (I never looked at the top of the function
to see it was $body, not @body)

So

  while (${@{$body}}[$#body] !~ /^\s*$/) {
    print "Line is ****" . ${@{$body}}[$#body] . "****\n";
    pop @{$body};
    #print STDERR ".";
  }


Now I am reading the code as cruise through the body from the last line up
and pop the elements until we get to the first line that begins with white
space. So I created this test (which works) :

my @original = ('1', '2','3', '4', '5');
my $body  = \@original;

  while (${@{$body}}[$#body] !~ /^3$/) {
    print "Checking ****" . ${@{$body}}[$#body] . "****\n";
    pop @{$body};
    #print STDERR ".";
  }

foreach $line(@{${body}}){
 	print "Current Line : $line\n";
}

Running the program outputs

Checking ****5****
Checking ****4****
Current Line : 1
Current Line : 2
Current Line : 3

But now that I look at it, if the original code is just trying to read the
last element anyway, why would you not just ${@{$body}}[-1] which is all
$#body does anyway?

I guess I must be confused, better have some beer.

Rick


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




More information about the MailScanner mailing list