Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Use of uninitialized value in concatenation (.) or string

by P0w3rK!d (Pilgrim)
on May 20, 2003 at 14:21 UTC ( #259459=perlquestion: print w/replies, xml ) Need Help??

P0w3rK!d has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I have a piece of code calls a function in a module A. That function calls a function in module B along with using one of the global variables in module B as an argument to that function.

package Foo::A; use 5.008; use strict; use warnings; require Exporter; #use AutoLoader qw(AUTOLOAD); use Carp; use Foo::B ':all'; our @ISA = qw(Exporter); @EXPORT or @EXPORT_OK our %EXPORT_TAGS = ( 'all' => [ qw( aMethod ... ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw(); our $VERSION = '1.00'; ... sub aMethod { bMethod("$OURVAR test data"); } ... 1; __END__ ############################################3 package Foo:B; use 5.008; use strict; use warnings; require Exporter; #use AutoLoader qw(AUTOLOAD); our @ISA = qw(Exporter); our %EXPORT_TAGS = ( 'all' => [ qw( bMethod $OURVAR ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw(); our $VERSION = '1.00'; # something like this sub bMethod { my $foo = shift; print "$foo\n"; } ... 1; __END__
The error is as follows:

Use of uninitialized value in concatenation (.) or string at C:/Perl/site/lib/Foo/B.pm line 141.

The error refers to the $OURVAR which is exported by the "B" module along with the bMethod().

Why am I getting this error? How do I fix it?

Thank you :)

-P0w3rK!d

Replies are listed 'Best First'.
Re: Use of uninitialized value in concatenation (.) or string
by japhy (Canon) on May 20, 2003 at 14:28 UTC
    You never defined $OURVAR. Put something in it, or it will remain uninitialized.

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

      Funny. I thought I replied to this. ...

      I put in a request to fix the code example. For some reason, my cut+paste failed when I copied things over in the "real" module. The code you see is just an example of the problem. Nonetheless, I fixed the "real" problem.

      And yes...it is a warning.

      Thanks :)

      -P0w3rK!d

Re: Use of uninitialized value in concatenation (.) or string
by Joost (Canon) on May 20, 2003 at 14:43 UTC
    Why am I getting this error? How do I fix it?

    • <pedantic>It's not an error, it's a warning</pedantic>
    • use our $OURVAR = "somevalue" in module B
    perldiag or use diagnostics; will probably help you.

    Joost

    -- #!/usr/bin/perl -np BEGIN{@ARGV=$0}s(^([^=].*)|=)()s; =Just another perl hacker\
Re: Use of uninitialized value in concatenation (.) or string
by KPeter0314 (Deacon) on May 20, 2003 at 14:48 UTC
    Japhy is right, initialization is the key.

    I sheepishly admit I come from the old school where declaring variables is necessary. A sideline from starting as a COBOL, RPG, and Transact programmer. It became a habit and use strict; requires it. See Perldoc strict for more info.

    This will get you there:

    use vars qw($OURVAR) = ();
    Add other variables inside the parens to initialize them too.

    -Kurt

      Read the code again. use strict; is everywhere.
      Thanks :)
        What is meant is that use strict; requires that variables be initialized.

        To quote from the perldoc:strict where strict vars is implied by not specifying what to be strict about:

        "strict vars" This generates a compile-time error if you access a variable that wasn't declared via "our" or "use vars", localized via "my()", or wasn't fully qualified.
        The use vars qw($OURVAR) = (); pragma actually declares the variable $OURVAR and initializes it to a known null value instead of leaving it uninitialized. Perl cares about the difference.

        -Kurt

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://259459]
Approved by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2019-12-11 13:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?