5 ms·
Yes, the sigils can make Perl code look noisy, especially as Perl uses curly braces and semicolons too. However, they do have a couple of nice benefits: firstly
by jonathansizz 14y ago
Yes, the sigils can make Perl code look noisy, especially as Perl uses curly braces and semicolons too. However, they do have a couple of nice benefits: firstly, they make variable interpolation easier (and less noisy!) than in other languages like Ruby and Python. Secondly, sigils make it easy to see what kind of data you are dealing with, obviating the need to scroll through your program to the variable declaration.
- thecoffman 14y agoThe sigils make variable interpolation easier only in the most generic case "interpolate $me". Anything more sophisticated requires a temporary variable.
- raiph 14y agoI am not especially enamored of variable interpolation, but for those that are, Perl 6 does a much cleaner job than Perl 5 imo.
- draegtun 14y agoYou can avoid using temporary variables with the @{[...]} and ${\...} idioms: my $x = 1; say "$x + 1 = @{[ $x + 1 ]}"; sub plus1 { $_[0] + 1 } say "$x + 1 = ${\plus1($x)}";
- hobbified 14y agoWell... arguably they make it easier in the half-dozen simplest cases. Which just happen to be what's needed 90% of the time.
- encoderer 14y agoI've not touched Perl aside from modifying and using basic scripts for process automation and administration tasks. But since you called-out Python and Ruby, I'm curious what you meant. In Python, for example, interpolation would look like: print "I ate a %s for %s" % ('banana', 'lunch) (or the newer way with nominally more keystrokes) print "I ate a {0} for {1}".format('banana', 'lunch') I've done plenty of PHP work and I get that I can do "{$varhere}" but for strings of any length or complexity it was totally common to use sprintf() an I have to assume the same readability principles apply in Perl?
- ionforce 14y agoIn Perl you could write print "I ate a $fruit for $meal" Or printf 'I ate a %s for %s', $fruit, $meal
- e12e 14y ago"This is %(adjective)s readable Python in %(genetive)s opinion" % {"adjective":"more", "genetive":"my"} > 'This is more readable Python in my opinion' edit: variable names Also, I agree that for this simple case, perl (and other's) simple dollar substitution is nicer.
- e12e 14y agoSince there was a mention of extending the language in this thread, there's also: http://lfw.org/python/Itpl.html http://lfw.org/python/Itpl.html
- Someone 14y agoHuh? That will tell you wether foo is a hash or not, but not what kind of things it contains. So, as soon as you subscript you $foo or @foo or €foo, you are lost again. A good IDE would be of much more help (and strong typing makes writing such an IDE way easier, but that is a different issue)