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.
 
  • Locked thread
Ellie Crabcakes
Feb 1, 2008

Stop emailing my boyfriend Gay Crungus

welcome to hell posted:

Even among the IRC crowd you aren't going to see a lot of consistency on style preferences for minor things like this.
When it comes to people who hang out on IRC talking about their programming language of choice, minor is sort of relative.

Adbot
ADBOT LOVES YOU

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

welcome to hell posted:

Even among the IRC crowd you aren't going to see a lot of consistency on style preferences for minor things like this.

For the parens, yeah, no real concencus. Too many C devs who associate () with function call. For the intermediate arrow though, there is concensus. Generally only those who don't know about its optionality leave it in.

qntm
Jun 17, 2009

Mithaldu posted:

A true perler also has a sense of humor.

I don't know, in my experience people who like Perl are pretty defensive about it.

welcome to hell posted:

Even among the IRC crowd you aren't going to see a lot of consistency on style preferences for minor things like this.

Style inconsistency? In a programming language whose core design principle was "There should be multiple redundant ways to do literally everything"? Well, I never.

Sebbe
Feb 29, 2004

Mithaldu posted:

For the intermediate arrow though, there is concensus. Generally only those who don't know about its optionality leave it in.

I didn't know about this. So, dereferencing arrows are optional precisely when?

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

Sebbe posted:

I didn't know about this. So, dereferencing arrows are optional precisely when?
Inbetween any of these cases: [][], []{}, {}{}, {}[], and any repeats of [] or {} after those. This exists because nobody wants to read the arrow everytime when the code tries to go 6 levels deep into a complex structure, aka:

$hash->{shoop}->{da}->[5]->{woop}->[9]->{etc}

Only the first one is needed here.


qntm posted:

I don't know, in my experience people who like Perl are pretty defensive about it.
Defensive? Or constantly faced with people who have primarily second-hand knowledge or speak only in hyperbole?

qntm posted:

Style inconsistency? In a programming language whose core design principle was "There should be multiple redundant ways to do literally everything"? Well, I never.
Eventual consistency is a thing, at least among tribes.

Mithaldu fucked around with this message at 20:15 on Aug 14, 2015

toadee
Aug 16, 2003

North American Turtle Boy Love Association

Mithaldu posted:

Inbetween any of these cases: [][], []{}, {}{}, {}[], and any repeats of [] or {} after those. This exists because nobody wants to read the arrow everytime when the code tries to go 6 levels deep into a complex structure, aka:

$hash->{shoop}->{da}->[5]->{woop}->[9]->{etc}

I'm certainly not at the level of many in terms of perl mavenhood or whatever, but, I honestly don't mind looking at the arrows in any way. It's also slightly less confusing to not ever have to wonder do I need an arrow here or not.

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

toadee posted:

I'm certainly not at the level of many in terms of perl mavenhood or whatever, but, I honestly don't mind looking at the arrows in any way. It's also slightly less confusing to not ever have to wonder do I need an arrow here or not.
One of the first documents a newbie will probably encounter when learning about Perl is http://perldoc.perl.org/perldsc.html , and there that kind of use is already in the very first code example.

If you're very early on in your Perl, or never read any of the perl documentation, or simply learned from a not-so-great tutorial found via google, then it might seem confusing, but to the vast majority of perl people it's second nature to omit them, for sheer convenience for the future reader, and themselves.

toadee
Aug 16, 2003

North American Turtle Boy Love Association

I mean does the arrow confuse you or something?

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

toadee posted:

I mean does the arrow confuse you or something?
It slows down the reader, as well as the writer, without providing anything positive, to either the reader or the interpreter.

toadee
Aug 16, 2003

North American Turtle Boy Love Association

Mithaldu posted:

It slows down the reader, as well as the writer, without providing anything positive.

It provides consistency, and if there were a decent IDE it would just be written for you. Also I believe given the way humans read it doesn't slow that down at all either.

Really I just have a problem with people getting all butthurt over trivial bullshit. If you don't want to use them, great. It's not like it's actually a negative factor in any way other than your own mind and preference. This kind of poo poo is what actually makes people hate asking for programming advice on the internet.

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

