simple use of eval of somethinng else

Discussion in 'Perl Misc' started by Billy Patton, Feb 20, 2007.

  1. Billy Patton

    Billy Patton Guest

    I have a string
    $expecxted_status = "!= 0";
    $status = 0;

    What I'm trying to do is

    if ($status != 0) {
    ....
    }


    How do I get the $expected_status to evaluate to the boolean that it is, in
    relation to $status?


    $a = '== 0';
    $b = '2';
    eval { "$b $a" }; warn $@ if $@;

    The above does nothing.
    Billy Patton, Feb 20, 2007
    #1
    1. Advertising

  2. Billy Patton

    Ch Lamprecht Guest

    Billy Patton wrote:
    > I have a string
    > $expecxted_status = "!= 0";
    > $status = 0;
    >
    > What I'm trying to do is
    >
    > if ($status != 0) {
    > ...
    > }
    >
    >
    > How do I get the $expected_status to evaluate to the boolean that it is, in
    > relation to $status?


    use strict;
    use warnings;
    my $s = '==1';
    my $t = '0';
    my $result = eval $t.$s ? 1:0;
    print $t,$s,' evaluates to ',$result;

    If you describe your task , you most probably will get answers that are more
    useful than this.

    Christoph

    >
    >
    > $a = '== 0';
    > $b = '2';
    > eval { "$b $a" }; warn $@ if $@;
    >
    > The above does nothing.
    >
    >



    --
    use Tk;use Tk::GraphItems;$c=tkinit->Canvas->pack;push@i,Tk::GraphItems->
    TextBox(text=>$_,canvas=>$c,x=>$x+=70,y=>100)for(Just=>another=>Perl=>Hacker);
    Tk::GraphItems->Connector(source=>$i[$_],target=>$i[$_+1])for(0..2);
    $c->repeat(30,sub{$_->move(0,4*cos($d+=3.16))for(@i)});MainLoop
    Ch Lamprecht, Feb 20, 2007
    #2
    1. Advertising

  3. Billy Patton

    Mirco Wahab Guest

    Billy Patton wrote:
    > How do I get the $expected_status to evaluate to the
    > boolean that it is, in relation to $status?
    >
    > $a = '== 0';
    > $b = '2';
    > eval { "$b $a" }; warn $@ if $@;
    >
    > The above does nothing.


    use strict;
    use warnings;

    my $s1 = '== 0';
    my $s2 = '2';

    print eval( "$s2 $s1" ) ? 'true' : 'false';
    print "\nerror $@" if $@;

    see: perldoc -f eval
    (EXPR eval)

    Regards

    M.
    Mirco Wahab, Feb 20, 2007
    #3
  4. Billy Patton

    Guest

    "Billy Patton" <> wrote:
    > I have a string
    > $expecxted_status = "!= 0";
    > $status = 0;
    >
    > What I'm trying to do is
    >
    > if ($status != 0) {
    > ...
    > }
    >
    > How do I get the $expected_status to evaluate to the boolean that it is,
    > in relation to $status?
    >
    > $a = '== 0';
    > $b = '2';
    > eval { "$b $a" }; warn $@ if $@;


    You are using the block eval on something which just happens to be
    a string. You probably want to do a string eval:

    my $result = eval "$b $a"; warn $@ if $@;
    print something_to_do_with($result);

    > The above does nothing.


    It does plenty. It prints nothing. Which is expected, as you
    haven't told it to print anything.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Feb 20, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    25
    Views:
    660
    MonkeeSage
    Oct 1, 2006
  2. kj
    Replies:
    15
    Views:
    548
    Lawrence D'Oliveiro
    May 23, 2009
  3. A
    Replies:
    8
    Views:
    795
    James Kanze
    Aug 28, 2010
  4. Gergely Kontra
    Replies:
    16
    Views:
    230
    Devin Mullins
    Sep 20, 2005
  5. Lee

    eval() how else

    Lee, Aug 31, 2004, in forum: Javascript
    Replies:
    4
    Views:
    86
    Thomas 'PointedEars' Lahn
    Sep 4, 2004
Loading...

Share This Page