Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Fibonacci Generator

by Hofmator (Curate)
on Aug 10, 2001 at 19:21 UTC ( [id://103904]=note: print w/replies, xml ) Need Help??


in reply to Fibonacci Generator

You could avoid those ugly ifs before every printout by saying

if ($opt_c) { $\ = "\n"; } else { $\ = " "; }
at the top of your program (see perlvar). Your prints then simply become print; or print $y;

And two random remarks, you might be interested in this recent thread, also dealing with the Fibonacci series and I hope you developed your program using strict and warnings :)

-- Hofmator

Replies are listed 'Best First'.
Re: Re: Fibonacci Generator
by sifukurt (Hermit) on Aug 10, 2001 at 19:50 UTC
    Ooooo, I like that. Hadn't even thought of doing it that way. I'm updating the posted code using your suggestion.

    I think I developed using strict and whatnot. I almost always do unless it is only going to be a two- or three-liner. Sometimes I still unconsciously rebel against my COBOL days and forget to use strict, but that happens far less often than it used to.
    ___________________
    Kurt
      if ($opt_c) { $\ = "\n"; } else { $\ = " "; }
      You can avoid that ugly if/else and excess braces by writing:
      $/= $opt_c ? "\n" : " ";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-19 04:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found