|
Casao posted:When did stat start returning an arrayref instead of an array? Cause every thing I can find on the internet says it'll return an array, but I have to reference before I can pull any thing out. code:
|
# ? Apr 23, 2011 01:57 |
|
|
# ? May 21, 2024 22:39 |
|
There are a couple modules, File::stat and File::Stat (ugh), that can replace the stat function with a different version. Perhaps one of those is causing your problem.
|
# ? Apr 23, 2011 12:17 |
|
Is there an easy way to get the difference between 2 calls of localtime(time)? Like break it down by hours/minutes/seconds?
|
# ? Apr 25, 2011 21:46 |
|
Call localtime in list context and it gives you the breakdown. From there all you need to do is subtract each element in a loop (or if you're feeling wizardly, use List::MoreUtils's pairwise).
|
# ? Apr 25, 2011 23:12 |
|
It's not terribly pretty code, but here's what I use to grab the time into a nice, human-readable format. I think I stole it from somewhere off the internet.code:
|
# ? Apr 26, 2011 01:39 |
|
If you want ugly code, here you go:code:
|
# ? Apr 26, 2011 02:26 |
|
There are also a million date manipulating modules you could use. Date::Time, Date::Manip, and Date::Calc come to mind.
|
# ? Apr 26, 2011 04:25 |
|
code:
|
# ? Apr 26, 2011 06:46 |
|
qntm posted:That solution does work, but I foresee problems if the existing tree already contains elements ending in "_foo", e.g. "A" and "A_foo". The existing "A" will be converted to "A_foo" on the first pass, while the existing "A_foo" will be left alone. On the second pass, you will end up with "A_foo_foo" and "A_foo_foo" respectively, which is wrong. Ah, you're correct. I didn't realize that problem. Thank you for pointing that out! I'll try your code snippet.
|
# ? Apr 26, 2011 08:02 |
|
uG posted:
What does this mean? "with" is not a built-in Perl function and it doesn't seem to have been imported from anywhere. Actually, nor are "has" or "around". Also, what is the point of "$VERSION = eval $VERSION;"?
|
# ? Apr 26, 2011 10:33 |
|
qntm posted:What does this mean? "with" is not a built-in Perl function and it doesn't seem to have been imported from anywhere. They come from Moose::Role. No idea about the version thing though.
|
# ? Apr 26, 2011 11:57 |
|
Anaconda Rifle posted:If you want ugly code, here you go: I have a script that runs a set of instructions and can take anywhere from under a minute to several hours depending on the input. I'd like to print to the log file when it's finished how long the whole thing took. I'm using this at the start and end of the log: pre:($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); $stamp = "Start logger.err\n%4d-%02d-%02d %02d:%02d:%02d\n======================================"; printf $stamp,$year+1900,$mon+1,$mday,$hour,$min,$sec; printf $log $stamp,$year+1900,$mon+1,$mday,$hour,$min,$sec; # $log is the output file Anyway, I'd like to get the difference in time between the first printing and the last - how long the whole thing took.
|
# ? Apr 26, 2011 14:10 |
|
Clanpot Shake posted:Thanks to you and the other people, but you seem to have misread my question. I'll be more clear. What you really want to do is get the start time and store that in a variable and the end time as a variable and subtract.
|
# ? Apr 26, 2011 15:40 |
|
Mithaldu posted:They come from Moose::Role. No idea about the version thing though. It mainly has to do with CPAN and using _ in the version. code:
quote:The eval converts the string "0.001_001" to a number, following the rules for Perl numeric literals (which allow underscores for visual separation). The result is the number 0.001001. uG fucked around with this message at 15:53 on Apr 26, 2011 |
# ? Apr 26, 2011 15:48 |
|
clockwork automaton posted:What you really want to do is get the start time and store that in a variable and the end time as a variable and subtract. pre:Start logger.err 2011-04-26 11:36:25 ====================================== ====================================== End logger.err 2011-04-26 11:37:10 Total time taken: 00:01:-15
|
# ? Apr 26, 2011 16:40 |
|
Clanpot Shake posted:This is what I get when I store each call in different variables and subtract them: code:
|
# ? Apr 26, 2011 17:14 |
|
uG posted:Subtract the epoch of each time (use DateTime). Alternatively:
|
# ? Apr 26, 2011 19:14 |
|
I tracked my problem down to Catalyst::Action::REST, which only checks the traits during a GET request. It still sets the flag looks_like_browser, so I can just check inside the POST method. But I can't help and think there is a reason they did this, even though it seems you would want to return different things on a POST depending on if it was a browser request or a non browser REST request.Clanpot Shake posted:This works, thanks. Out of curiosity, does localtime(time) return drastically different results between linux and windows? I'm running this on linux and it looks good, wondering if it will look the same on windows.
|
# ? Apr 27, 2011 03:18 |
|
code:
code:
|
# ? Apr 28, 2011 19:15 |
|
I don't do MVC much, but I'm pretty sure you want:code:
code:
|
# ? Apr 30, 2011 22:49 |
|
How do I get an anonymous reference to the keys of a hash? I have a subroutine which expected a single argument, and that argument should be a reference to an array. I want to extract the keys from a hash and submit those keys to my subroutine, ideally in a one-liner instead of having to create a named @keys array. The problem is, creating a reference to a the array returned by "keys" actually creates a an array of references to keys. Why Perl does this, I have absolutely no idea. But how do I stop it? code:
|
# ? May 9, 2011 13:06 |
|
You use [] to create a reference to an anonymous array:code:
|
# ? May 9, 2011 13:20 |
|
Yes, I just realised. I've used square brackets to make anonymous arrays in a [1, 2, 3] kind of style about a million times, but I never realised you could use them like "[(1, 2, 3)]" or "[@keys]" before. I kind of assumed that would return an array with only one array reference as an element.
|
# ? May 9, 2011 13:29 |
|
Any advice for building a port scanner/proxy finder, module wise? Right now i'm using Nmap::Scanner to get a list of open ports. Next i'll probably use LWP::UserAgent to try to connect via proxy to a txt file on the server to see if the open port is a proxy. I'm also supposed to detect the difference between: quote:Anonymity levels - applies for http/https proxies only. Am I going to have to connect through the proxy to a known cgi script which would return all the ENV variables, and then compare them to what they should be? uG fucked around with this message at 03:49 on May 16, 2011 |
# ? May 14, 2011 23:59 |
|
How can I print the current package or program name? Pseudo code: code:
|
# ? May 17, 2011 17:12 |
|
mister_gosh posted:How can I print the current package or program name? That is actually almost it. code:
|
# ? May 17, 2011 17:47 |
|
qntm posted:That is actually almost it. Thanks! That makes googling for it easier (left my Perl in a Nutshell book in the wrong location today.
|
# ? May 17, 2011 17:56 |
|
qntm posted:
code:
|
# ? May 18, 2011 01:41 |
|
Do you guys have any clever ideas for scraping a site and trying to extract relevant data from the HTML? My buddy is trying to scrape some data for fantasy football from this site - http://www.nfl.com/fantasy/story/09000d5d817fb977/article/headline - Slurping up the HTML is trivial with LWP, but parsing out those stats would be very painful and expensive. This has to be a common problem that's been solved a million times before! I found a few modules that look applicable (HTML::Element, HTML::TreeBuilder) but I'm not sure what the easiest approach is.
|
# ? May 24, 2011 20:10 |
|
Web::Scraper is the poo poo. You can extract HTML using CSS selectors or XPath. I used it recently to scrape the translation status of our project from a site that uses fixed-width images as progress bars. code:
Filburt Shellbach fucked around with this message at 20:23 on May 24, 2011 |
# ? May 24, 2011 20:16 |
|
I've been using Web::Scraper recently too for writing a generic content embedding service, similar to what twitter does for certain links in tweets. Here is an example that scrapes the title and introduction to wikipedia articles.
|
# ? May 24, 2011 20:40 |
|
Let's turn this into a "Stupid question megathread" for a second, because I certainly feel stupid for not seeing why this won't work:code:
|
# ? May 25, 2011 00:31 |
|
mobby_6kl posted:
Shouldn't this be 'for' instead of 'while'?
|
# ? May 25, 2011 01:29 |
|
Erasmus Darwin posted:Shouldn't this be 'for' instead of 'while'? code:
|
# ? May 25, 2011 01:47 |
|
Yeah doesn't split return an array, so you should iterate over it with "for" and not "while"? Correct me if I'm wrong (which I may be, since I'm not positive on this), but 'while' runs until its expression returns 0, which split will never do since it's feeding you an array instead.
|
# ? May 25, 2011 03:01 |
|
Yes, that's it . For some reason I was sure split worked with while (even though @a=split... still made sense to me ), so I thought I was screwing up something else. Thanks! uG posted:or... This... doesn't seem to work but that's ok because I'm not biased toward while in any way, and foreach does what I need.
|
# ? May 25, 2011 17:43 |
|
I've created a simple port scanner/proxy tester. It tries to use open ip/port combos it finds as a proxy to connect to a specified URL, which shows me the connections ENV variables (so I can determine how anonymous it really is). I've now been told it needs to test proxies to see if they have keep alive enabled. I'm not quite sure how to handle that... would I need to send a Keep Alive header, and look for one sent back? Or does this involve keeping a socket open to listen and see if any keep alive packets are sent?
|
# ? May 28, 2011 05:04 |
|
uG posted:I've created a simple port scanner/proxy tester. It tries to use open ip/port combos it finds as a proxy to connect to a specified URL, which shows me the connections ENV variables (so I can determine how anonymous it really is). I've now been told it needs to test proxies to see if they have keep alive enabled. I'm not quite sure how to handle that... would I need to send a Keep Alive header, and look for one sent back? Or does this involve keeping a socket open to listen and see if any keep alive packets are sent? If the socket stays open after a HTTP request/response, the proxy has keep alive on.
|
# ? May 28, 2011 12:15 |
|
Roseo posted:If the socket stays open after a HTTP request/response, the proxy has keep alive on. I'm trying to see if I can access the underlying IO::Socket::INET that LWP uses, but I don't think I can... uG fucked around with this message at 17:20 on May 28, 2011 |
# ? May 28, 2011 15:39 |
|
|
# ? May 21, 2024 22:39 |
|
I'm looking over code from an internship to see if I've gotten any better at coding. The project was to pull web logs from multiple servers then store and process them on a separate server. I created and used a XML file as the data structure of all the servers and the sites hosted on each server. I persuaded the server admin to install XML::Simple to simplify handling XML. During the project, a need arose to duplicate the structure and invert it like so:code:
code:
|
# ? May 28, 2011 17:54 |