|
qr is a function that defines a regex-like object, much like q and qq define single and double quoted strings in my previous example. I don't think Perl lets you set a variable to a regex-like object using slashes. And you probably shouldn't either. If you want to keep your regex inside variables, store them in single quoted strings, and stick the variable in your regex, like so: Perl code:
But Mithaldu is right, maybe you should try reading up on Perl first, before jumping right in? Rohaq fucked around with this message at 23:33 on Nov 13, 2013 |
# ? Nov 13, 2013 23:28 |
|
|
# ? Jun 3, 2024 23:51 |
|
e: q != e
|
# ? Nov 13, 2013 23:42 |
|
Mithaldu posted:Wow. I'd strongly suggest you read that book before doing anything else. Whereever you've been learning Perl, it's been teaching you in the worst possible way. Rohaq posted:But Mithaldu is right, maybe you should try reading up on Perl first, before jumping right in? It's...complicated. We've been tasked to rewrite our Python scripts that we've been working on for the past two months in Perl within 4 days of first being exposed to Perl. This is an online terminal Masters intro course. I'm gonna go curl up with Modern Perl and question my life choices.
|
# ? Nov 13, 2013 23:43 |
|
That's odd; is there any reason it has to be in Perl? Python has a perfectly capable regex module called 're'; it's different from the way Perl implements regex - it's a separate module, and not an inherent comparison operator, like =~ in Perl. Unless you're using some kind of custom Perl module for your work, of course, then that would make sense, but I thought that Python was pretty much the most popular language in the bioinformatics world.
|
# ? Nov 14, 2013 00:30 |
|
Pollyanna posted:It's...complicated. We've been tasked to rewrite our Python scripts that we've been working on for the past two months in Perl within 4 days of first being exposed to Perl. This is an online terminal Masters intro course. Or maybe even order the full book. Perl is rather easy to learn. However pretty much any resource for it written before 2011 teaches practically Perl 4 and is 20 years out of date. Once you have modern references you should be able to get up to speed pretty quickly. quote:I thought that Python was pretty much the most popular language in the bioinformatics world.
|
# ? Nov 14, 2013 01:00 |
|
Perl is common in the bioinformatics community because that's been the main language since like 2001. Most of the relevant modules and libraries are built in Perl. People stick to it because it's well-established and was used in things like the Human Genome Project. (ps is that not a loving badass title for project cmon just say it out loud and try not to swoon) But yeah, I prefer Python for programming in general. Regular expressions can be super useful in bioinformatics, but there's other tools we need as well and Python is just as good at those, possibly better than Perl.
|
# ? Nov 14, 2013 04:49 |
|
I use both languages; they've both got their strong points, though I generally prefer Perl for anything ETL related, because the inline regex comparison operators make quickly setting up regex for data extraction a piece of piss, and I prefer Python for anything involving writing small tools quickly, and for anything related to handling and visualising data, because numpy and pylab/matplotlib are quite frankly loving badass.
|
# ? Nov 14, 2013 05:23 |
|
Does anyone have any experience with NTLM auth for web apps, especially Dancer? I can build an LDAP bind easily enough, but it would be best if I could use the NTLM automated negotiation on top of this. Background is that I've got an internal web app that keeps expanding, and as it gets rolled out to new teams we end up either creating a dozen more accounts, or we end up creating one for an entire team, which I hate. Going to move to LDAP, but I'd also like to hook in NTLM, since it works with just about everything now.
|
# ? Dec 5, 2013 14:39 |
|
Say I have a string "AGCT". If I try to run:code:
EDIT: Whoops, the answer is "$output =~ tr/AGCT/TCGA/;". Wish that was a bit clearer.
|
# ? Dec 13, 2013 22:48 |
|
Successive statements are normally executed successively in an imperative language.
|
# ? Dec 13, 2013 22:58 |
|
Otto Skorzeny posted:Successive statements are normally executed successively in an imperative language. Yeah, I totally brainfarted on that. I figured it out not long after, to be fair!
|
# ? Dec 14, 2013 00:50 |
|
Sorry about the double post, but I've got another issue. I'm trying to use CGI.pm to make a webpage, and part of my code is not working correctly:Perl code:
I suspect that this is because there is no data being passed after submitting the textarea form. Why? Doesn't it work exactly the same as textfield?
|
# ? Dec 16, 2013 03:38 |
|
Pollyanna posted:Sorry about the double post, but I've got another issue. As full effect measure i strongly recommend you start by reading Modern Perl (an evening), and then Ovid's Beginning Perl (a week). Links to both free and payable versions are on http://perl-tutorial.org As for your code, i recommend reading the CGI docs again if you really wish to continue using it (bad idea). It seems to me that you got the syntax of the parameters passed for style wrong, since other calls in the docs format it like this: code:
|
# ? Dec 16, 2013 19:26 |
|
Mithaldu posted:Oh god, did they give you that godawful BioPerl programmer book to learn from? Nope. No book at all. We've been learning off of our professor's lecture notes with maybe a link to some CPAN docs, which has been...lacking, to say the least. I didn't even know that Bioperl had a book associated with it (Any good books/tutorials for doing bioinfo in Perl would help, tho!) I didn't really wanna bring this up, but this is an assignment. CGI is required I've been working through Modern Perl, though at a snail's pace. Beginning Perl is a new one, I'll check it out.
|
# ? Dec 16, 2013 21:12 |
|
CGI isn't bad at all if you use it with a template system like Template::Toolkit or HTML::Template. I suppose that's outside the scope of your assignment though, so it probably doesn't help you at all.
|
# ? Dec 16, 2013 21:49 |
|
HTML::Template with CGI really can do quite a bit and makes things so much neater and easier, thanks to keeping the HTML and perl code separate. For the current issue though, I would try printing what is returned from $cgi->param with no argument to see what the textarea's stuff is getting passed in as. Perhaps like: Perl code:
|
# ? Dec 16, 2013 22:19 |
|
Pollyanna posted:Nope. No book at all. We've been learning off of our professor's lecture notes with maybe a link to some CPAN docs, which has been...lacking, to say the least. I didn't even know that Bioperl had a book associated with it (Any good books/tutorials for doing bioinfo in Perl would help, tho!) I feel for you. Right now the main thing i can tell you as for getting help and learning is: Get on irc.perl.org and sit in #perl-help (perl help) and #pdl (perl scientists). Use a shell, or an irc bouncer so you don't annoy the living piss out of people by dropping every 5 minutes your cellphone gets out of tower range; then proceed to ask way too many questions and get really good. That said, if you can skip the whole rat's nest of actually generating the HTML with CGI, you'll spare yourself a ton of grief. (HTML::Template isn't entirely painful, but if you can i'd recommend the current cream of the crop, Text::Xslate.) If you are required to do that, at least try not to print directly, but actively separate the workflow such that you first figure out all the data you want on the website, then generate the html into a single scalar, then print that. Did my guess about the style parameter help?
|
# ? Dec 16, 2013 22:54 |
|
Mithaldu posted:As for your code, i recommend reading the CGI docs again if you really wish to continue using it (bad idea). It seems to me that you got the syntax of the parameters passed for style wrong, since other calls in the docs format it like this: That's for referencing a .css file, I think. The {-style=>"height: 200px; width: 300px;"} format is for inline CSS (yeah, I know). toadee posted:For the current issue though, I would try printing what is returned from $cgi->param with no argument to see what the textarea's stuff is getting passed in as. With a textfield, I get $VAR1 = [ 'input', 'submit_sequence' ];, and it works, so let's look for that. With a textarea... code:
code:
As for the other approaches to generating HTML, I have some experience with HTML templating, so I'll definitely look into Template and Xslate. Thanks, guys!
|
# ? Dec 17, 2013 01:12 |
|
When in doubt, print it out A huge portion of my debugging issues are solved when I just print out every variable involved and then go look for why something is getting something it isn't supposed to.
|
# ? Dec 17, 2013 01:21 |
|
Pollyanna posted:Okay, so the input parameter is not getting passed for some reason. Is it because of the way I wrote it? If I try print $cgi->textarea({-style=>"height: 200px; width: 300px;", -name=>"input"});... The (curly) braces make a big difference. The braces indicate that a new hash table should be created containing the keys/values inside the braces and than that hash table should be passed to the textarea() method. The text area method doesn't want a hash table, so passing it one causes things not to work. CGI is a little confusing about what methods want hash tables and what don't, so it helps to check the perldoc often.
|
# ? Dec 17, 2013 05:18 |
|
Pollyanna posted:That's for referencing a .css file, I think. The {-style=>"height: 200px; width: 300px;"} format is for inline CSS (yeah, I know). Just to expand on this a bit, since it's one of the biggest things with parameters in Perl: Whenever you call a function or a method, everything you pass to it gets passed as one big list. So, for example: $cgi->textarea(-style => "height: 200px; width: 300px;", -name => "input"); This is the same as: my @list = (-style => "height: 200px; width: 300px;", -name => "input"); $cgi->textarea(@list); The => is called the fat comma, and it makes this the same as: my @list = ("-style", "height: 200px; width: 300px;", "-name", "input"); $cgi->textarea(@list); Hashes in perl are just lists, where odd entries are keys, and even are values. Since we're passing lists, you can use it as a hash. Generally, the code for a function expecting this will work something like: code:
code:
The big differences here is that the first example is a brand new hash -- if you were to change the values inside the myFunction, they would only stay changed in the scope of myFunction -- once you exit, the changes are lost. Passing by reference means you are changing the original hash anytime you make changes -- if you were to have myFunction change the -name field, it would be changed permanently.
|
# ? Dec 23, 2013 13:02 |
|
I've downloaded a bioinformatics script written in French that I'm trying to make work having never used Perl before this week (but knowing a bit of Python) and not knowing French. I suspect the problem I'm having is due to the authors not including everything that it requires as it's not finding some file, but I'm not sure. Here's the edited relevant chunk of code, it fails on the final line:Perl code:
hmmpfam /.../profilsHMM-Tases/transp110.hmm /.../modified_input_trad Fatal Error when trying to execute hmmpfam: No such file or directory at genome_HMM_search_E1_1.pl line 302, <PROFILS> line 27. hmmpfam is a module in Bioperl (which is installed), but that's the first mention of it in the script. The other two files mentioned in the error message exist in the locations it's looking for them in. Any clues as to what's going wrong here would be appreciated.
|
# ? Feb 13, 2014 18:03 |
|
JayTee posted:
Perl code:
However, it's not actually running that command string, instead it's running: code:
|
# ? Feb 13, 2014 18:30 |
|
drat, I was hoping it wasn't that. Time to email the authors. Thanks for the info!
|
# ? Feb 13, 2014 18:46 |
|
JayTee posted:I've downloaded a bioinformatics script written in French that I'm trying to make work having never used Perl before this week (but knowing a bit of Python) and not knowing French. I suspect the problem I'm having is due to the authors not including everything that it requires as it's not finding some file, but I'm not sure. Here's the edited relevant chunk of code, it fails on the final line: Might not help, but I"m assuming you used automated translation here... "lit" does mean bed, but here it means "read."
|
# ? Feb 14, 2014 13:52 |
|
code:
Full code: code:
|
# ? Feb 28, 2014 17:45 |
|
Due to how sparse the documentation is, i can't give you a solution, but i can say two things: 1. Your subforums scraper is definitely the wrong path to take. Look at the synopsis and it shows it's grabbing all "li.status" elements into the array "tweets", then uses the scraper to get attributes for the tweets from the elements inside each li. Possibly also look at https://metacpan.org/source/MIYAGAWA/Web-Scraper-0.37/eg to get more examples. 2. Get on irc.perl.org and ask miyagawa in #plack, after all the wrote the thing. (3. strict, warnings)
|
# ? Feb 28, 2014 19:52 |
|
I'm not sure if this is the best way to do it or not, but after redoing the XPath bits I was able to extract all the subforums. I guess the part that confuses me is code:
code:
code:
|
# ? Feb 28, 2014 20:12 |
|
Good that you worked it out. The way you did it is actually what i thought you'd need to be doing.
|
# ? Feb 28, 2014 20:14 |
|
And miyagawa modules usually handle your strict/warnings incantations
|
# ? Feb 28, 2014 20:19 |
|
I've never seen them to that before, and Plack, Web::Scraper, Hash::MultiValue don't. Can you give any examples?
|
# ? Feb 28, 2014 21:08 |
|
Mithaldu posted:I've never seen them to that before, and Plack, Web::Scraper, Hash::MultiValue don't. Can you give any examples? https://github.com/miyagawa/web-scraper/blob/master/lib/Web/Scraper.pm#L2-L3 https://github.com/plack/Plack/blob/master/lib/Plack.pm#L3-L4 https://github.com/miyagawa/Hash-MultiValue/blob/master/lib/Hash/MultiValue.pm#L3 If you use these modules it imports their 'use strict' and 'use warnings' I thought? e: i see now that it doesn't, don't know why I thought that for so long uG fucked around with this message at 21:47 on Feb 28, 2014 |
# ? Feb 28, 2014 21:44 |
|
As you found, these don't, they just set strict and warnings for that module. Modules that export pragmas have to have these calls in their import method: https://metacpan.org/source/CHROMATIC/Modern-Perl-1.20140107/lib/Modern/Perl.pm#L33
|
# ? Feb 28, 2014 22:18 |
|
Need help with a regex... Runnable example code: https://gist.github.com/anonymous/0d89484375909786e5b5 (iterates over each line and outputs [OK] or [ERROR]) code:
'Joe Shmoe rush for 10 yards, penalty MICHIGAN -420 yards declined' The solution i'm looking for I thought would go something like: code:
It may be worth mentioning that (?:(?!,.*?penalty)|(?!,.*?penalized)|\Z) is to handle a line of text that has more than 1 penalty (like: 'Southern Utah penalized -5 yards, Michigan penalized 11 yards'). ,.*? is supposed to use ", TEAM NAME penalty" as an 'end of this penalty' token. I can't just split them apart on a comma because sometimes it will insert a player's name into the play like: 'PENALTY HAWAII intentional grounding (Brennan, C) 0 yards to the Hawaii19, PENALTY HAWAII illegal block 10 yards' and it would split on "Brennan, C"
|
# ? Apr 29, 2014 20:30 |
|
uG posted:
Instead of trying to wrestle that regex into doing what you want, you might try to break it into smaller pieces. Something like: Perl code:
Extortionist fucked around with this message at 23:01 on Apr 29, 2014 |
# ? Apr 29, 2014 22:51 |
|
Extortionist posted:Instead of trying to wrestle that regex into doing what you want, you might try to break it into smaller pieces. Something like: I tried that after getting frustrated with this but it doesn't iterate over the matches like I want. The code you posted lacks negative lookahead so it will take "penalty smu 10 yards blah blah, penalty msu 5 yards", then the first match will be "penalty smu 10 yards blah blah, penalty", leaving "msu 5 yards" not to get iterated over. Adding negative lookahead leaves the (.*?) (aka $1 aka $penalty_phrase) to always capture nothing.
|
# ? Apr 29, 2014 23:45 |
|
uG posted:I tried that after getting frustrated with this but it doesn't iterate over the matches like I want. The code you posted lacks negative lookahead so it will take "penalty smu 10 yards blah blah, penalty msu 5 yards", then the first match will be "penalty smu 10 yards blah blah, penalty", leaving "msu 5 yards" not to get iterated over. Adding negative lookahead leaves the (.*?) (aka $1 aka $penalty_phrase) to always capture nothing. Perl code:
|
# ? Apr 30, 2014 00:01 |
|
Hey, I've got a pair of questions: I have a custom test that I've written in Perl for the purposes of load testing our company's web-based app. Because my boss was the one who originally coded the app which is obtuse and arcane, and because the requirements placed on the test are equally obtuse and arcane (I have to synchronize each instance so each runs as simultaneously as possible, including final submission to the server), I can't use any existing software or frameworks. I have a Perl script that simulates a browser and performs the exact sequences of GETs and POSTs and redirects to test the app. The question, then, is what exactly am I looking for when load testing the server? The server is a Windows Server 2008 machine running IIS7. The goal my boss handed down is to find out what it takes to "break the server", but he himself doesn't actually know what that means so I can't ask him for any more clarification. What counters would I be tracking in Perfmon to determine where the bottleneck is, besides the standard CPU/memory? As a secondary question, I'm trying to separate STDOUT and STDERR output into two separate logfiles - I want regular program output to go to one, and errors to go to the other logfile. This is what I've got, stolen from elsewhere on the internet: Perl code:
What's going on here? Does STDERR only actually contain things I specifically output to it , i.e. PRINT STDERR "This is an error.\n"; ? Since I'm running hundreds of separate instances across multiple geographically distributed VMs, I can't get any individual script output. Is my best bet for debugging basically to be throwing a PRINT STDERR "Some debug message" after almost every line of code?
|
# ? Apr 30, 2014 09:08 |
|
Olesh posted:I have a custom test that I've written in Perl for the purposes of load testing our company's web-based app. Because my boss was the one who originally coded the app which is obtuse and arcane, and because the requirements placed on the test are equally obtuse and arcane (I have to synchronize each instance so each runs as simultaneously as possible, including final submission to the server), I can't use any existing software or frameworks. I have a Perl script that simulates a browser and performs the exact sequences of GETs and POSTs and redirects to test the app. Olesh posted:As a secondary question, I'm trying to separate STDOUT and STDERR output into two separate logfiles - I want regular program output to go to one, and errors to go to the other logfile. This is what I've got, stolen from elsewhere on the internet: Try IO::Handle (core perl module). Here is a bit from perlmonks: code:
Olesh posted:My code is still in progress and there are still issues I'm running into (for example, I discovered that WWW::Mechanize will apparently throw an exception and the script will end if it fails to GET a page for any reason) but none of these errors are showing up in the logfile designated by $errlog, nor are they showing up in $logfile. Olesh posted:Is my best bet for debugging basically to be throwing a PRINT STDERR "Some debug message" after almost every line of code?
|
# ? Apr 30, 2014 20:23 |
|
|
# ? Jun 3, 2024 23:51 |
|
uG posted:I'm not sure if i completely understand your 'synchronize each instance' requirement... do you mean you run a single threaded perl script from all of your server instances at the same time? Because what you should really be doing to hammer a server is using threads or an async module (and a module to make mechanize async friendly, LWP::Protocol::AnyEvent::http) like AnyEvent to fire off hundreds of connections from each server at the same time. From there you could do stuff like log the response time, make sure it returns what you expect, etc and look for where, say, the response time falls apart or you start getting ->response codes you don't expect. Currently, when I'm running the test, I have anywhere between 1 and 40 VMs running, and each VM is triggered via a PHP script to run X copies of the perl script. Each perl script is a separate instance, with a total number of instances being equal to (# of VMs) * (X copies per VM). As far as the requirements go, I don't understand it entirely myself. My boss has this idea that clients are going to want to know what happens if, as users go through the application, the stars align and 10,000 users all click the submit button at the exact same instant. Thus, for the load testing, since I don't possess a machine capable of running 20,000 instances, I have to have some way to verify that each seperate VM is synched up and requests are reaching the server at the same instant (or as close as I can manage). He also is insistent that each instance has to be as close to a real user as possible, i.e., they have to go through the app from start to finish hitting every page and submitting using the data generated by the app, necessitating the labyrinthine sequence of GET and POSTs (51 in total). Successfully navigating the app generates a database entry as well, which is sort of the final arbiter of whether or not any errors occurred. All while ensuring that each request hits the server as near-simultaneously as possible. My ultimate goal in this is to simulate a variable number of users, find out at what number of users errors occur, identify the bottleneck (whether it's CPU, memory, etc), and be able to use the data to guide future expansion with regard to load balancing when that becomes necessary in the future. The idea of event driven programming, like in AnyEvent is almost completely foreign to me. All of the work I've done so far has been PHP/javascript based; this is my only foray into Perl ever and the only time I've ever used an event for anything was through a need to use top.postMessage() in javascript to bypass the normal restrictions on cross-domain scripting. My boss, as far as I'm aware, has never even heard of it - all of his code is 100% block code. After looking into AnyEvent::http, I'm not sure it's suitable. Getting from the start of the app to the end of it requires continuity, which is why the automatic cookie handling of WWW::Mechanize was so helpful. I'm having trouble visualizing how I could run a single script, generate a variable number X of sub-processes which each asynchronously handle log-writing, maintain a tightly synchronized schedule of page requests based on the system time, while maintaining the continuity required along each sub-process short of actually forking the process itself, which does not appear significantly different than simply running multiple instances. At the very least, I don't know how I would dynamically generate and maintain an arbitrary number of user agents for the continuity I require. To give you a more precise example of what I mean, I know that in javascript I can generate an arbitrary number of variables and access them later by storing them in an object, without knowing ahead of time how many variables I will need. JavaScript code:
Perl code:
uG posted:Try IO::Handle (core perl module). Here is a bit from perlmonks: I'll give that a shot. uG posted:You can set WWW::Mechanize->new( autocheck => 0 ); to handle the errors yourself (check $mech->success) or use Try::Tiny (or use an eval block if you can't use CPAN); I appreciate the suggestions! I can use CPAN; I'm just not very linux literate so installing a new module requires me to actually go back to my written instructions, vs using the Perl Package Manager that comes with ActiveState Perl.
|
# ? Apr 30, 2014 23:33 |