473,511 Members | 10,700 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1557
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
7582
by: beliavsky | last post by:
By mistake I coded something like print ("1" > 1) and got the result "True". Comparing an integer and a string seems meaningless to me, and I would prefer to have an exception thrown. Can...
50
6097
by: dataangel | last post by:
I wrote a function to compare whether two strings are "similar" because I'm using python to make a small text adventure engine and I want to it to be responsive to slight mispellings, like...
32
8806
by: ataru | last post by:
I want to find the position of a character in a string and replace it another if it is actually there, and I'd like the operation to be efficient. I'm assuming the "standard" way to do this is...
11
2028
by: jbperez808 | last post by:
>>> rs='AUGCUAGACGUGGAGUAG' >>> rs='GAG' Traceback (most recent call last): File "<pyshell#119>", line 1, in ? rs='GAG' TypeError: object doesn't support slice assignment You can't assign to...
19
1503
by: Anthony Irwin | last post by:
Hi, I am new to c and am having trouble with strings can anyone give me some quick pointers or point me to a good c strings tutorial? Below is a program I am working on. Kind Regards,...
4
2000
by: Kza | last post by:
Hi, just in the process of maintaining some software that used some funy old string library and char*s , and we are updating everything to use std::strings. (or should I say std::basic_string<>s) ...
4
2803
by: roxorsoxor2345 | last post by:
I have this custom string class that I have created. #include <cstdlib> #include <iostream> using namespace std; class Cstring { private:
4
455
by: CoreyWhite | last post by:
/* WORKING WITH STRINGS IN C++ IS THE BEST WAY TO LEARN THE LANGUAGE AND TRANSITION FROM C. C++ HAS MANY NEW FEATURES THAT WORK TOGETHER AND WHEN YOU SEE THEM DOING THE IMPOSSIBLE AND MAKING...
5
1469
by: Michael Yanowitz | last post by:
Hello: I have been searching for an easy solution, and hopefully one has already been written, so I don't want to reinvent the wheel: Suppose I have a string of expressions such as: "((($IP =...
6
4095
by: cutlass | last post by:
Need help in thus script. Trying to create the script that uses comparison operators and functions to compare two strings entered by user. When I add in the info in the script section everything...
0
7251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7367
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7430
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7089
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5673
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5072
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1581
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
790
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.