470,827 Members | 1,730 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,827 developers. It's quick & easy.

Strings and Operators

Sorry if this occurs twice, my nicely typed one just vanished. Anyway in brief:

I want to store a range in a string, e.g. '2-5'.

I tried $range = $numOne.'-'.$numTwo+1;

And $range stored the sum of $numOne+1!
I got it to work with,

$range = $numOne.'-'.($numTwo+1);

I understand why this works not not why my initial instinct didn't.
Could someone please enlighten me?

Thanks
James
Jul 19 '05 #1
2 1513
dna

this problem relates to operator/list precedence with and without
parenthesis.

for a good reference please read through 'perlop' in the perldocs. you will
be enlightened!

good luck

"JamesW" <gi*******@hotmail.com> wrote in message
news:27*************************@posting.google.co m...
Sorry if this occurs twice, my nicely typed one just vanished. Anyway in brief:
I want to store a range in a string, e.g. '2-5'.

I tried $range = $numOne.'-'.$numTwo+1;

And $range stored the sum of $numOne+1!
I got it to work with,

$range = $numOne.'-'.($numTwo+1);

I understand why this works not not why my initial instinct didn't.
Could someone please enlighten me?

Thanks
James

Jul 19 '05 #2
dna

another thing, i would bet that specifying the -w option would have thrown
an error/warning when you tried to run that code... make sure you try to
always do:

#!/usr/bin/perl -w

use strict; ## mandatory as well! :)

[code]

"dna" <magmalianathotmaildotcom> wrote in message
news:Qr********************@magma.ca...

this problem relates to operator/list precedence with and without
parenthesis.

for a good reference please read through 'perlop' in the perldocs. you will be enlightened!

good luck

"JamesW" <gi*******@hotmail.com> wrote in message
news:27*************************@posting.google.co m...
Sorry if this occurs twice, my nicely typed one just vanished. Anyway
in brief:

I want to store a range in a string, e.g. '2-5'.

I tried $range = $numOne.'-'.$numTwo+1;

And $range stored the sum of $numOne+1!
I got it to work with,

$range = $numOne.'-'.($numTwo+1);

I understand why this works not not why my initial instinct didn't.
Could someone please enlighten me?

Thanks
James


Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by beliavsky | last post: by
50 posts views Thread by dataangel | last post: by
32 posts views Thread by ataru | last post: by
19 posts views Thread by Anthony Irwin | last post: by
5 posts views Thread by Michael Yanowitz | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.