Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Use of uninitialized value in pattern match (m//)

by anaconda_wly (Scribe)
on Oct 31, 2012 at 17:05 UTC ( #1001709=perlquestion: print w/replies, xml ) Need Help??
anaconda_wly has asked for the wisdom of the Perl Monks concerning the following question:

I don't know why below error message(I add it in the comment)

{ package packageA my %hash_map = ( "name" => "path", ......, ); sub new{ ........ } sub get{ my $class = shift; my $componentName = @_; my $path = $component_path{$componentName}; #error: #Use of uninitialized value $path in pattern match (m//) at below... if($path =~ m/HKEY_LOCAL_MACHINE/){ dosomthing; } } }

Replies are listed 'Best First'.
Re: Use of uninitialized value in pattern match (m//)
by choroba (Chancellor) on Oct 31, 2012 at 17:12 UTC
    The key $componentName does not exist in %component_path or is assigned an undef. The reason might be you assign the number of subroutine arguments to $componentName: instead of
    my $componentName = @_;
    you probably meant
    my ($componentName) = @_; # list context
    my $componentName = $_[0];
    or even
    my $componentName = shift;
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      Yes, you both are right. I missed the componentName's value when called. Thanks!
Re: Use of uninitialized value in pattern match (m//)
by Corion (Pope) on Oct 31, 2012 at 17:10 UTC

    What is the value of $componentName, and what are the values of %component_path? The error message suggests that $component_path{ $componentName } is uninitialized, which likely means that the value of $componentName is not what you expect it to be.

    I recommend printing out the value of $componentName.

Re: Use of uninitialized value in pattern match (m//)
by space_monk (Chaplain) on Oct 31, 2012 at 17:22 UTC
    AFAICT, the hash $component_path is not defined in the example you gave, so $path in the get() method will also be undefined, so you are trying to pattern match against an undefined variable.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1001709]
Approved by toolic
[ELISHEVA]: well then since the obvious possible mistakes on my part have been ruled out, SOPW it is.
[ELISHEVA]: the data source, or one of them, is the OECD - they provide a *lot* of data that ought to be easily available to perl programmers.
[erix]: it might be cunning to mention the module in the title... :)
[ELISHEVA]: fancy that - a title that actually describes the problem :-)
[ELISHEVA]: but actually thanks for the reminder
[Discipulus]: DBI::CSV + utf8 = BOO?M
[erix]: in extremis we tend to forget stuff ;)
[ELISHEVA]: \Disciplus : lol
[Discipulus]: and ELISHEVA we waait one your post since ~2years... ;=)
[ELISHEVA]: has it really been that long?

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2017-05-28 20:38 GMT
Find Nodes?
    Voting Booth?