That's not what it says for me. For me it says,

String found where operator expected at G:\x.pl line 15, near ""Y" "\n +"" (Missing operator before "\n"?) String found where operator expected at G:\x.pl line 17, near ""N" "\n +"" (Missing operator before "\n"?) Global symbol "$AAGCTT" requires explicit package name at G:\x.pl line + 14. syntax error at G:\x.pl line 15, near ""Y" "\n"" Execution of G:\x.pl aborted due to compilation errors.
Which sounds about right. Let's go through those errors one by one, shall we?

String found where operator expected at G:\x.pl line 15, near ""Y" "\n"" (Missing operator before "\n"?)

Look at that. Perl is even being so helpful as to point out what's wrong with that line. The missing operator it's talking about, would be the comma operator. But why wouldn't you just write that as print "Y\n";?

The next error message? I think you can figure that one out.

Global symbol "$AAGCTT" requires explicit package name at G:\x.pl line 14.

Yep. That regex is never going to work. In regular expressions, $ means "end of string". Surely nothing can appear after the end of a string, right? So Perl's being so liberal as to guess what you meant there, and it thinks you want to match against some variable $AAGCTT. This is why I have asked you whether you want to match against a variable or against a literal string. Turns out neither was the case and you meant ^ there all along, which means "beginning of string". Which would work.

We asked for examples, so that we could understand your problem better. In an attempt to simplify your problem, you kept coming up with contrived sample data like abcdefgabcdefgabcdefg, but the monks here aren't afraid of a little DNA. You could've told us -or shown us, preferably- that you were dealing with data in which you needed to find a specific DNA sequence at a specific location.

Anyway, I digress. The question we should be asking ourselves here is, "do you really need regular expressions?" Well, no. Because i's not really like you're pattern matching. Again, we could've caught this much sooner if you had just answered my question: "yes, muba, I do want to check if a literal string, "AAGCTT" to be precisely, appears at the calculated position in file 2." And I would've told you,

"Well, AnonMonk. That's fairly easy. How about this?

my $substring = "AAGCTT"; read $fhCharacters, $data, length($substring); if ( $data eq $substring) ) {
If you run into any problems, let us know! Good luck."

syntax error at G:\x.pl line 15, near ""Y" "\n""

Perl's being so kind as to point to that line again, in case we missed it the first time around or anything. At the same time, it's not pointing out several other things wrong with your code, so let me do that for you.

You should close your if block with a } before the else keyword, and similarily you should open your else block with a { after that keyword.

From a readability point of view, the indentation of the else keyword is one level too deep. And while we're discussing indentation levels anyway, the my ($strand, $chr, $position)... line should go one level deeper. These are just cosmetic issues, of course, but in the long run you really profit from picking up the good habits right from the start.

Speaking of good habits, your script should begin with the lines use strict; and use warnings;. You might want to move your top line down two lines.

Apply these fixes, and let us know how that works out for you.


In reply to Re^3: matchin a pattern 250 characters up and down stream by muba
in thread matchin a pattern 250 characters up and down stream by Anonymous Monk

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.