toadee posted:

butthurt over trivial bullshit
Your assumption that i'm somehow butthurt over you intending to keep using it is weird. All i was doing is trying to explain things as plainly and helpfully as possible, because you indicated you're not very experienced with Perl. In any case, you disagree, and i'm content to let you do that.

toadee
Aug 16, 2003

North American Turtle Boy Love Association

Well helpful hint, if you want to offer a constructive tip, just be like 'hey, cool thing to note: you can actually skip the arrows after the first one, if you like the readability/ease of typing better'. Instead of a mini diatribe over idiosyncratic perl and proper convention.

Mithaldu
Sep 25, 2007

Let's cuddle. :3:

toadee posted:

idiosyncratic
Ha ha.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Speaking of barcodes, does anyone have experience using Perl to generate barcodes? I'm tackling a project at work where the goal is to take a text file that contains a Name and Account Number, and to generate a tiff image that contains the Name, the Account Number, and a barcode (generated from the Account Number).

I'm 99% sure the barcode standard for this is Code39.

Mithaldu
Sep 25, 2007

Let's cuddle. :3:
No experience myself, but there are a few modules: https://metacpan.org/search?q=code39

Ellie Crabcakes
Feb 1, 2008

Stop emailing my boyfriend Gay Crungus

Hughmoris posted:

Speaking of barcodes, does anyone have experience using Perl to generate barcodes? I'm tackling a project at work where the goal is to take a text file that contains a Name and Account Number, and to generate a tiff image that contains the Name, the Account Number, and a barcode (generated from the Account Number).

I'm 99% sure the barcode standard for this is Code39.
Something like this should do the trick:
code:
use Image::Magick;
use Data::Dumper;
use strict;
my $image = Image::Magick->new();
$image->ReadImage("canvas:white");

my %barcode = (
	font=>"free3of9.ttf",
	pointsize=>64,
	text=>"5563844",
	fill=>"black",
);
my %label = (
	pointsize=>12,
	text=>"Fred MacMurray - 5563844",
	fill=>"xc:#999999",
);

my $barcodeMetrics = getMetrics($image,%barcode);
my $labelMetrics = getMetrics($image,%label);
my ($imageWidth,$imageHeight) = ($barcodeMetrics->{width}+10,$barcodeMetrics->{height}+$labelMetrics->{height}+10);
$image->Resize(geometry=>"${imageWidth}x${imageHeight}!");
$image->Annotate(%barcode,x=>5,y=>5+$barcodeMetrics->{yOffset});
$image->Annotate(%label,x=>($imageWidth/2)-($labelMetrics->{width}/2),y=>$barcodeMetrics->{height}+10+$labelMetrics->{yOffset});
$image->Write("test.tiff");

sub getMetrics {
	my ($image,%options) = @_;

	my @metrics = $image->QueryFontMetrics(%options);
	return {
		width=>$metrics[4],
		height=>$metrics[5],
		yOffset=>$metrics[2],
	};
}
You can download the code39 font a few places.

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

Mithaldu posted:

No experience myself, but there are a few modules: https://metacpan.org/search?q=code39

Thanks, the PDF::ReportWriter looks promising.


John Big Booty posted:

Great stuff...

Wow, thank you for taking the time to write that up. I'm going to give it a shot and I'll let you know how it turns out.

Ellie Crabcakes
Feb 1, 2008

Stop emailing my boyfriend Gay Crungus

Hughmoris posted:

Thanks, the PDF::ReportWriter looks promising.


Wow, thank you for taking the time to write that up. I'm going to give it a shot and I'll let you know how it turns out.
No problem. I used to do quite a bit of work with ImageMagick, so it wasn't much of a stretch.

If ReportWriter doesn't quite fit your needs, it's PDF::API2 does all the heavy lifting and allows for more granularity. Keep in mind, though, that in PDFs, 0,0 is the bottom left. Also, you'll probably have to factor in the ascender/descender of the font. PDF can be a pain in the rear end.

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

John Big Booty posted:

No problem. I used to do quite a bit of work with ImageMagick, so it wasn't much of a stretch.

