|
Hi i am new to this forum but have probably a really basic question.
What i want to do is pipe a file into my script(I got this part) and then output the contents to the screen(I'm good here) but i want to be able to make sure there is only 1 blank line between each line of text taken in and that is where i am kinda lost at.
#while there is input available
#read a line
#increment a line counter
#print a line with a line number and a tab
$line = <STDIN>;
while(defined($line))
{
$Line_Number++;
#print "$Line_Number\t|| $line\n";
#print $line;
$line = <STDIN>;
#if statement for blank lines
if($line eq "\n")#this is where i am screwing it up
{
#print"blank Line\n";
print "$Line_Number\t||\n";#what i want it to do is print 1 single blank line if there is more than 1 blank line and the line number a tab and the || and then newline
}
}
|
|
|
you need to break the request down quite dramatically.
#what i want it to do is print 1 single blank line if there is more than 1 blank line and the line number a tab and the || and then newline
becomes.
#what i want it to do is..
#-if there is more than 1 blank line:
#-print 1 single blank line and the line number a tab and the || and then newline
tell me again, what do you want to do?
|
|
|
#-print 1 single blank line and the line number a tab and the || and then newline
\n$line_no\t||\n
the problem is that you're dealing with only one line at a time when really you need to interact with multiple lines simultaneously.
So you take that whole thing and put it into a single variable.
once you have that you do something like:
$stringcontainingthewholetext =~ s/\n+/\n$line_no\t||\n/gi;
although i do recommend starting off with just replacing \n+ with "eeeeeeee" or something like that.
|
|
|