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

Hy there When I execute the Script Perl complains: "Global symbol "$t_client_types" requires explicit package name at Class_t_clients.pm" even though I declared the variable "$t_client_types" with 'our' in the Main Script. Can someone explain this behaviour to me ? Thank's Denis
------- Main Script ------- #!/usr/bin/perl -w use strict; use warnings; use Class_t_client_types; our $t_client_types = Class_t_client_types->new(); # ^^^ # I'm using 'our' to make '$t_client_types' globally # available in the main Script. (...) ----- Package ----- package Class_t_client_types; sub inventory { my $self = shift; my $ip = shift; my $id_t_macaddrs = shift; my $id_t_clients; # inventory client_types my $id_t_client_types = $t_client_types->inventory(); # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # Perl complains: Global symbol "$t_client_types" requires exp +licit package name at Class_t_clients.pm # this will teturn noop if the client is not yet inventorized my $id_t_status = $query->get_id_t_status_by_id_t_macaddrs($id +_t_macaddrs); # inventory $id_t_clients = cast2db::Class_t_clients->find_or_create( # GLOBAL VARIABLE id_t_macaddrs => $id_t_macaddrs, ip => $ip, id_t_client_types => $id_t_client_types, id_t_status => $id_t_status, ); # set time use POSIX qw(strftime); my $inventory_date = strftime "%Y-%m-%d", localtime; my $inventory_time = strftime "%H:%M:%S", localtime; $id_t_clients->inventory_date($inventory_date); $id_t_clients->inventory_time($inventory_time); $id_t_clients->update; return $id_t_clients; }

Replies are listed 'Best First'.
Re: Strange Problems wit Class::DBI
by almut (Canon) on Nov 10, 2008 at 09:43 UTC

    Is your package in a separate file? If so, then this is expected behavior, as our is lexically scoped, and the lexical scope of the main script ends at the end of the file.

    Personally, if I really wanted to have a global variable, I would just use the fully-qualified notation instead: $::id_t_client_types (or $main::id_t_client_types, which might better hint at what's going on).

      Thank's a lot Sorry, I was in a state of mental derangement in other parts of my Script I had allready used '$::' aka '$main::' before but later on I forgot about it and I wasted 2 days with googling for a solution. ;.) Hollydays might be a good solution.