2009/7/28 John W. Krahn <jwkr...@shaw.ca>:

Thanx for gettig back to me.

> Which error?  Copy and paste the error message you are receiving.

Opps sorry. Here you are. Every time I start the httpd I get

 Processing config file: /etc/apache-modperl/conf.d/dev_vhost.conf
Subroutine addItemsToBasket redefined at
/export/web/lib/MyApp/Basket.pm line 347, <DATA> line 238.
Subroutine addItemToBasket redefined at
/export/web/lib/MyApp/Basket.pm line 355, <DATA> line 238.

>
>> This offending code reads a like this:
>>
>>
>> package Some::Pack;
>> ..
>> ..
>>
>>
>> sub addItemsToBasket {
>>  my ($bid, $items) = @_;
>>        foreach my $i (@items) {
>
> Is @items global?  Because you are not declaring it in lexical scope.

Another opps,  that's a typo sorry. It should read
               foreach my $i ( @{$items} ) {

>
>>            addItemToBasket($bid, $i);
>>        }
>> }
>>
>> sub addItemToBasket {
>>   my ($bid, $item) = @_;
>>   ...
>>   ...
>>   # do some work that adds item
>>  }
>
> That is very confusing.  Why do you have two subroutines with almost
> identical names and almost identical functionality?

Yes, in my defence, I found it this way. That's why I am nervous of
removing one or the other. The singular function (addItemToBasket)
expects a single scalar argument in $item. The plural
(addItemsToBasket) expects an arrayref in $item. It loops through and
passes the basket_id ($bid) and the item ($i) to the singular
function.

>> addItems expects an array ref, addItem expects a scalar. I'm sure it's
>> possible to merge the 2 subroutines with the use of `wantarray`
>
> wantarray() is used for the return value of a subroutine, not for the
> arguments a subroutine accepts.

I see.
>
>> or `ref` to see what the 2nd argument is.
>
> Why not just pass a scalar and a list?

Because there is a lot of code and I won't know, until it throws an
error, if there is existing code that passes scalar directly to the
singular function. I'm just worried that I break some existing
functions.

>
> sub addItemsToBasket {
>    my ( $bid, @items ) = @_;
>
>
>> I'm a bit nervous of doing that
>> because if I remove one of the subs, there might be a bit of code
>> somewhere that still refers to it. grep -r might help but still I am
>> uneasy with the thought. I'd appreciate any strategy that might help
>> with this.
>>
>> My question though is why the warning?
>
> Earlier you said it was an error?  And what exactly is it?
>
>
>> Is it simply the order in which
>> the subroutines are placed within package? My experiments would say
>> not.
>
> Are you using parentheses every time you use these subroutines?

As far as I know, yes. Certainly wherever I have called the fucntions I have.

Thanx,
Dp.

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to