[Bioperl-l] commandexts and array refs bug - found problem, not sure of best fix

Chris Fields cjfields at illinois.edu
Thu Jun 10 14:58:56 UTC 2010


On Jun 10, 2010, at 8:43 AM, Ben Bimber wrote:

> hello,
> 
> a little while ago i posted a bug about commandexts when you pass an
> array ref.  when you pass an arrayref of files, instead of a string
> with 1 file, you get an error saying 'cannot use string '......' as an
> array ref while strict refs in place'.  i believe i understand the
> bug, but am not entirely sure the best way to fix it.  here's the
> original code from commandexts.pm, starting line 989:
> 
>    my @files = @args{@specs};
>    # expand arrayrefs
>    my $l = $#files;
>    for (0..$l) {
> 	if (ref($files[$_]) eq 'ARRAY') {
> 	    splice(@files, $_, 1, @{$files[$_]});
> 	    splice(@switches, $_, 1, ($switches[$_]) x @{$files[$_]});
> 	}
>    }
> 
> It throws the error on the second splice().  The reason is b/c
> $files[$_] isnt an array ref anymore, b/c we just expanded it in the
> line before.  Truthfully, I dont entirely understand why we're
> expanding out @switches for each file.  Maybe i'm missing something
> obvious, but why would we want these copied?

Maybe @file and @switches are in-sync and thus need similar expansion?  Not sure, personally.

> however, there's couple ways around it:
> 
> 1. save the value of  @{$files[$_]} by adding: my @tmp =
> @{$files[$_]};, then using @tmp on that line
> 2. put the second splice() before the first
> 3. if the idea is actually to expand @switches against every file,
> then move this outside the for loop

The first one seems safest.  The real question is, do any of these solutions work?  Do any of the modules requiring the command extensions in bioperl-run show problems, for instance?

> I originally posted that this could be fixed by surrounding the
> problem line with 'no strict'/ 'use strict'; however, that really only
> worked b/c the command I was using did not actually have any switches.
> I doubt it would work properly if your command had them.
> 
> -Ben

I think, if one of the proposed solutions works, pick which you think is the best and go with it.  Test it out, then we can commit this to github.  

BTW, sorry about the warnocking, a number of us (myself included) have been extremely busy as of late.

chris



More information about the Bioperl-l mailing list