perl(1) question
Mark Ovens
marko at freebsd.org
Sun Sep 3 19:11:48 BST 2000
Does index() ignore leading whitespace? A perl(1) script I have
appears to be doing just that. Isolating the relevant lines I have:
#!/usr/bin/perl -w
open 'CONTENTS',"/usr/mark/scrap" or die "cannot open /usr/mark/scrap";
until (eof 'CONTENTS') {
chomp ($line = <CONTENTS>);
$i = index($line, /FOO/i);
print "line\=$line\n";
print "i \= $i\n";
};
close 'CONTENTS';
Running this on a file containing:
Foobar
Foobar
foobar
FOOBAR
foOBar
I get:
# ./scrap.pl scrap
Use of uninitialized value at ./scrap.pl line 7, <CONTENTS> chunk 1.
line=Foobar
i = 0
Use of uninitialized value at ./scrap.pl line 7, <CONTENTS> chunk 2.
line= Foobar
i = 0
Use of uninitialized value at ./scrap.pl line 7, <CONTENTS> chunk 3.
line= foobar
i = 0
Use of uninitialized value at ./scrap.pl line 7, <CONTENTS> chunk 4.
line= FOOBAR
i = 0
Use of uninitialized value at ./scrap.pl line 7, <CONTENTS> chunk 5.
line= foOBar
i = 0
#
So index() appears to be ignoring the leading whitespace because it
always returns 0.
Also, what causes the "Use of uninitialized value...." warning? I
cannot see anything wrong with the script. I've checked Learning Perl
by Schwartx and Christiansen and the perl manpages; also the code is
taken from the original script which doesn't give this warning.
Any pointers would be greatly appreciated.
TIA
--
4.4 - The number of the Beastie
________________________________________________________________
51.44°N FreeBSD - The Power To Serve http://www.freebsd.org
2.057°W My Webpage http://ukug.uk.freebsd.org/~mark
mailto:marko at freebsd.org http://www.radan.com
More information about the Ukfreebsd
mailing list