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
Hughmoris
Apr 21, 2007
Let's go to the abyss!
I'm trying to follow an online tutorial for learning Perl (no programming experience) and I'm hitting a hurdle while doing an example.
code:
#!/usr/bin/perl
#examples
use warnings;
use strict;


my @questions = qw(Java Python Perl C);
my @punchlines = {
	"None. Change it once, and its the same everywhere...",
	"One, he just stands below...",
	"A millon, one to change it...",
	'CHANGE?!!"'
};

print "Please enter a number between 1 and 4: ";
my $selection = <STDIN>;
$selection -= 1;
print "How many $questions[$selection] ";
print "programmers does it take to change a lightbulb?\n\n";
sleep 2;
print $punchlines[$selection], "\n";
That gives me an error of:
code:
Use of uninitialized value in print at helloworld.pl line 21, <STDIN> line 1.
Could someone point out what I'm missing?

Adbot
ADBOT LOVES YOU

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

Filburt Shellbach posted:

You want parentheses not braces.

That did it, thank you.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
I'm trying to teach myself a little Perl to pass the time, I'm reading Learning Perl 5th Edition as a reference. I'm running into my first problem that I cannot seem to wrap my head around.

I have a list of words in "dictionary.txt", and I want to have the user give an input and the program checks to see if the input is a word in the dictionary, and lets the user know if it is. I've googled the poo poo out of searching for strings in an array. I don't know if I'm just tired or what but I can't seem to get a grasp on how to do it. Here is what I have so far:

code:

use 5.010;

open (DICTIONARY, "dictionary.txt");
@words = <DICTIONARY>;
close(DICTIONARY);

chomp($string = <STDIN>);
Could someone break the search part into basic steps?

Hughmoris
Apr 21, 2007
Let's go to the abyss!
I tackled Project Euler, Problem 13: http://projecteuler.net/problem=13

Can someone give me advice on how I could have handled this more efficiently? Bear in mind, I've been messing with Perl for about a week now.


code:

#!/usr/bin/perl
use 5.010;
use warnings;
use strict;

my $line;
my $total;
my @newtotal;
my @slicetotal;


open (myinputfile, "numbers.txt");
while(<myinputfile>)
{
	my($line) = $_;
	chomp($line);
	$total += $line;
}

@newtotal = split(//, $total);
splice(@newtotal, 1, 1);
@slicetotal = @newtotal[0..9];
print join('', @slicetotal);

The part towards the bottom feels goofy but I was't sure how else to take the first 10 digits of a really long number.

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

Roseo posted:

Here's how I'd do it, with some notes below.

code:
#!/usr/bin/perl
use 5.010;
use warnings;
use strict;

use Math::BigInt;

my $total = Math::BigInt->new(0);

open(my $inputfile, '<', "numbers.txt") or die "Unable to open numbers.txt: $!";
while(my $line = <$inputfile>) {
	$total += $line;
}

say 'The first 10 digits are "', substr($total, 0, 10), '"';
Don't predeclare variables
Three argument open
Filehandle as a scalar, not as a bareword
Always check return value of file operations for success (or 'use autodie')
Assign line to scalar on loop line
Don't need to chomp in this case, newlines'll implicitly get stripped during the string->number conversion
Use Math::BigInt so you don't get the scientific exponentation conversion
Use say so you get newlines at the end of your output
Treat the number as a string and substring it

Thanks for taking the time to type all that out, I'll definitely take a look.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Since the OP is over 4 years old, I have to ask. Is 'Learning Perl' still the go to guide for inexperienced programmers trying to learn the language? I've peeked at 'Modern Perl' but it looks a little sparse for a rookie such as myself.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Ok, I need someone to point me in the right direction. I know how to search a string or file for a word and print out that word. What I want to do now is search a file for a word, and if it finds it, print out the entire sentence that contains that word. Whats a good way to approach this?

*For example, the text file is a short story and I want to search for a character's name, and print out every sentence that has the name.

Hughmoris fucked around with this message at 01:08 on Dec 13, 2011

Hughmoris
Apr 21, 2007
Let's go to the abyss!
The OP is going on 7 years old. For beginner programmers who are looking at programming as a hobby, should I be looking at perl 5 or 6? Is Learning Perl still the go to book?

Hughmoris
Apr 21, 2007
Let's go to the abyss!
As merely something to do, I've been muddling my way through Beginning Perl. I've discovered CodeAbbey.com so I've been trying to work on problems as I work my way through the book.

I'm already stuck. Here is the problem #3:
http://www.codeabbey.com/index/task_view/sums-in-loop


Basically, I have an N amount (the first number) of pairs of numbers. I want to read in a pair of numbers, add them, print the sum, then move on to the next pair of numbers.
code:
data:
3
100 8
15 245
1945 54

answer:
108 260 1999
My issue is that I don't know how to read in one line at a time. The website states I should copy/paste my input but I think it would be easier just to place the input in a text file, and then read the file. Any thoughts how I should attack this?

*It looks like this is a theme on some of their problems. Read in a line of user input, perform some operation on that line, then move onto the next line and repeat.

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

Olesh posted:

Helpful information...

Thanks for taking the time to write that up. After hacking away at it, I managed to get the correct solution. It ain't pretty but it works.
code:
#open test data file and read in data
my $filename = "sums_in_loop_data.txt";
open my $test_data, '<', $filename
	or die "Cannot open '$filename' for writing: $!";

#read in a line, separate line into array, sum elements of array
while (my $line = <$test_data>){
	my $sum = 0;
	my @numbers = split(' ', $line);
	for my $element(@numbers){
		$sum+=$element;
		}
	print "$sum ";
	}
Any tips on making that more elegant or streamlined?

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

homercles posted:

I don't want to go golf crazy or anything silly, but I'd do this. Might even use File::Slurp to remove the manual fh open if the file is known to be quite small. Removing boiler plate via core-ish modules.

code:
use List::Util qw(sum);
my $filename = "sums_in_loop_data.txt";
open my $test_data, '<', $filename
	or die "Cannot open '$filename' for writing: $!";

print sum(split), " " while <$test_data>
With file::slurp, and using join:
code:
use List::Util qw(sum);
use File::Slurp qw(slurp);
use feature qw(say);
my $filename = "sums_in_loop_data.txt";
say join " ", map { sum split } slurp $filename;

I'll have to sit down and try to figure those out. Now that I've figured out how to properly read in a file and split it into an array, I've knocked out the next 5 problems. :unsmith:

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Still working my way through the basics of Perl using Beginning Perl. When declaring a subroutine, is it recommended to declare it at the beginning or end of the program? I'm using an online IDE at the moment and the program seems to run both ways. I can declare the subroutine before I ever call it, or I can declare the subroutine after I call it. Both run fine.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
I've written my first simple script in Python, and I want to try and write it in Perl to compare the two.

I'm getting stuck on understanding how calling CPAN modules and functions work. I'm on Windows 8, I installed Strawberry Perl, and I used its CPAN client to install CAM::PDF. Now, looking at the CAM::PDF page, there is a getpdftext.pl under the Documentation section that I want to use.

Is that getpdftext.pl part of the CAM::PDF module that I installed? How do I go about calling it in a very simple script? I think I understand how to use that script from a command line but I'm not sure how to incorporate it into another script.


My first goal is to write a very basic script that converts "testFile.pdf" to a text file, and I want to do it from within a script, not the command line.

Hughmoris fucked around with this message at 02:57 on Feb 22, 2015

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

Mithaldu posted:

It's probably not installed. Just click source on its page, copy-paste the code into an appropiately named file, then in your script use backticks like so to call it:

code:
my $output =  `perl $scriptname $arguments`;
Additionally, you sound very confused, which is ok, but also like you didn't read *any* teaching materials on Perl, which is less ok. Please head to http://perl-tutorial.org and read some of the stuff linked there. (i recommend ovid's beginning perl, and modern perl)

Thanks for this.

You're right, I probably am not doing as much reading as I need to in order to understand the basics of Perl, but I have done some. I've been reading ovid's book. Either way, thanks again for posting a solution.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Been reading up Modern Perl and trying to convert some of my simple Python scripts to Perl.

For my first: I have a folder full of .vgr files. For each file in the directory, I want to iterate line by line to see if it contains the string "LOAD_ORDER=OIS=208972". If it does, I want to stop, print the name of that file then move on to the next file.

Perl code:
use warnings;
use strict;
use diagnostics;

my @vgr_files = glob("*.vgr");
foreach my $file (@vgr_files)
{
	open my $fh, '<', $file
		or die "can't open it";
	
	foreach (<$fh>)
		{
		 	if ($_ =~ /LOAD_ORDER=OIS=208972/)
		 	{
		 		print "$file\n";
		 		last;
		 	}

		}
}
Can I make this code any cleaner/quicker? Also, I ran into a problem where I couldn't glob the .vgr files in the directory using a full file path. I'm thinking it has something to do with spaces in the file path (glob("c:\folder\new folder\*.vgr")). I couldn't get it working so I just moved my script to that folder and used glob("*.vgr")

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

