salmonix has asked for the wisdom of the Perl Monks concerning the following question:

Pacem, Domini!

I receive this error from Encode::Detect::Detector :

Encode::Detect::Detector::handle() -- THIS is not a blessed SV reference at TestEncoding.plx line 19.

The code is simple, almost taken from the man page.

#!/bin/perl -w use feature ":5.10"; use strict; use Carp; use Encode::Detect::Detector; open my $FILE,'TALT432.txt'; my @file=<$FILE>; close $FILE; say get_encoding(@file); sub get_encoding { my @data=@_; my $res; my $enc = Encode::Detect::Detector->new(); my $l; foreach ( @data ) { $enc->handle( $data[$l] ); $l++; } $enc->eof; return $res if $res=$enc->getresult(); }

Versions of modules:

Modules are installed in the user's ~/.perl/ etc. path locally. I have checked the Perl installation with the appropriate Gentoo tools and perl-cleaner, reinstalled the modules in the local path, but nothing changed and my humble knowledge has reached it borders.

Replies are listed 'Best First'.
Re: Encode::Detec::Detector: This is not an SV reference error
by ww (Archbishop) on Sep 29, 2010 at 13:11 UTC

    To expand on Khen1950fx's correct observation, some vars are customarily or (in this case) inherently allowed in specific cases only.

    "Customarily" applies to the likes of $a and $b -- are allowed elsewhere, but, by convention, are reserved for use in sorting. OTOH, $1 is reserved for use in regex capture.

    perl -e "use strict; my $1='foo'; if ($foo=~/(f)/){print $1;}" Can't use global $1 in "my" at -e line 1, near "my $1" Global symbol "$foo" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors.

    Note the problem with $foo above... despite which the attempted illegal use of $1 had precedence with the compiler's error checking.

    And just to beat this deceased equine a bit more, eliminating the $foo issue (and use strict;) leads to this:

    perl -e "my $1='foo'; if ($1=~/(f)/){print $1;}" Can't use global $1 in "my" at -e line 1, near "my $1" Execution of -e aborted due to compilation errors.

    In short, use meaningful variable names... and learn which (tempting) low-keystroke vars are meaningful to Perl.

    Updated penultimate para to acknowledge/highlight the elimination of strict

Re: Encode::Detec::Detector: This is not an SV reference error
by Khen1950fx (Canon) on Sep 29, 2010 at 10:59 UTC
    Just an observation...$1 is global, so you can't use it with 'my'. Also, remember that Encode::Detect::Detector doesn't encode but only decodes, so your sub get_encoding should probably be "get_decoding".
      $1 is global...
      font problem: $1 (one) often looks like $l (lowercase el), but isn't the same...
Re: Encode::Detec::Detector: This is not an SV reference error
by suhailck (Friar) on Sep 29, 2010 at 08:54 UTC
      May be changing the line
      my $l; to my $l=0;
      will help here coz the undefined value of $l is passed at first to the handler method.