Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > String Concatenation problems

Reply
Thread Tools

String Concatenation problems

 
 
Daniel Bergquist
Guest
Posts: n/a
 
      07-13-2004
Consider the following chunk of code:
--------------------------------------------------
open (IN, "<:raw", "test2.txt") or die "Can't open test.txt";

chomp($line = <IN>);

# Capture excerpt
$line =~ m/>([^<]+)/;

# Copy first line of excerpt
$pExcerpt = $1;

# Next line
chomp($line = <IN>);

# Untill we have reached the end of the section
until($line =~ m/<\/p>/i) {

# Capture useful text
$line =~ m/([^<]+)/;
chomp($line = <IN>);
}

# Capture the rest of the useful text
$line =~ m/([^<]+)/;

$pExcerpt = "$pExcerpt $1";

print "final: $pExcerpt\n";
-----------------------------------------------------------



The file test2.txt is as follows:
-------------------------------------------------
<p class=p1>I consider myself fortunate to stand before you today as I
make my
defense against all the accusations of the Jews. <i>Acts 26:2</i></p>


----------------------------------------------

When run:
P:\WEBPOP\EXPERI~1>excerpt.pl
defense against all the accusations of the Jews. you today as I make
my

P:\WEBPOP\EXPERI~1>


When I change the concatenation to as follows:
$pExcerpt = "$1 $pExcerpt";
The result is:
P:\WEBPOP\EXPERI~1>excerpt.pl
final: defense against all the accusations of the Jews. I consider
myself fortunate
to stand before you today as I make my

P:\WEBPOP\EXPERI~1>

Which is how I would expect it to work. Why does it not work the first
way(which is the way I need it)?


Perl reports itself as v5.8.3 built for MSWin32-x86-multi-thread,
binary build 809 provided by ActiveState Corp.


Thanks!

Daniel Bergquist
 
Reply With Quote
 
 
 
 
Daniel Bergquist
Guest
Posts: n/a
 
      07-14-2004
You may ignore my posting. I'm getting help in comp.lang.perl.misc.
Turns out part of my problem is that I'm trying to parse HTML with
regex's, apparently a deadly sin...

Daniel Bergquist
 
Reply With Quote
 
 
 
 
Joe Smith
Guest
Posts: n/a
 
      07-16-2004
Daniel Bergquist wrote:

> Consider the following chunk of code:
> --------------------------------------------------
> open (IN, "<:raw", "test2.txt") or die "Can't open test.txt";
> chomp($line = <IN>);


Why on earth would you be using binmode (:raw) and chomp() together?

> defense against all the accusations of the Jews. you today as I make my


That looks suspiciously like a line of text ending with "as I make my"
being partially overwritten by another line. That's what happens when
you use chomp() is a manner such that it strips the "\n" but leaves "\r"
from a line ending with "\r\n".

Do you get any better results when you change "<:raw" to just "<"?
-Joe
 
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
String concatenation vs. string formatting Andrew Berg Python 13 07-10-2011 11:24 PM
String Concatenation & Removing Space Sparky Arbuckle ASP .Net 5 09-01-2005 10:47 PM
String concatenation versus StringBuffer Darren Java 5 07-28-2004 09:35 AM
Re: Use of uninitialized value in concatenation (.) or string Error Sukhbir Dhillon Perl 1 04-05-2004 02:31 AM
what's the difference between VHDL 93 CONCATENATION and VHDL 87 CONCATENATION? walala VHDL 3 09-18-2003 04:17 AM



Advertisments