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