The four noisy horsemen of Perl hate
phoenixtrap.com
phoenixtrap.com
I still haven't found another language as easy and fast to do text manipulation, parsing, calling out to the shell, regex, whatever. For scripting, Perl is awesome.
Recently I've been using Python instead, simply because I feel like I'm the last person in tech who likes Perl. This stuff is all doable in Python but I still miss my good ol' Perl.
My 2 biggest complaints with Python vs Perl are 1) regex's - the perl syntax is so much faster and easier, and 2) running other command line programs from the shell and reading their output. Perl makes both of those things absurdly quick and easy to do.
You can really see Perl's influence in Ruby when it comes to text manipulation, everything you need is likely in the standard library.
If you're not yet fully sold on Python, Ruby might be worth a try. It's like Perl's elegant, sensible cousin.
With Python, I first have to ensure that the page I'm reading is no more than 2-3 years old, then the copy and paste requires me to re-fix the code, since the syntax is too brittle to stand up to whitespace changes.
I find that I also often have to re-fix the code because so many Python example writers present their examples as REPL sessions, with the code I want to actually copy littered with ">>>" prompts and the output from each individual line's execution.
That said I do like perl for many things python just isn't as elegant at and your comment about old documentation still staying fresh is pretty true
This comment strikes me as similar - here's a design decision that makes a simple task more complex, and error prone. Not that copying pasting large volumes is a good thing.
v for visual mode, select text
:%s/\t/ /g
boom selected text to PEP8 standard from tabssame if it's spaced otherwise evenly (Interpreter will give you a hard time if it isn't and won't execute the script, so what even is it if not that). your tabstop settings set to this should be fine for the << >> method. It's really not that hard?
I think it quickly fell down when it became the way to do dynamic web applications for which it wasn’t really suited. As horrible as php was (then) from a language perspective it’s purpose built nature, made it way easier for early web uses. It did a good job of solving one problem and stayed in its lane.
It’s interesting that it seems, for the most part, that Ruby was mostly relegated to it’s use in Rails. It was probably one of the easiest and most intuitive languages I’ve picked up (I never got into python) and it quickly became my defacto scripting language though now I pretty much just use node since JavaScript is my day to day and I'm so familiar with the ecosystem.
sub pretty_print {
my ($filename, $text, $text_width) = @_;
Not as good as if it was just built into the language itself but better then the alternative.You can pass various arguments to a subroutine like you do in any other programming language and they can be acessed inside the function using the special array @_. Thus the first argument to the function is in $_[0], the second is in $_[1], and so on.
#!/usr/bin/perl
# Function definition
sub Average {
# get total number of arguments passed.
$n = scalar(@_);
$sum = 0;
foreach $item (@_) {
$sum += $item;
}
$average = $sum / $n;
print "Average for the given numbers : $average\n";
}
# Function call
Average(10, 20, 30);
reference:
https://www.tutorialspoint.com/perl/perl_subroutines.htmBash, Ruby, and Perl all support this style of argument passing.
Perl does not have named formal parameters, but instead supports passing arguments as lists / arrays. You can pass any number of arguments of any supported type this way.
If you've never programmed in a language that supports passing arguments in this manner, it will seem foreign.
However, argument passing in this manner has many benefits (eg easy to extend a function def, can easily add optional / req params with basic checking within subroutine) and after 15 min of doing it this way you don't really think about it again.
Python lets your function signature have required positional arguments, variable positional arguments (*args) AND variable keyword args (**kwargs). And everyone uses these features because it makes programming much more pleasant and manageable.
**kwargs is especially important for complex packages like sklearn or pandas, which have many functions with lots of options that often change with version. It would be utterly unimaginable to build these magnificent packages while chained to the underpowered, antiquated Perl style of argument passing.
Respectfully, isn't this just the same amount of work to define named function arguments?
In Perl you do the work of unpacking the array and then validating data. In Python you have the work of defining the function arguments and then validating the received data.
> Python lets your function signature have required positional arguments, variable positional arguments (*args) AND variable keyword args (*kwargs). And everyone uses these features because it makes programming much more pleasant and manageable.
Perl supports this as well. Same functionality as *kwargs is found by passing a hash to a subroutine. And of course *args is analogous to how Perl subroutines were designed to work.
Or you can use shift sequentially (my preferred style)
Or you can use traditional function signatures, which are behind a feature flag because of backwards compatibility.
Assembly language doesn't have function arguments. You just decide what to put in each register when you begin the function. So you can remember that eax is the count, ebx is the pointer to the buffer, or whatever. Or if you're a nice programmer you write a comment there.
In reality, function arguments are an abstraction. You push your arguments onto a stack and read them off that stack. It's just that so many modern languages have that abstraction that we forget how it works underneath.
Perl’s successor language, Raku, has sub arguments (even with lambdas) and optional type constraints.
[1] https://www.effectiveperlprogramming.com/2015/04/use-v5-20-s...
At the time, I thought it made a lot of sense, after using other languages where this feature was standard and required.
However, I've since abandoned its use in Perl, because the traditional Perl way is much more flexible.
I do try to keep my `shift` statements towards the top of a sub, however.
sub PaintHouse {
my $house = shift;
my $color = shift;
if (!$house || !$color) {
WriteLog('PaintHouse: warning: sanity check failed');
return '';
}
print "painting $house with $color paint";
return 1;
}If so, that's not the kind of flexibility I ever want to see in a programming language.
I hardly ever use shift like this, preferring instead the more readable argument copying:
sub PaintHouse {
my ($house, $color) = @_;
...I'm sure he thought he was making his functions easier to reuse in different contexts but in practice the actual result is that it's impossible to modify any of those functions without considering _every possible_ combination of parameters that could be passed in. Often what should be a simple fix becomes something much more time consuming.
There is a place for flexibility in software design, but the parameter list of a function is not one of those places in my opinion.
I tried Go and Typescript and realized that the extra code is really, really worth the security, refactorability and safety.
I now frown on my beloved Python for being so permissive
my $house = shift;
my $color = shift;
if (!$color) {
$color = GetDefaultHouseColor();
} my $house = shift;
my $color = shift // GetDefaultHouseColor(); #!/usr/bin/perl
use Modern::Perl '2015';
use feature qw(signatures);
no warnings qw(experimental::signatures);
sub foo($bar, $baz) { $bar+$baz }
say foo(40, 2);
See `man feature` for details.Or use CPAN modules: https://metacpan.org/pod/signatures , https://metacpan.org/pod/Function::Parameters
I don't write much Perl these days, I suppose the language will always have a spot in my heart, and whenever I need to quickly whip up a script that is too complicated for my puny shell-foo, I know where to turn to. :)
His quote at the end is ironic: “There are only two kinds of languages: the ones people complain about and the ones nobody uses.” I don’t hear people complain about Perl much. Mostly I see blogs about how people should use it more.
I've used it professionally on and off most of my career. I hate it.
\documentclass[tikz]{standalone}
\newcommand\irregularcircle[2]{% radius, irregularity
\pgfextra {\pgfmathsetmacro\len{(#1)+rand*(#2)}}
+(0:\len pt)
\foreach \a in {10,20,...,350}{
\pgfextra {\pgfmathsetmacro\len{(#1)+rand*(#2)}}
-- +(\a:\len pt)
} -- cycle
}
\begin{document}
\begin{tikzpicture}
\coordinate (c) at (0,0);
\coordinate (d) at (1,2);
\draw[blue,rounded corners=1mm] (c) \irregularcircle{1cm}{1mm};
\draw[red,rounded corners=1mm] (d) \irregularcircle{1cm}{1mm};
\end{tikzpicture}
\end{document}
Unfortunately I ran out of time and still have no idea what the final 3 lines of the irregularcircle command do, or why the \pgfmathsetmacro\len{} is repeated twice.Divide the circle in angles of 10 degrees. Each one will be a node for drawing the line. Then go to 10,20,30,40 degrees etc until reaching 350 degrees and assign a length for the radius in each node
This length will be is the desired radius of the circle plus a small amount of irregularity that is randomly assigned but starting at a value provided as second argument. Finally we need to close the circle with -- cycle. The polygon is defined as a -- b -- cycle, or in this case:
starting_node -- {iteration} -- closing_node. Iteration is a list of values for the radius each ten degrees.
If I'm not wrong, we need to use the macro two times because the first time we use a starting value with angle = 0 and then we iterate over the whole circle. We need to assure that we start and end exactly at the same radius value (the radius provided as first argument) so the polygon line will close correctly. Therefore the first and last node can't have any irregularity.
Especially in the modern era of type safety and type inference, it can be hard to tell what variable "is" just by looking at its name or assignment. Whereas `%names` gives you a clue.
On reflection, my biggest critique of Perl is also its biggest strength: it's just so easy to use regular expressions. It's such an important language primitive, people use regex everywhere.
Unfortunately, even experts miss regex edge cases, and when regex fails, it can fail spectacularly. Then future-you (or worse, someone else) has to parse and fix that massive regex you wrote after drinking two espressos.
In general, clear beats clever. Even if it means your clear, lengthier solution is actually slower.
There's things you can drink that are worse for clarity than espressos...
Of course Perl is more functional than OO so maybe it's time for a comeback now the pendulum has swung back...
Then another breaking factor was, I think, actually the long slow Apache 2 and mod_perl 2 migration back then, leaving Perl in one of the areas where it used to dominate in limbo for a long time as other alternatives like standalone appservers and the like simply were not very common initially, so there was no clear migration path. I still think, this was worse than the Perl 6 confusion.
In the end, we're now in some kind of downward spiral, where Python, Ruby, PHP have MASSIVE advantages in regards to the scope of their package repositories, while CPAN support of modern things, especially interfaces to Web APIs, is permanently half assed and unfinished.
Most people use Moose (or its variants) so they don't have to bless things anymore.
That is a personal preference. I dislike the experience of working in Perl and will not work with it again if possible.
this already confused me. is the $ vigil for scalars? Why is address using it? Isn't address an array here?
Don't get it.