develooper Front page | perl.perl5.porters | Postings from June 2013

Re: [perl #118667] doc and code mismatch on some space character(classe)s

Thread Previous
From:
Smylers
Date:
June 29, 2013 14:15
Subject:
Re: [perl #118667] doc and code mismatch on some space character(classe)s
Message ID:
20130629141439.GA4434@stripey.com
James E Keenan via RT writes:

> On Fri Jun 28 07:36:04 2013, sdaoden wrote:
> 
> >   $ perl -e 'print "$^V:";$i="\x{00A0}"'\
> >       -e ';if($i=~/[[:space:]]/){print "1"}'\
> >       -e ';if($i=~/\s/){print "2"}'\
> >       -e ';if($i=~/\p{IsSpace}/){print "3"}'\
> >       -e ';print "\n"'
> 
> If I copy-and-paste your program into a terminal, I get syntax errors
> when I attempt to run it:
> 
> $ perl -e 'print "$^V:";$i="\x{00A0}"'\
> > -e ';if($i=~/[[:space:]]/){print "1"}'\
> > -e ';if($i=~/\s/){print "2"}'\
> > -e ';if($i=~/\p{IsSpace}/){print "3"}'\
> > -e ';print "\n"'
> syntax error at -e line 1, near ""\x{00A0}"-e"

Jim, you're missing the spaces before the -e at the start of the second
and following lines.

The \ tells the shell to completely remove the line-break that follows
it. So the way you've written it the shell invokes perl with -e as its
first argument and the second one as:

  print "$^V:";$i="\x{00A0}"-e

That is, that second -e is part of the Perl to be interpreted (as the
argument to the first -e), not an option to perl.

Put the spaces in and everything works fine. (Or put a space at the end
of lines, just before each \ -- as long as there's space somewhere it'll
split the arguments up.)

Or instead of each \ and line-break just type a space, so you get one
long line in your shell -A it'll wrap (which is presumably why Steffen
split it up in the first place).

Or omit the ' before each \ and also omit the -e and ' at the start of
each line -- so when your shell glues the pieces together the whole
program is one argument to the single -e on the first line.

Or omit both the '\ and the -e and ' -- so the argument to the first -e
is one long string with actual line-breaks in it. Perl will happily skip
over the line-breaks before each ; character.

TMTOWTDI!

> Attempting to debug the syntax error, I started with this:
> 
> $> perl -e 'print "$^V:";'
> $>
> 
> ... and got no output.

I get output from that:

  $ perl -e 'print "$^V:";'
  v5.14.2:

I see that your prompt there has a > in it after the $ (which your first
example doesn't), looking like it could be your shell thinks that was a
continuation line of some sort, following problems with a previous
command, perhaps?

> Consulting 'perlvar', I learned that $^V holds
> "[T]he revision, version, and subversion of the Perl interpreter,
> represented *as a C<version> object*.  [Emphasis added.]  So right off
> the bat, there is a problem with this one-liner.

It looks to me like version overloads stringification. Though checking
perldoc version I couldn't see where it says that.

And perhaps the C<version> in the doc you quoted above would be better
as L<version> -- but those are separate issues from this ticket.

Cheers

Smylers
-- 
Stop drug companies hiding negative research results.
Sign the AllTrials petition to get all clinical research results published.
Read more: http://www.alltrials.net/blog/the-alltrials-campaign/

Thread Previous


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