There're a quiet a few bugs in this, and I think you'd really benefit from putting use strict at the top of your programs.

Anyway, you're missing a curly bracket, and you've spelt "view" wrongly in your print statement, so you'd never get a proper result.

Also, the string you're trying to match: "(view: pa_Iden etc etc)" has got spaces in it, so you'll never succeed in your match if you use the non-whitespace character, \w. You could substitute that for "." which matches anything, although I have heard monks say that ".*" is bad practice (I'm still quite a novice tho', so I don't know why they say this!).

Finally, when you assign to $view, you mean $2, not $1. You could do with taking out some of those brackets, which are confusing you with backreferences.

Here's a version which works:

while(<check>) { if (m/^(?:Update Status:)\s*(\w+)/) { $target = $1; } if ($target eq "open") { if (m/^(?:Update Status:)\s*(\w+)\s*(.*)$/) { $view = $2; } print "$target\n"; print "$view\n"; close(check); } }
However, here's a slightly more concise version which only uses one regex:
while(<check>) { if (m/^(?:Update Status:)\s*(\w+)\s*(.*)$/) { if ($1 eq "open") { $view = $2; print "$view\n"; close(check); } } }
Note that in each of these, as soon as an "Update: open" line is found, the file is closed. I don't know if that's what you want, but if not, you'll have to move that close(check); line.

HTH
Dennis


In reply to Re: regex on a line by Basilides
in thread regex on a line by Sara

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.