Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Perl Paradigm

by tradez (Pilgrim)
on Jan 29, 2003 at 21:13 UTC ( #231096=perlquestion: print w/replies, xml ) Need Help??
tradez has asked for the wisdom of the Perl Monks concerning the following question:

Ok Monks, Try this on for size. I am working with code that in a nutshell has a part that looks like this:
while ($i < $entry){ $i = $entry (2/3); }
etc.... Whereas $i is being iterated earlier in the script. The part I don't get is the fact that my script will go through the iteration one last time when the $i var becomes equivalent to the $entry var. Hence when
while(($i < $entry) && ($i ne $entry){ $i = $entry(2/3); }
is ran, i get the output I am looking for. Can you please help explain this perl paradigm to me?

"Never underestimate the predicability of stupidity"
- Bullet Tooth Tony, Snatch (2001)

Replies are listed 'Best First'.
Re: Perl Paradigm
by dragonchild (Archbishop) on Jan 29, 2003 at 21:20 UTC
    I'm not even sure what you're doing. There's a few issues with the snippets you posted:
    1. In the while, you treat $entry as a number. Then, you treat it as a subroutine name. Do you have a bunch of subroutines named 1, 2, 3, etc?
    2. Assuming you mean $i = $entry * (2 / 3);, the code will never end.
    3. In the second snippet, you are doing a numeric check, then a string check. (< is numeric, ne is string.) While this will work (because both $i and $entry will be converted to strings and compared), it's better to do numeric checks if you're dealing with numbers.

    I guess what I'm asking is - what on earth are you doing? What is $entry?

    Oh - predicability has 2 't's in it. :-)

    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Re: Perl Paradigm
by Ovid (Cardinal) on Jan 29, 2003 at 21:21 UTC

    I will confess that I am most confused. What you have is not valid syntax. Is there something you have left out of your code?

    $ perl -MO=Deparse -e 'while ($i<$entry){$i = $entry (2/3)}' syntax error at -e line 1, near "$entry (" -e had compilation errors. while ($i < $entry) { ; }


    New address of my CGI Course.
    Silence is Evil (feel free to copy and distribute widely - note copyright text)

Re: Perl Paradigm
by dbp (Pilgrim) on Jan 29, 2003 at 21:19 UTC
    I think you must be mistaken. Maybe you should post the actual code.

    Update:Is $i a number? I notice you are using ne in the second example which is for non-numeric data. Less-than will have interesting results if $i or $entry aren't numbers.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://231096]
Approved by particle
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2018-06-18 23:21 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (111 votes). Check out past polls.