Lets just say I have this text.
MEANINGLESS TEXT Bob is cool Bill is dumb Ted is cruel Sally wines allot Hit me on my pager 9207882332 I can't see the headlights. I'm blind now. ALTERNATIVE TEXT Turtles are faster than Bill's thought process Bill is dumb Ted is cruel Ted needs to get hit by a bus Sally should buy a muzzle Hit me on my pager 9207882332 I hate brights
Now let's say I specify $var on (STDIN). The $var would be the phone number in the line "Hit me on my pager". Now each section has a different amount of lines and the text for some of the lines is different in each section except for the "Hit me on my pager" line. Now if I do a match on that number and I wanted to print the section head if the number is found and a few selected lines from each heading how would I go about telling PERL that for "MEANINGLESS TEXT" "Bob is cool" is line3 and "Bill is dumb" is line4 and for "ALTERNATIVE TEXT" - "Ted is cruel" is line5 and "Sally should buy a muzzle" is line7 with all this text being in the same file so I can do something roughly equivalent to the following. Here's why I can't do a match on certain lines and I can only specify the line to print. Let's say under "MEANINGLESS TEXT" line4 is what I want to print but it won't always say "Bill is dumb" tommorow it might say "Sally is dumb" I USED ASTERISKS FOR LT AND GT BRACKETS SO THEY DON'T GET HTMLIFIED
print "What number?"; chomp($var = *STDIN*); $var1 = "MEANINGLESS TEXT"; $var2 = "ALTERNATIVE TEXT"; $line3 = (However you tell PERL that this is line1 of the "MEANINGLESS + TEXT" record block); $line4 = (However you tell PERL that this is line4 of the "MEANINGLESS + TEXT" record block); $line5 = (However you tell PERL that this is line5 of the "ALTERNATIVE + TEXT" record block); $line7 = (However you tell PERL that this is line7 of the "ALTERNATIVE + TEXT" record block); open(FILE, "resultsdata"); while (*FILE*) { if (/$var/ && /$var1/) { print "$var1\n"; print "$line3\n"; print "$line4\n"; if (/$var/ && /$var2/) { print "$var2\n"; print "$line5\n"; print "$line7\n"; } } }
(My dilemma is an if statement with the (and) operator won't match both scalars it only matches the first scalar $var or vice versa if I switched their positions, and the fact that I don't know how to tell PERL what and where a line is.
HELP!

The Brassmon_k

In reply to Can PERL know a line without matching? by brassmon_k

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.