Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > parse newline

Reply
Thread Tools

parse newline

 
 
ela
Guest
Posts: n/a
 
      02-08-2009
It's always a nightmare for me to parse newline characters. No matter \n,
10, 13, I just don't know why some newlines are printed. As the file is
generated by another program, I cannot see the source code, and manual
inspection does not discover any abnormalty.

using chop, chomp or to use replace cannot help. Does anybody have
experience in handling this?


 
Reply With Quote
 
 
 
 
Martijn Lievaart
Guest
Posts: n/a
 
      02-08-2009
On Sun, 08 Feb 2009 17:05:47 +0800, ela wrote:

> It's always a nightmare for me to parse newline characters. No matter
> \n, 10, 13, I just don't know why some newlines are printed. As the file
> is generated by another program, I cannot see the source code, and
> manual inspection does not discover any abnormalty.
>
> using chop, chomp or to use replace cannot help. Does anybody have
> experience in handling this?


Something like:

chomp;
s/\x0d$//;

Should always do the trick. If not, you have something very strange going
on.

M4
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      02-08-2009
"ela" <(E-Mail Removed)> wrote:
>It's always a nightmare for me to parse newline characters. No matter \n,
>10, 13, I just don't know why some newlines are printed. As the file is
>generated by another program, I cannot see the source code, and manual
>inspection does not discover any abnormalty.
>
>using chop, chomp or to use replace cannot help. Does anybody have
>experience in handling this?


Your program is missing a semicolon on line 42.

jue
 
Reply With Quote
 
ela
Guest
Posts: n/a
 
      02-08-2009
>
> Something like:
>
> chomp;
> s/\x0d$//;
>
> Should always do the trick. If not, you have something very strange going
> on.
>


Have already tried that before and it doesn't solve...


 
Reply With Quote
 
ela
Guest
Posts: n/a
 
      02-08-2009

"Jürgen Exner" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "ela" <(E-Mail Removed)> wrote:
>>It's always a nightmare for me to parse newline characters. No matter \n,
>>10, 13, I just don't know why some newlines are printed. As the file is
>>generated by another program, I cannot see the source code, and manual
>>inspection does not discover any abnormalty.
>>
>>using chop, chomp or to use replace cannot help. Does anybody have
>>experience in handling this?

>
> Your program is missing a semicolon on line 42.
>
> jue


line 42????????

Well I've tried :

chop $identiy;
chomp ($identiy);
chop $identiy;
$identity =~ s/\x0d$//;

All fail.


 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      02-08-2009
"ela" <(E-Mail Removed)> wrote:
>"Jürgen Exner" <(E-Mail Removed)> wrote in message
>> "ela" <(E-Mail Removed)> wrote:
>>>It's always a nightmare for me to parse newline characters.


What character set are you using? None of the common ASCII-based
character sets (WIndows-1252, ISO-Latin-xxx, Unicode, ...) has a newline
character. See also below.

>>>No matter \n,
>>>10, 13, I just don't know why some newlines are printed. As the file is
>>>generated by another program, I cannot see the source code, and manual
>>>inspection does not discover any abnormalty.

[...]
>> Your program is missing a semicolon on line 42.

>
>line 42????????


Apparently you've never read The Hitchhikers Guide through the Galaxy.

Long form: how do you propose us to fix your code without seeing it?
Have you seen the posting guidelines that are posted here twice a week?

>Well I've tried :
>
> chop $identiy;


This will remove the last character of $identiy.
How do you know that last character is actually the newline?

> chomp ($identiy);


This will remove a trailing $/ from $identiy, whatever $/ may be set to
on your system (usually "\n").
Did you check that $/ matches the tail of $identiy?

> chop $identiy;


This looks identical to the first line?

> $identity =~ s/\x0d$//;


This is working on $identity instead of $identiy. Is that what you meant
to do?

One common problem are format incompatibilities between Windows, Mac,
and Unix. They use different characters/character combinations to denote
a line break. Therefore you should be very explicit about if you are
talking about a line feed character(LF), a carriage return
character(CR), or a logical newline entity of your OS.

Aside of that I suspect that you are looking at the wrong spot and your
real problem is somewhere else, like e.g. a misspelled variable name as
above

As strongly suggested in the posting guidelines please post a
self-contained, minimal program that demonstrates your problem, in your
case including some sample input data, preferable as a _DATA_ section.

jue
 
Reply With Quote
 
Cosmic Cruizer
Guest
Posts: n/a
 
      02-08-2009
"ela" <(E-Mail Removed)> wrote in
news:gmm79b$dsa$(E-Mail Removed):

> It's always a nightmare for me to parse newline characters. No matter
> \n, 10, 13, I just don't know why some newlines are printed. As the
> file is generated by another program, I cannot see the source code,
> and manual inspection does not discover any abnormalty.
>
> using chop, chomp or to use replace cannot help. Does anybody have
> experience in handling this?
>
>


You might be encountering NUL characters. I run into the NUL character
problem when working with Windows event logs. Try to use the following on
your data: =~ s/\0/\t/g; You can change "\t" to whatever you need.

Example:
# Get event data
my $streaingTest = $Event{Strings};

# Change NUL to tab for event data
$streaingTest =~ s/\0/\t/g;

....Cos
 
Reply With Quote
 
Martijn Lievaart
Guest
Posts: n/a
 
      02-09-2009
On Sun, 08 Feb 2009 23:36:39 +0800, ela wrote:


>> Something like:
>>
>> chomp;
>> s/\x0d$//;
>>
>> Should always do the trick. If not, you have something very strange
>> going on.
>>
>>

> Have already tried that before and it doesn't solve...


Funny, did you try hexdumping the files?

M4
 
Reply With Quote
 
Martijn Lievaart
Guest
Posts: n/a
 
      02-09-2009
On Sun, 08 Feb 2009 23:36:39 +0800, ela wrote:


>> Something like:
>>
>> chomp;
>> s/\x0d$//;
>>
>> Should always do the trick. If not, you have something very strange
>> going on.
>>
>>

> Have already tried that before and it doesn't solve...


BTW, I did mean both statements and in that order.

M4
 
Reply With Quote
 
Ted Zlatanov
Guest
Posts: n/a
 
      02-09-2009
On Sun, 8 Feb 2009 23:51:54 +0800 "ela" <(E-Mail Removed)> wrote:

e> Well I've tried :

e> chop $identiy;
e> chomp ($identiy);
e> chop $identiy;
e> $identity =~ s/\x0d$//;

e> All fail.

Assuming your text is in FILE.TXT:

od -t u1 -t a FILE.txt

What does your text show for the lines that are not correctly processed
by your program?

Ted
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to ignore newline in Parse::RecDescent freesoft12@gmail.com Perl Misc 10 04-30-2010 03:23 AM
optparse: parse v. parse! ?? 7stud -- Ruby 3 02-20-2008 05:20 AM
How to parse a string like C program parse the command line string? linzhenhua1205@163.com C Programming 19 03-15-2005 07:41 PM
Regular expression that doesn't recognize newline Antonio ASP .Net 0 01-19-2005 09:23 AM
expression eats newline Gerard Oberle Perl 3 08-01-2003 05:06 PM



Advertisments