simple scratch variable parsing

G

Grant

Hello! I've got scratch variables like:

c1
sc1
sr1

The letters involved should either be "c", "sc", or "sr", and the
number(s) could be any. This is pulled from the URL, and I'd like to
make sure it's formed correctly, so I'd rather not just filter it for
letters and filter it for numbers. It seems like I'd need to check it
character by character? How can I do this? I'm a Perl newbie.
Thanks!

- Grant
 
T

Tad McClellan

Grant said:
Hello! I've got scratch variables like:


How is a "scratch variable" different from a "variable"?

c1
sc1
sr1


Those are not variables. Variables in Perl have sigils.

Those are probably values rather than variables.

The letters involved should either be "c", "sc", or "sr", and the
number(s) could be any. This is pulled from the URL, and I'd like to
make sure it's formed correctly, so I'd rather not just filter it for
letters and filter it for numbers. It seems like I'd need to check it
character by character? How can I do this?


if ( $scratch =~ /^(c|sc|sr)\d+$/ )
{ print "valid\n" }
else
{ print "not valid\n" }
 
G

Grant

Tad McClellan said:
How is a "scratch variable" different from a "variable"?




Those are not variables. Variables in Perl have sigils.

Those are probably values rather than variables.




if ( $scratch =~ /^(c|sc|sr)\d+$/ )
{ print "valid\n" }
else
{ print "not valid\n" }

Thank you very much Tad!

- Grant
 

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

Forum statistics

Threads
474,266
Messages
2,571,091
Members
48,773
Latest member
Kaybee

Latest Threads

Top