Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

StommePoes's scratchpad

by StommePoes (Scribe)
on May 18, 2009 at 08:03 UTC ( #764595=scratchpad: print w/replies, xml ) Need Help??

Lama example, 5th edition, page 41, Special Array Indices

First an array is introduced:

$rocks[0] = 'bedrock'; #One element... $rocks[1] = 'slate'; #another... $rocks[2] = 'lava'; #and another... $rocks[3] = 'crushed rock'; #and another... $rocks[99] = 'schist'; #now there are 95 undef elements

then there's

$end = $#rocks; #99, which is the last element's index $number_of_rocks = $end + 1 #okay, but you'll see a better way late +r $rocks[$#rocks] = 'hard rock' #the last rock

I thought, because I didn't quite see what the sudden appearance of $number_of_rocks meant, that somehow a new index was being tacked on at the end of the array, and then given the value of 'hard rock'. I didn't realise that 'schist' was no more and that it's $rocks[99] = 'hard rock'.

Niet een slimme poes.

#!/usr/bin/perl use strict; use warnings; print "Type in a string: \n"; chomp ($string = <STDIN>); $string.=' '; print "Type in a number: \n"; chomp ($int = <STDIN>); if ($int >= 100) { print "Whoa, too big man.\n"; } else { print "The result is \n", $string x $int,"\n"; }
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2023-02-04 12:14 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (31 votes). Check out past polls.