Different results using the substr command

2005-01-05 Thread Albert Kaltenbaeck
I am having problems with the substr command.
It appears under OSX Perl the length value is being ignored.
This code worked under MacPerl with the old open statement being open 
(THEFILE ,::clientd.html);.
All I changed was the open statement with a new path.
When I ask Perl OSX to print $line (the full string) I get the 
following...

html
head
meta http-equiv=content-type content=text/html;charset=ISO-8859-1
META HTTP-EQUIV=Pragma CONTENT=no-cache
meta name=description Content=Offline
titleP a u s e d/title
meta name=generator content=Albert Kaltenbaeck
meta http-equiv=refresh content=15
titleO f f l i n e/title
/head
body bgcolor=#00
IMG SRC=D:\offline.gif WIDTH=400 HEIGHT=300 ALIGN=bottom
/body
/html
Great! it is reading the file correctly. But when I ask Perl to print 
$playing (using the substr command) I get the following...

ntent-type content=text/html;charset=ISO-8859-1
META HTTP-EQUIV=Pragma CONTENT=no-cache
meta name=description Content=Offline
titleP a u s e d/title
meta name=generator content=Albert Kaltenbaeck
meta http-equiv=refresh content=15
titleO f f l i n e/title
/head
body bgcolor=#00
IMG SRC=D:\offline.gif WIDTH=400 HEIGHT=300 ALIGN=bottom
/body
/htm
It is starting at the beginning of the file and not the 6th line.
Using MacPerl I get the word Offline in the sixth line and hacking 
off the three characters on the end. (what I want)
I have tried using 167 as the offset and -3 as the length.
When I do this the starting point is correct but it does not seem to 
acknowledge the length value because I get the rest of the entire 
string.
Is there an issue now because I am using Unix line breaks and not 
Macintosh?

here is how I am using substr.
$. = 0;
open (THEFILE,../../../../Documents/ge/ClientD.html) or die Line 96 
  . (localtime) .   . $! . \n\n\n;
do {$line =THEFILE} until $. == 6 || eof;
close (THEFILE);
$playing = substr($line,35,-3);

Albert

Re: Different results using the substr command

2005-01-05 Thread Joseph Alotta
I am wondering that even if you get substr to work, you probably would 
have code that
is too specific and hacky.  You probably want to match off of some of 
the keywords,
so that if things move your program won't break.

Joe.
On Jan 5, 2005, at 3:14 PM, Albert Kaltenbaeck wrote:
I am having problems with the substr command.
It appears under OSX Perl the length value is being ignored.
This code worked under MacPerl with the old open statement being open 
(THEFILE ,::clientd.html);.
All I changed was the open statement with a new path.
When I ask Perl OSX to print $line (the full string) I get the 
following...

html
head
meta http-equiv=content-type content=text/html;charset=ISO-8859-1
META HTTP-EQUIV=Pragma CONTENT=no-cache
meta name=description Content=Offline
titleP a u s e d/title
meta name=generator content=Albert Kaltenbaeck
meta http-equiv=refresh content=15
titleO f f l i n e/title
/head
body bgcolor=#00
IMG SRC=D:\offline.gif WIDTH=400 HEIGHT=300 ALIGN=bottom
/body
/html
Great! it is reading the file correctly. But when I ask Perl to print 
$playing (using the substr command) I get the following...

ntent-type content=text/html;charset=ISO-8859-1
META HTTP-EQUIV=Pragma CONTENT=no-cache
meta name=description Content=Offline
titleP a u s e d/title
meta name=generator content=Albert Kaltenbaeck
meta http-equiv=refresh content=15
titleO f f l i n e/title
/head
body bgcolor=#00
IMG SRC=D:\offline.gif WIDTH=400 HEIGHT=300 ALIGN=bottom
/body
/htm
It is starting at the beginning of the file and not the 6th line.
Using MacPerl I get the word Offline in the sixth line and hacking 
off the three characters on the end. (what I want)
I have tried using 167 as the offset and -3 as the length.
When I do this the starting point is correct but it does not seem to 
acknowledge the length value because I get the rest of the entire 
string.
Is there an issue now because I am using Unix line breaks and not 
Macintosh?

here is how I am using substr.
$. = 0;
open (THEFILE,../../../../Documents/ge/ClientD.html) or die Line 
96   . (localtime) .   . $! . \n\n\n;
do {$line =THEFILE} until $. == 6 || eof;
close (THEFILE);
$playing = substr($line,35,-3);

