|
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:
code:
|
# ¿ Jul 14, 2010 03:02 |
|
|
# ¿ May 2, 2024 03:30 |
|
Filburt Shellbach posted:You want parentheses not braces. That did it, thank you.
|
# ¿ Jul 14, 2010 03:08 |
|
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:
|
# ¿ Nov 23, 2011 09:41 |
|
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:
|
# ¿ Nov 27, 2011 22:37 |
|
Roseo posted:Here's how I'd do it, with some notes below. Thanks for taking the time to type all that out, I'll definitely take a look.
|
# ¿ Nov 27, 2011 23:05 |
|
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.
|
# ¿ Nov 30, 2011 05:32 |
|
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 |
# ¿ Dec 13, 2011 01:06 |
|
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?
|
# ¿ May 8, 2014 03:22 |
|
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:
*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.
|
# ¿ Jun 3, 2014 03:40 |
|
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:
|
# ¿ Jun 3, 2014 04:46 |
|
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. 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.
|
# ¿ Jun 3, 2014 06:04 |
|
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.
|
# ¿ Jun 8, 2014 23:39 |
|
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 |
# ¿ Feb 22, 2015 02:48 |
|
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: 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.
|
# ¿ Feb 25, 2015 03:09 |
|
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:
|
# ¿ Mar 26, 2015 03:21 |
|
uG posted:
That hurts my brain. Can you break this down? Perl code:
Hughmoris fucked around with this message at 04:23 on Mar 26, 2015 |
# ¿ Mar 26, 2015 04:17 |
|
uG posted:
Thanks for taking the time to write that up.
|
# ¿ Mar 26, 2015 04:35 |
|
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.
|
# ¿ Mar 28, 2015 03:38 |
|
Thanks, this will give me some light reading to do over the weekend.
|
# ¿ Mar 28, 2015 05:14 |
|
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:
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:
|
# ¿ Mar 28, 2015 06:32 |
|
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: 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.
|
# ¿ Mar 28, 2015 16:01 |
|
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:
*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:
Hughmoris fucked around with this message at 05:21 on Mar 30, 2015 |
# ¿ Mar 30, 2015 04:57 |
|
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. 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 |
# ¿ Mar 30, 2015 05:57 |
|
EVGA Longoria posted:If you have CPAN access, https://metacpan.org/pod/Data::Fake will give you: I didn't even think to look on CPAN for a data generator. I need to poke around there a little bit more.
|
# ¿ Mar 31, 2015 02:54 |
|
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:
*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 |
# ¿ Apr 1, 2015 03:53 |
|
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:
|
# ¿ Apr 4, 2015 03:27 |
|
EVGA Longoria posted:Movies is an array of movies. You'd need to loop through it. 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:
Hughmoris fucked around with this message at 05:46 on Apr 4, 2015 |
# ¿ Apr 4, 2015 04:25 |
|
EVGA Longoria posted:Movies is an array of movies. You'd need to loop through it. 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:
Perl code:
|
# ¿ Apr 4, 2015 16:27 |
|
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. 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.
|
# ¿ Apr 4, 2015 16:51 |
|
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. 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.
|
# ¿ Apr 7, 2015 00:03 |
|
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:
*Disregard, found something on CPAN (Text::Table) that makes it easy peasy. code:
Hughmoris fucked around with this message at 03:53 on Apr 7, 2015 |
# ¿ Apr 7, 2015 03:13 |
|
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:OM 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 |
# ¿ Apr 9, 2015 02:50 |
|
Sebbe posted:My personal go-tos for that are WWW::Mechanize and HTML::Query. 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
|
# ¿ Apr 14, 2015 02:22 |
|
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.
|
# ¿ May 3, 2015 03:57 |
|
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.
|
# ¿ May 4, 2015 13:06 |
|
RICHUNCLEPENNYBAGS posted:Using a Perl script to automate Lotus Notes. The 90s are back. They never left. 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.
|
# ¿ May 7, 2015 16:37 |
|
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?
|
# ¿ May 9, 2015 01:59 |
|
Roseo posted:Look at Dancer::Plugin::SimpleCRUD 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.
|
# ¿ May 9, 2015 02:42 |
|
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 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. Hughmoris fucked around with this message at 04:12 on May 13, 2015 |
# ¿ May 13, 2015 01:54 |
|
|
# ¿ May 2, 2024 03:30 |
|
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
|
# ¿ May 13, 2015 17:43 |