Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Continued Fractions

by fundflow (Chaplain)
on Nov 16, 2000 at 21:10 UTC ( #41996=note: print w/replies, xml ) Need Help??


in reply to Continued Fractions

Cool script. Thanks.

Small suggestion: It is usually useful to make scripts pipeable, which is really easy for us perlers. All you need to do is change the input to something like:

print "Please enter a number or expression: "; my $num=<> || exit(0); print "How many iterations: "; my $count=<> || exit(0); $num=eval($num); chomp($count);
and then it will work from stdin and will exit on ^D (^Z on dos?) if it reads from STDIN.

Cheers

Replies are listed 'Best First'.
Re (tilly) 2: Continued Fractions
by tilly (Archbishop) on Nov 16, 2000 at 22:40 UTC
    First of all as merlyn has pointed out, seeing interactive messages mixed with reading from @ARGV usually is a sign of problems.

    Secondly I intentionally didn't make it pipeable. The point of this script is to let people figure out how it works, and then run it interactively (adding debug messages if you want) to give people a sense of how well it works. Any programmer should be able to figure out how to hit control-C. *shrug*

    Before making it pipeable what I would do is add some logic to cut off at a sufficiently good approximation rather than trying to display the approximation process to the user. My not doing so is my way of saying that this code is not meant to be particularly useful in a pipeline. I didn't do that here because the entire point is education, not production. That is, rather than give a useful answer, it shows you the successive steps towards one.

    In fact I probably would never make this pipeable. Instead it would go into a module, and you would use that module in your programs.

Re: Re: Continued Fractions
by Fastolfe (Vicar) on Nov 16, 2000 at 21:13 UTC
    Why would <STDIN> differ from <> in this respect? Hitting an EOF character should work the same in either case. The only difference between <STDIN> and <> is that the latter will step through the lines of any files specified on the command line:
    $ perl script.pl $ perl script.pl file1 file2 filen
    The first reads from the STDIN, but the second only references the contents of each of the files.
      Yup, little difference indeed.

      The emphasis was on the || exit thing. Without it the script will have to be killed explicitly, and perl script.pl < my_prepared_input > theoutput will loop forever.

      Anyway, it was just a small suggestion (and a good practice in general)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://41996]
help
Chatterbox?
and dust plays in a shaft of sunlight...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2017-12-11 07:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (288 votes). Check out past polls.

    Notices?