hello all, I have written a small subroutine and there seems to be some error in passing my variables to the subroutine. I am probably making an easy mistake in syntax, or it has to do with scope and private variables etc? Any help would be appreciated. Below is the part of the script related to the subroutine. In the subroutine the variable $proph is now =1 ?.
########### subroutine get host and taxid ### sub getDetails { my $proph=@_; my $host;my $taxid;my $genNum_proph; print "$proph\tproph inside sub"; my @proph_columns=split(/\_/,$proph); # get host info if ($proph_columns[0] =~ /^FP92/){ $host=$proph_columns[0]; } else { $host=join("_",$proph_columns[0],$proph_columns[1]); } if ($host =~ /^NZ/){ ## for wgs genomes just match first 7 cha +racters as only NZ_XXXX000000 are in tax2locus my $host=substr $host, 0, 7; } print "$host\t"; #get taxid my ($matching_key)= grep { /^$host/ } keys %tax2loc; $taxid=$tax2loc{$matching_key}; ## get number of proteins in the prophage if (exists $genesPerProphGen{$proph}){ $genNum_proph=$genesPerProphGen{$proph}; } else{ print "$proph doesn't have number of genes\n" } return($host,$taxid,$genNum_proph); } ##### Now make table with numbers ##### my $shared_table="$mci_file.sharedTab"; my $genNum_prophA;my $genNum_prophB;my $host_prophA;my $host_prophB; open (OUTs,">$shared_table"); print OUTs "# This table was generated using $0 on\t".scalar(localtime +(time))."\n"; print OUTs "#".join("\t",qw(Proph_genomeA Proph_genomeB hostA taxidA h +ostB taxidB Jacc Prots_Shared Protsin_prophA Protsin_prophB))."\n"; foreach my $prophA (keys %$overlap){ print "$prophA\tfrom overlap\t"; my($hostA,$taxidA,$genNum_prophA)=&getDetails($prophA); foreach my $prophB (keys %{$overlap->{$prophA}}){ my($hostB,$taxidB,$genNum_prophB)=&getDetails($prophB) +; my $A_notShared=$genNum_prophA-$overlap->{$prophA}{$pr +ophB}; my $B_notShared=$genNum_prophB-$overlap->{$prophA}{$pr +ophB}; my $Jac_denom=$overlap->{$prophA}{$prophB}+$A_notShare +d+$B_notShared; my $Jac=$overlap->{$prophA}{$prophB}/$Jac_denom; print OUTs join("\t",$prophA,$prophB,$host_prophA,$tax +idA,$host_prophB,$taxidB,$Jac,$overlap->{$prophA}{$prophB},$genNum_pr +ophA,$genNum_prophA)."\n"; } } close(OUTs);
FP929058_PFPR05 from overlap 1 proph inside sub1_ 1 does +n't have number of genes

In reply to passing variables to a subroutine by AWallBuilder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.