perl scripting - display string in single line

  • Xdrive
  • Newbie
  • Newbie
  • Xdrive
  • Posts: 9

Post 3+ Months Ago

i have a problem to displaying the text into a single line.
example:
perl
is
a
good
scripting
language.

instead of displaying the word into different line, i want to display the entire sentence into a single line:
sample output:
perl is a good scripting language.

please help.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

You better post your script code here.
  • Xdrive
  • Newbie
  • Newbie
  • Xdrive
  • Posts: 9

Post 3+ Months Ago

Code: [ Select ]
sub search_All_AND{
  ($term1,$term2,$term3,@text) = @_;
  print "<p>The results for $term1, $term2,$term3 </b> are : <br>";
  foreach $line (@text){
    if (($line=~ /$term1/i) and ($line=~ /$term2/i) and ($line=~ /$term3/i)){
        print "$line <br>";
    }
  } 
}
  1. sub search_All_AND{
  2.   ($term1,$term2,$term3,@text) = @_;
  3.   print "<p>The results for $term1, $term2,$term3 </b> are : <br>";
  4.   foreach $line (@text){
  5.     if (($line=~ /$term1/i) and ($line=~ /$term2/i) and ($line=~ /$term3/i)){
  6.         print "$line <br>";
  7.     }
  8.   } 
  9. }

this is the subroutine that print the word into different line. so i want to print the entire words into one sentence (single line).
hope u can understand the code.
  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

print "$line ";
  • Xdrive
  • Newbie
  • Newbie
  • Xdrive
  • Posts: 9

Post 3+ Months Ago

wat do u mean by
print "$line";
  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

Replace your line:

Code: [ Select ]
print "$line
";
  1. print "$line
  2. ";


with:

Code: [ Select ]
print "$line ";


Note there is a blank space after $line variable, whitin the quotes.
  • Xdrive
  • Newbie
  • Newbie
  • Xdrive
  • Posts: 9

Post 3+ Months Ago

sorry, i think i forgot to put something in between.
my code suppose to be
Code: [ Select ]
print"$line <br>";

with the code above, it displaying each word in different line. but when i deleted the <br>, it displaying the entire text into a single paragraph (which look messy). although there is a full stop at the end of the text (supposed to be go to the next paragraph, but it display into single paragraph).

i hope u can help me to debug.
  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

Well, if I did understand what you want, you will have to check for the full stop and add a print "\n\n"
Code: [ Select ]
print "$line ";

if ( <check for fullstop> ) print "\n\n";
  1. print "$line ";
  2. if ( <check for fullstop> ) print "\n\n";

You will have to check using a regular expression. I don't remember how to use them in Perl.
  • Xdrive
  • Newbie
  • Newbie
  • Xdrive
  • Posts: 9

Post 3+ Months Ago

have to check the full stop izit.i try now.
know about cookie?
  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

Not from Perl. A cookie is information you store in the user's browser for later use. In PHP you have a pair of functions for writting and reading cookies. Quite simple. I think you will find a Perl Library for that.
  • Xdrive
  • Newbie
  • Newbie
  • Xdrive
  • Posts: 9

Post 3+ Months Ago

i have looked at perl and CGI scripting that related to cookie, but i do not understand. how the cookie work.
mind to help me with the cookie stuff?if u know.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

//Guys - please use BBCode when posting code. Some HTML codes will parse and cause your post to display incorrectly and it can cause confusion as was the case in this post. The board parsed the break tag instead of displaying it as plain text.
  • _Leo_
  • Proficient
  • Proficient
  • User avatar
  • Posts: 279
  • Loc: Buenos Aires, Argentina

Post 3+ Months Ago

You can think of a cookie as a variable stored in the end-user's web browser. This variable is stored encrypted, for a specific domain and usually has an expire time.
This way, I can setup a cookie from my domain (http://www.drk.com.ar) in my visitors' browsers, I can do this cooki last a week and I will be able to read the cookie content only from my domain.
Let's say I write a cookie USERNAME with value "Leandro" for a week in a particular user. Later, I can build up a login form including the value for the username field so my user doesn't need to type it again. I will be able to read cookie values at the beginning of my CGI script.

In PHP at least you will have to make your user go to another page before reading a cookie value you just written.

I tried to make a conceptual description here. I have not worked with cookies in Perl, therefore I can't show you a sample code.
  • Xdrive
  • Newbie
  • Newbie
  • Xdrive
  • Posts: 9

Post 3+ Months Ago

thanks for the information

Post Information

  • Total Posts in this topic: 14 posts
  • Users browsing this forum: No registered users and 46 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.