If ReportWriter doesn't quite fit your needs, it's PDF::API2 does all the heavy lifting and allows for more granularity. Keep in mind, though, that in PDFs, 0,0 is the bottom left. Also, you'll probably have to factor in the ascender/descender of the font. PDF can be a pain in the rear end.

Just to follow up, your ImageMagic script worked like a champ after a tweaking it a little bit to fit my scenario. Thanks for that.

Now, I'm getting tripped up on something simple. I'm trying to parse a ' | ' delimited file.
code:
account|first|last
123|james|barr
456|rachel|ray
789|nikki|brown
Here is my script:
Perl code:
my $file = "delimitedTest.txt";

open(my $fh, '<', $file) or die "Can't open file.";

while (my $line = <$fh>) {
    chomp($line);
    my @fields = split('|' , $line);
    print "$fields[0]\t$fields[2]\n";
}
I want an output where the Account and Last is on the same line. For some reason, it's not splitting it on the ' | '. Here is my output:
code:
a     c
1     3
4     6
7     9
When I replace the ' | ' with a ' , ' it seems work just fine. What am I missing?

Toshimo
Aug 23, 2012

He's outta line...

But he's right!

Hughmoris posted:

Just to follow up, your ImageMagic script worked like a champ after a tweaking it a little bit to fit my scenario. Thanks for that.

Now, I'm getting tripped up on something simple. I'm trying to parse a ' | ' delimited file.
code:
account|first|last
123|james|barr
456|rachel|ray
789|nikki|brown
Here is my script:
Perl code:
my $file = "delimitedTest.txt";

open(my $fh, '<', $file) or die "Can't open file.";

while (my $line = <$fh>) {
    chomp($line);
    my @fields = split('|' , $line);
    print "$fields[0]\t$fields[2]\n";
}
I want an output where the Account and Last is on the same line. For some reason, it's not splitting it on the ' | '. Here is my output:
code:
a     c
1     3
4     6
7     9
When I replace the ' | ' with a ' , ' it seems work just fine. What am I missing?

First argument on split is a pattern, right? So it's treating that '|' as an "or" with two empty sides so everything matches and it gets split on every character? So '\|', maybe?

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

Toshimo posted:

First argument on split is a pattern, right? So it's treating that '|' as an "or" with two empty sides so everything matches and it gets split on every character? So '\|', maybe?

Doh! I knew I was missing something simple. Thanks!

Hughmoris
Apr 21, 2007
Let's go to the abyss!
I'm on the tail end of a work project, and am a bit stumped on what should be the easiest part.

At the end of my program, I end up with a .tif file. I want to transfer that .tif file to a \\server\filepath. What is a secure way to provide my script a \\server\filepath in addition to the username and password for the server, then securely transfer the .tif file?

I'm learning Perl as I go, so I may be missing something simple here.

*Perhaps something like Net::SCP::Expect?

Hughmoris fucked around with this message at 01:13 on Aug 28, 2015

Ellie Crabcakes
Feb 1, 2008

Stop emailing my boyfriend Gay Crungus

Hughmoris posted:

I'm on the tail end of a work project, and am a bit stumped on what should be the easiest part.

At the end of my program, I end up with a .tif file. I want to transfer that .tif file to a \\server\filepath. What is a secure way to provide my script a \\server\filepath in addition to the username and password for the server, then securely transfer the .tif file?

I'm learning Perl as I go, so I may be missing something simple here.

*Perhaps something like Net::SCP::Expect?
Is SSH running on the target machine?

Sebbe
Feb 29, 2004

I thought I'd share a small tool I find useful: perlopen

It's basically just a small script that searches your include path for a specific package, and opens it in your editor. E.g. perlopen WWW::Mechanize

Saves you some time from searching for the file if you want to, say, inspect the source of an installed CPAN module or whatnot.

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

John Big Booty posted:

Is SSH running on the target machine?

I don't have control of the target machine but I'm being told no, it doesn't have SSH. I want to say it runs some version of Windows Server, and the Perl script will be running on a Windows 7 computer running Strawberry Perl.

Ellie Crabcakes
Feb 1, 2008

