in reply to Re: cv = (irand(2))?"+":"-";
in thread cv = (irand(2))?"+":"-";

my $x = 1; my $y = 2; my $z = "+"; print $x $z $y;

I do not understand where the error is.

Replies are listed 'Best First'.
Re^3: cv = (irand(2))?"+":"-";
by davido (Cardinal) on Apr 05, 2016 at 14:48 UTC

    Variables cannot stand in for operators. Again, you're sort of just making syntax up as you imagine it ought to be. Reading perlintro may help you to bring your expectations in line with the reality of the language.


    Dave

      print eval "$x $z $y", $/; # :P

      monorels, don't really do that; it's snark here, not a good practice.

Re^3: cv = (irand(2))?"+":"-";
by monorels (Novice) on Apr 05, 2016 at 08:43 UTC
    my $x = 1; my $y = 2; my $z = "+"; print $x.$z.$y;

    I'm understand. <\p>