Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Fibonacci Generator

by Hofmator (Curate)
on Aug 10, 2001 at 19:21 UTC ( #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.
      if ($opt_c) { $\ = "\n"; } else { $\ = " "; }
      You can avoid that ugly if/else and excess braces by writing:
      $/= $opt_c ? "\n" : " ";

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2023-04-02 08:43 GMT
Find Nodes?
    Voting Booth?

    No recent polls found