I would like to kick things off with a Perl question. (this is almost E/N) I'm a beginner when it comes to programming. I work for my company's Build Team, which I've heard best described as "Half IT, half developer". Most of our stuff is written in Perl, so I picked up O'Reilly's Learning Perl and read through it. I've also grabbed Intermediate Perl, and am about halfway through that. For the last year or so, I've been doing a lot of development in Perl. I've dabbled in other languages, but this is really my first. I've written several scripts for use in a command prompt (my company is solely win32), and have recently started creating basic CGI web-apps. Basically, my question is, where do I go from here? I can continue learning Perl (I've only brief glimpses into Object-Oriented Perl), or I can focus on learning to create bigger and better web-apps with Perl, or I can move on to a different language altogether. I don't think I'll ever be a full-time developer, but obviously I enjoy coding in Perl and want to learn more, even if that means going to Python or Ruby. Lots of people are kinda pressuring me into learning Ruby, but I'm hesitant to try to "start over" and learn a whole new language. Part of the reason I'm happy with where I am with Perl is that I'm at a stage where I can produce actual deliverables, while still having plenty of room to learn more. So, Perl gurus, where do I go next?
|
|
# ¿ Oct 24, 2007 22:13 |
|
|
# ¿ Apr 30, 2024 06:37 |
InvSqrt posted:I want to start using my Perl knowledge for web development. 1) Set up Apache (I use IIS myself) to work with CGI (you can google this) 2) Create a perl file with "use CGI ':standard';" at the head. Save as *.cgi 3) Read the documentation on CGI.PM. I started out writing really simple apps. A single .cgi file with a simple HTML form that executed certain code based on how the user filled out the form. After that, I got more complex, adding in a Templating system and working under an MVC style. Personally, I recommend starting out making a flat .cgi file that handles everything. Get comfortable with what CGI can do, and how to write it. Then expand towards using mod_perl or Templates or whatever you like. EDIT: Triple Tech posted:1) mod_perl. To this day I'm still not sure what it does in that I haven't done anything with it myself. 2) Catalyst is a pretty big framework. Personally, I found the overhead to be HUGE. I'd use this if I were developing some HUGE perl web-app, but otherwise, I'd avoid it. I installed it and played around, and after a few hours, I was still really far from actually getting anything done. 3) I personally recommend Template Toolkit (recommended to me by another goon). It works well for my needs. syphon^2 fucked around with this message at 15:00 on Dec 6, 2007 |
|
# ¿ Dec 6, 2007 14:55 |
InvSqrt posted:Thanks guys. 1) Write a more complex index.pl that utilizes a form to gather input and then do something with that input. 2) Maybe play around with a few different types of forms, making more complex pages. 3) Use a templating system to separate out your HTML and Perl code 4) Use a full blown framework. 5) Take over the world. Then again, I'm only somewhere between steps 3 and 4 myself.
|
|
# ¿ Dec 7, 2007 00:25 |
SpeedFrog posted:It's even super easy to AJAXify the application if you bolt in CGI::Ajax or use a toolkit like Prototype or Ext. However, it doesn't look like it really works with Templating systems. It wants to create the html through it's build_html() method, which doesn't work with any templating systems I see. Any ideas how I can combine the two? EDIT: It looks like CGI::Ajax has other methods to use in case you don't want it to render the HTML. However, it still doesn't work. Here's my sample page. It tries to use Template Toolkit in conjunction with CGI::Ajax. Feel free to try it yourself. EDIT2: Hmmm, it apears that the Ajax works simply by invoking the CGI script again with a set of parameters, so that the CGI itself returns ONLY the value determined by the function. Maybe if I add some logic to detect those parameters, and bypass the rest of the page if they're included? EDIT3: I got it working. There's not as much documentation available out there as I'd like... but I found someone who got it working. It turns out I need to use a third parameter in $template->process to output the HTML to a scalar, rather than straight to STDOUT. Then, I use CGI::Ajax's build_html method to output the HTML instead. syphon^2 fucked around with this message at 18:04 on Dec 7, 2007 |
|
# ¿ Dec 7, 2007 14:07 |
dagard posted:This looks like what you want:
|
|
# ¿ Mar 12, 2008 15:06 |
Can anyone give me tips on using File::Find, or maybe point out a more appropriate module to use? (EDIT: I'd rather not use one that doesn't come with most default Perl distributions... ActivePerl 5.8 for Windows, in this case. I saw File::Find::Rule, but dismissed it because of that caveat) Basically, all I need to do is traverse a directory tree (it's actually a UNC path on a remote Win32 server) looking for a specific filename, and then determine the full path to that file. This file is unique (there's only 1 file by that name), but it could be anywhere in the tree. All I need is to find out where that file lives. The problem is, File::Find's 'wanted' function is just a callback, it's return value is ignored. I'm able to find the file I'm looking for, but I don't know how to get that info back to where I need it! Here's my code: code:
Here's the problem. find() ignores whatever is returned by wanted(). I can print the filename out, but I can't pass it back to my FunctionFullOfStuff where I need it. The only solution I can think of is making some global variable and stuff the filename there if it finds it. However, that's a pretty terrible idea as this function is in a shared .pm file... I don't want to just create random globals that most people won't care about. Any ideas? syphon^2 fucked around with this message at 15:47 on Mar 18, 2008 |
|
# ¿ Mar 18, 2008 15:44 |
Triple Tech posted:Couldn't you just declare your accumulator in the same scope as where the find function is called and just have wanted be an anonymous function? Here's my final code: code:
syphon^2 fucked around with this message at 16:48 on Mar 18, 2008 |
|
# ¿ Mar 18, 2008 16:23 |
This is getting a bit outside the scope of Perl... but hope you guys will still help me. TiMBuS posted:mod_rewrite stuff I want to access this URL: http://hostname/appname/app.cgi?param=foo Via this URL: http://hostname/appname/foo Looking at the example you provided, it seemed like it would be pretty straightforward, but I'm obviously screwing something up, as it's not working. This is what i added... code:
syphon^2 fucked around with this message at 18:40 on Apr 14, 2008 |
|
# ¿ Apr 14, 2008 18:08 |
Can anyone give an example of a Perl script (using Win32::OLE) which enumerates all websites installed in IIS (preferably either version 5 or 6) and just dumps the data out in some consumable format? I've found Win32::OLE and Win32::OLE::Enum, which seem like they'd do what I need. I'm not familiar with Win32::OLE or the IIS Metabase, so I don't even know how to parse the object for the data I need. I can find a few examples, but nothing that really does what I need. For example... this (scroll down a bit) manages to grab the default site, but then crashes my Perl interpreter! The code found here seems to work, but I have to provide it with a specific siteid to inspect (and I want to gather all sites, no matter their siteid). Any advice? EDIT: I'm muddling through it, but painfully slow. I guess what I'm asking for is a snippet of code or module or something that does what I need more gracefully. This code crashes Perl in certain scenarios (unknown yet) and I think won't work with IIS6. This is what I have so far code:
syphon^2 fucked around with this message at 17:51 on May 7, 2008 |
|
# ¿ May 7, 2008 17:22 |
Can anyone share a really simple method of timing my code? I want to see how long certain code takes (in milliseconds), but can't find a clear, easy way to do this. I've tinkered around with time(), localtime(), Time::HiRes, and Benchmark. I'm basically looking for something that'll do this... code:
|
|
# ¿ Jun 19, 2008 18:17 |
dagard posted:I've honestly almost always just used Time::HiRes for things like that. From http://search.cpan.org/~jhi/Time-HiRes-1.9715/HiRes.pm quote:tv_interval
|
|
# ¿ Jun 19, 2008 21:46 |
I've got another simple question (boy, this really shows how incompetent I am at reading documentation!) I'm using Win32::TieRegistry to gather information from the registry of a series of remote servers. My script has 6 methods, each which need to connect to the registry and grab some data. After implementing Time::HiRes, I can see that this is causing quite a delay, as each of these methods grabs several keys, and the methods are called multiple times for various servers. Since all the keys I'm interested are stored under HKLM/Software/CompanyName, I'd like to connect once and get a dump of all sub keys just once, and then let Perl iterate through the data structure rather than connect multiple times to get the data it needs. Any ideas? It seems like the whole module is built around connecting to the registry each time for individual keys.
|
|
# ¿ Jun 20, 2008 15:23 |
Does anyone know of a way to take a dump (heh heh) of a portion of the Win32 registry, and store it in a hash to be parsed through later? A script I'm working on gathers data from a bunch of remote servers, some of them across the world. The data I need all resides within a key in HKLM/Software/KEYNAME, and isn't terribly large. I'd like gather all these keys in one go, and use Perl to iterate through them. I'm currently using Win32::TieRegistry to do this. code:
As I mentioned, some of the servers are (physically) very far away, so the latency is very high. Win32::TieRegistry seems to re-connect to the server each time it needs to gather a registry value. In some of the extreme cases, it's taking my script anywhere from 2-10 seconds to gather each registry key, for a total of about 30 seconds per server. This is SLOOOOOW. Do you guys know of anything that will connect to the remote server, take a dump of the Key I specify (and all subkeys), then disconnect, maybe giving me a hash of the whole Key? I tried using Win32::TieRegistry, but it only seems to support tied-hashes (meaning, even though I try to store all the data at once, Win32::TieRegistry remotely queries each key as it's needed). Any ideas?
|
|
# ¿ Jun 30, 2008 19:53 |
I'll try that tomorrow... but like I said, I suspect Win32::TieRegistry only works with tied-hashes. Thus, when it goes through the loop, it makes and breaks the connection for every iteration. That's what happened when I tried it earlier (although I did it slightly differently). EDIT: It's as I suspected. Using either snippet of code from above, creating the hash is reasonably quick (around the order of 600-800ms on my test scenario). Executing 'print Dumper(%copy);', however, took approximately 51938ms. EDIT2: Well, I'm starting to think the bottleneck isn't Win32::TieRegistry, but really just the act of querying a remote registry. On a whim, I changed to calling reg.exe with a backtick (reg.exe is WinXP's native command line registry tool) code:
syphon^2 fucked around with this message at 23:27 on Jun 30, 2008 |
|
# ¿ Jun 30, 2008 22:06 |
Erasmus Darwin posted:Rather than relying on the registry query code to handle communicating with each remote server, what about installing a local script on each one that bundles up all the relevant registry keys and spits it out as a single blob of data to your main script?
|
|
# ¿ Jul 1, 2008 13:57 |
Is this the best way to sort hashrefs alphabetically (well, ASCI-betically)? Something seems inefficient about it, but it's how I've been doing it so far.code:
|
|
# ¿ Aug 29, 2008 17:12 |
I don't know, it seemed that creating a new array and sorting it JUST for the sake of iterating through another hash in a certain manner (alphabetized) wasn't the best way to do things. I had no valid reasons to think so, I just wanted to make sure.
|
|
# ¿ Aug 29, 2008 21:21 |
Has anyone used CGI-Ajax? I need a way to implement a callback from an Ajax function, but it doesn't look like it supports it. I have an app that queries a remote server for a bunch of service statuses (running|stopped|starting). Using CGI-Ajax, I've implemented a 'refresh' button, which refreshes the service status in an Ajaxy manner (doesn't reload the whole page). This currently works fine. What I want to do, is make my 'refresh' button change into a 'loading' button while the refresh process is running (usually takes anywhere from 1-6 seconds). Then, when the Ajax request has completed, it'd change back into a 'refresh' button. I'm getting feedback from my users that they want/need more visual feedback that the process is running (if no service-statuses have changed, there's no visual feedback that anything at all is happening). I'm going to commit a cardinal sin, and paste my javascript code here, as it is the relevant code. The ajax_refresh_services() function is a Perl function... the first param is the server name and second is the name of the div to paste the output into. code:
What I think needs to happen, is for me to be able to specify a callback in my ajax_refresh_services() function. That way, when the services are refreshed, it'd change my button back to the original loading button. I googled around but it doesn't look like CGI-Ajax supports this. Any ideas?
|
|
# ¿ Sep 30, 2008 13:21 |
Hmm, I guess I was just hoping for someone to come in and say 'oh you could just use the so-and-so method for a call-back'. I have a couple solutions in mind, but I don't like them (involves putting too much HTML into my .pm file). EDIT: Ok, I'll hijack my own post for a completely different question involving HTML::Template and best practice. How would you guys do this? I have a web-app that displays a bunch of junk, and one thing it displays is an overall "Pass|Fail". Stylistically speaking, I want to color this text, green if it's a 'pass', red if it's a 'fail'. HTML::Template doesn't have a lot of function, since it tries to separate code and design (I know template toolkit can do this by matching the variable in the template, but I really like HTML-Template's idea of keeping code out of your HTML). The only way I could think of was computing what color the font should be inside my method, and then passing the template two variables. code:
code:
syphon^2 fucked around with this message at 22:31 on Sep 30, 2008 |
|
# ¿ Sep 30, 2008 22:15 |
TiMBuS posted:CGI::Ajax allows you to specify a javascript callback instead of a div to insert the returned xml(html) into. The how-to is on the perldoc page: TiMBuS posted:e: why not make a css class for 'Fail' and 'Pass' and use <span class='<TMPL_VAR COLOR>'> <TMPL_VAR COLOR> </span> Thanks so much for your help guys!
|
|
# ¿ Oct 1, 2008 12:14 |
Does anyone have any advice for making Perl talk to Active Directory? My company is a Windows shop, and we use AD in both our corp workstations and test lab. The growing trend among my team is to interrogate DL's (which as I understand it, are the same thing as AD groups) to determine system authorization. I've tried a couple how-tos, one on Net::LDAP and another that uses Win32::OLE, but I couldn't get either example working with my existing network. I think there's just too much about AD/LDAP I don't know about, so I don't even know where I'm going wrong. Any advice would be greatly appreciated.
|
|
# ¿ Oct 12, 2008 22:21 |
Ninja Rope posted:I've used Net::LDAP many times to interact with Active Directory and it has worked quite well. Where exactly are things failing? (please forgive the fairly messy variable delcaration, I tried to sanitize my code before posting it here) code:
code:
EDIT: I figured it out. I had a coworker sit with me (who'd done something similar in Ruby), and we were able to figure it out. I had my Search Base all wrong. syphon^2 fucked around with this message at 13:44 on Oct 13, 2008 |
|
# ¿ Oct 13, 2008 12:04 |
Use Data:umper to view the data structure. At the very least, you can paste it here and people can tell you how to de-reference it properly.
|
|
# ¿ Oct 13, 2008 23:54 |
Has anyone used Win32::OLE to access remote registry keys, instead of Win32::TieRegistry? I'm trying to compare the performance of the two, and the only example I could find of using Win32::OLE to grab remote registry data is... cumbersome, to say the least. Here's the example: http://aspn.activestate.com/ASPN/Mail/Message/activeperl/2965351 Here's the code (adapted to my own needs): code:
|
|
# ¿ Oct 21, 2008 18:05 |
The environment I'm running in is very geographically diverse (it's not uncommon for a server from Seattle to query one in Dublin or Sydney), so latency is quite high. Also, Win32::TieRegistry operates via a tied-hash... it doesn't ever seem to store data in local memory. I have a web-page which queries registry information real-time, so it gathers about 8 reg-keys from a series of remote servers. This runs SLOW, so I'm looking to speed it up. Setting up some timestamps, I can see that Win32::TieRegistry seems to operate (roughly) in this manner... 1) Connect to remote server 2) Gather reg-key value 3) Disconnect from remote server Now repeat that process serially for 8 reg-keys across 30 servers, and you see why I'm looking for performance gains. I can save myself a lot of time if I can find a way to take a dump (heh heh) of a certain Registry Key and all its sub-keys, and then just let Perl navigate it internally as a hashref or something. I couldn't find any way to do this with Win32::TieRegistry, so I was trying other means.
|
|
# ¿ Oct 21, 2008 20:41 |
tef posted:If speed is important why don't you do it in parallel ? yaoi prophet posted:Back when I had to solve this problem, I did it by installing an "agent" script , either on the local machines, or on a machine close to them on the network, which would gather up the data and store it locally so that I could poll it in one big chunk. Sped things up tremendously, but I have no idea how applicable that solution is to you.
|
|
# ¿ Oct 22, 2008 10:38 |
Mithaldu posted:You may wanna try using http://search.cpan.org/~mlehmann/Coro-4.8/Coro/Socket.pm and http://search.cpan.org/~mlehmann/Coro-4.8/Coro.pm to get parallelization. Coro allows such kinda stuff without having to gently caress around with multiple processes or Perl's horrible threads. Take the following code... for example (ripped straight from http://search.cpan.org/~mlehmann/Coro-4.8/Coro.pm with a timer added in) code:
code:
What am I doing wrong?
|
|
# ¿ Oct 22, 2008 15:46 |
|
|
# ¿ Apr 30, 2024 06:37 |
Erasmus Darwin posted:I think you're probably better off using Win32::Process like you were thinking of before. EDIT: I just thought of something else... Win32::Process::Create is like fork, in that I can't share variables, right?
|
|
# ¿ Oct 22, 2008 17:52 |