Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
WoolTurtle
May 2, 2006
I saw that the previous Perl thread is long dead, so I want to start a new one.

I've been writing a solo (mostly text processing) project in Perl for a couple years now, and I loving love it.

Only registered members can see post attachments!

Adbot
ADBOT LOVES YOU

Neslepaks
Sep 3, 2003

get a therapist, op

Sirocco
Jan 27, 2009

HEY DIARY! HA HA HA!
My condolences.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
My brother in law works in Perl and he thinks it's the dog's bollocks, but I wouldn't want to work in Perl any more than I'd want to work in PHP. Being fair though I expect it's better than PHP though (wouldn't be difficult).

Brother in law comes out with stuff like "Perl 6 is the only language with true unicode support" (I'm definitely failing to quote him verbatim here, but he has a habit of coming out with provocative statements that invite disagreement).

Why should anyone fancy doing a project in Perl, OP, and not some other scripting language like Python or Ruby? Isn't it a bit of a dead end if you want to learn languages you can use to get a job?

WoolTurtle
May 2, 2006
I already know languages that can get me a job, but I chose to use Perl for myself.

I like Perl because it's pretty likely I can run it on another machine without some dependency issue.

Because it a glue language, there are not likely to be breaking changes in future versions.

Another (optional) portion of my project is :D PHP, for similar reasons--it usually just kind of works.

I'm aiming for easy installation and low maintenance, so that's why I chose Perl.

I also hate whitespace syntax, so Python was out until I figured out I can do commented braces.

qntm
Jun 17, 2009
Perl code:
print reverse "hello world";
# "hello world"

my $string = reverse "hello world";
print $string;
# "dlrow olleh"

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

qntm posted:

Perl code:
print reverse "hello world";
# "hello world"

my $string = reverse "hello world";
print $string;
# "dlrow olleh"

explain this. I want to know how this programming language can be so bad.

qntm
Jun 17, 2009
Actually to be honest that post is fairly mean-spirited and I apologise. This is a thread for people who like Perl and people liking Perl doesn't hurt me so I'm going to back off.

To answer your question, Perl has a unique feature known as context-sensitivity. Every Perl expression is evaluated in one of two contexts, list context or scalar context. The context is provided by the code surrounding the expression, and the expression can (and frequently does) return different results depending on that context.

In this case the expression in question is reverse "hello world".

The print statement evaluates all of its arguments in list context. In list context, the reverse function treats all of its arguments as entries in a list and then returns a reversed list. In this case the list has a single scalar entry, the string "hello world", and so the returned value is the same single-entry list again, which print then prints out.

The my $string = assignment evalutes the right-hand side in scalar context. In scalar context, reverse treats all of its arguments as a single scalar - casting them to strings and concatenating them all together if necessary - and then returns a single reversed string.

Tanners
Dec 13, 2011

woof

qntm posted:

Actually to be honest that post is fairly mean-spirited and I apologise. This is a thread for people who like Perl and people liking Perl doesn't hurt me so I'm going to back off.

To answer your question, Perl has a unique feature known as context-sensitivity. Every Perl expression is evaluated in one of two contexts, list context or scalar context. The context is provided by the code surrounding the expression, and the expression can (and frequently does) return different results depending on that context.

In this case the expression in question is reverse "hello world".

The print statement evaluates all of its arguments in list context. In list context, the reverse function treats all of its arguments as entries in a list and then returns a reversed list. In this case the list has a single scalar entry, the string "hello world", and so the returned value is the same single-entry list again, which print then prints out.

The my $string = assignment evalutes the right-hand side in scalar context. In scalar context, reverse treats all of its arguments as a single scalar - casting them to strings and concatenating them all together if necessary - and then returns a single reversed string.

Thats interesting. Is there an example of idiomatic Perl that uses this? Cause its still kindof hard to wrap my head around.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

qntm posted:

Perl has a unique feature known as context-sensitivity. Every Perl expression is evaluated in one of two contexts, list context or scalar context.

This sounds extremely bad and needlessly confusing, and likely to be a huge source of bugs. It seems to me that it would be much better to have the user explicitly indicate what sort of behaviour they want than try to be clever and let them change the program's behaviour subtly through context. Can someone explain why I'm wrong?

TheFluff
Dec 13, 2006

FRIENDS, LISTEN TO ME
I AM A SEAGULL
OF WEALTH AND TASTE

Hammerite posted:

This sounds extremely bad and needlessly confusing, and likely to be a huge source of bugs. It seems to me that it would be much better to have the user explicitly indicate what sort of behaviour they want than try to be clever and let them change the program's behaviour subtly through context. Can someone explain why I'm wrong?

You're not really wrong, but Perl's gimmick is preferring idiomatic shorthand convenience over almost everything else, and the differences are usually not subtle. There's very intentionally no consistency whatsoever in what the builtin functions that can return lists do in scalar context - the documentation uses the (in)famous phrasing "in general, they do what you want, unless you want consistency". localtime() returns a string representation instead of a C-like time struct if used in scalar context. map() - which is more like what many other languages would call flatMap since each input element can map to any number of output elements, and in fact even to zero elements - returns the number of elements of the resulting list rather than the list itself. Some of the file I/O functions like readline() and readdir() return the next entry and advances the filehandle pointer in scalar context, while using them in list context reads until EOF and returns a list of files/lines/whatever, so they're stateful in one context but not really in the other. splice() - which splices like an array like Array.splice() in JavaScript - returns the last element removed in scalar context, or undefined if no elements were removed. sort() in scalar context has undefined behavior.

In Perl's defense though it's usually not hard to see what the context is because of the sigils that prefix variables - scalars are prefixed with $, arrays with @. You declare the context with the sigil, like
Perl code:
@array = ('a', 'b', 'c');
$foo = @array; # foo now contains the value 3 (length of array)
@foo = @array; # foo now contains the array ('a', 'b', 'c')
If you balk at this little bit of subtlety though I'm sure you'd be delighted to know that Perl encourages the use of implicit arguments and variables. For example, if you have a list of hexadecimal numbers as strings and want to print them in decimal form, knowing that the builtin function hex() converts a hexadecimal string to a number, you might write
Perl code:
@numbers = ('0x10', '0x20', '0x30');
foreach (@numbers) {
  print(hex(), "\n");
}
If you're not familiar with Perl, you might be wondering where the iterator/loop variable is, and why there's no argument being passed to hex(). The answer is that if you don't explicitly declare a loop variable, you get a default one called $_ automatically, and most functions that only take one argument will let you omit that argument, operating on $_ instead if you do so. Except in some cases, of course - shift() (array shift, removes the first element from an array and returns it) defaults to shifting @_ (implicit list of arguments) inside of functions/subroutines, but not if used in the global scope - there it defaults to shifting @ARGV (the list of command line arguments to the program) instead.

Another example of this focus on idioms is the return values from low-level syscalls that return 0 or a positive integer on success but a negative value on failure. In languages with modern exceptions you'd write something like
code:
result = fcntl(...)
if (result < 0) {
  throw SomeError()
}
but in Perl, where you raise an exception by calling die(), the idiom is

Perl code:
my $flags = fcntl($filehandle, F_GETFL, 0)
    or die "Can't fcntl F_GETFL: $!";
Now, if fcntl() returned 0, you'd throw even though the call succeded because 0 is falsey, the or wouldn't shortcircuit and you'd reach the die() statement. So to fix that, fcntl() and a bunch of other syscalls return the string "0 but true" instead of just 0 - it's truthy in boolean context but implicitly converts to 0 in numeric context. Normally in Perl trying to use a string that starts with a valid numeric value but has other stuff after that as a number would work but cause a runtime warning, but the string "0 but true" is specifically exempt from this particular warning.

Perl is full of little weirdnesses like this and that's why it's fun. It's a very old language, which shows, and it has wildly different design goals from basically any language that's in common use today, but that's part of the charm. Unlike some of the more obnoxious languages like PHP or JavaScript that are full of weird and annoying issues because of historical mistakes, Perl isn't weird by accident - it was very intentionally designed to be weird.

It was the first language I learned back in the day and I have quite a bit of fondness for it. Wouldn't want to work with it, though.

TheFluff fucked around with this message at 17:41 on Jan 9, 2020

TheFluff
Dec 13, 2006

FRIENDS, LISTEN TO ME
I AM A SEAGULL
OF WEALTH AND TASTE
Man, writing that up made me remember how hilarious Perl is. Did you know that substr() can be used as the left hand side of an assignment?

Perl code:
    my $name = 'fred';
    substr($name, 4) = 'dy';         # $name is now 'freddy'
pyf perl trivia

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
If you take a list, and use it in scalar context, you get the number of items in it. Pretty useful in a bunch of places.

But what if you have one of these functions that works differently in scalar context, but you want to call the listy version and then count how many values there are? You could just use a temporary, as described above, but the true Perl master would use the goatse operator =()= (alternatively written =( )=, if you prefer authenticity over compactness).

For example, to count how many times a regex matches a string:

code:

my $count =()= $str =~ /myregex/g

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
I think you'll find it should be

my $count ≗()= $str =~ /myregex/g

Makrond
Aug 8, 2009

Now that I have all the animes, I can finally
become Emperor of Japan!
I remember I wrote an IRC bot about a decade ago in Perl and boy howdy is it a weird language. Being such an old language though (Perl 5 was already over 25 years old at the time) it's very easy to just code until you run into a problem, Google the problem, find a solution and keep working. On top of that, being a language where the only real idiom is "do it however the gently caress you want" there's relatively few arguments about what the best way to accomplish a particular task is so you don't get bogged down in the StackOverflow-style arguments about how x or y solution is "better" with very little elaboration on why.

In my opinion those are attractive (and underrated) qualities about a language for an inexperienced programmer. Perl is easier to get started with. As mentioned above, Perl is also designed to be weird, rather than being weird by mistake, and the unintentional weirdness tends to get corrected so the language ends up having fewer annoyances for an individual programmer over time than something like PHP. Perl is easier to keep using.

I wish I still had some of the source code for that bot so I could post it in here and be laughed at. I remember I talked in an IRC chat about a problem I was trying to solve and the weird old dude who did the original graphics layer overhaul for Dwarf Fortress called me an idiot and did something in a single line that had taken me 2 functions and a 2D array and I still hadn't actually cracked it. Then he tried to encourage me to use an external atomic decay RNG to roll dice for some reason. Those were the days.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
that explanation made me love Perl even more. i love quirky languages with fun features and bizarre design goals, and embracing the ambiguity rather than it feeling like arguing with a reddit user who says "well, actually" every post and links to yourfallacyis.com

Makrond
Aug 8, 2009

Now that I have all the animes, I can finally
become Emperor of Japan!
It definitely comes with caveats. Asking for help can get you ten different answers from three different people. On top of that, 10 years ago Raku didn't exist yet so you'd occasionally go to download something from CPAN and it would have some bizarro OO implementation with hostile syntax. That still happens but people who actually want OO Perl can do more than just write terrible packages now.

Makrond fucked around with this message at 03:13 on Jan 11, 2020

WoolTurtle
May 2, 2006
Thank you all for reminding me all the reasons to love Perl.

Good Sphere
Jun 16, 2018

My brain still does not want to accept Perl Idioms with &&, II. Not like C-style, or most of what I've seen.

code:
my ($first, $second) = ( 1, 0 );
print "Truth\n" if $first++ && $second++;
print "First: $first\nSecond: $second\n";
__OUTPUT__
First: 2
Second: 1
# Note: Both are evaluated because the first one is
# true.  But "Truth" isn't printed, because only one
# of the two expressions evaluated "true".
[download]
https://www.perlmonks.org/?node_id=301355

So if you have something like:
if( obj.isTrue() && obj ) { ... }

If obj.isTrue() equals true, then it's going to ignore obj after &&. I know this is obvious those familiar with the language, but it's a notable difference that may not be too obvious to those starting out.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
That's exactly how it works in every other language though?

Using side-effecting expressions there is weird, but that's on the person writing side-effecting expressions in that context.

WoolTurtle
May 2, 2006
That's exactly the kind of code I avoid writing.

Ape Fist
Feb 23, 2007

Nowadays, you can do anything that you want; anal, oral, fisting, but you need to be wearing gloves, condoms, protection.
Isn't Perl supposed to be, like, profound unpleasant to write?

TheFluff
Dec 13, 2006

FRIENDS, LISTEN TO ME
I AM A SEAGULL
OF WEALTH AND TASTE

Ape Fist posted:

Isn't Perl supposed to be, like, profound unpleasant to write?

Where did you get that idea? It's completely the opposite. Perl is loving hilarious to write, you'll sit there giggling to yourself about whatever cleverness you might've come up with. It can be really annoying to read though because there are so many ways to express the same thing and there are many subtleties hidden everywhere.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
Perl still rules, but looking at the Perl I wrote years ago makes me want to barf.

e: the first thing I wrote at my current job was a program to generate EEPROM images for a bunch of different product configurations by parsing a couple of Excel spreadsheets and spitting out a bunch of Intel hex files. I used Moose for the OO system and did all the heavy lifting with a couple of CPAN modules. Got the whole thing working and bug-free in about a week, which blew the socks off the guy I was reporting to at the time, who had previously thought we were going to have to delay product launch for a month while the firmware dude on that project got all the configs made. I recall the unit test report that prove generated also impressed some people. Good times back then.

Blotto Skorzany fucked around with this message at 21:22 on Jan 21, 2020

Soricidus
Oct 21, 2010
freedom-hating statist shill
Perl5 is the best bad language. I still use it for little scripts and glue and it’s good

wanda
Dec 8, 2010

I still love Perl as well. One of the first non-work things I did with Perl was build a basic forum with it. I feel compelled to revisit the idea given that I'm currently confined to my home and furlough'd.

Perl 5 that is. I still haven't looked at Perl 6.

dobbymoodge
Mar 8, 2005

I loved Perl when, in 2010, I took a sysadmin job at a university and the password database glue script my friend - a smooth brained Perl wizard - wrote in high school as an intern in 1998 was still working flawlessly in the heart of the identity management system, running every single time anyone or anything needed to authenticate. My understanding is that it still runs to this day.

I hate Perl whenever I have to see, write, or understand it.

mobby_6kl
Aug 9, 2009

Blotto Skorzany posted:

Perl still rules, but looking at the Perl I wrote years ago makes me want to barf.

e: the first thing I wrote at my current job was a program to generate EEPROM images for a bunch of different product configurations by parsing a couple of Excel spreadsheets and spitting out a bunch of Intel hex files. I used Moose for the OO system and did all the heavy lifting with a couple of CPAN modules. Got the whole thing working and bug-free in about a week, which blew the socks off the guy I was reporting to at the time, who had previously thought we were going to have to delay product launch for a month while the firmware dude on that project got all the configs made. I recall the unit test report that prove generated also impressed some people. Good times back then.
Agreed Perl rules haters should :frogout:

At my first real job we once needed to scrape some data off web for a project. It wasn't really my responsibility but both I and a CS PhD type colleague said we'll have a crack at it. I, despite being a terrible programmer, had the script chugging along in an hour or two, while the guy was still writing parser factory-factories or some poo poo.

Balsa
May 10, 2020

Turbo Nerd
As someone who lives in PHP Land, I've though about going over to the Perl boat, but I'm afraid of CPAN that thing scares me as much as composer does. Overall, what are the main language differences between the two?

PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord
Alright, I have a Perl question. Well, actually two if you include "why am I using Perl".

I'm using an install of Perl 5.20.1 on AIX Unix and I am being told that the following code is wrong:
code:
#!/usr/bin/perl
use Net::FTP;

$ftp = Net::FTP->new("<INSERTFQDNHERE>", Debug => 1)
    or die "Cannot connect! $@";
Error: Cannot connect! Net::FTP: connect: Invalid argument at line 4.

Ultimately I need to apply a Passive argument to this constructor as well but I removed it to ensure that wasn't the cause. This is basically straight lifted from their documentation and I have no idea why it's failing. I've tried changing the server to a variety of values including the IP address, tried single quotes instead of double. Help. :(

PierreTheMime fucked around with this message at 22:30 on Jul 12, 2020

salisbury shake
Dec 27, 2011
Gonna be honest, Raku looks cool, but that's probably because I've never written a line of Perl in my life.

PierreTheMime
Dec 9, 2004

Hero of hormagaunts everywhere!
Buglord

PierreTheMime posted:

Net::FTP: connect: Invalid argument at line 4.

So apparently this issue was that the FTP host was refusing the connection and my code was not invalid. The exact same code to another server worked just fine. Very helpful error message :thumbsup:

Soricidus
Oct 21, 2010
freedom-hating statist shill
I can’t believe Apple is planning to remove perl from macos, thereby ruining its status as “scripting tool that’s better than sh+sed/awk and always predictably there on every unixy platform”

HaB
Jan 5, 2001

What are the odds?
This thread is bringing back a lot of memories. My first programming job in like...1999 involved a lot of Perl. It was my daily driver for several years. I even used to answer questions on perlmonks.

I rarely use it now and have forgotten more than I once knew, but even so - if I need to quickly transform a text file into some other format, Perl is still the first thing I reach for. It's like a Marshall amp - it does ONE THING really, really, really well. But as a general purpose language? Eh. Way too many better options these days.

I'm most pissed about my regex skills rusting. I can still bust out a clever one from time to time, but I can no longer just spit out some JEDI poo poo on the first try. Sad.

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



The only time I have used perl was for a coding assignment for a junior developer job like 6 years ago. I didn't know perl so I was trying to learn it for the assignment, I think I made it about 30 minutes and starting to delve in to sigils before deciding that no job could be worth that.

*Don't take it as a knock if you like the language, I'm sure it's a lot better if you're trying to learn it from basics like a book, instead of for a coding assignment.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Generally speaking, what is the current market like as a Perl developer?

I know the joke of "Perl is dead" etc... but for those of you who are comfortable with Perl, is there work to be had? Are Junior Developers in Perl still a thing these days?

Soricidus
Oct 21, 2010
freedom-hating statist shill
Much as I have a soft spot for Perl, I can’t imagine wanting a job working with it today. You’d either be stuck in hell maintaining the old Perl code so bad nobody dares port it, or you’d be working with the kind of person who thinks it’s a good idea to start major new projects in old unpopular languages, and neither of those sounds fun

Hughmoris
Apr 21, 2007
Let's go to the abyss!

Soricidus posted:

Much as I have a soft spot for Perl, I can’t imagine wanting a job working with it today. You’d either be stuck in hell maintaining the old Perl code so bad nobody dares port it, or you’d be working with the kind of person who thinks it’s a good idea to start major new projects in old unpopular languages, and neither of those sounds fun

Yeah, that's what I figured. I enjoy learning enough Perl for small personal scripts but I can imagine working on old enterprise software is not quite as fun.

FastEddie
Oct 4, 2003

Craigslist is written in perl. Larry Wall himself works (worked?) there. It might be a good place to work if you like perl.

Adbot
ADBOT LOVES YOU

duck monster
Dec 15, 2004

FastEddie posted:

Craigslist is written in perl. Larry Wall himself works (worked?) there. It might be a good place to work if you like perl.

Oh theres plenty of places that still use Perl. You just need to have at least one backpacker murder conviction in your resume before you'll be offered one.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply