CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
<STDIN> question

 



dimilinowski
Novice

Sep 25, 2008, 11:41 PM

Post #1 of 5 (541 views)
<STDIN> question Can't Post

How would I accept a <STDIN> answer in a specific format? Like "what is your social security number?"



Example

12-45-65789



Thanks

Diane
Diane Milinowski


sajanagr
Novice

Sep 26, 2008, 12:41 AM

Post #2 of 5 (540 views)
Re: [dimilinowski] <STDIN> question [In reply to] Can't Post

how abt taking ur input as scalar and later d numbers use regex...
Not all who wander are lost ---- /me


KevinR
Veteran


Sep 26, 2008, 8:28 AM

Post #3 of 5 (525 views)
Re: [dimilinowski] <STDIN> question [In reply to] Can't Post

Use a regular expression to validate the data format after recieving it from input.


Code
my $social = <STDIN>; 
chomp ($social);
if ($social =~ /^\d\d\d\-\d\d\-\d\d\d\d$) {
its good do somthing
}
else {
its not good do something
}


There are plenty of regular expression articles and tutorials on the internet.
-------------------------------------------------


dimilinowski
Novice

Oct 4, 2008, 11:42 AM

Post #4 of 5 (484 views)
Re: [KevinR] <STDIN> question [In reply to] Can't Post

I don't really understand what all the \d, \d, ~ means.

Diane
Diane Milinowski


KevinR
Veteran


Oct 4, 2008, 12:23 PM

Post #5 of 5 (483 views)
Re: [dimilinowski] <STDIN> question [In reply to] Can't Post

\d means one digit. \d\d means two digits. etc etc.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives