Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Help with code

by myocom (Deacon)
on Jul 17, 2001 at 22:31 UTC ( [id://97404]=note: print w/replies, xml ) Need Help??


in reply to Help with code

The problem is that you have blindly put in 'my' to keep strict happy. Unfortunately, you did so *everywhere*, including places where it isn't appropriate. The key bit that's causing your current problems is this:

foreach my $subdir (my @dirlist) { #...

The my @dirlist creates a new (and empty) @dirlist. You mean to refer to the one you tried to create earlier with this bit:

my @iresdir = readdir IRESDIR; foreach my $dir (@iresdir) { push (my @dirlist, $dir); } closedir IRESDIR;

...however, that code also has an error. The code "push (my @dirlist, $dir);" pushes the current $dir onto a lexically scoped @dirlist. The problem is that the scope for @dirlist goes away once you hit that next closing brace on the next line. So effectively, you push the directory onto an array, then throw the array away.

I suggest two things. One, read up on scoping. In particular, Dominus' Coping with Scoping article. Two, you're reinventing the wheel here. It would be best to use File::Find for this sort of thing.

Replies are listed 'Best First'.
Re: Re: Help with code
by speedo (Initiate) on Jul 18, 2001 at 18:15 UTC
    Thanks for suggesting the reference "Coping with Scoping". It was both informative and easy to read. Now that that problem is cleared up I can see that my program is crashing in the last foreach block. This is the error message I will get:
    MSG: unable to parse location successfully out of UO3722.1:1..548, ignoring feature (seqid=MMKCNAS2) ______________ Can't call method "location" on an undefined value at /usr/local/lib/perl5/site/5.6.1/Bio/SeqIO/FTHelper.pm line 136.
    Now what does that mean? And is it the first or second problem that is causing the code to be aborted? Thanks again for your help, speedster.

      In general, messages like "Can't call method "location" on an undefined value ..." mean that you are trying to call a method on an object that doesn't exist (either you haven't created it with its constructor or the object has been destroyed). In this case, it appears that the code that is trying to call a method is in one of the Bio::SeqIO modules. That doesn't rule your code out entirely, but it does make it harder to track down the problem. You might check the docs for that series of modules to see if there are any hints there.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-19 18:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found