At 07:24 PM 6/11/01 -0500, Tom Yarrish wrote:
>Well, if anyone is interested, my first day at Sun's Perl Class went
>pretty well. However, I do have a couple of questions that came up during
>the course of the day. I'm hoping someone can clarify.
>
>1) Okay, with array slices...they give you an example of doing this:
>
> ($f[0], $f[1], $f[2]) = @array
>(are the parentheses correct with this? I'm doing the example from memory)
That's correct, if a bit odd for illustrating array slices. Better would
have been something like
($f[0], $f[1], $f[2]) = qw(my brain hurts);
and pointing out that the array slice syntax (see below) is exactly
equivalent to this.
>Why can't you do this:
>
> ($f[0..2]) = @array
Think dollar sign = scalar = one and only one thing. At sign = array =
several things. Therefore,
@f[0..2] = qw(my brain hurts);
>I tried it and it didn't work (obviously), but I was curious as to the
>reason why.
>
>2) With a hash, does the "key" part of the hash have to be a string, or
>can it be a number?
Doesn't matter, Perl will stringify it anyway. You won't be able to tell
the difference.
>3) Why can you do this:
>
> print "$foo";
>or this
> print "@bar";
>but not this
> print "%foobar";
It just is that way. Larry probably felt that the usefulness of hashes
interpolating was not worth giving up another character that would have to
be escaped if desired literally.
>I am actually enjoying the class so far, it's definitely what I needed to
>get kick started in Perl (I just don't have the time to read all my
>O'Reilly books on my own). Of course, I'm sure the Stonehenge Training
>would be better, but they have to set up shop in Chicago ;p
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com