Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Re: Re: Input/Output through the Keyboard

by pg (Canon)
on Nov 13, 2002 at 05:45 UTC ( [id://212494]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Input/Output through the Keyboard
in thread Input/Output through the Keyboard

Using eval is one solution:
$_ = <STDIN>; print eval;

Replies are listed 'Best First'.
Re: Re: Re: Re: Input/Output through the Keyboard
by pg (Canon) on Nov 13, 2002 at 05:58 UTC
    Solution is further simplified after matter, the final solution is in above post.
Re: Re: Re: Re: Input/Output through the Keyboard
by pg (Canon) on Nov 13, 2002 at 06:15 UTC
    I cooked a little bit:
    while (<STDIN>) { chomp; if ($_ eq "quit") { exit; } print eval "$_", "\n"; }
Re^3 Input/Output through the Keyboard
by @rocks (Scribe) on Nov 13, 2002 at 06:24 UTC
    Hmm... This is interesting. I was thinking more on the lines of something that had to do with foreach except only dealing with the one variable you enter because of course your only enter one line. Something like:?

    #!/usr/bin/perl<P> $input=<>; foreach $input++1;
    but of course that doesn't work! I need to use foreach on arrays not scalars and I think I messed up the foreach thing too. A programmer told me that  evalis a module? I don't want to use modules.

    -@rocks

      eval() is part of the standard distribution of PERL.

      If you wanted to allow the program to keep running until the user exits you could use something like this:

      #!/usr/bin/perl $| = 1; while( ) { print "Number, plz: "; $input = <>; chomp $input; print "\nOutput is: ", ( ($input*2)-1 ), "\n"; }
      That seemed to work on my system.



      If you make something idiot-proof, eventually someone will make a better idiot.
      I am that better idiot.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://212494]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-26 03:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found