more useful options PerlMonks

### Re: Precedence design question...'x' & arith

by BrowserUk (Pope)
 on Jul 05, 2013 at 07:14 UTC ( #1042625=note: print w/replies, xml ) Need Help??

in reply to Precedence design question...'x' & arith

I have a dim memory of someone saying that x has the precedence it has, so that you can write:

```print 'this' . ' ' x \$spaces . 'that';

Without the need for parens.

If \$spaces is variable, precalculate it:

```\$spaces = \$n * rand() + theNumberYouFirstThoughtOf();
print 'this' . ' ' x \$spaces . 'that';

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Precedence design question...'x' & arith
by perl-diddler (Hermit) on Jul 05, 2013 at 20:04 UTC
```print 'this' . ' ' x \$spaces . 'that';
This would function unchanged. Someone else made an erroneous statement about 'x' having higher precedence. It doesn't. It has the same as '*', '/', and '%'. I'm saying -- combine your integers first. So above -- without the need for parents, you can write your 2nd example in 1 statement:
```print 'this' . ' ' x \$n * rand() + theNumberYouFirstThoughOf() . that'
+;

You can't do the above in 1 statement in perl, 'now', but you could if you bumped the **non-combining** string operations down 1 precendence level so you can evaluate the complete numeric expression, and use that as input to your 'x' operand which needs an integer on it's right side. Same holds true for '.' at same precedence as '+' and '-'.

```perl -we'
print +2-2 . '*' . 2-2 .'='. -4+4-4+4 . '=' 0;
'
#current perl:
Argument "0*2" isn't numeric in subtraction (-) at -e line 2.
Argument "-2=-4" isn't numeric in addition (+) at -e line 2.
2=0
# proposed would give the integer ops higher precedence and get them
out of the way of the string-combining parts.  Thus:

perl -we'
print +(2-2) . "*". (2-2) . "=" . (-4+4-4+4) . "=". 0 ."\n";
'

0*0=0=0
Thus showing the benefit and effect of proper precedence and evaluating the integer ops at higher precedence than the string ops.
∎ (Q.E.D.)?
;-)
You can't do the above in 1 statement in perl, 'now', ...

Of course you can:

```sub theNumberYouFirstThoughtOf{ 3 };;
\$n=1;
print 'this' . ' ' x ( \$n * rand() + theNumberYouFirstThoughtOf() ) .
+'that';;
this   that

I'm not arguing with your logic. But that's mostly because I cannot see the point in thinking about something that isn't going to change.

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
The requirement was 1 statement w/o parens...sorry, I wasn't clear .. the w/o parens was stated earlier.

Why wouldn't it change?

I.e. what possible reason could there be for it not to change? Are you saying Perl is a Dead language? The only languages that do not changes are dead ones -- and nobody uses them except as historical or examples of things not to do...

Do you think perl is somehow immune to this?

Create A New User
Node Status?
node history
Node Type: note [id://1042625]
help
Chatterbox?
 [Discipulus]: he eh latinos superstitious peoples.. [Discipulus]: here at my \$work fuc**ing bas**ds proposed to everyone 20 free month of pay to leave [Discipulus]: I expect a cut of 20% of emplyoment nexet year..

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2018-05-23 20:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
World peace can best be achieved by:

Results (172 votes). Check out past polls.

Notices?