[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

RE: [MacPerl] Please don't Laugh at me...



Don't feel bad. We were all new once, some of us several times. :)

When you check <STDIN> for information, it returns whatever you typed in,
plus the carriage return you used to end it with. But, it also stores the
information in a string.

By Perl convention, an identifier in all upper case is a file handle --
something used to identify a file on disk. So, you're trying to match what
your user typed in with a file handle -- or at any rate, something that
isn't in a variable (no $ identifier at the beginning) -- so it won't work.

One way to do this is to try to match a regular expression. Here's one way
to do it:

print ('Who's typing? ');
$input = <STDIN>;
if ($input =~ /pauline/i)
    {
    print ("Hola amigo\n")
    }
else
    {
    print("I don't know you\n")
    }

without going into a lot of detail (there are entire books written on
regular expressions), the third line above checks to see whether the
variable $input, which we got by reading a line from the console (STDIN),
contains the string "pauline" in any combination of upper and lower case. So
your user could type in "Pauline", "pauline", "PaUlInE", or "I'm Pauline" or
"Pauline isn't here, this is Sylvia" or even "SaintPaulInEphesus" and it
will still match the regular expression. It won't, however, match "Fred" or
"Paul" or even "P a u l i n e" because it's looking for that exact string of
seven characters (in any case, of course).

Hope this helps!

-- Creede

> -----Original Message-----
> From: Jorge A. Chica [mailto:jac4586@acf2.nyu.edu]
> Sent: Monday, August 23, 1999 11:37 AM
> To: macperl@macperl.org
> Subject: [MacPerl] Please don't Laugh at me...
> 
> 
> I am relatively new to MacPerl and I would like to know what is wrong
> with my code.
> 
> print ('Please type something: ');
> $input = <STDIN>;
> if ($input = PAULINE){
> print ("Hola amigo\n")
> }else{
> print("I don't know you\n")
> }
> 
> I want it to print out hola amigo if the STDIN is Pauline.  
> If not I want
> it to print out I don't know you.  Sorry to bother you guys...
> 
> Jorge 
> 
> 
> ===== Want to unsubscribe from this list?
> ===== Send mail with body "unsubscribe" to macperl-request@macperl.org
> 

===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org