in reply to (tye)Re5: Hash slices ?
in thread Hash slices ?
Here are a few lines from perldata:
Here are the lines of code together with how I read them.but entire arrays or array slices are denoted by '@', which works much like the word "these" or "those": @days # ($days[0], $days[1],... $days[n]) @days[3,4,5] # same as @days[3..5] @days{'a','c'} # same as ($days{'a'},$days{'c'}) and entire hashes are denoted by '%': %days # (key1, val1, key2, val2 ...)
Now please explain why I shouldn't take the .. as being a range operator in list context. That is what it looks like was meant, and that fits perfectly...# An array is written like @days and can be thought # of as a list of values @days # ($days[0], $days[1],... $days[n]) # Arrays can be sliced, and a slice of a literal list # is the same as taking a slice of something that # returns a list (in this case a range operator) @days[3,4,5] # same as @days[3..5] # Hash lookups can also be sliced, and a slice of a # literal list is the same as taking a literal # list of lookups. @days{'a','c'} # same as ($days{'a'},$days{'c'}) # You write a hash like %days, and you can think of # it as a list of key/value pairs. %days # (key1, val1, key2, val2 ...)
Also note that the "can think of" that I inserted has an implicit, "but that isn't quite correct" inserted...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re (tilly) 11: Hash slices ?
by tye (Sage) on Apr 16, 2001 at 10:46 UTC | |
by tilly (Archbishop) on Apr 16, 2001 at 16:12 UTC |