Albert



Re: Different results using the substr command

2005-01-05 Thread Sherm Pendley
On Jan 5, 2005, at 4:14 PM, Albert Kaltenbaeck wrote:
I am having problems with the substr command.
No you're not. :-)
You're barking in the wrong forest here - both the offset and length 
values you passed to substr() are being used just fine. You're getting 
exactly what you asked for from substr() - the contents of $line, 
starting at offset 35 and omitting the last three characters.

The difference is that, on MacOS, $line had just that, one line from 
the input file. It appears here to have the whole file in it. I suspect 
a line ending problem - verify that the input file has UNIX line 
endings.

PS: Now you've found out why most of us use and recommend HTML::Parser 
- it's much less pain than trying to parse HTML by hand.

sherm--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


Re: Different results using the substr command

2005-01-05 Thread John Delacour
At 3:14 pm -0600 5/1/05, Albert Kaltenbaeck wrote:
I am having problems with the substr command.
It appears under OSX Perl the length value is being ignored.
This code worked under MacPerl ...

Do you get the expected result when you run this ?:
$f = ClientD.html;
$/ = \n;
open F, $f or die $!;
while (F) {
print $.. -- $_;
}
If not then you need to consider your line endings.
JD



Re: Different results using the substr command

2005-01-05 Thread Doug McNutt
At 22:23 + 1/5/05, John Delacour wrote:
If not then you need to consider your line endings.

And remember that MacPerl subscribes to the MPW convention that reverses the 
meanings of \n and \r for the Mac.

ftp://ftp.macnauchtan.com/Software/LineEnds/FixEndsFolder.sit (52 kB)
ftp://ftp.macnauchtan.com/Software/LineEnds/ReadMe_fixends.txt  (4 kB)

might be useful.

-- 
--  There are 10 kinds of people:  those who understand binary, and those who 
don't --


Re: Different results using the substr command

2005-01-05 Thread Albert Kaltenbaeck
Thank you,
with all your help I have found the issue is the HTML file I am reading 
does not have unix lineends.
That is the problem.

Thanks again!
Albert
On Jan 5, 2005, at 3:14 PM, Albert Kaltenbaeck wrote:
I am having problems with the substr command.
It appears under OSX Perl the length value is being ignored.
This code worked under MacPerl with the old open statement being open 
(THEFILE ,::clientd.html);.
All I changed was the open statement with a new path.
When I ask Perl OSX to print $line (the full string) I get the 
following...

html
head
meta http-equiv=content-type content=text/html;charset=ISO-8859-1
META HTTP-EQUIV=Pragma CONTENT=no-cache
meta name=description Content=Offline
titleP a u s e d/title
meta name=generator content=Albert Kaltenbaeck
meta http-equiv=refresh content=15
titleO f f l i n e/title
/head
body bgcolor=#00
IMG SRC=D:\offline.gif WIDTH=400 HEIGHT=300 ALIGN=bottom
/body
/html
Great! it is reading the file correctly. But when I ask Perl to print 
$playing (using the substr command) I get the following...

ntent-type content=text/html;charset=ISO-8859-1
META HTTP-EQUIV=Pragma CONTENT=no-cache
meta name=description Content=Offline
titleP a u s e d/title
meta name=generator content=Albert Kaltenbaeck
meta http-equiv=refresh content=15
titleO f f l i n e/title
/head
body bgcolor=#00
IMG SRC=D:\offline.gif WIDTH=400 HEIGHT=300 ALIGN=bottom
/body
/htm
It is starting at the beginning of the file and not the 6th line.
Using MacPerl I get the word Offline in the sixth line and hacking 
off the three characters on the end. (what I want)
I have tried using 167 as the offset and -3 as the length.
When I do this the starting point is correct but it does not seem to 
acknowledge the length value because I get the rest of the entire 
string.
Is there an issue now because I am using Unix line breaks and not 
Macintosh?

here is how I am using substr.
$. = 0;
open (THEFILE,../../../../Documents/ge/ClientD.html) or die Line 
96   . (localtime) .   . $! . \n\n\n;
do {$line =THEFILE} until $. == 6 || eof;
close (THEFILE);
$playing = substr($line,35,-3);

Albert
Albert Kaltenbaeck
15324 West 144th Terrace
Olathe, Kansas 66062
(913) 780-3835 Home
(913) 206-4579 Cell