bizarre index() function behavior

M

me

First I thought I was crazy, then I tested this, seems to work
differently:

$teststr = " <P>A J SERVICES LIMITED</FONT></P></TD>";
position is 12


But when I read this in from a file:

sysopen(FH, $default_input_file, O_RDONLY) or
die "sysopen failed: $!\n";

while ($read_buf = readline(FH)) {
# parse the field value out of the entire string
$ret_val = index($read_buf, "<P>");

THEN:
$ret_val = 1


What causes this to be different?? I thought it was because of leading
spaces but I also tried to use "\<P\>" and "A J SERVICES" but the index
value is always 1.


thanks for your thoughts
 
T

Tore Aursand

me said:
First I thought I was crazy, then I tested this, seems to work
differently:
[...]

Not here. Show us the whole code, and/or try printing out each line each
time.
 
A

A. Sinan Unur

First I thought I was crazy, then I tested this, seems to work
differently:

$teststr = " <P>A J SERVICES LIMITED</FONT></P></TD>";



But when I read this in from a file:

sysopen(FH, $default_input_file, O_RDONLY) or
die "sysopen failed: $!\n";

while ($read_buf = readline(FH)) {
# parse the field value out of the entire string
$ret_val = index($read_buf, "<P>");

THEN:
$ret_val = 1


What causes this to be different?? I thought it was because of leading
spaces but I also tried to use "\<P\>" and "A J SERVICES" but the index
value is always 1.

C:\Documents and Settings\asu1\My Documents> cat a.pl
use strict;
use warnings;

my $teststr = q{ <P>A J SERVICES LIMITED</FONT></P></TD>};
print index($teststr, '<P>'), "\n";

while($teststr = <DATA>) {
print index($teststr, '<P>'), "\n";
}
__DATA__
<P>A J SERVICES LIMITED</FONT></P></TD>

C:\Documents and Settings\asu1\My Documents> perl a.pl
12
12
-1

Please take a look at the posting guidelines for this group and try to
put together the shortest script that still exhibits the problem. We
cannot help you with a problem we cannot observe.

Sinan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top