tag:blogger.com,1999:blog-1828118433462570262.post1420154236054827204..comments2023-03-25T02:17:46.279-07:00Comments on Ben Wing's tech blog: Perl sucksUrbanVagabondhttp://www.blogger.com/profile/12785106679306885678noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-1828118433462570262.post-53596578014224144312015-02-23T09:00:30.427-08:002015-02-23T09:00:30.427-08:00perl -e 'use strict; my $a=[["a",&qu...perl -e 'use strict; my $a=[["a","b"], 1]; print $a->[0]->[0]'<br /><br />Also, perldoc warnings. All code written since 2010 should have warnings turned on, and it would have told you about at least 50% of your mistakes.<br /><br />It sucks its not on by default, sure, but it can't be made on by default due to legacy compat reasons. <br /><br />It looks like you ended up with an archaic book that was simply no longer relevant and you got a lot of outdated advice, and then dumped your existing preconceptoins on top of that. ( For instance, anyone with rudimentary knowledge of perl will tell you "a" + "b" is math, not concatenation , you want "." for that. )KENTNLhttps://www.blogger.com/profile/03928687531294568058noreply@blogger.comtag:blogger.com,1999:blog-1828118433462570262.post-72033747729251324772014-11-29T14:11:11.697-08:002014-11-29T14:11:11.697-08:00I first picked up Perl about two years ago. It was...I first picked up Perl about two years ago. It was unpopular and had a bad reputation and I wanted to see what the fuss was about. References are somewhat consistent, but unnecessarily complex. It's easy to get them wrong and not notice, and hard to debug if you do make a mistake. Using references to arrays and hashes is more convenient in general, but you frequently have to deference them to use the builtin functions and wind up having two syntaxes for many things. The Perl documentation is in some ways not helpful since it's geared more towards people trying to get an in-depth understanding of all the minutiae than actually trying to use the language. Here's my attempt at a condensed explanation.<br /><br />my @a = ("a", "b"); # array of "a" and "b"<br />print $a[0];<br /><br /># pathological autoflattening behavior<br />my @a = ("a", ("b", "c")) # array of "a", "b", and "c" <br />print $a[2] # prints "c"<br /><br /># array reference<br /># sigils and -> both dereference scalars. <br /># $,@,% indicates the type of the expression you are getting back,<br /># not the type of container.<br />my $a = ["a", "b"];<br />print $a->[0]; # prints "a".<br />print $$a[0]; # also prints "a". can also be explicitly written ${$a}[0]<br /><br />@{$a}[0] # one element slice of $a ... the @ means you're getting an array.<br /><br /># indexing is in some ways pretty consistent.<br /># if you want an array of values corresponding to keys from a hash<br /># you can take a hash slice<br />my %h = (key0 => 'value0', key1 => 'value1', key2 => 'value2');<br />@h{'key0', 'key1', 'key0'} # ('value0', 'value1', 'value0')<br /><br /># values of a hash sorted by key.<br />@h{sort keys %h}<br /># same thing for a hash reference<br />@{ $hashref }{sort keys %$hashref}Greghttps://www.blogger.com/profile/01423731793969349477noreply@blogger.comtag:blogger.com,1999:blog-1828118433462570262.post-86450971742548862932014-06-11T14:19:37.341-07:002014-06-11T14:19:37.341-07:00I'm trying to learn Perl, and I must admit it&...I'm trying to learn Perl, and I must admit it's a much more painful experience than learning Python. I still haven't figured out how to avoid putting "my" everywhere, for example.<br />Maybe Perl 6 will be better?xiconethttps://www.blogger.com/profile/14442792513853888855noreply@blogger.com