Found it:
Here's a bit of code that emulates what should happen:
use strict;
use warnings;
package Text;
sub new
{
my $class = shift;
my $text = shift;
return bless { TEXT => $text }, $class;
}
sub as_trimmed_text
{
my $self = shift;
my $text = $self->{TEXT};
$text =~ s/^\s*(.*?)\s*$/$1/;
return $text;
}
package main;
my @texts = ( Text->new(' foo '), Text->new(' bar '), Text->new(' baz '));
my @trimmed = map { $_->as_trimmed_text() } @texts[1, 2];
print "Trimmed were: ", join(',', map { "'$_'" } @trimmed);
This works, and works fine; I get:
Trimmed were: 'bar','baz'
But if I replace the map with this line:
my @trimmed = map { $_->as_trimmed_text() } @texts[2, 3];
All of a sudden I get this output:
Can't call method "as_trimmed_text" on an undefined value
This is because '3' is outside the range of valid values in @texts, so it autovivifies a new entry, and makes it undef
. Then, your map does
undef->as_trimmed_output()
which barfs. I'd check your array slice again, and make sure that you aren't grabbing values outside the actual indexes available, and barring that, verify that you are actually processing HTML::Element members with that map
. A quick Data::Dumper::Dumper
on the values in @columns
will help immensely.
For example, if you then change your array to contain
my @texts = ( Text->new(' foo '), Text->new(' bar '), ' baz ');
and try to run it, I now get your error:
Can't call method "as_trimmed_text" without a package or object reference at map.pl
So, double check to make sure the contents of your array are actually all blessed instances of the class you're trying to call the method of.