From owner-freebsd-questions Sun Sep 3 11: 4:10 2000 Delivered-To: freebsd-questions@freebsd.org Received: from mta06-svc.ntlworld.com (mta06-svc.ntlworld.com [62.253.162.46]) by hub.freebsd.org (Postfix) with ESMTP id 553B937B43E for ; Sun, 3 Sep 2000 11:04:07 -0700 (PDT) Received: from parish.my.domain ([62.255.97.1]) by mta06-svc.ntlworld.com (InterMail vM.4.01.02.27 201-229-119-110) with ESMTP id <20000903180404.TSBA312.mta06-svc.ntlworld.com@parish.my.domain> for ; Sun, 3 Sep 2000 19:04:04 +0100 Received: (from mark@localhost) by parish.my.domain (8.9.3/8.9.3) id TAA02804 for questions@freebsd.org; Sun, 3 Sep 2000 19:04:09 +0100 (BST) (envelope-from mark) Date: Sun, 3 Sep 2000 19:04:09 +0100 From: Mark Ovens To: questions@freebsd.org Subject: perl(1) question Message-ID: <20000903190409.B255@parish> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.2.5i Organization: Total lack of Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 = ); $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, chunk 1. line=Foobar i = 0 Use of uninitialized value at ./scrap.pl line 7, chunk 2. line= Foobar i = 0 Use of uninitialized value at ./scrap.pl line 7, chunk 3. line= foobar i = 0 Use of uninitialized value at ./scrap.pl line 7, chunk 4. line= FOOBAR i = 0 Use of uninitialized value at ./scrap.pl line 7, 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@freebsd.org http://www.radan.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message