0

my problem is that i'm getting no Output at the end of Script.. All the prints while parsing are ok, but arrays at end are empty.

What i'm doing wrong? Isnt this the way to handle the refs?

thx 4 response

my %branches = ();
print "<pre>";
my %tmp_branch;

while (defined($_ = shift @bugs)) {
    my $bug_id = $_->id;
    my $bug_product = $_->product;
    my $content = $browser->get("http://****?ticket=".$bug_id);
    $content = $content->decoded_content;

    my @rows = split /\n/, $content;
    my $trigger = 0;

    while (defined($_ = shift @rows)) {
        chomp;
        if ($_ eq "") {
            $trigger = 0;
        }
        elsif (/Branch: (.*)/) {
            if (exists $branches{$1}) {
                my $branch_ref = $branches{$1};
                %tmp_branch = %$branch_ref;
                print "existing Branch: $1\n";
            } else {
                my %new_branch = ();

                my @sources = ();
                my @wfs = ();
                my @methods = ();

                $new_branch{'sources'} = \@sources;
                $new_branch{'methods'} = \@methods;
                $new_branch{'wfs'} = \@wfs;

                $branches{$1} = \%new_branch;
                %tmp_branch = %new_branch;
                print "new Branch: $1\n";
            }
        }
        elsif (/Sourcen.*:/) {
            $trigger = "sources";
        }
        elsif (/geaenderte Methoden.*:/) {
            $trigger = "methods";
        }
        elsif (/geaenderte Workflows.*:/) {
            $trigger = "wfs";
        }
        elsif ($trigger && $_ ne "") {
            my $tmp_array_ref = $tmp_branch{$trigger};
            my @tmp_array = @$tmp_array_ref;
            push @tmp_array, $_;
            print "find $trigger: $_\n";
        }
    }
}

print "\n\n\n";

while (my ($k,$v)=each %branches){
    my $branch_ref = $v;
    my %tmp_branch = %$branch_ref;
    my $sources_ref = $tmp_branch{'sources'};
    my @sources = @$sources_ref;
    my $methods_ref = $tmp_branch{'methods'};
    my @methods = @$methods_ref;
    my $wfs_ref = $tmp_branch{'wfs'};
    my @wfs = @$wfs_ref;

    print "Branch: $k\nSources:\n";
    print @sources;
    print "\nMethods:\n";
    print @methods;
    print "\nWorkflows:\n";
    print @wfs;
    print "\n";
}

print "</pre>";

Sample Input:

    Kontext Auswertung fuer Ticket: #12345 (xxxxSomeTextxxx)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    HINWEIS: xxxxSomeTextxxx

    Branch: HEAD
    ~~~~~~~

    Sourcen (4):
    IamArow
    IamArow2
    IamArow3
    IamArow4

    geaenderte Methoden (1):
    IamArow

    geaenderte Workflows (2):
    IamArow
    IamArow2
n0script
  • 3
  • 2
  • 1
    Without input data, this is hard to understand. Are you using `strict` and `warnings`? You should not assign stuff to `$_`, use a normal variable instead. Are you trying to parse a bugzilla or jira? – simbabque Dec 17 '13 at 09:45
  • 2
    I suggest you use Data::Dumper to look at your variables in the `while`-loop as the program runs. Probably you are losing them somewhere. – simbabque Dec 17 '13 at 09:48
  • Ye, the script is inside ur Bugzilla ;) But it only checks ID and Product. The input comes from and external Servlet we are using to see changings in sources, methods and workflows Sample Input is : Branch: HEAD ~~~~~~~ Sourcen (2): SomeTextBlablubThisisARow SomeTextBlablubThisisARow geaenderte Methoden (3): SomeTextBlablubThisisARow SomeTextBlablubThisisARow SomeTextBlablubThisisARow geaenderte Workflows (4): SomeTextBlablubThisisARow SomeTextBlablubThisisARow SomeTextBlablubThisisARow SomeTextBlablubThisisARow – n0script Dec 17 '13 at 09:58
  • Without line breaks, this makes no sense. Please [edit] your question and add the sample input. – simbabque Dec 17 '13 at 10:16
  • sry cant put newline in this comment, and new answer only every 8 hours :/ But tobyink's Answer looks like the Problem i have – n0script Dec 17 '13 at 10:56
  • That's why I said you should [edit] the post. I even gave you the link to [edit] it. Here it was again. ;-) You should read the [faq] if you are having trouble using Stack Overflow. – simbabque Dec 17 '13 at 11:48
  • woops, didnt realise that :P sry, was my first time asking here ^^ – n0script Dec 17 '13 at 14:07

1 Answers1

2

It's quite hard to figure it out without any input data, because it means that we can't run a copy of the script on our own machines! It is generally pretty useful if your sample code is self-contained!

That said, I think your problem stems from doing this kind of thing:

my $branch_ref = $branches{$1};
%tmp_branch = %$branch_ref;

The second line does a shallow copy of the hash, so %tmp_branch is no longer the same hash as the one referenced by $branches{$1}. When you add data to the %tmp_branch hash, you are not adding data to the $branches{$1} hash.

@tmp_array suffers similarly.

tobyink
  • 13,478
  • 1
  • 23
  • 35
  • thank you so much, made my day ;) fixed it by pushing directly to the ref with "push @$tmp_array_ref, $_;" – n0script Dec 17 '13 at 11:38