What is Perl 6?
chromatic writes "Perl.com has a new article entitled What is Perl 6?. It analyzes the changes to the language in light of the good and bad points of Perl 5 and provides new information about the current state of the project: Perl 6 exists, you can write code in it today, and it's more consistent and easier to use than Perl 5."
Did you read the same article I wrote or is your post from the mysterious future? Larry announced Perl 6 in the summer of 2000.
how to invest, a novice's guide
Here http://www.pugscode.org/ is something on the PUGS project, which is making an implementation of Perl 6 in Haskell, conformant to the spec.
Apparently they are having a lot of fun.
http://www.thebricktestament.com/the_law/when_to_
Oh please.
"Especially when every perl doc I see around tells me to use curved parentheses for lists, and @ prefixes for variables that refer to them..."
How hard did you look, really? If you go to Google and type in perl list of lists, the FIRST link takes you here.
And within 1/2 a page, you see this:
Damn anti-Perl trolls :-)
-- Trinity in high heels carrying a whip: The donimatrix - there is no spoonerism
Can you recommend a resource for OOP with Perl?
Right now i found all i needed in the Perl.org site - this OO tutorial for Perl is pretty complete. There's also this one, which is oriented to begginers.
In fact, i always keep a browser window open to Perl.org when i'm coding Perl - the tutorials are very nice, but the function reference has been priceless to me.
Yes, that's really intuitive, thanks. Especially when every perl doc I see around tells me to use curved parentheses for lists, and @ prefixes for variables that refer to them, and I have no clue what data structure you've used above.
You're right; you do need curved parens for real lists. It may be helpful to think of the @ mark as referring to multiple values, rather than to a list specifically. It's also used for list and hash slices, like this: @list[1,3,5] and @names{'tom', 'dick', 'harry'} (Both of those expressions really just evaluate to lists, but, particularly with the hash slice, that's not necessarily obvious).
The other responders, in their haste to point out how much perlier-than-thou they are, have glossed over the fact that 'my $list = [[1,2],[3,4],5,[6,7,8]];', as you've pointed out, doesn't exactly produce a list of lists. It produces a data structure that's close enough to a list of lists that they can call it that without being entirely wrong.
(Warning: Perl content. I love Perl, so it'll probably sound like I'm rambling. My apologies.)
You can't directly create a list of lists in Perl. Not possible, because they'll get flattened. But what you can do is create a list of *references* to lists. There are two ways to do this:
my @list1 = (1, 2, 3);
my @list2 = (4, 5, 6);
my @combined = (\@list1, \@list2);
Or:
my @combined = ([1, 2, 3], [4, 5, 6]);
This second syntax is called the anonymous list syntax.
The upshot is that lists are surrounded by (), as you already know, but that by replacing them with [], you get a reference to a list with no other name. The same can be done for hashes with {}, which means that all Perl data structures can be arbitrarily nested.
So, your Python example, in Perl, would create a reference to a list of references to lists. Its elements would be accessed like this:
my $list = [[1,2],[3,4],5,[6,7,8]];
print $list->[0][1] # prints 2
The -> is used for dereferencing, but Perl is clever enough to figure out that the value of '$list->[0]' is also a reference, and doesn't require you to write the -> between [0] and [1].
You could also write your example like this:
my @list = ([1,2],[3,4],5,[6,7,8]); # note the ()
print $list[0][1] # *also* prints 2!
It turns out Perl is *still* clever enough to figure out that $list[0] is a reference, and will automatically dereference it for you. No -> required.
I hope this helps clear things up a bit!
Intuitively, a new user would look at the TOC and see perldata "Perl Data Types" and think that the complete definition of the 3 main Perl data types would be described. So rsidd looks for instructions on creating multidimensional arrays, sees "List value constructors" and gets this:
So they head over to perlref (an extra level of indirection) and notice in Item 2:
But this isn't really easy to understand. Why does he need an arrayref when he wants an array?
@array = [1, 2, ['a', 'b', 'c']];
That isn't the same as what he wants. In fact, it's not what you'd expect from DWIM. It's a single entry array, not a multidimensional array. It's not even a list of lists (unless you perform a little magic on it).
So finally after struggling with this and ending up with some ugly monstrosity like the following:
@array = @{[1,2,\@{['a','b','c']}]};
Now his code works, but it isn't very easy to understand, and the maintainers of this code are going to tell everyone how evil and illegible Perl is because the programmer here couldn't figure out how to make a multidimensional array.
The only FAQ entry with the term "multidimensional" in it refers to some DBM-specific topic that doesn't seem to have any relation to the problem at hand. While "list of lists" may be the preferred term in the Perl community, it would be nice to have a FAQ entry like "How do I create a multidimensional array?"
As you've mentioned, perllol has the exact syntax of how to do this. Unfortunately for our poor programmer, the link to that is buried in the See Also section alongside perldsc (which is large and contains quite a bit of irrelevant information like 'use strict' information, while at the same time not providing very detailed information about the data structures themselves). The very first 'perldoc perllol' page displayed gives the answer immediately:
Why is it so hard to get to this simple explanation? Why should a neophyte have to go through two documents to finally get to perllol? The FAQ should describe the technique using "multidimensional" as a keyword.
I love Perl, and I love the depth and breadth of the Perl docs, but they are difficult to navigate for Perl neophytes.
Dang it, copy-and-paste missed a couple of sentences at the end. Here they are, in context:
It turns out Perl is *still* clever enough to figure out that $list[0] is a reference, and will automatically dereference it for you. No -> required. The beauty of this automatic dereferencing is that it allows Perl to DWIM (Do What I Mean): Perl is perfectly content to let you pretend that a 'list of *references* to lists' is actually just a 'list of lists'. The downside of the automatic dereferencing is that it turns the easy-to-miss difference between '((1,2),(3,4))' and '([1,2],[3,4])' into Just Another Bit Of Fiddly Syntax To Remember.
Because in Perl
"1"."2" eq "12"
and
1 + 2 == 3
If a loosely typed language is using + for concatenation, it's poorly designed (you'd end up typing more to specify what you want done).
You need to know that the concatenation of two variables is not the same as adding them together.
Slightly relieved that Perl 6 switched from using underscore to tilde for concat - underscore is overloaded with so many other tasks already. Unfortunately ~ still requires shift to be pressed on my keyboards, but I guess they are running out of symbols, and at least I think ~ won't require you to keep putting spaces around it to disambiguate it from other meanings.