Space proplem

2005-10-14 Thread Martha kavishe



Hi There; 

i have this problem of space in my program. 
The program requires a user to send in Either GU1 or TR1. When they send GU1 or 
TR1 it accepts it and that is fine. But My concern is; if they send GU 1 or TR 
1(Leaving spaces before the number) then the program doesn't accept. It goes 
straight to the else statement. Please check the code, i'm a begginer in 
programming please someone help me.. 

This is just part of the code;

#!/usr/bin/perl -w

use DBI;

$dsn= 
"dbi:mysql:db_manofthematch:localhost";my $user= "mysql";my $password = 
"mysql123";$dbh = DBI-connect($dsn,$user,$password);

##GET ARGS 
##$msg = $ARGV[1];$source = 
$ARGV[0];

$msg =~ s/\"/'/igx;

$time = localtime();open (OUTFILE 
,"C:\\logs\\man.txt");print OUTFILE 
"$time\t$source\t$msg\n";close(OUTFILE);

$found = 0;

 GU 


if (($msg=~ /gu1/i) 
 ($msg !~ /gu1[0123456789]+/i)){$vote = 
'gu1';$found = 1;}
else
{print 
".Erro.";}$dbh-disconnect;exit;

Please help 
me...


Re: Space proplem

2005-10-14 Thread pan
Hi Martha,

Although I do not understand exactly what it is that
you want, the following could help ...

#1# $msg =~ s/\/'/igx;
#2# if (($msg=~ /gu1/i)  ($msg !~ /gu1[0123456789]+/i))

First remove line #1#.
I guess you did an attempt to remove quotes here, that weren't even there
(you can see if you print $msg).

Then change line #2# to:

if($msg =~ /gu ?1/i)

Then a single space is allowed, if you would like to allow
more whitespace there (any number of tabs or spaces), you could also do
if($msg =~ /gu[ \t]*1/i)

Maybe you should also extend your code to check that there are
any arguments (you assume $ARGV[1] exists).

For obtaining program arguments, I like to use Getopt,
see one of these links:
http://www.cs.mcgill.ca/~abatko/computers/programming/perl/howto/getopts/
http://aplawrence.com/Unix/perlgetopts.html

Hope that helps.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response