Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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:


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 line 942, near "s/ /'_' x length $1/egrx"
syntax error at 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?

Replies are listed 'Best First'.
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.


      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!

      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

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

    Seems to work fine for me on a mac running 5.16.0

    #!/usr/bin/perl # 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 so it would use the perlbrew versions. If I run it with ./ it uses the system install of 5.12.3 and I get your bareword error.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://990758]
Approved by Ratazong
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2017-12-12 03:26 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (324 votes). Check out past polls.