codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  blank lines  perlnewb at 03:15 on Saturday, September 05, 2009
 

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
}
}



  Re: blank lines  hermanningjaldsson at 20:50 on Thursday, September 10, 2009
 

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?


  Re: blank lines  hermanningjaldsson at 20:56 on Thursday, September 10, 2009
 

#-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.










CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  issues with simplexml_load_string/SimpleXMLElement on PHP 5.1/Linux
•  Re: blank lines
•  Re: Help: Trouble with z-Index and SELECT lists
•  Need hosted_button_id value from PayPal generated code
•  program C++
•  Test hacker - receive award !
•  Re: open excel file in html page
•  Can any one say me the coding to create a JTextField in runtime
•  Building SSO(Single Sign On) Custom URL


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2009