Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
Keep It Simple, Stupid
 
PerlMonks  

Re: matching problem

by linuxer (Deacon)
on Feb 24, 2013 at 20:10 UTC ( #1020420=note: print w/ replies, xml ) Need Help??


in reply to matching problem

Apart from the bad format of the data section:

You declare $locus_acc_no, but you don't initialize it; therefor it stays undefined.

In your while-Loop you provide this undefined value as argument to ModuleMatching::MatchLAC() which tries a pattern matching against that value.

$locus_acc_no is intentionally undefined, so the warning is correct. You are using an undefined value within a pattern matching.

So, what exactly are you wondering about?


Comment on Re: matching problem
Select or Download Code
Re^2: matching problem
by Balaton (Initiate) on Feb 24, 2013 at 22:41 UTC
    Thanks Linuxer, Here are my changes, now the program finishes and I have no error message but I only have the locus_acc_no = printed out several times and it has no value. Thanks, B
    #!/usr/bin/perl -w use strict; use warnings; use lib "/d/user2/aszend01/BCII/240213"; use ModuleMatching; my $locus_acc_no = ""; my $key = 1; print '$key = ', $key, "\n"; # test for not allowing more than one file to work on unless (1 == scalar(@ARGV)){ die "two many files"; } # test if the infile cannot be opened open(IN, $ARGV[0]) or die "unable to open input file $ARGV[0]\n"; while (my $line = <IN>) { # give the number of records a new key number started with 1 incre +mented with 1 in each new record devided with "//" signs if ($line =~ /^\/\//){ $key++; print '$key = ', $key, "\n"; $locus_acc_no = ""; } # locus_acc_no if ($line =~ ModuleMatching::MatchLAC($locus_acc_no)) { print "locus_acc_no ", $locus_acc_no; # print $2, "\n"; # $hLocus_Acc{$key} = $1; # print "%hLocus_Acc{$key} = $1\n"; # $hLength{$key} = $2; # print "%hLength{$key} = $2\n"; } }
      I only have the locus_acc_no = printed out several times and it has no value.

      Use a text editor, and do a search on $locus_acc_no. You will see it occurs 4 times in the code:

      1. my $locus_acc_no = "";
        Here it is declared and initialised to the empty string.

      2. $locus_acc_no = "";
        Here (within an if block) it is conditionally re-set to the empty string.

      3. if ($line =~ ModuleMatching::MatchLAC($locus_acc_no)) {
        Here it is passed into1 the function ModuleMatching::MatchLAC.

      4. print "locus_acc_no ", $locus_acc_no;
        Here its value is printed.

      So it is never set to anything but the empty string, which is what gets printed! This is essentially the same point already made by linuxer, above. You fixed the warning but failed to address the underlying logic problem.

      I don’t know anything about the ModuleMatching module, which I can’t find on CPAN, but I think it’s highly unlikely that this line:

      if ($line =~ ModuleMatching::MatchLAC($locus_acc_no)) {

      can be correct. But without knowing what sub ModuleMatching::MatchLAC is supposed to do, it’s hard to give advice.

      Hope that helps,

      1Since Perl uses pass-by-reference, it is possible that ModuleMatching::MatchLAC sets the value of $locus_acc_no; except that MatchLAC receives no information to use in determining the new value.

      Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-04-17 22:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (458 votes), past polls