Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hello Monks,

It seems I got some kind of Heisenbug. In my code, there seems to be something wrong, but I can not track it down by debuging. I got a working peace of code. Now, as I want to extend the functionality it seems that variables turning to be defined / undefined depending if going into and return from a subfunction.

It looks like this:

package DATABASE_ANALYSIS; use strict; use warnings; use diagnostics; use DBI qw(:sql_types); use DBD::SQLite; use ITF::ErrorHandling; use vars qw($VERSION $HEADER @ISA @EXPORT); use Exporter; $VERSION = q$Revision: 0.0.1 $; $HEADER = q$Header: DATABASE_ANALYSIS$; @ISA = qw(Exporter); @EXPORT = qw( ConnectToDatabase($) GetDBContent Disconnect GetParent ResolveContainer ); my ( $comp_by_pac, $container_by_pac, $containers, $src_by_comp, $src_by_test, $xml_structure, $analyzed_comps, $root_dir, $project_root, $PAC_by_Id, $COMP_by_Id, $TEST_by_Id, $COMPs_by_Name, $REL_by_Parent, $REL_by_Child, $dbh ); sub ProcessContainers { my $start_container = $_[0]; my $container; #Process PAC or COMP if given. if ( not defined $start_container ) { $start_container = $PAC_by_Id->{1}{'Name'}; } #If no token is given on command line, then the project name is #taken as standard token - script dies in case it does not exist die "Could not find Project name, try to provide project name (PAC) as tok +en! --token=MyProjectName " if ( not defined $start_container ); #Resolve all subsequent appearing PAC and STCOMP to COMPS #Background: COMPS can directly resolved to SourceFiles # 1. Get starting contianer # 2. Resolve subsequent containers if ( exists $container_by_pac->{$start_container} ) { $container = ${ $container_by_pac->{$start_container} }; } elsif ( exists $containers->{$start_container} ) { $container = $containers->{$start_container}; } #Add to xml structure $xml_structure->{$start_container} = $container; ResolveContainers($container); } sub ResolveContainers { my $start_container = $_[0]; goto COMPPROCESSING if ( ref $start_container eq 'HASH' ); foreach my $item ( @{$start_container} ) { if ( ( $item->[1] eq 'PAC' ) or ( $item->[1] eq 'STCOMP' ) ) { #Recursive analysis ResolveContainers( ${ $container_by_pac->{ $item->[0] } } +); } else { #Add Element to comps list $analyzed_comps->{ $item->[0] } = $item; } } return; COMPPROCESSING: #Add Element to comps list $analyzed_comps->{ $start_container->{'Name'} } = $start_container +; return; }
Notice the global variables in the package. They are defined by calling other functions not put into this code collection here.

However, I am calling the ProcessContianer sub with appropriate parameter. Most important here, it is initializing the $xml_structure variable at the end. I can verify the values in the Eclipse-Debugger (EPIC plugin) and all looks fine!. Then I am calling the ResolveContainers sub. Once I am inside this function all globals (to this package) turning to undef but one $container_by_pac. Even the variable I was passing to the subfunction is listed as undef. Doing a print in the debugger is also giving me nothing -> undef.

However, once in the called ResolveContainer sub I assign the parameter which is listed as undef to the $start_container variable. It works perfect. There are all expected values. How comes it that way?

Any help is appreciated!

Best regards! Tobias

In reply to package variables turning suddenly to undef and back again depending on subfunction call by tobias_hofer

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the monks are chillaxin'...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (3)
    As of 2018-02-23 01:18 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (300 votes). Check out past polls.