Martha kavishe ha scritto:
Hi All,
I received some response to my problem but unfortunately my problem isn't solved, I'm still struggling..

Thank you all for your contribution

Here is a better short code for the program which gives a clear picture of what I'm trying to ask help for.

use DBI;

$dsn= "dbi:mysql:db_martha: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\\martha.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;

}

elsif (($msg =~ /gu2/i) && ($msg !~ /gu2[0123456789]+/i))

{

$vote = 'gu2';

$found = 1;

}

.

.some more elseif statements here

.

elsif (($msg =~ /gu10/i)&& ($msg !~ /gu10[0123456789]+/i))

{

$vote = 'gu10';

$found = 1;

}

elsif (($msg =~ /gu11/i)&& ($msg !~ /gu11[0123456789]+/i))

{

$vote = 'gu11';

$found = 1;

}

if ($found == 1)

{

$statement = "insert into t_count (time_in, sender, code) values (now(),'$source','$msg')"; #insert into a database

$sth= $dbh->prepare("$statement");

$sth->execute;

print "You entered $vote .\n"; }

else

{

print "Error message or anything....for testing";

}

$dbh->disconnect;

exit;

#######EndHere######

from the above code, the program accepts GU1 to GU11 but not GU 1(space before no), when i send GU 1, it jumps to the else statement. I want the program to ignore the space......

Are you sure you are calling the script using "GU 1" ? If you don't use quotes your program will see GU and 1 as separate arguments.
This is because the shell treats space as argument separator.


I thought by putting x on the line ($msg =~ s/\"/' /igx;) will ignore the space but it doesn't

Your suggestion/help are highly appreciated...

Help me please



--
Marcello Romani
Developer
Spin s.r.l.
Reggio Emilia
http://www.spinsoft.it


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


Reply via email to