|
Hughmoris posted: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
|
# ? May 13, 2015 18:13 |
|
|
# ? May 15, 2024 21:36 |
|
Hughmoris posted:Lots and lots. Was it mst? Anyhow, if local::lib is suggested, you usually don't have convenient root access, and local::lib allows you to install modules just anywhere and then point the code at that.
|
# ? May 15, 2015 10:51 |
|
Mithaldu posted:Was it mst? Yep, it was mst. Lacking a project, I decided to tackle reddit's easy Weekly Programming Challenge. The goal is to calculate the standard deviation of a given list of values and round to 4 decimal places. I have a working solution but my code looks extremely clunky. Any tips on where I could improve it for best practice/style? Perl code:
Hughmoris fucked around with this message at 04:50 on May 16, 2015 |
# ? May 16, 2015 03:34 |
|
You can bum lines of perl all day and turn it into barely intelligible nonsense. That code is readable and does what it says on the tin.
|
# ? May 16, 2015 04:39 |
|
Hughmoris posted:I have a working solution but my code looks extremely clunky. Nonsense. It could always look worse. Perl code:
Toshimo fucked around with this message at 06:06 on May 16, 2015 |
# ? May 16, 2015 06:00 |
|
Is there any reason you used map, instead of postfix for?Perl code:
- Hughmoris posted:Yep, it was mst. Nice, and nice code. Have you seen http://perl-tutorial.org yet?
|
# ? May 16, 2015 10:49 |
|
Mithaldu posted:Is there any reason you used map, instead of postfix for? Yep, I have that site bookmarked. I know I've remarked on it earlier but web scraping is an exercise in frustration for me. There doesn't seem to be many newbie-friendly tutorials out there for Perl, so I've been trying to easter-egg my way solutions. For this problem, I'm trying to scrape a page that has the highest points in each state. Using the Web::Scraper module that someone suggested earlier, I'm able to get some information. I want to print just the state name and it's corresponding elevation value, NOT the highest point. Unfortunately, what I have scrapes all 3 values and I'm not sure how to adjust it. Perl code:
*And my variable naming convention is all jacked up due to repeatedly guessing at a solution. Initially I was just trying to grab the state names but it's grabbing everything in the table. Hughmoris fucked around with this message at 04:40 on May 18, 2015 |
# ? May 18, 2015 04:32 |
|
Two things: 1. You want to have a structure that contains more structures. If i read the docs of Web::Scraper right, that means you need to have one scraper that finds the structure which contains the structures that have the data you want (i.e. scrape for the trs), which then passes on to a subscraper that converts the individual TDs into text. That way you end up with an array that contains arrays, and can go through each group and grab the first and third value. 2. I highly recommend not using foreach, since it's literally just an alias to for. There is no advantage to it.
|
# ? May 18, 2015 10:56 |
|
Mithaldu posted:2. I highly recommend not using foreach, since it's literally just an alias to for. There is no advantage to it. Perl code:
Perl code:
|
# ? May 19, 2015 00:55 |
|
syphon posted:Really? I've always trended towards foreach, only because it's more explicit. Is there any advantage to sticking with just "for"? You know that you can declare a named variable for the current element of whatever you're iterating over with the for form in the same way you can with the foreach form, right? e: cf. http://codepad.org/efwlG7kH Blotto Skorzany fucked around with this message at 01:12 on May 19, 2015 |
# ? May 19, 2015 01:10 |
|
syphon posted:Really? I've always trended towards foreach, only because it's more explicit. Is there any advantage to sticking with just "for"?
|
# ? May 19, 2015 02:29 |
|
Mithaldu posted:Just in case Blotto's post didn't make it more clear (though i'm unclear how saying "it's an alias" is not clear enough): The advantage to for is four letters less to type AND less to read for developers who come after you, since aside from the letters "each", for and foreach are literally the same thing. They're different names that result in identical code.
|
# ? May 19, 2015 03:07 |
|
Put another way, "more letters" doesn't mean "more explicit".
|
# ? May 19, 2015 03:09 |
|
Mithaldu posted:Two things: I couldn't quite get it to work the way you mentioned. I did however discover a List::MoreUtils function called natatime that allows me to print an array in chunks. This code allows me to print the state and it's corresponding elevation: Perl code:
Hughmoris fucked around with this message at 03:17 on May 19, 2015 |
# ? May 19, 2015 03:11 |
|
Hughmoris posted:I can't say I really understand what's going on here: while (my @vals = $it->()) When you call natatime , you get back a (reference to a) subroutine. Whenever you call this subroutine (i.e., the $it->() call), it gives you the n (in this case 3) next elements of the list you provided. The while-loop then terminates once there are no more values to return, since the empty list is a falsy value. If you're curious, you can see the implementation here.
|
# ? May 19, 2015 09:06 |
|
John Big Booty posted:Which doesn't really strike me as being a very meaningful advantage. Hughmoris posted:I couldn't quite get it to work the way you mentioned. Anyhow, great to hear you managed to get it to be how you wanted it.
|
# ? May 19, 2015 17:19 |
|
Sebbe posted:When you call natatime , you get back a (reference to a) subroutine. Whenever you call this subroutine (i.e., the $it->() call), it gives you the n (in this case 3) next elements of the list you provided. The while-loop then terminates once there are no more values to return, since the empty list is a falsy value. Thanks, that breakdown makes sense. Anyone here working on any Perl projects? Anyone work with Perl for their day to day jobs? Anyone else currently trying to learn Perl? If so, do tell. Hughmoris fucked around with this message at 00:37 on May 27, 2015 |
# ? May 27, 2015 00:30 |
|
Hughmoris posted:Anyone here working on any Perl projects? Anyone work with Perl for their day to day jobs? Anyone else currently trying to learn Perl? If so, do tell. And in day job terms i've been doing Perl since 2005, and i still learn new things. (The locale affects how sprintf works!)
|
# ? May 27, 2015 10:15 |
|
Hughmoris posted:Thanks, that breakdown makes sense. My team uses Perl for scripting. We built a suite of scripts that help us and the developers work in the environment.
|
# ? May 27, 2015 11:24 |
|
We use perl where i work for a few websites/web-accessible forms and for a bunch of scripts. I tend to use it whenever I need to write scripts or reports that may eventually need to be rerun by someone else since our environment supports it.
|
# ? May 28, 2015 00:34 |
|
I am developing a simple application for managing firewall rules, the backend that interfaces with the actual device (all Cisco ASA's) is written in perl because I need good regex capabilities. In retrospect I could have used PHP but I already had a standard set of custom perl functions left over from previous projects. I've also used it in the past to create a simple cli interface for blacklisting/quarantining devices on a network (paired with Expect).
|
# ? May 29, 2015 02:06 |
|
Hughmoris posted:Thanks, that breakdown makes sense. Don't use natatime to parse a Web::Scraper data structure. If you need some more example code you could take a look at https://github.com/ugexe/SomethingAwful--Forums/blob/master/lib/SomethingAwful/Forums/Scraper/Forum.pm Web::Scraper is just a thin DSL for xpath, so if something isn't working the way you think it should its probably your xpath. Hughmoris posted:Thanks, that breakdown makes sense. I use Perl5 and Perl6 for $work in sports analytics (lots of Web::Scraper stuff)
|
# ? Jun 5, 2015 03:47 |
|
Is there a stripped down vi clone written in Perl?
|
# ? Jun 5, 2015 09:21 |
|
gently caress the mods posted:Don't use natatime to parse a Web::Scraper data structure. If you need some more example code you could take a look at https://github.com/ugexe/SomethingAwful--Forums/blob/master/lib/SomethingAwful/Forums/Scraper/Forum.pm How are you liking Perl6?
|
# ? Jun 6, 2015 00:11 |
|
I like it, it's just slow and the ecosystem is lacking (although active and growing). When Inline::Perl5 works you can even subclass perl 5 code and do stuff like code:
|
# ? Jun 6, 2015 07:58 |
|
I'm fairly new to perl, is the "my" statement when declaring a variable necessary? Does it somehow differentiate between local/global? Edit: and an actual question-question: I am learning perl on a sandbox linux server, thinking that it will come in handy for system administration / computer janitoring. One of the things that I was attempting to do was useradd. code:
last edit: I know that this is dangerous / unsecure as hell to do, just trying to learn the basics. du -hast fucked around with this message at 12:43 on Jul 13, 2015 |
# ? Jul 13, 2015 12:23 |
|
I'm not sure what you're learning from, but the likelihood that your learning material is horrible is high. Please have a look at http://perl-tutorial.org for learning materials that are known to not be hostile to newbies. As for my, it is not strictly necessary and you can program without it, however it is strongly recommended to use my and use strict; use warnings; in conjunction as that protects you from many bugs. Global/local: You want to learn about lexical scoping, it's a bunch to explain, so please look it up. Getting STDERR from child processes: https://metacpan.org/pod/Capture::Tiny Return value: http://perldoc.perl.org/functions/system.html , in short, use code like this: code:
|
# ? Jul 13, 2015 13:13 |
|
du -hast posted:I'm fairly new to perl, is the "my" statement when declaring a variable necessary? Does it somehow differentiate between local/global? Basically, yes and yes. my declares a local (i.e. locally scoped, lexical) variable. Perl code:
Perl code:
Perl code:
Perl code:
qntm fucked around with this message at 16:55 on Jul 13, 2015 |
# ? Jul 13, 2015 16:47 |
|
I'm still new to Perl but I just wrote a script for work that will scrape a Lotus Notes database and write content to an Excel sheet, with requested formatting. I don't know how other languages compare on those items but Perl made it a breeze.
Hughmoris fucked around with this message at 00:03 on Aug 13, 2015 |
# ? Aug 13, 2015 00:00 |
|
Well, I may have spoke too soon. I think I'm getting hung up on dereferencing. I have a block of code that looks something like this:Perl code:
code:
Hughmoris fucked around with this message at 04:43 on Aug 13, 2015 |
# ? Aug 13, 2015 04:37 |
|
Hughmoris posted:Well, I may have spoke too soon. I think I'm getting hung up on dereferencing. I have a block of code that looks something like this: code:
|
# ? Aug 13, 2015 09:17 |
|
John Big Booty posted:
code:
|
# ? Aug 13, 2015 09:26 |
|
Mithaldu posted:You mean: code:
|
# ? Aug 13, 2015 21:51 |
|
John Big Booty posted:grep {/value/i}
|
# ? Aug 13, 2015 22:18 |
|
Mithaldu posted:A true perler would've known to use a comma there, i'm going to have to confiscate your card. code:
|
# ? Aug 13, 2015 22:37 |
|
John Big Booty posted:
|
# ? Aug 13, 2015 22:58 |
|
Mithaldu posted:A true perler also has a sense of humor. I've met a few true perlers and I wouldn't be so sure of that...
|
# ? Aug 13, 2015 22:59 |
|
syphon posted:I've met a few true perlers and I wouldn't be so sure of that... To be honest, i'm biased by IRC and ShadowCat specifically. If you've interacted with schmorp, then well, my sympathies.
|
# ? Aug 13, 2015 23:06 |
|
Mithaldu posted:A true perler also has a sense of humor.
|
# ? Aug 13, 2015 23:29 |
|
|
# ? May 15, 2024 21:36 |
|
Mithaldu posted:You mean:
|
# ? Aug 14, 2015 02:48 |