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

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?

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

Comment on Perl Paradigm
Select or Download Code
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.

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) { ; }

    Cheers,
    Ovid

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://231096]
Approved by particle
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (9)
As of 2014-07-28 07:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (193 votes), past polls