meanroc has asked for the wisdom of the Perl Monks concerning the following question:

Hello guys, I am new on perl..I coded:

if ($resul =~ /xss/) { print "\a site vulneravel!!!\n\n"; } else { print "\a site nao vulneravel!!!\n\n"; }

And run right... But I want to transform this on a variable.. How can I do this??TKS

Replies are listed 'Best First'.
Re: Dounds with "if" statement
by hdb (Monsignor) on Jan 23, 2014 at 21:26 UTC

    Use the ternary operator:

    $response = $resul =~ /xss/ ? "\a site vulneravel!!!" : "\a site nao v +ulneravel!!!"; print "$response\n\n";
Re: Dounds with "if" statement
by McA (Priest) on Jan 23, 2014 at 21:36 UTC

    In some cases probably more readable:

    my $response = "\a site nao vulneravel!!!\n\n"; if ($resul =~ /xss/) { $response = "\a site vulneravel!!!\n\n"; }

    A matter of taste.

    Regards
    McA

Re: Dounds with "if" statement
by Kenosis (Priest) on Jan 23, 2014 at 21:55 UTC

    Probably less readable, but another ternary option--used inline:

    use strict; use warnings; my $resul = 'string stuff'; my $resp = "\a site " . ( $resul =~ /xss/ ? 'nao ' : '' ) . "vulnerave +l!!!\n\n"; print $resp;
Re: Dounds with "if" statement
by kcott (Archbishop) on Jan 24, 2014 at 11:42 UTC

    G'day meanroc,

    Here's a more succinct way to do that:

    print "\a site ", ($resul !~ /xss/ and "nao "), "vulneravel!!!\n\n";

    -- Ken