Stop emailing my boyfriend Gay Crungus

Hughmoris posted:

I don't have control of the target machine but I'm being told no, it doesn't have SSH. I want to say it runs some version of Windows Server, and the Perl script will be running on a Windows 7 computer running Strawberry Perl.
Not really a windows guy, but try this: http://migo.sixbit.org/software/smb-perl/

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

John Big Booty posted:

Not really a windows guy, but try this: http://migo.sixbit.org/software/smb-perl/

Ended up just mapping the network drive by utilizing NET within the Perl script, then disconnecting the drive when file finished transferring. For a script that would be running 24/7, and transferring up to 50 files a day I'm not sure if this is the best long term solution. Ideally, the computer running the script just stays mapped to the network drive but the server-owner is wary doing that, not sure why.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
I stumbled upon this tutorial on how to do a basic scrape of Craigslist. As a learning exercise, I want to try and do something similar with Perl. If you look at that link, Python has a slick way of accumulating all of the information and placing it in a neat table and graphing off it. Does Perl have something similar, or am I better off just copying it to an excel spreadsheet?

Here's what I have so far. It calls the webpage, scrapes the listing data, and sorts it by price. Its pretty neat how easily Perl sorts an array of hashes.
Perl code:
use Modern::Perl '2015';
use diagnostics;

use URI;
use Web::Scraper;
use Text::Table;
use Data::Dumper;

my $apts = scraper {
    process 'p[class="row"]', "apts[]" => scraper {
        process 'a[class="hdrlnk"]', title => 'TEXT';
        process 'span[class="housing"]', brSize => 'TEXT';
        process 'time', dateTime => '@datetime';
        process 'span[class="price"]', price => 'TEXT';
    };
};

my $res = $apts->scrape(URI->new("http://pensacola.craigslist.org/search/apa?bedrooms=1&is_furnished=1"));

#strip the $ sign from the price to allow sorting
for my $apt (@{$res->{apts}}) {
    $apt->{price} =~ s/\$//;
}

#sort apts by price, from lowest to highest and return to new array
my @sortedApts = sort { $a->{price} <=> $b->{price} } @{$res->{apts}};

for my $apt (@sortedApts) {
    say "$apt->{dateTime}\t$apt->{title}\t$apt->{price}";
    }

Hughmoris fucked around with this message at 06:57 on Sep 14, 2015

Mithaldu
Sep 25, 2007

Let's cuddle. :3:
I've never done that kind of ad-hoc rendering, but you can maybe do it with PDL: http://pdl.perl.org/

http://pdl.perl.org/?page=demos/plot2D

Azhais
Feb 5, 2007
Switchblade Switcharoo

toadee posted:

I'm certainly not at the level of many in terms of perl mavenhood or whatever, but, I honestly don't mind looking at the arrows in any way. It's also slightly less confusing to not ever have to wonder do I need an arrow here or not.

You could just never use arrows! No confusion!

$$hash{shoop}{da}[5]{woop}[9]{etc}

xorex
Jul 23, 2002
whatever
This may not be the appropriate place to ask this question, but I'm hoping to get the opinion of those familiar with Perl, rather than just basic troubleshooting.

I have an application that is not launching. When attempting to do so from the command prompt, I receive an error message: "Error: Can't locate perl58.dll Make sure the ActivePerl bin directory is in your PATH"

This application does not require an underlying installation of ActivePerl. Normally it will create a folder under "Username\AppData\Local\Temp\pdk-UserName-####" (seemingly random, four digit number), with perl58.dll in that folder, after which, I am assuming it would use that dll as the Perl interpreter. Currently, it does create the folder in the temp directory along with perl58.dll, it just doesn't get any further than that.

So it seems like it is creating perl58.dll in the location it should, but is failing to read it.

I am at a loss what to try to correct this and am running out of time. I've tried some stupid things (installing ActivePerl, manually putting perl58.dll somewhere and adding the location to PATH), but nothing has worked or provided any clues so far. I've backtracked looking at every change that has been done to the system since the application was last working and I feel I've eliminated every possibility that makes any sense at all.

