Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Bareword found error on MacOS

by zuma53 (Beadle)
on Aug 30, 2012 at 14:07 UTC ( #990758=perlquestion: print w/ replies, xml ) Need Help??
zuma53 has asked for the wisdom of the Perl Monks concerning the following question:

Hi--

This is probably a no-brainer, but it is something I'm not seeing. I had posted a question on PM, and got a solution (Thanks, Monks!). It works fine on Windows, but when I try running it on a Mac, it errors out.

$stripped = $select =~ s/ ( ' .*? ' ) /'_' x length $1/egrx;
Bareword found where operator expected at x.pl line 942, near "s/ /'_' x length $1/egrx"
syntax error at x.pl line 942, near "s/ /'_' x length $1/egrx"

On the left side of the regex, I want to look for single quotes. The single quotes on the right side is for the repeat operator (right?). I've tried escaping them to no avail (though I think doing that means something else in the regex entirely).

Why is this malformed only on a Mac?

Comment on Bareword found error on MacOS
Download Code
Re: Bareword found error on MacOS
by Fletch (Chancellor) on Aug 30, 2012 at 14:11 UTC

    OS shouldn't matter; more germane would be the versions of Perl involved on both sides (i.e. what does perl -v print on the wintendo box and on the Mac box).

    Update: Not to mention the spurious r modifier on the regex probably doesn't help.

    Update further: OK, so apparently that's a new modifier looks like in 5.14, which probably explains your problems. I get a gripe from my 5.12.4 too so probably you've got 5.14 or newer on your wintendo box and something before that on your mac. Teach me to go play over in clojure land I guess.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      Win: 5.14


      I will have to get back to you on the Mac version, as my laptop is at home.

      Update: Not to mention the spurious r modifier on the regex probably doesn't help.

      Welcome to perl 5.14

      Yessss!

      You identified the problem right off. My Mac was running 5.12. I got another copy from ActiveState and it runs with no issues.

      Thanks to everyone for your help!

Re: Bareword found error on MacOS
by bitingduck (Friar) on Aug 30, 2012 at 15:25 UTC

    Seems to work fine for me on a mac running 5.16.0

    #!/usr/bin/perl # bareword.pl use strict; use warnings; my $select="this isn't a'regular 'expression"; print $select."\n"; my $stripped = $select =~ s/ ( ' .*? ' ) /'_' x length $1/egrx; print $stripped."\n"; print $1."\n"; print $select."\n";
    And gives me:
    this isn't a'regular 'expression this isn_____regular 'expression 't a' this isn't a'regular 'expression

    Edit Also works fine under 5.14.2

    Another Edit Are you sure you're running the right perl version on the mac? If it's picking the perl from the shebang then you could be using the system perl, where you want to use different one (e.g. installed via perlbrew). In my two tests above I ran it with perl bareword.pl so it would use the perlbrew versions. If I run it with ./bareword.pl it uses the system install of 5.12.3 and I get your bareword error.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://990758]
Approved by Ratazong
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2014-08-28 07:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (257 votes), past polls