uG posted:

code:
use Modern::Perl;
use Path::Class;
use experimental qw/smartmatch/;
use FindBin;

my @exts = (qr/vgr$/);
dir("$FindBin::Bin/data_directory")->recurse(callback => sub {
    my $file = (-f $_[0] && $_[0] ~~ @exts) ? $_[0] : return;
    open my $fh, '<', $file; 
    while(<$fh>) { say $file and last if m/LOAD_ORDER=OIS=208972/ }
    close $fh;
});
This is how i'd do it

That hurts my brain. Can you break this down?
Perl code:
dir("$FindBin::Bin/data_directory")->recurse(callback => sub {
    my $file = (-f $_[0] && $_[0] ~~ @exts) ? $_[0] : return;

Hughmoris fucked around with this message at 04:23 on Mar 26, 2015

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

uG posted:

code:
# An array containing precompiled regexes that we will use to match against the file name.
# In this case its a single regex, but you could put as many as you want into the array
my @exts = (qr/vgr$/);

# `dir` is a Path::Class object, and in this case it the directory given as an argument ($FindBin::Bin just points to the /path to the perl script) and recursively 
# runs the supplied callback each time it finds a file or folder
dir("$FindBin::Bin/data_directory")->recurse(callback => sub {
    
    # The first parameter supplied to the callback is the name of the folder or file. Since we are not interested in folders, we will test if its a file with `-f $file`
    # We also apply the filter on file extension here with the smart match operator, '~~', which basically says "does $_ match anything in @exts?" and tries to match appropriately 
    # @exts contains a regex, its doing something like `for (@exts) { return $file if $_ =~ m/vgr$/; }`
    my $file = (-f $_[0] && $_[0] ~~ @exts) ? $_[0] : return;

Thanks for taking the time to write that up.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Trying to learn simple databases and Perl, together. I installed SQLite and am using the DBD::SQLite module. Any recommend readings to ease my way into using Perl with databases?

For my first database, I was going to try a project someone here in CoC recommended. Create a table full of randomized patient names, social security #s, home address and insurance carrier.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Thanks, this will give me some light reading to do over the weekend.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Played with perl and DBI a little more. I successfully created my first database and figured out how to loop over a file containing names, and enter those names into my database. However, it is slow as dirt.

I have a 1,220-line file, called combined_names.txt where each line has a first name and last name:
code:
alexander hamilton
harry dresden
sarah smith
My database has 3 columns: Id, fname, lname

Here's my ugly code that creates the database, then iterates over my combined_names list and inserts the names into the db. Takes about 30 seconds to insert 1,220 rows... Any tips?
Perl code:
#!perl
use warnings;
use strict;
use diagnostics;
use DBI;

my $dbfile = "sample.db";

my $dsn = "dbi:SQLite:dbname=$dbfile";
my $user = "";
my $password = "";
my $dbh = DBI->connect($dsn, $user, $password, {
	PrintError => 0,
	RaiseError => 1,
	AutoCommit => 1,
	FetchHashKeyName => 'NAME_1c',
	});

my $sql = <<'END_SQL';
CREATE TABLE patients (
	id		INTEGER PRIMARY KEY,
	fname 	VARCHAR(100),
	lname	VARCHAR(100)
	)
END_SQL

$dbh->do($sql);

my @split_names = ();

open my $fh, '<', 'C:/Strawberry/Projects/Names_project/combined_names.txt'
	or die "Can't open it";

foreach (<$fh>)
{
	@split_names = split / /, $_, 2;
	$dbh->do('INSERT INTO patients (fname, lname) VALUES (?,?)', undef, $split_names[0], $split_names[1]);
}

$dbh->disconnect;

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

uG posted:

Look into turning autocommit off if transactional integrity doesn't have to be considered. Also prepare() the statement outside the loop


toadee posted:

To expand on this, outside the loop:

code:
my $sth = $dbh->prepare('INSERT INTO patients (fname, lname) VALUES (?,?)');
Then inside the loop:

code:
$sth->execute( @bind_vars );
That should run quite a bit faster.

Wow. Turning off autocommit and then preparing my statement outside the loop dropped my create & write time from ~ 32 seconds to being less than 1 second. Thanks.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
What is a non-clunky way to generate an SSN? I have a working solution but I'm thinking there is a more elegant solution...
Perl code:
	$ssn_first = sprintf("%03d", int(rand(999)));
	$ssn_middle = sprintf("%02d", int(rand(99)));
	$ssn_last = sprintf("%03d", int(rand(999)));
	$ssn = "$ssn_first-$ssn_middle-$ssn_last";
My new way is to generate a random 9-digit number but I can't find how to splice it and insert the '-' characters. Python has spoiled me in this regard.

*Hot drat, I'm really enjoying learning the powers of regular expressions. I created a new solution, not sure if its better or worse:
Perl code:
my $ssn = sprintf("%09d", int(rand(999999999)));
$ssn =~ s/(\d{3})(\d{2})(\d{4})/$1-$2-$3/;
print $ssn;  #outputs a formatted number 123-45-6789

Hughmoris fucked around with this message at 05:21 on Mar 30, 2015

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

het posted:

Depending on how much you care about performance, probably faster to do something like $ssn = substr($ssn, 0, 3) . "-" . substr($ssn, 3, 2) . "-" . substr($ssn, 5, 4); (clunky compared to python's string slices, admittedly)

Thanks, that's what I was shooting for originally but I couldn't quite figure it out.

Toshimo posted:

If someone else wants to handle a technical implementation of what you've written, by all means.

But a valid US SSN has additional criteria beyond just being a series of 9 numbers that you'd probably want to take into account:
...
...
...

Hmmm. I honestly never paid much attention to the rules and regulations behind generating an SSN, learned something new today. For the purposes of my small project, I'm being lazy and including everything. Thanks for that info though.

Hughmoris fucked around with this message at 06:01 on Mar 30, 2015

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

EVGA Longoria posted:

If you have CPAN access, https://metacpan.org/pod/Data::Fake will give you:

Perl code:
use Data::Fake::Core;
	my $ssn = fake_digits("###-##-####");

I didn't even think to look on CPAN for a data generator. I need to poke around there a little bit more.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
I'm trying to understand subroutines in perl. I'm following a short tutorial on Perl Maven and I'm unable to replicate the lesson: http://perlmaven.com/subroutines-and-functions-in-perl

Here is what I have. Its supposed to take in a first and last name, then call the subroutine and print those names as an illustration of how parameters are handled. However, nothing is printing for me after I enter the two names.
Perl code:
#!perl
use strict;
use warnings;
use diagnostics;

my $first_name = prompt("First name: ");
my $last_name = prompt("Last name: ");

sub prompt{
	my ($text) = @_;
	print $text;

	my $answer = <STDIN>;
	chomp $answer;
	return $answer;
}
Am I making a simple mistake somewhere?

*Well poo poo, I think I misunderstood how the function works. I was thinking the function would print the names I entered but I guess it's printing the actual prompt ("First name: ) etc... I'm a dummy.

Hughmoris fucked around with this message at 04:14 on Apr 1, 2015

Hughmoris
Apr 21, 2007
Let's go to the abyss!
I'm fiddling around and trying to understand a little bit about APIs. For practice, I'm making a JSON call to rottentomatoes for any new dvd releases. Here is the returned dataset: http://pastebin.com/dEjuKAiZ

My problem is that I don't know how to extract useful information from that dataset. For instance, if I wanted to return all the "title" values.

Here is what I have so far from piecing together stackoverflow ideas. Any pointers?
Perl code:
use strict;
use warnings;
use diagnostics;
use LWP::Simple;
use JSON qw( decode_json );
use Data::Dumper;

my $url = "http://api.rottentomatoes.com/api/public/v1.0/lists/dvds/new_releases.json?apikey=...";

my $json = get($url)
	or die "can't retriever url";
	
my $decoded_json = decode_json($json);

#print Dumper $decoded_json;

print "Title: ", $decoded_json->{"movies"}{"title"};
That gives me an error saying its not a HASH reference.

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

EVGA Longoria posted:

Movies is an array of movies. You'd need to loop through it.

Perl code:
use strict;
use warnings;
use diagnostics;
use LWP::Simple;
use JSON qw( decode_json );
use Data::Dumper;

my $url = "http://api.rottentomatoes.com/api/public/v1.0/lists/dvds/new_releases.json?apikey=...";

my $json = get($url)
	or die "can't retriever url";
	
my $decoded_json = decode_json($json);

my $movies = $decoded_json->{"movies"};

for my $movie ($movies) {
	print "Movie Title: " . $movie->{title};
}

Hmmm. I copied and ran your code and got an error "Not a hash reference at line 17" which is print "Movie Title: " . $movie->{title};

*Hopped on perl IRC and they helped me arrive to this solution, which will print out the title of each movie. I really need to sit down and try to understand how referencing and dereferencing works.
Perl code:
use warnings;
use diagnostics;
use LWP::Simple;
use JSON qw( decode_json );
use Data::Dumper;

my $url = "http://api.rottentomatoes.com/api/public/v1.0/lists/dvds/new_releases.json?apikey=...";

my $json = get($url)
    or die "can't retriever url";
    
my $decoded_json = decode_json($json);

print $_->{title}."\n" for @{$decoded_json->{movies}};

Hughmoris fucked around with this message at 05:46 on Apr 4, 2015

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

EVGA Longoria posted:

Movies is an array of movies. You'd need to loop through it.

Perl code:
use strict;
use warnings;
use diagnostics;
use LWP::Simple;
use JSON qw( decode_json );
use Data::Dumper;

my $url = "http://api.rottentomatoes.com/api/public/v1.0/lists/dvds/new_releases.json?apikey=...";

my $json = get($url)
	or die "can't retriever url";
	
my $decoded_json = decode_json($json);

my $movies = $decoded_json->{"movies"};

for my $movie ($movies) {
	print "Movie Title: " . $movie->{title};
}

After trying to understand referencing/dereferencing a little more (I still don't really get it), as an exercise I tried to figure out why the above code wouldn't work.

It's missing the array dereference at this line:
Perl code:
for my $movie ($movies) {
	print "Movie Title: " . $movie->{title};
}
When I change it to this, it runs great.
Perl code:
for my $movie (@$movies) {
	print "Movie Title: " . $movie->{title};
}

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

EVGA Longoria posted:

What version of perl are you running? They've changed a bunch of things with referencing at various points, so it might be that.

Though I didn't test the code, so I might just be completely wrong.

Also, the code they wrote uses $_ which is a magic variable and is sometimes bad practice, since it can change easily.

I'm using Strawberry Perl, v5.20.1

Yeah I know I shouldn't use the $_ operator but it's just cool to see how much information can be extracted using such a small amount of code. :3:

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

John Big Booty posted:

All a reference is is a pointer to a value. To access or manipulate that value and its members, you have to dereference, using the infix operator (->) or the appropriate sigil.
I've never took any CS courses or learned languages that used pointers so this is a bit new to me. I think I have the idea of referencing down pat but I start getting tripped up when I have nested dicts within arrays within dicts, and trying to get to the data I want. I just need to do some more readings and examples on the subject.


John Big Booty posted:

Is Perl on Windows any less miserable than I remember?

Its been working for me without any problems but I'm not really asking a lot of it, just basic learning/tutorials.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Is there a clean and simple way to format text tables?

Here is my output from grabbing the latest dvd releases and their release dates:
code:
Jinn(2014) 2015-04-12
A Most Violent Year(2015) 2015-04-07
The Immigrant(2014) 2015-04-07
The Voices(2015) 2015-04-07
Interstellar(2014) 2015-03-31
The Imitation Game(2014) 2015-03-31
Wild(2014) 2015-03-31
Island Of Lemurs: Madagascar(2014) 2015-03-31
Wild Card(2015) 2015-03-31
The Rewrite(2015) 2015-03-31
The Hobbit: The Battle of the Five Armies(2014) 2015-03-24
Unbroken(2014) 2015-03-24
Into the Woods(2014) 2015-03-23
Penguins Of Madagascar(2014) 2015-03-17
Exodus: Gods and Kings(2014) 2015-03-17
Annie(2014) 2015-03-17
I'd like to align the title and release date but everything I've found so far looks pretty drat complicated to accomplish it.

*Disregard, found something on CPAN (Text::Table) that makes it easy peasy.

code:
Title                                           DVD Release
Jinn(2014)                                      2015-04-12
A Most Violent Year(2015)                       2015-04-07
The Immigrant(2014)                             2015-04-07
The Voices(2015)                                2015-04-07
Interstellar(2014)                              2015-03-31
The Imitation Game(2014)                        2015-03-31
Wild(2014)                                      2015-03-31
Island Of Lemurs: Madagascar(2014)              2015-03-31
Wild Card(2015)                                 2015-03-31
The Rewrite(2015)                               2015-03-31
The Hobbit: The Battle of the Five Armies(2014) 2015-03-24
Unbroken(2014)                                  2015-03-24
Into the Woods(2014)                            2015-03-23
Penguins Of Madagascar(2014)                    2015-03-17
Exodus: Gods and Kings(2014)                    2015-03-17
Annie(2014)                                     2015-03-17

Hughmoris fucked around with this message at 03:53 on Apr 7, 2015

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Does anyone have any recommended readings or tips for learning how to scrape a webpage with perl?

I'm wanting to scrape a local minor league baseball team's schedule for this year. It looks like the table that holds the dates is generated with javascript. The schedule is found here:http://www.milb.com/milb/stats/stats.jsp?t=t_sch&cid=4124&sid=t4124&stn=true

I'm googling for some ideas but they seem to be all over the place, including using selenium, phantomJS, Mojo::DOM and so on. Any tips on how to go about this?

*Hopped on IRC #perl and someone opened my eyes on how to use the network analyzer tool in Chrome. I found where the schedule data is stored, and I'm thinking I'll have a much easier time parsing this:
http://www.milb.com/gen/stats/jsdata/2015/clubs/t4124_sch.js?m=1428547560266

Hughmoris fucked around with this message at 04:09 on Apr 9, 2015

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

Sebbe posted:

My personal go-tos for that are WWW::Mechanize and HTML::Query.

As an example, here's a recent thing I made, which scrapes some messages from a login-protected site to a JSON API.

leedo posted:

I'm a big fan of Web::Scraper


Thanks for these. I've been poking around with Web::Scraper and having a little bit of luck

Hughmoris
Apr 21, 2007
Let's go to the abyss!
Using Perl in a Windows environment, is there a simple way to check if an application is open? In my script, I want to check if LotusNotes.exe is open before continuing. If it's not, I want to kill the script. Google is showing few examples and they seem a little beyond my understanding.

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

Roseo posted:

https://metacpan.org/pod/P9Y::ProcessTable looks to be a cross platform implementation but for win32 ultimately wraps https://metacpan.org/pod/Win32::Process::Info and https://metacpan.org/pod/Win32::Process. I'd use the one that you grasp the api easiest on.

Thanks for this.

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

RICHUNCLEPENNYBAGS posted:

Using a Perl script to automate Lotus Notes. The 90s are back.

They never left. :smug:

I'm not a programmer, was just looking for the easiest way to go about monitoring a Lotus Notes inbox for a work project. Strawberry Perl happen to work right out of the box, and I found a Perl script from 2003 that I could tweak to my purposes. I had a working solution in about 30 minutes. Very cool stuff.

Hughmoris
Apr 21, 2007
Let's go to the abyss!
If I'm a dummy with little knowledge of Perl and no knowledge of web apps, is Dancer2 my easiest path to creating a simple web app?

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

Roseo posted:

Look at Dancer::Plugin::SimpleCRUD

http://advent.perldancer.org/2011/2

Thanks. I don't know if I'll even get that far as I can't successfully install Dancer2. On ubuntu, using the command "CPAN install dancer2" will do some processes and eventually display "Running Build install
make test had returned bad status, won't install without force" before stopping the install.

I then tried "cpan force install dancer2" and "cpan fforce install dancer2" and they both ended with the same result and same error message. Not sure where to go from here.

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

John Big Booty posted:

Which test failed?

Lots and lots.


Mithaldu posted:

1 get on irc, the dancer people have a channel and love to help

2 to force install, launch the CPAN shell by calling cpan as it is, then run force install whatever

3 if tests fail on a cpan install, copy paste the whole output to gist.github.com or pastie.org, so people don't have to read your mind ;)

4 get on irc, seriously

(irccloud is a great free tool for that)

I took your advice and hopped on perl IRC. Someone was nice enough to help me out. They had me install the perl module local::lib for reasons I don't fully understand but I'm up and running now. Just created my first "Hello world!" web app. :3:

Hughmoris fucked around with this message at 04:12 on May 13, 2015

Adbot
ADBOT LOVES YOU

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

John Big Booty posted:

This is never the right answer.

I'm pretty unfamiliar with how modules are installed but it seemed like everything failed. Unfortunately I didn't save a copy of the log before I fixed the problem so I can only give vague answers

  • Locked thread