Hi All,
I am using perl to get the data from the form fields and I have a text area from where if some one enters data like below:
"This is test
And this is also test
This is also test."
So here you can notify the text is entered with hitting of enter key to have the line break. But I am having the problem while saving the data entered in this field in a text file then there also it is saving with these line breaks(new lines) so if am trying to upload the file to the fields then it is saying that invalid file.
So I was thinking is there a way in perl to remove the new line character from the string while saving the form data. So that I will not have the problem while uploading.
Please let me know with some sample examples to solve this I will be waiting for all your valuable responses.
Thanks,
Chittaranjan :)
8 41721
Hi All,
I am using perl to get the data from the form fields and I have a text area from where if some one enters data like below:
"This is test
And this is also test
This is also test."
So here you can notify the text is entered with hitting of enter key to have the line break. But I am having the problem while saving the data entered in this field in a text file then there also it is saving with these line breaks(new lines) so if am trying to upload the file to the fields then it is saying that invalid file.
So I was thinking is there a way in perl to remove the new line character from the string while saving the form data. So that I will not have the problem while uploading.
Please let me know with some sample examples to solve this I will be waiting for all your valuable responses.
Thanks,
Chittaranjan :)
You will want to read up on the chomp() function. That does what you want.
Regards,
Jeff
I have a simpler Perl question, but chomp doesn't seem to be doing the trick.
I've input a file in paragraph mode (ie set $/="") as much of the data i need to isolate is multi-line. I have set up a while (<>) loop, in which I have several if statements to pattern match. I am saving long text strings into a hash but I need the values not to have any embedded "/n", such as:
Justice Hudson did not participate in the consideration or decision of\n
this case.
I need the entire sentence (ie the entire string) as a value in a hash with no embedded "\n". I can isolate the pattern fine, and I can assign this string to a hash value, but no matter what i do I can't remove that "\n" since it is embedded in a string (opposed to being at the end, which would be no problem to remove).
Any suggestions?
Thanks a bunch!
Michael
I should also note that once i have isolated the entire string (with embedded "\n") to a hash value, say $case{'judges'} for example, and i try the following after the while (<>) loop:
if (exists $case{'judges'}){
$case{'judges'}=~s/\n//g;}
i get the following when i try to print $case{'judges'}:
Justice Hudthis case.t participate in the consideration or decision of
which just makes me sad. :-(
Any idea what i am doing wrong?
Thanks, again.
Michael
There is something else going on. As you can see by this example, removing newlines is no problem: - my $test = qq{this
-
is a
-
test
-
};
-
print "before:\n";
-
print $test;
-
$test =~ s/\n/ /g;
-
print "\nafter:\n";
-
print $test;
Thanks for your help but I still am apparently breaking Perl. I tried your test and yes, it works. But when I try to apply it to my script, all hell breaks lose. At its most basic, this is my script: -
#!/usr/bin/perl -w
-
my %case = (); # case hash
-
my $judges = ''; # temp key
-
open (IN, "/Users/MicWood/Documents/Perl/Opinion\ Scripts/output.txt");
-
$/=""; # paragraph input mode
-
while (<IN>) {
-
if (/^JUDGES:\s(.+)\n\n/s){
-
$case{'judges'}=$1};
-
next;}
-
print "before:\n";
-
print $case{'judges'};
-
$case{'judges'}=~ s/\n/ /;
-
print "\nafter:\n";
-
print $case{'judges'};
-
print "\n";
-
The result between the two prompts:
before:
Justice HUDSON did not participate in the consideration or decision of
this case.
after:
this case.SON did not participate in the consideration or decision of
Why is it transposing the two parts of the string?
Thanks again!
Michael
Whoops:
that should be:
$case{'judges'}=~ s/\n/ /g;
not
$case{'judges'}=~ s/\n/ /;
But same transposed result as before.
Thanks
Michael
Maybe something do with the way you are printing the output while still in the loop, try like this: -
#!/usr/bin/perl -w
-
my %case = (); # case hash
-
my $judges = ''; # temp key
-
open (IN, "/Users/MicWood/Documents/Perl/Opinion\ Scripts/output.txt");
-
$/=""; # paragraph input mode
-
while (<IN>) {
-
if (/^JUDGES:\s(.+)\n\n/s) {
-
$case{'judges'}=$1;
-
last;
-
}
-
close (IN);
-
print "before:\n";
-
print $case{'judges'};
-
$case{'judges'}=~ s/\n/ /;
-
print "\nafter:\n";
-
print $case{'judges'};
-
print "\n";
-
If that does not help, post the input file or attach it to a post.
$test =~ s/\n/ /g;
can you explain this is this find and replace kind of thing
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Yazar Yolait |
last post by:
I want to skip lines in a file that are blank and that start with "&". So I
strip(None) them and then startswith("&") but the only problem is if the
line has nothing but white space and I...
|
by: Surya Kiran |
last post by:
Hi all,
I'm facing a wierd problem.
I've a file, which is getting updated every now and then. and i'm
having another program, which monitors the file. I've to read the file
line by line, and in...
|
by: Someonekicked |
last post by:
if you create a new file , open it and only hit enter then save. if you use
seekg(0,ios::end) and then tellg(), tellg() will return 2 (not 1); so new
line character is considered as two characters....
|
by: Christopher Lusardi |
last post by:
How would I put an end of line character in the second line below?
Textbox1.Text = "Hello "
Textbox1.Text =
Textbox1.Text = "World"
Thanks,
Chris Lusardi
|
by: Brand Bogard |
last post by:
Does the C standard include a library function to convert an 8 bit character
string to a 16 bit character string?
|
by: bruce |
last post by:
hi...
i'm running into a problem where i'm seeing non-ascii chars in the parsing
i'm doing. in looking through various docs, i can't find functions to
remove/restrict strings to valid ascii...
|
by: KK |
last post by:
Dear comp.lang.c++,
The code below reads off strings of a file into a vector.
ifstream srcfile("c:\\test.txt");
istream_iterator<stringstrIter(srcfile), eos;
vector<string strvec(strIter, eos);...
|
by: LEM |
last post by:
Hi,
I'm trying to remove any empty lines from a string, and I am doing the
following:
String pp;
pp = "\r\n\r\n1\r\n23\r\n\r\n4";
pp = pp.Replace("\r\n\r\n", "\r\n");
|
by: dougancil |
last post by:
I have the following code:
Imports System.Data.SqlClient
Public Class Main
Protected WithEvents DataGridView1 As DataGridView
Dim instForm2 As New Exceptions
Private Sub...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |