develooper Front page | perl.perl5.porters | Postings from August 2008

Re: [perl #30660][PATCH] Repeated spaces on shebang line stopsoption parsing

Thread Previous | Thread Next
From:
H.Merijn Brand
Date:
August 26, 2008 00:16
Subject:
Re: [perl #30660][PATCH] Repeated spaces on shebang line stopsoption parsing
Message ID:
20080826091616.19dd87c6@pc09.procura.nl
On Tue, 26 Aug 2008 08:43:55 +0200, Renée Bäcker
<renee.baecker@smart-websolutions.de> wrote:

> Nicholas Clark wrote:
> > On Mon, Aug 25, 2008 at 10:47:31AM +0200, Rene Bcker wrote:
> >   
> >> Make perl recognize additional switches when more than one space is used...
> >>     
> >
> > Do you have an example of what this is solving? It seems a logical change to
> > make, but I'm guessing as to what the problem is.
> >   
> 
> Attached is a small script. Without this patch it just recognizes the -s
> switch but not the -w switch.
> 
> >   
> >> --- perl.c.old	2008-08-25 10:35:38.000000000 +0200
> >> +++ perl.c	2008-08-25 10:26:22.000000000 +0200
> >> @@ -3370,8 +3370,10 @@
> >>  	return s;
> >>      case '*':
> >>      case ' ':
> >> -	if (s[1] == '-')	/* Additional switches on #! line. */
> >> -	    return s+2;
> >> +        while( *s && isSPACE(*s) )
> >> +          ++s;
> >>     
> >
> > That can be
> >
> >        while( isSPACE(*s) )
> >          ++s;
> >
> > because isSPACE('\0') is going to be false.
> >
> >
> > But is using isSPACE() correct, given that '\r', '\n' and particularly '\t'
> > are handled differently in code below?
> > (And no, I'm not intimately familiar with what it is doing, or why)
> >   
> 
> So this should be rewritten as
> 
>   while( *s && ( s[0] == ' ' ) )
>       ++s;

That is just one test too many, as it is effectively the same as

    while (*s == ' ') s++;

if *s == (char)0, *s == ' ' will be false
If you also want to allow tabs,

    while (*s == ' ' || *s == '\t') s++;

-- 
H.Merijn Brand          Amsterdam Perl Mongers  http://amsterdam.pm.org/
using & porting perl 5.6.2, 5.8.x, 5.10.x, 5.11.x on HP-UX 10.20, 11.00,
11.11, 11.23, and 11.31, SuSE 10.1, 10.2, and 10.3, AIX 5.2, and Cygwin.
http://mirrors.develooper.com/hpux/           http://www.test-smoke.org/
http://qa.perl.org      http://www.goldmark.org/jeff/stupid-disclaimers/

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About