snowy has asked for the wisdom of the Perl Monks concerning the following question:

Still very much a newbie to Perl and programming in general and finding this a bit of a challenge

I have the following bit of code and either get an uninitalised value in the print command or in the match statement.

Why?

#! usr/bin/perl use warnings; use strict; my @allrecords; my $record; my $beginning_annotation; my $ending_annotation; my $alignment_section; unless (open (BLAST, "result.fasta")){ print "Can not open data file \n"; exit; } $/ = "BLASTP 2.2.3 [Apr-24-2002]"; @allrecords = <BLAST>; foreach $record (@allrecords){ ($beginning_annotation, $ending_annotation, $alignment_section, $re +cord) = @_; ($$beginning_annotation, $alignment_section, $$ending_annotation) = ($record =~ /(.*^ALIGNMENTS\n)(.*)(^ Database:.*)/ms); print $beginning_annotation; } exit;

I have checked that the seperator works

Thanks in advance

Catherine

Replies are listed 'Best First'.
Re: Uninitalised Values - What does it mean?
by thelenm (Vicar) on Jun 19, 2002 at 15:54 UTC
    Inside your foreach loop, you're assigning a list of variables from @_. But if this code is your entire program, it looks like there is nothing in @_. Did you mean @ARGV? Or did you mean something like split ' ', $record?

    Since there was nothing in @_ when you assigned several variables to its contents, all those variables are still uninitialized. So when you try to perform a match on $record, you get a warning, as well as when you try to print $beginning_annotation (you did use warnings and strict, which is definitely good :-)

    Another thing I noticed: did you mean to have double dollar-signs on $$beginning_annotation and $$ending_annotation?

    -- Mike

    --
    just,my${.02}

(jeffa) Re: Uninitalised Values - What does it mean?
by jeffa (Bishop) on Jun 19, 2002 at 16:04 UTC
    I am going waaaay out on limb here, but i would rather spend my energy learning how to use bioperl instead of debugging a hand rolled parser. Check out their excellent tutorial if have not already. We can still help you with this problem, but please provide some sample data for us to work with.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: Uninitalised Values - What does it mean?
by ckohl1 (Hermit) on Jun 19, 2002 at 15:51 UTC
    You could stop the warning that you are seeing by moving your variable declaration inside your loop, and/or initializing the variables before you actually attempt to assign an unknown value to the variables (e.g. $record = '';).

    Chris
Re: Uninitalised Values - What does it mean?
by Gilder (Initiate) on Jun 19, 2002 at 17:46 UTC
    When you open a file the way he is, do you need to use a redirect?
    unless (open (BLAST, "<result.fasta")){ print "Can not open data file \n"; exit; }
    I prefer opening files this way:
    open BLAST, "<result.fasta" or die "Can not open data file: $!\n";
    You may try adding a print statement in the foreach loop to print $record to make sure it has the data you want in it.
      There are many ways to deal with open failures. Yours is more common than his, but that doesn't make one better than the other. Your messages appear on STDERR, his on STDOUT. You exit with a failure status, he exits successfully.

      Just use whatever works best for you.

      Abigail

Re: Uninitalised Values - What does it mean?
by Pug (Monk) on Jun 19, 2002 at 15:41 UTC
    One thing that may help is if you give some sample data.
    --
    Eric