Unfortunately, I can't really go in to many details regarding the application...Is anyone familiar with this method of packaging and have any ideas what could cause it to screw up like this?

Mithaldu
Sep 25, 2007

Let's cuddle. :3:
You want to download this program: https://technet.microsoft.com/en-us/library/bb896645.aspx?f=255&MSPPError=-2147217396

Run it, then try and start your software, then pause it and check the log to see where it's trying to read that dll in.

xorex
Jul 23, 2002
whatever
Access protection - McAfee antivirus. Figures it was something stupid I overlooked.

Thanks. It didn't provide the direct solution, but it did point me in the right direction.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Now that Perl 6 has been released, anyone been messing around with it?

fuck the mods
Mar 30, 2015
What do you want to know about it?

qntm
Jun 17, 2009

Hughmoris posted:

Now that Perl 6 has been released, anyone been messing around with it?

I've only been messing about with Perl 6 so that I can lambast its design on a superficial level.

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

gently caress the mods posted:

What do you want to know about it?

Just curious what people thought of it, and if you're currently using it for anything. I've rewritten a couple of small scripts for work in Perl 6, and I'm enjoying the language so far but I'm a beginner so I'm sure I'm just skimming the surface of the language.

Azhais
Feb 5, 2007
Switchblade Switcharoo
I'm too old to learn new syntax. Perl5 for life!

:corsair:

fuck the mods
Mar 30, 2015

Hughmoris posted:

Just curious what people thought of it, and if you're currently using it for anything. I've rewritten a couple of small scripts for work in Perl 6, and I'm enjoying the language so far but I'm a beginner so I'm sure I'm just skimming the surface of the language.

I've got my share of gripes but I still like it. I also contribute to the core regularly and do some contract work with it.

Some of the good stuff:

Cross platform IO stuff (class IO::Path)

Threads/async stuff

Lazyness

NativeCall (no more XS hell)

Math stuff (although I can't comment much on this)

Dashes in variable names (also Unicode characters)

Grammars (To me this is the killer feature)

Essentially has its own version of Moose built in


Some of the bad stuff:

You can't pass data from an IO handle (Socket, File) from one thread to another (LOL. The reason is because it uses a scheduler per thread and libuv doesn't like that or something). So you aren't going to be doing much of stuff like handling web requests in one thread and reading them from another.

The first time a module is used it precompiles it so script startup time is slower the first time you run a script (a rather new thing from a rushed "upgrade" before release, which to me is unacceptable)

I guess the REPLs suck (I don't use them so I wouldn't know)

Flattening lists/arrays can sometimes be ugly and confusing for a beginner

The ecosystem (its full of XXX ported from Perl 5 !! without using idiosyncratic Perl6 [and usually without understanding the code they ported to begin with], the majority of other modules are just small things you'd probably prefer to write yourself due to the large feature set of the language itself, people putting authoring dependencies inside their depends due to bad advice from self promoters... I could go on here but im biased so i'll stop)

Slow, CPU/Memory use


The community could be seen as good or bad. You can easily talk to larry, and there are quite a few other people who are extremely knowledgeable that are usually available. At the other end theres an influx of users who know just enough to give themselves an ego larger than their skill level, so you need to do a lot of cutting through the noise of people promoting themselves instead of teaching (i've never seen so much "well I did xxx with my module yyy" when referring to every little thing"). All the core developers are great though.

I know its been like a million years since it was announced, but if it had just 1 more year I think it would have been for the best. The current release is called '6.c', and there are already breaking changes for a version '6.d' along with other breaking changes that need to be made. On the plus side there are some more features to be added that didn't make it yet (like the double pointed pipe operator; my @x = 1,2,3; my @y = 3,4,5; my @z; @x ==> @y ==>> @z)

Adbot
ADBOT LOVES YOU

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

gently caress the mods posted:

I've got my share of gripes but I still like it. I also contribute to the core regularly and do some contract work with it...

Thanks for taking the time to type that up. Even though I'm a beginner programmer who mainly does it as a hobby, I really hope Perl 6 takes off. With all the time and effort that I'm sure has gone into it over the past 15+ years, I hope it gets an honest shake.

  • Locked thread