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

Re^2: Population of HoAoA based on file contents

by state-o-dis-array (Hermit)
on May 22, 2012 at 22:24 UTC ( #971903=note: print w/replies, xml ) Need Help??

in reply to Re: Population of HoAoA based on file contents
in thread Population of HoAoA based on file contents

I'm going to deal with just this section, I think once you understand/update what is happening here, everything else you have will work.
my $id; # ?? foreach my $window ( @{ $data{$id} } ) { # only pass windows with > min number of stats (i.e. >1 for now), an +d # of course we also ignore any 'undef' windows. next unless scalar @{ $data{$id} }[$window] >= 2; foreach my $individual ( keys(%data) ) {
First, I think that you understand that having an undefined $id as a hash key won't work. And to fix this, you want to just rearrange your for loops.
foreach my $id ( keys %data ){ foreach my $window ( @{$data{$id}} ){

Just this will get you much further. There is still a problem with the second loop though, at least in how you use $window in the subsequent code. You are attempting to use $window as an index, but it's not an index. Since you have experience using Data::Printer, I suggest going ahead and checking out what $window is.

Now, the way to fix things with the fewest number of overall edits is to change the second for loop.

foreach my $id ( keys %data ){ foreach my $window ( 0 .. $#{$data{$id}} ){ next unless scalar @{ $data{$id}[$window] } >= 2;
Then in your method calls, just change those to align with the scalar test above:
\@{ $data{$id}[$window] }
I hope that helps.

Replies are listed 'Best First'.
Re^3: Population of HoAoA based on file contents
by iangibson (Scribe) on May 24, 2012 at 19:53 UTC

    Thanks for your further help on this. I feel like I'm almost there, but not quite.. I made the changes you suggested, but I'm still getting errors starting at the line

    next unless scalar @{ $data{$id}[$window] } >= 2;

    The error is:

    Can't use an undefined value as an ARRAY reference

    Is this referring to $window? Regarding the way I was using it above, was $window the outer array that holds all the smaller arrays? Even if this is true, I don't see why I'm getting the error messages I'm getting.

      Hmm, based on your expectation for your data, I'm guessing what you probably need is to add:
      next unless ref( $data{$id}[$window] ) eq "ARRAY";
      just before the line getting the error.

        That appears to have fixed that problem. However, now I'm getting errors from the module:

        Can't call method "isa" on unblessed reference at /usr/local/share/per +l/5.14.2/Bio/PopGen/ line 901, <GEN0> line 182.

        I went back and re-ran my simpler code from earlier (i.e. where I just passed a file without building windows), and I'm now getting a similar error on this too, whereas before it successfully gave me output.

        This is very strange, so I'll have to investigate further to see how to proceed.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://971903]
[Discipulus]: i have a different opinion: automation is always worth: first i can use Perl (and this is good), then later you can reuse parts to automate others tasks. My $boss everytime say:'how much time you spend doing this?' So generally i present a perl solution
[Corion]: Discipulus: Yes, but the chart gives some limits on whether it's really worth spending time for saving your time. If you gain enjoyment, automating is still great, but it doesn't save time ;)
[Discipulus]: Corion are you would able to realize such thing? O_O
[Corion]: In the same vein I have a script that automates Firefox to enter some data into another system. It's not faster than the people using the script if they were to do it manually, but they prefer not having to check the data and not having typos when ...
[Corion]: ... entering the data
[Corion]: Discipulus: I don't know whether I could really do that, but the init process itself mostly launches other processes, and the whole startup is just following a path of dependencies and making sure they are all running. Which basically is what ...
[Discipulus]: when at work my time is (temporarly) owned by the firm, so i do not care (coworkers whatch movies.. I code Perl)
[Corion]: ... make already does, except for files instead of programs. But maybe with some /proc hackery, that could be eliminated and one could use plain make :-D
[choroba]: systemd just makes is asynchronous
[choroba]: so, make -j

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2017-07-27 09:28 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (408 votes). Check out past polls.