Syntax error Question

Syntax error Question

am 07.04.2004 20:21:31 von Kamal Ahmed

Hi All,

Following is part of a script that generates events:

>From (original code)

$data{'action'} = (intRand(12) < 11) ? 'accept' : 'drop';
if (needError($actionErrRate)) {
if (intRand(20) < 3) {
$data{'action'} = 'deny';
} elsif (intRand(20) < 5) {
$data{'action'} = ' accept ';
} elsif (intRand(20) < 5) {
$data{'action'} = 'a c c e p t';
} elsif (intRand(20) < 5) {
$data{'action'} = 'acc\'eptdeny';
} else {
$data{'action'} = badString();
}
}

to:

$data{'action'} = (intRand(12) < 11) ? 'accept' : 'drop' : 'allow' :
'authcrypt' : 'authorize' : 'ctl' : 'deauthorize' : 'decrypt' :
'encrypt' : 'keyinst' : 'reject' ;
if (needError($actionErrRate)) {
if (intRand(20) < 3) {
$data{'action'} = 'deny';
} elsif (intRand(20) < 5) {
$data{'action'} = 'accept';
} elsif (intRand(20) < 5) {
$data{'action'} = 'drop';
} elsif (intRand(20) < 5) {
$data{'action'} = 'allow';
} elsif (intRand(20) < 5) {
$data{'action'} = 'authcrypt' ;
} elsif (intRand(20) < 5) {
$data{'action'} = 'authorize' ;
} elsif (intRand(20) < 5) {
$data{'action'} = 'ctl' ;
} elsif (intRand(20) < 5) {
$data{'action'} = 'deauthorize' ;
} elsif (intRand(20) < 5) {
$data{'action'} = 'decrypt' ;
} elsif (intRand(20) < 5) {
$data{'action'} = 'decrypt' ;
} elsif (intRand(20) < 5) {
$data{'action'} = 'encrypt' ;
} elsif (intRand(20) < 5) {
$data{'action'} = 'keyinst' ;
} elsif (intRand(20) < 5) {
$data{'action'} = 'reject' ;
} elsif (intRand(20) < 5) {
$data{'action'} = 'a c c e p t';
} elsif (intRand(20) < 5) {
$data{'action'} = 'acc\'eptdeny';
} else {
$data{'action'} = badString();
}
}


I am getting the folowing exception:


$ ./GenChkp.pl 2 2
elseif should be elsif at ./GenChkp.pl line 213.
syntax error at ./GenChkp.pl line 205, near "'allow' :"
syntax error at ./GenChkp.pl line 213, near ") {"
syntax error at ./GenChkp.pl line 215, near "} elsif"
Execution of ./GenChkp.pl aborted due to compilation errors.


Any help would be appreciated.

Thanks,

-Kamal.

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

RE: Syntax error Question

am 07.04.2004 20:37:08 von marms

I think you are very confused about the ternary operator

( expr ? s1 : s2 )

You wrote:

$data{'action'} = (intRand(12) < 11) ? 'accept' : 'drop' : 'allow' :
'authcrypt' : 'authorize' : 'ctl' : 'deauthorize' : 'decrypt' :
'encrypt' : 'keyinst' : 'reject' ;

Not sure what you are trying to do in this statement, but it is
not valid Perl.

--
Mike Arms


> -----Original Message-----
> From: Kamal Ahmed [mailto:Kamal.Ahmed@esecurity.net]
> Sent: Wednesday, April 07, 2004 12:22 PM
> To: perl-win32-users@listserv.ActiveState.com;
> activeperl@listserv.ActiveState.com
> Subject: Syntax error Question
>
>
> Hi All,
>
> Following is part of a script that generates events:
>
> >From (original code)
>
> $data{'action'} = (intRand(12) < 11) ? 'accept' : 'drop';
> if (needError($actionErrRate)) {
> if (intRand(20) < 3) {
> $data{'action'} = 'deny';
> } elsif (intRand(20) < 5) {
> $data{'action'} = ' accept ';
> } elsif (intRand(20) < 5) {
> $data{'action'} = 'a c c e p t';
> } elsif (intRand(20) < 5) {
> $data{'action'} = 'acc\'eptdeny';
> } else {
> $data{'action'} = badString();
> }
> }
>
> to:
>
> $data{'action'} = (intRand(12) < 11) ? 'accept' : 'drop' : 'allow' :
> 'authcrypt' : 'authorize' : 'ctl' : 'deauthorize' : 'decrypt' :
> 'encrypt' : 'keyinst' : 'reject' ;
> if (needError($actionErrRate)) {
> if (intRand(20) < 3) {
> $data{'action'} = 'deny';
> } elsif (intRand(20) < 5) {
> $data{'action'} = 'accept';
> } elsif (intRand(20) < 5) {
> $data{'action'} = 'drop';
> } elsif (intRand(20) < 5) {
> $data{'action'} = 'allow';
> } elsif (intRand(20) < 5) {
> $data{'action'} = 'authcrypt' ;
> } elsif (intRand(20) < 5) {
> $data{'action'} = 'authorize' ;
> } elsif (intRand(20) < 5) {
> $data{'action'} = 'ctl' ;
> } elsif (intRand(20) < 5) {
> $data{'action'} = 'deauthorize' ;
> } elsif (intRand(20) < 5) {
> $data{'action'} = 'decrypt' ;
> } elsif (intRand(20) < 5) {
> $data{'action'} = 'decrypt' ;
> } elsif (intRand(20) < 5) {
> $data{'action'} = 'encrypt' ;
> } elsif (intRand(20) < 5) {
> $data{'action'} = 'keyinst' ;
> } elsif (intRand(20) < 5) {
> $data{'action'} = 'reject' ;
> } elsif (intRand(20) < 5) {
> $data{'action'} = 'a c c e p t';
> } elsif (intRand(20) < 5) {
> $data{'action'} = 'acc\'eptdeny';
> } else {
> $data{'action'} = badString();
> }
> }
>
>
> I am getting the folowing exception:
>
>
> $ ./GenChkp.pl 2 2
> elseif should be elsif at ./GenChkp.pl line 213.
> syntax error at ./GenChkp.pl line 205, near "'allow' :"
> syntax error at ./GenChkp.pl line 213, near ") {"
> syntax error at ./GenChkp.pl line 215, near "} elsif"
> Execution of ./GenChkp.pl aborted due to compilation errors.
>
>
> Any help would be appreciated.
>
> Thanks,
>
> -Kamal.
>
> _______________________________________________
> ActivePerl mailing list
> ActivePerl@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: Syntax error Question

am 07.04.2004 21:26:11 von Rob Dixon

Mike Arms wrote:
>
> I think you are very confused about the ternary operator
>
> ( expr ? s1 : s2 )
>
> You wrote:
>
> $data{'action'} = (intRand(12) < 11) ? 'accept' : 'drop' : 'allow' :
> 'authcrypt' : 'authorize' : 'ctl' : 'deauthorize' : 'decrypt' :
> 'encrypt' : 'keyinst' : 'reject' ;
>
> Not sure what you are trying to do in this statement, but it is
> not valid Perl.

Mike's quite right. It would help if you didn't ask questions about
code that Perl throws out.

I don't know what 'intRand' does, but perhaps you mean something like:

my @action = qw/
accept drop allow authcrypt
authorize ctl deauthorize decrypt
encrypt keyinst reject
/;

$data{action} = $action[intRand(scalar @action)];

HTH,

Rob

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs