Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^4: Shift returning pointer

by rgb96 (Acolyte)
on Mar 16, 2009 at 18:56 UTC ( [id://750987]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Shift returning pointer
in thread Shift returning pointer

Okay, I figured out where my problem is. here it is.

push @{$EnvsToRun->{data}}, [$environment, $duration, $config];

When I try to add it to a list with 3 columns, I get the array ref, but if I take the square brackets off, I get three separate entries, with the variable argument in the first column of each entry with they other two as 0s. If I use the brackets, I get the array ref, and then the other two columns are fine. I've tried a few combos of parantheses and brackets, but the brackets seem to be the only things that matter.

Replies are listed 'Best First'.
Re^5: Shift returning pointer
by bellaire (Hermit) on Mar 16, 2009 at 19:04 UTC
    You're confusing me. Once again, you're showing me half of your code (the assignment part this time), and not the part where you are getting the values out. This is new code, and I'm a little frustrated that you say you've found the problem, and it's in code you never showed us. Are you trying to say that $environment is an array ref, but otherwise your code works fine? That's what my previous reply was attempting to fix. I didn't mean for you to take away all brackets everywhere, especially considering I've never seen this line of code before. Would you care to post a more complete code sample?

      Sorry, the whole program is 1000+ lines. I'll try to be more clear. I have two tree views, and I want a person to be able to select an element from one, press a button, and have that element to be added the second treeview on the right. Below are the declarations for both lists, The first is $Envs, the second is $EnvsToRun. Also, where I fill the first list, get the element that I want to put into the second list, and where I add the element to the second list. $duration and $config are variables that I am not having problems with.

      $Envs = Gtk2::Ex::Simple::List->new_from_treeview ( $abaNewWindow->get +_widget('Envs'), 'Environments' => 'text'); $EnvsToRun = Gtk2::Ex::Simple::List->new_from_treeview ( $abaNewWindow +->get_widget('EnvsToRun'), 'Environments' => 'text', 'Duration' => 'd +ouble', 'Config' => 'int'); open(ENVIRONMENTS, "environments.txt"); while(<ENVIRONMENTS>){ my $line = $_; chomp($line); push @{$Envs->{data}}, $line; } close(ENVIRONMENTS); $environment = shift @{$Envs->{data}}; print $environment; push @{$EnvsToRun->{data}}, [$environment, $duration, $config];
        You still left out the portion where you are reading from @{$EnvsToRun->{data}}. The thing to keep in mind here is that $EnvsToRun->{data} is a reference to an array. This array holds one entry per environment. That entry itself is a reference to another, inner array, which has 3 elements. I suspect you are reading it something like this:
        my ($environment, $duration, $config) = @{$EnvsToRun->{data}};
        That's not right, you'll get an array ref in $environment. You forgot that @{$EnvsToRun->{data}} holds many inner lists, each of them with 3 elements in it. To get the first one out by itself, you'd do something like this (note the ->[0]):
        my ($environment, $duration, $config) = @{$EnvsToRun->{data}->[0]};
        In practice, to deal with all of the combinations, you need to iterate over the outer array and then for each item there process the inner array. Like this:
        for my $CurrentEnv (@{$EnvsToRun->{data}}) { my ($environment, $duration, $config) = @$CurrentEnv; ... }
        If you don't want many inner lists, but just the one, you shouldn't be using push at all when assigning to $EnvsToRun->{data}. Instead, a simple assignment:
        $EnvsToRun->{data} = [$environment, $duration, $config]; ... later ... ($environment, $duration, $config) = @{$EnvsToRun->{data}};

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://750987]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-25 13:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found