# confused on a run on equation

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
Hi All,

Why does this work,
\$Rev =~ s; \$Rev -= 1.0;

But this doesn't subtract correctly?
\$Rev =~ s - 1.0;

Many thanks,
-T

## Re: confused on a run on equation

Because =~ is not an assignment operator (nor is it an arithmetic
operator). =~ is a binding operator that applies the substitution
operation on the right-hand side to the entity on the left-hand side,
\$Rev in this case.

The expression \$Rev =~ s returns the number of substitutions
made (either 0 or 1 in this case). The value 1.0 is then subtracted
from this, but is then discarded, since there is no assignment to any
variable. \$Rev retains the value resulting from the substitution
operation.

You can get the substitute operator to return the result of the
substitution by supplying the /r option. In that case, the bound
variable is a copy of \$Rev and not the original, which is left intact,
so you still have to assign it somewhere to preserve it:

\$Rev_minus_1 = (\$Rev =~ sr) - 1.0;

See 'perldoc perlop' and search for 'Regexp quote-Like Operators' for
details.

--
Jim Gibson

## Re: confused on a run on equation

On 08/11/2015 06:43 PM, Jim Gibson wrote:

Hi Jim,

So I mixed reals and string inappropriately.  :-[

Thank you for helping me with this,

-T

## Re: confused on a run on equation

On 08/11/2015 06:43 PM, Jim Gibson wrote:

\$ perl -e '\$Rev="3b12"; \$Rev = (\$Rev =~ sr) - 1.0; print "\$Rev\n"'

Bareword found where operator expected at -e line 1, near "sr"
syntax error at -e line 1, near "sr"
Execution of -e aborted due to compilation errors.

Poop!  (not my exact word.)

## Re: confused on a run on equation

On Wednesday, 12 August 2015 11:32:10 UTC+5:30, T  wrote:

Look for a space between the /r regex modifier & the }

## Re: confused on a run on equation

On 08/11/2015 11:43 PM, sharma__r@hotmail.com wrote:

Not seeing it.  Would you mind writing it out?

## Re: confused on a run on equation

On Wednesday, 12 August 2015 13:26:58 UTC+5:30, T  wrote:

perl -e '\$Rev="3b12"; \$Rev = (\$Rev =~ s r) - 1.0; print "\$Rev\n"'

## Re: confused on a run on equation

On 08/12/2015 01:41 AM, sharma__r@hotmail.com wrote:

\$ perl -e '\$Rev="3b12"; \$Rev = (\$Rev =~ s r) - 1.0; print "\$Rev\n"'

Bareword found where operator expected at -e line 1, near "s r"
syntax error at -e line 1, near "s r"
Execution of -e aborted due to compilation errors.

Poop!

## Re: confused on a run on equation

Yeah.  Hunting syntax errors is a bitch.  First you dissect your code to
find offending statement.  Then stare at it.  Then read 'perldoc
perlop', 'Regexp Quote-Like Operators' section.  And then realize your
ancient perl doesn't do 'r' modifier.

--
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom

## Re: confused on a run on equation

On 08/12/2015 04:33 AM, Eric Pozharski wrote:

Mumble.

Without the "r", gets wrong answer.

\$ perl -e '\$Rev="3b12"; \$Rev = (\$Rev =~ s) - 1.0; print "\$Rev\n"'
0

## Re: confused on a run on equation

On 13.08.15 08:26, T wrote:

With fewer trails of punctuation characters' context dependent
meaning, if any, and less need for exegesis,

\$ perl -e '\$Rev="3b12"; \$Rev =~ s; \$Rev -= 1.0; print "\$Rev\n"'

## Re: confused on a run on equation

On 08/13/2015 03:11 AM, G.B. wrote:

Hi G.B.,

I have been doing this:

\$Rev =~ s; \$Rev -= 1.0;

I was just curious why I couldn't run them together.  I think
the answer is to wait till I upgrade to SL7 and try it again
with a newer version of Perl.

Thank you for the help,
-T

## Re: confused on a run on equation

On Thursday, 13 August 2015 11:56:30 UTC+5:30, T  wrote:
[snip]

what it means is you have an old perl running, as the /r modifer was introduced
in perl 5.14. to check, run this:
perl -Mv5.14 -e ';' -> should fail
or:  perl -v   -> should print version

## Re: confused on a run on equation

On 08/13/2015 07:50 AM, sharma__r@hotmail.com wrote:

Hi Sharma,

I will have to just wait till I upgrade th SL7.

Many thanks,
-T

\$ rpm -qa perl
perl-5.10.1-136.el6.x86_64

\$ perl -Mv5.14 -e ';'
Perl v5.14.0 required--this is only v5.10.1, stopped.
BEGIN failed--compilation aborted.

\$ perl -v
This is perl, v5.10.1..

## Re: confused on a run on equation

*SKIP*

He can't do it.  Ancient perl.

--
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom

## Re: confused on a run on equation

On 08/12/2015 04:21 AM, Eric Pozharski wrote:

Within the next few months, I hope to be on EL7.