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

Drew Marshall drew.marshall at trunknetworks.com
Tue Mar 10 13:40:19 GMT 2009


On 10 Mar 2009, at 12:00, Julian Field wrote:
>>>>> Jules
>>>>>
>>>>   And if that doesn't work wouldn't this do the same thing?
>>>>
>>>> my @bodycheck = @{$body};
>>>>
>>> This will involve making a copy of the entire message in
>>> memory. *Very*
>>> expensive thing to do, need to avoid this at all costs.
>>>> for ($i=(@bodycheck-1);$i>= 0; $i--){
>>>> 	last if @bodycheck[$i] =~ /^\s*$/;
>>>>
>>> you don't really mean @bodycheck[$i] do you? Surely you mean
>>> $bodycheck[$i]?
>>>> 	print "Line is ****". at bodycheck[$i]."****\n";
>>>> 	pop @{$body};
>>>> }
>>>>
>>> So yes, it would do the same thing, but it will take a hell of a lot
>>> longer to do, and will use a lot more memory too.
>>>> Rick
>>>>
>>>>
>>
>> Well really I doubt the need to make the copy, just seems somehow  
>> wrong to
>> use a for loop on something that we are shortening with each  
>> iteration but
>> since the loop is bottom up and the pop is from the bottom you  
>> could just
>> use $body because you are effectively just operating on the last  
>> item at a
>> given moment.
>>
>> And, pardon my lack of ability to wrap my head around perl's  
>> handling of
>> arrays (yes I don't care what perl thinks, a hash is an associative  
>> array so
>> it should be able to be addressed directly by index or by key  
>> without all
>> the machinations) I think I would then mean
>>
>> for ($i=(@{$body}-1);$i>= 0; $i--){
>> 	last if @{$body}[$i] =~ /^\s*$/;
>>
> You can't do @array[$index] to access the index'th element of array.
> You mean $body->[$i] I *think*. I must admit I get a bit lost in all  
> the
> redirections at times myself :-)
>
> for ($i=(@{$body}-1); $i>=0 $i--) {
>   last if $body->[$i] =~ /^\s*$/;
>   pop @{$body};
> }
>
> definitely looks possible.
>
>> 	print "Line $i is ****".@{$body}[$i]."****\n";
>> 	pop @{$body};
>> }
>>
>> If we are trying to do this by index->value not key->value. Again I  
>> am
>> assuming the point is to pop off the body info from the end forward  
>> until
>> reaching either a blank line or a line of nothing but white space.
>>
>> ??
>>
>> Rick


Ok, I'm lost but as and when you would like me to do something, don't  
hesitate to shout :-)

Drew


More information about the MailScanner mailing list