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

Hi all, I'd very much like to use the perl string length function, but my script is throwing an error which indicates my global symbol requires explicit package name. Is there a perl module I need to include to use the perl string length function? Alternately, how would I find the list of perl include modules available, and determine where in these include modules the string length function is located? please/thanks, Tracy Wiseman, software engineer, Silicon Valley
  • Comment on what perl module to include to use string length function?

Replies are listed 'Best First'.
Re: what perl module to include to use string length function?
by NetWallah (Canon) on May 08, 2015 at 00:16 UTC
    Welcome to the Monastery!

    "global symbol requires explicit package name" is a result of "use strict;".

    You can correct that by declaring the variable in question like:

    my $variable;
    Perl has a built-in "length" function that returns the string length. No Module is necessary.
    my $length = length($variable);
    There are a TON of modules - we do not refer to them as "include" modules in Perl.

    These are available at CPAN.

    There are also a number of modules that come pre-installed with a Perl distribution.

    If you have questions with coding, it would help immensely if you posted a code sample, using <code> tags.

            "You're only given one little spark of madness. You mustn't lose it."         - Robin Williams

Re: what perl module to include to use string length function?
by toolic (Bishop) on May 08, 2015 at 01:14 UTC
Re: what perl module to include to use string length function?
by davido (Cardinal) on May 08, 2015 at 13:40 UTC

    ...my script is throwing an error which indicates my global symbol requires explicit package name. Is there a perl module I need to include to use the perl string length function?

    No. This is just a matter of learning how to program with strictures enabled. Your script probably has use strict; somewhere toward the top. strict does three things (all with the aim of making your life easier as a programmer, and your code more robust): (1), it requires that you pre-declare your variables (strict vars). (2), it requires that you avoid symbolic references; using a variable's contents as a variable name (strict refs). (3) It requires that you not leave barewords laying around (strict subs).

    Your code is failing because you have violated one of the rules that 'strict' enforces; strict vars -- you haven't pre-declared a variable that you are using. This could be an oversight, or it could be a spelling error in your code. Either way, it's a compile time error, and totally unrelated to using length.


    Dave