I'm not entirely sure what you're trying to do. Surely, all lines in your file will be between two lines beginning with h, aside from those before the first line beginning with h, and after the last line beginning with h?
It might make it easier to understand the problem if you give some sample data, and the result you expect to get. Have a look through this: How do I post a question effectively?
Finally, based on your question, my best guess would be something like this:
#!/usr/bin/perl
use strict;
use warnings;
my $file = $ARGV[0];
my $check = 0;
my @line;
while (<DATA>)
{
@line = split('', $_);
$check += 1 if $line[0] eq 'h';
if ($check%2 == 1)
{
if (($line[0] eq 'j') || ($line[0] eq 'E') || ($line[0
+] eq 'G'))
{
print STDOUT "$_";
}
}
}
__DATA__
aaaaa 1
bbbbb 2
hhhhh 3
fffff 4
rrrrr 5
lllll 6
jjjjj 7
HHHHH 8
EEEEE 9
GGGGG 10
hhhhh 11
jjjjj 12
EEEEE 13
GGGGG 14
I hope that helps.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|