I have a problem with a pattern match. I want to print what the match is whether it be by using $1 or assigning the match to another variable. It seems to be taking a scalar of the value instead of the value and I don't know why unless perl 5.10.1 is an issue

my $procount2 = 1; foreach my $readingframe2(@protein){ my $protein; print "string is $readingframe2\n"; my $fada; if($readingframe2 =~ /MHGR/){ print "$1\n"; ($protein)= $readingframe2 =~ /MHGR/; $fada = length($protein); print "motif is $protein\n"; if($fada >=1){ print "length of motif is $fada\n"; print OUT1 "Protein $procount2\n$protein\n"; $procount2++; } } }

Here is what comes up in the console:

$ perl readingframe.pl Enter file name t.txt Enter output file name o.txt string is MHGRRRRRRRRRRRRRRRRRRRRRRRRRRRRRD_MHGRRRRRRRRRRRRRRRRRRRRRRR +RRRRRRD_ Use of uninitialized value $1 in concatenation (.) or string at readin +gframe.pl line 68, <> line 2. motif is 1 length of motif is 1 string is CMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVTECMAAAAAAAAAAAAAAAAAAAAAAAA +AAAAAVT string is AWPPPPPPPPPPPPPPPPPPPPPPPPPPPPP_LNAWPPPPPPPPPPPPPPPPPPPPPPPP +PPPPP_L

In reply to Regular expression problems by rattytatty

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.