Click here to get back home

generic declaration of variables

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
generic declaration of variables Ela 03-20-2008
Posted by ccc31807 on March 21, 2008, 11:13 am
Please log in for more thread options
> `perldoc perldata` offers....
>
> If you're confused about why you use an '@' there on a hash slice
> instead of a '%', think of it like this. The type of bracket (square or
> curly) governs whether it's an array or a hash being looked at. On the
> other hand, the leading symbol ('$' or '@') on the array or hash
> indicates whether you are getting back a singular value (a scalar) or a
> plural one (a list).

Thanks. I was afraid that I would get an answer like this, 'You do it
that way because Larry said to.' I understood the operation because I
had modified the code in question and had run it several times to
determine if it in fact worked as advertised. It did.

I didn't understand the concept, but now I see it. I'm not entirely
comfortable with it, but I at least have a head knowledge, and assume
that the experiential knowledge will come with use. Perl has been
accused of being willfully obscure, and at moments like this I
sympathize with this accusation.

Thanks again for your explanation. It did indeed do the trick.

CC

Posted by Lawrence Statton on March 21, 2008, 11:50 am
Please log in for more thread options
> Thanks. I was afraid that I would get an answer like this, 'You do it
> that way because Larry said to.'

I don't understand that statement at all -- every language has it's
syntax rules ... When writing C we use parens to indicate function
calls, not because Dennis said to, but because that's what the
compiler will accept.

>
> I didn't understand the concept, but now I see it. I'm not entirely
> comfortable with it, but I at least have a head knowledge,

Well, if slice notation is uncomfortable to you, there is no
compulsion to use it.

>
> Thanks again for your explanation. It did indeed do the trick.
>


--
        Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer software consists of only two components: ones and
zeros, in roughly equal proportions. All that is required is to
place them into the correct order.

Posted by ccc31807 on March 21, 2008, 3:02 pm
Please log in for more thread options
> > Thanks. I was afraid that I would get an answer like this, 'You do it
> > that way because Larry said to.'
>
> I don't understand that statement at all -- every language has it's
> syntax rules ... When writing C we use parens to indicate function
> calls, not because Dennis said to, but because that's what the
> compiler will accept.

I didn't mean to be insulting. Maybe I should have said, 'You do it
this way because this is the way you do it.' I remember the first time
anyone really explained objects to me (in Java). I had been writing
Java the way it's taught, classes, objects, properties, methods, etc.,
just by rote. Then, one day, someone who really knew what he was doing
explained ADTs, the difference between primitive types and classes,
allocation of the heap, references, and so on. It made a lot more
sense with a mental picture of using 'new' to allocate storage for an
object based on a class definition.

It's one thing to follow the rules, it's another to understand the
rationale for the rules. I understand the necessity of conforming to
the syntax of a language, but I also attempt to understand the reason
for the syntax.

Thanks again, CC.

Posted by Peter J. Holzer on March 21, 2008, 8:07 pm
Please log in for more thread options
>> > Thanks. I was afraid that I would get an answer like this, 'You do it
>> > that way because Larry said to.'
>>
>> I don't understand that statement at all -- every language has it's
>> syntax rules ... When writing C we use parens to indicate function
>> calls, not because Dennis said to, but because that's what the
>> compiler will accept.

And of course the C compiler will accept it because Dennis said it
should ;-).


> I didn't mean to be insulting. Maybe I should have said, 'You do it
> this way because this is the way you do it.'
[...]
> It's one thing to follow the rules, it's another to understand the
> rationale for the rules. I understand the necessity of conforming to
> the syntax of a language, but I also attempt to understand the reason
> for the syntax.

You'd have to ask Larry why he chose this particular syntax. One reason
why Perl is "strange" is that Larry - unlike most programming language
designers - is a linguist. So he borrowed lots of concepts from natural
languages. The sigils are articles (the English language has only one
specific article "the", which is used for singular and plural and all
genders, but most European languages distinguish between singular and
plural - so does Perl).

        hp


Posted by Ben Bullock on March 21, 2008, 8:08 pm
Please log in for more thread options
On Fri, 21 Mar 2008 08:13:44 -0700, ccc31807 wrote:

> I didn't understand the concept, but now I see it. I'm not entirely
> comfortable with it, but I at least have a head knowledge, and assume
> that the experiential knowledge will come with use. Perl has been
> accused of being willfully obscure, and at moments like this I
> sympathize with this accusation.

When we put a $ in front of a hash or array, we tell Perl to think of the
hashes and arrays as if they are scalars:

for (my $i=0;$i<@ARGV;$i++) {
$args = $ARGV[$i];
}

When we put a @ there, we tell Perl to think of a hash or array as a
whole array:

@args = @ARGV;

So Perl is very clever, it can understand that we want to bung a whole
list of stuff into a hash indexed by another list of stuff without typing
"<", "=", "0", "$" seven times, "+" twice, "[]" twice, "()", "{}", and ;
once, and also without having to type "for", or "ARGV" twice, or "$i"
five times.

Similar ThreadsPosted
NetServer::Generic -- welcome message ?? March 30, 2006, 5:04 am
generic increment of number/string November 21, 2006, 11:21 am
Generic Syntax highlighting module June 17, 2007, 9:33 am
[perl-python] generic equivalence partition February 24, 2005, 4:48 am
Creating and outputting a generic data structure? January 17, 2006, 10:00 am
Generic fingerprint ie hash value for compex data structure? July 24, 2004, 9:39 am
Detecting the declaration of a variable? October 21, 2005, 11:18 am
Strange asterisk use in a hash declaration November 23, 2004, 6:31 am
been using Java too long: please help with dynamic "our" declaration January 25, 2006, 2:52 pm
Variable declaration - C vs script style July 31, 2007, 8:01 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap