# String Comparison

I am tring to do a condition on a string,

it looks like this.......->

if(\$string =~ /[0...650]/)
{
do something

}

I am tring to compare a range from 0 - 650 at the being of the string.

• : I am tring to do a condition on a string,
:
: it looks like this.......->
:
: if(\$string =~ /[0...650]/)
: {
: do something
:
: }
:
: I am tring to compare a range from 0 - 650 at the being of the string.
:
That won't work because [...] constructs a character class. Plus yours is wrong because it should be ".." rather than "..." to construct a range. The problem is you if you write:-

0..650

Actually that's equivalent to saying construct a character class with all values between 0 and 6 as well as the numbers 5 and 0 (which you've already included).

If you want to check if there is a number at the start of a string and that it's in a certain range, then you need to do something like:-

[code]if (\$string =~ /^(d+)/ && \$1 >= 0 && \$1 <= 650) {
# do something
}[/code]

Here we check three things:-

1) That \$string starts with a number. ^ means "look at the start of the string". d means a digit, + means one or more digits and putting it in brackets captures that number and stores it in \$1 (if we have another set of brackets later, it'd store it in \$2, etc).

2) That the captured value \$1 is greater than or equal to 0.

3) That the captured value \$1 is less than or equal to 650.

Thus this condition only evaluates true if \$string starts with a number between 0 and 650 inclusive.

Jonathan

###
for(74,117,115,116){\$::a.=chr};((\$_.='qwertyui')&&
(tr/yuiqwert/her anot/))for(\$::b);for(\$::c){\$_.=\$^X;
/(p.{2}l)/;\$_=\$1}\$::b=~/(..)\$/;print("\$::a\$::b \$::c hack\$1.");

• : : I am tring to do a condition on a string,
: :
: : it looks like this.......->
: :
: : if(\$string =~ /[0...650]/)
: : {
: : do something
: :
: : }
: :
: : I am tring to compare a range from 0 - 650 at the being of the string.
: :
: That won't work because [...] constructs a character class. Plus yours is wrong because it should be ".." rather than "..." to construct a range. The problem is you if you write:-
:
: 0..650
:
: Actually that's equivalent to saying construct a character class with all values between 0 and 6 as well as the numbers 5 and 0 (which you've already included).
:
: If you want to check if there is a number at the start of a string and that it's in a certain range, then you need to do something like:-
:
: [code]if (\$string =~ /^(d+)/ && \$1 >= 0 && \$1 <= 650) {
: # do something
: }[/code]
:
: Here we check three things:-
:
: 1) That \$string starts with a number. ^ means "look at the start of the string". d means a digit, + means one or more digits and putting it in brackets captures that number and stores it in \$1 (if we have another set of brackets later, it'd store it in \$2, etc).
:
: 2) That the captured value \$1 is greater than or equal to 0.
:
: 3) That the captured value \$1 is less than or equal to 650.
:
: Thus this condition only evaluates true if \$string starts with a number between 0 and 650 inclusive.
:
: Jonathan
:
: ###
: for(74,117,115,116){\$::a.=chr};((\$_.='qwertyui')&&
: (tr/yuiqwert/her anot/))for(\$::b);for(\$::c){\$_.=\$^X;
: /(p.{2}l)/;\$_=\$1}\$::b=~/(..)\$/;print("\$::a\$::b \$::c hack\$1.");
:
:
Thank you so much... You Rock.

#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!