Strings and Operators

J

JamesW

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
 
D

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
 
D

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:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top