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

Ben Bimber bimber at wisc.edu
Thu Jun 10 09:43:04 EDT 2010


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?

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

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.


More information about the Bioperl-l mailing list