473,230 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 software developers and data experts.

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 1553
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
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
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
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
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
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
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
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
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
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
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.