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

Re^4: Use Hash? Array? Still confused after all these years.

by brian_d_foy (Abbot)
on Jul 22, 2005 at 03:16 UTC ( #477085=note: print w/replies, xml ) Need Help??


in reply to Re^3: Use Hash? Array? Still confused after all these years.
in thread Use Hash? Array? Still confused after all these years.

I don't say "non negative numbers" either, because you can't use most "non negative numbers" for array indices. I say "counting numbers", "whole numbers", or "cardinal numbers" depending on my mood. It's not really a teaching preference so much as accurately describing the concept.

--
brian d foy <brian@stonehenge.com>
  • Comment on Re^4: Use Hash? Array? Still confused after all these years.

Replies are listed 'Best First'.
Re^5: Use Hash? Array? Still confused after all these years.
by exussum0 (Vicar) on Jul 22, 2005 at 11:41 UTC
    Which non negative numbers aren't usable?

    ----
    Give me strength for today.. I will not talk it away..
    Just for a moment.. It will burn through the clouds.. and shine down on me.

      Pi? 0.06? Rational numbers (negative or not) are not usable array indices.

        I hate to nitpick, because I agree that "non negative numbers" is certainly technically imprecise, and "non negative integers" is overly verbose (an entire extra word! *gasp*), compared to "whole numbers". (Incidentally, "counting numbers" doesn't include zero.) But, check this out:

        perl -Mstrict -lwe 'my @a = (0..20); print $a[$_] for 3.14159, 0.06, ( +75/9), (-75/9)' 3 0 8 13

        Perl seems to be doing an implicit 'int' on the index. (Anyone with better understanding of internals know where this happens? I tried creating a simple Tied class, and the FETCH func still sees a whole number.) This allows you to write $array[rand @array] rather than $array[int rand @array], for example.

        Sort of.
        $array[0.06] = 4;
        is fine with Perl. Just don't expect it to be different from $array[1/4]!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2021-02-26 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?