|
Perl rocks so much. I just used Bot::BasicBot and XML::Simple to get a bot announcing commits in a project's IRC channel. Here's a complete and working (but less generalized) version of it. code:
|
# ? Mar 14, 2008 21:39 |
|
|
# ? May 21, 2024 14:45 |
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 |
|
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?code:
|
# ? Mar 18, 2008 15:51 |
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 |
|
Edit: tab + enter ==
Redbeard fucked around with this message at 13:35 on Mar 19, 2008 |
# ? Mar 19, 2008 13:27 |
|
I've been doing some dangerous mucking around (too much reading source code to Damian Conway modules...). I actually got a module working which enables this syntax:code:
code:
The fact that perl lets me pull this off is sort of simultaneously entertaining and frightening.
|
# ? Mar 20, 2008 03:43 |
|
yaoi prophet posted:I've been doing some dangerous mucking around (too much reading source code to Damian Conway modules...). I actually got a module working which enables this syntax: Perl is really cool. I'm a big fan of AUTOLOAD http://64.233.167.104/search?q=cach...lient=firefox-a
|
# ? Mar 20, 2008 17:12 |
|
yaoi prophet posted:It's only run-time checking, of course, but it's an interesting (ab)use of subroutine attributes. Isn't it sad that there are so many modules like this on CPAN? There are tons and tons of attempts to add things to the language to make it seem modern and sane. I think it was a big mistake to set perl adrift to work on parrot and perl6. There's some cool stuff out there, like Moose, but the fact that it needs to exist is a red flag. And the problem with all of this run-time compensation is that it really does take its toll on performance with heavy use (and I'm of the opinion that you either use it everywhere or not at all). Plus it adds to module dependency hell. For example, to install Catalyst you basically become a CPAN mirror... it's horrible.
|
# ? Mar 20, 2008 18:38 |
|
I'm trying to use PERL to get rid of duplicate files in a big, big ole directory with similar but different file names. I plan to use the file sizes to differentiate between the different files. For example, awful 5343.jpg awful 6064.jpg something 252.jpg something 1524.jpg something 1814.jpg something 2904.jpg something 4252.jpg something 5524.jpg something 6814.jpg something 7904.jpg Where there are only three actually different "something" pictures, and the "awful" pictures are the same. I plan to replace the numbers after the files - those are totally arbitrary - with the file size, so that I get, awful k10408k.jpg something k13394.jpg something k15304.jpg something k18708.jpg The loop that I intend to use. code:
Narpas fucked around with this message at 23:22 on Mar 22, 2008 |
# ? Mar 22, 2008 23:06 |
|
Narpas posted:I'm trying to use PERL Please call it Perl or perl. PERL reeks with everything wrong about the language. Narpas posted:The problem is that the line $size = -s "$file"; returns "" for $size. Is there a different way to get the file size, or should I just pass a function to bash? -s $file returning the empty string means it couldn't find the file. Are you sure you're in the right directory and that $file is there? If you're building up @files through readdir, they won't have the directory name prepended - you have to manually do that.
|
# ? Mar 22, 2008 23:34 |
|
Sartak posted:Please call it Perl or perl. PERL reeks with everything wrong about the language. code:
Kidane fucked around with this message at 00:18 on Mar 23, 2008 |
# ? Mar 23, 2008 00:15 |
|
Well, I knew, academically, about making a hash table, but I didn't realize they were implemented simply - I've always figured that they were needlessly complex for small scale tasks. Also, Sartak - I loved your LP Nethack, assuming that's, in fact, you.
Narpas fucked around with this message at 04:43 on Mar 23, 2008 |
# ? Mar 23, 2008 04:39 |
|
Narpas posted:Well, I knew, academically, about making a hash table, but I didn't realize they were implemented simply - I've always figured that they were needlessly complex for small scale tasks. Hash tables are very very useful for tasks small and large. Perl can probably be blamed for most modern languages having hash tables built into the language (or at least in a standard library). Narpas posted:Also, Sartak - I loved your LP Nethack, assuming that's, in fact, you. Yeah, that's me
|
# ? Mar 23, 2008 05:16 |
|
I am writing a quick perl script to find all instances of "size" in a file and then delete that line. The problem is my regular expression also catches other lines where it has "size" but inside another word. For example, I want it to get rid of the line "Size: 4234" but not "Install-Size: 34234". Here is the code I have been working on: code:
|
# ? Mar 25, 2008 19:32 |
|
scrabbleship posted:I am writing a quick perl script to find all instances of "size" in a file and then delete that line. The problem is my regular expression also catches other lines where it has "size" but inside another word. For example, I want it to get rid of the line "Size: 4234" but not "Install-Size: 34234". Well this will help a little: if(/(^|\s)size/i) Just see if there is a space in front of size or if it is at the beginning of the line.
|
# ? Mar 25, 2008 19:45 |
|
Narpas posted:Well, I knew, academically, about making a hash table, but I didn't realize they were implemented simply - I've always figured that they were needlessly complex for small scale tasks. perl, along with most modern scripting languages, implements hash tables as a core data type. Also, I would recommend that you take an md5 checksum of the file instead of checking its size to see if they're the same - it's possible that two files have the same filesize but different contents.
|
# ? Mar 25, 2008 19:55 |
|
Subotai posted:Well this will help a little: Maybe you should try word boundaries. code:
|
# ? Mar 25, 2008 20:31 |
|
Triple Tech posted:Maybe you should try word boundaries. But that matches "Install-Size: 34234" which he doesn't want to be matched. I'd say a combination: code:
|
# ? Mar 25, 2008 20:36 |
|
Sartak posted:But that matches "Install-Size: 34234" which he doesn't want to be matched. I'd say a combination: Thanks, that one seemed to do the trick.
|
# ? Mar 27, 2008 01:07 |
|
genericadmin posted:... Plus it adds to module dependency hell. For example, to install Catalyst you basically become a CPAN mirror... it's horrible. So install ACME::Everything. Problem solved :-) Perl may have some weirdness, but are there any other languages in which this even possible?
|
# ? Mar 29, 2008 20:30 |
|
I'm trying to set up a web site to take credit cards through authorizenet using the AIM system. I'm slightly familiar with perl so I'm trying to implement their sample code. http://developer.authorize.net/samplecode/ They've hard coded all of the values like cc number, name, address into the script and I am able to set the script up on my web site and it works fine so I know all my passwords and permission settings are ok. The problem I have, and it is probably because I have to training at all in comp sci, is editing the script to accept the values from a form and pass those values to the gateway. For example, one value in my form: <input id="FormsEditField1" type="text" name="Amount" style="white-space:pre" value="50.00" size="10" maxlength="10"> I have the form set up to post this value to the perl script. The original perl script says: x_amount => "12.23", So I changed that to x_amount => "Amount", x_amount being the value that the gateway recognizes as the total charge and Amount being the data from my form. But I get an error that says no valid amount supplied. Am I supposed to write some actual code to get it to process the form data or can I just change this or another section somehow? tef posted:You realise that "Amount" is a string and "$Amount" is the string containing the variable $Amount ? Does that mean I need to define the "$Amount" variable somewhere in the perl script beyond x_amount => "$Amount", ?
|
# ? Apr 2, 2008 18:14 |
|
poofactory posted:x_amount => "12.23", The "12.23" is a string literal. So is "Amount". Your $Amount is a scalar variable, which is a thing that holds whatever value is assigned to it. Whenver you say $Amount, perl treats it as "the value stored in $Amount". When a scalar variable appears in a double-quoted string (like the last line above) it will be evaluated, meaning its value is replaced into the string at the position it occurs. You don't need the quotes in your above code ("$Amount" and $Amount are the same here). Also, I'm not sure what's going on in the rest of your script, but something has to assign a value to $Amount before it will be useful to you. In your case, you want to assign it the data from the HTTP request form input. How you do that depends on what perl modules you are using to work with request data.
|
# ? Apr 2, 2008 18:59 |
|
genericadmin posted:In your case, you want to assign it the data from the HTTP request form input. How you do that depends on what perl modules you are using to work with request data. Thank you. I understand that is my problem. I haven't added anything to the sample code other than my passwords/account numbers. What do I add to the perl script to take care of this? Do I simply add "use xyz module" or do I need to code something more complicated to parse the data pairs? Thanks.
|
# ? Apr 2, 2008 19:14 |
|
poofactory posted:What do I add to the perl script to take care of this? A developer. You are handling credit card details, so if you don't know about CGI, form escaping or the difference between "$Amount" and "Amount" it is time to give up and find someone who can. (Sorry for the turn about, I was willing to give you the benefit of the doubt in missing something obvious - but your later posts expose your inexperience fully)
|
# ? Apr 2, 2008 23:14 |
|
tef posted:A developer. Aye. When in doubt, look up "due diligence" and the legal ramifications of the lack thereof as it concerns credit card information. You don't want to be holding this bag.
|
# ? Apr 2, 2008 23:23 |
|
tef posted:A developer. Well, I thought that if the sample code had everything set up and I just needed to configure a couple variables then I could do it. But if it is a lot more than that, I'll find a developer.
|
# ? Apr 3, 2008 00:53 |
|
Someone posted a module that, when ncluded, would change all string literals to pirate speak or something like that, does someone remember the link?
|
# ? Apr 3, 2008 18:34 |
|
heeen posted:Someone posted a module that, when ncluded, would change all string literals to pirate speak or something like that, does someone remember the link? I wrote that and mentioned it in one of the earlier perl threads, but I don't think I ever posted it. Let me see if I can dig it up. Edit: Found it. In Pirate.pm: code:
code:
npe fucked around with this message at 19:01 on Apr 3, 2008 |
# ? Apr 3, 2008 18:55 |
|
yaoi prophet posted:I wrote that and mentioned it in one of the earlier perl threads, but I don't think I ever posted it. Let me see if I can dig it up. you could fix that if you were so inclined. instead of doing a substitution in the overload method, you could instead return a tie::scalar'd variable (of, say, a new Tie::Pirate). the FETCH method of Tie:Pirate could then be overloaded to something like this: code:
you can actually do some extremely goofy poo poo this way, as you can effectively modify any runtime behavior of perl you could possibly dream of. i wrote an example of some of this using an early version of PadWalker (which is even more powerful now, it looks like!) a long time ago: http://www.perlmonks.org/?node_id=316345
|
# ? Apr 3, 2008 21:47 |
|
Of course, although tied hashes are actually a sane way to accomplish this sort of thing, whereas I was trying to come up with a hilariously inappropriate prank abusing one of the most wtf aspects of perl (being able to overload string literals). I'm thinking of replacing the pirate stuff (which seemed novel at the time but is pretty cliche by now) with something more insidious, like replacing ascii numerals with similar-but-different unicode versions. Edit: Sub::Sealed is pretty funny. Somewhere I have a module I wrote that will set UNIVERSAL::AUTOLOAD to a routine that will search for any semi-close matches for undefined subroutines that get called, including pawing through local directories for .pm files. Prank perl is the best. npe fucked around with this message at 02:53 on Apr 4, 2008 |
# ? Apr 4, 2008 02:50 |
|
I'm having an incredibly strange issue. I'm grabbing info from an sql database to fill a spreadsheet with info that dates back 45 days, and I am keeping track of the number of days that are actually being filled in for purposes of getting accurate averages. This variable is incremented sequentially when it prints a value onto the spreadsheet. This is being done in one giant for loop. In the next one, I use the variable to calculate the averages, but I am running into divide by zero errors. Between the for loops, I have the variable printing out, and in the averaging loop, I have it printing if the variable is 0. This is the output from the program: Daycount dbz: 0 Daycount dbz: 0 Daycount dbz: 0 Daycount dbz: 0 Daycount dbz: 0 12345 Technically speaking, the 12345 should be on the top, because that's the output from the print between the for loops, and the Daycount dbz's should be on the bottom, because they're literally the last line of code. Is this a scope issue? The variable is declared at the top of the subroutine.
|
# ? Apr 4, 2008 03:21 |
|
We could guess better if you posted some code.
|
# ? Apr 4, 2008 07:12 |
|
yaoi prophet posted:Of course, although tied hashes are actually a sane way to accomplish this sort of thing, whereas I was trying to come up with a hilariously inappropriate prank abusing one of the most wtf aspects of perl (being able to overload string literals). nono, you misunderstand. you overload AND tie. so your overload constructor looks like this: code:
quote:Edit: Sub::Sealed is pretty funny. Somewhere I have a module I wrote that will set UNIVERSAL::AUTOLOAD to a routine that will search for any semi-close matches for undefined subroutines that get called, including pawing through local directories for .pm files. Prank perl is the best. http://search.cpan.org/~davecross/Symbol-Approx-Sub-2.06/
|
# ? Apr 4, 2008 09:29 |
|
Oh, awesome. Great, now I'm going to waste more time on Evil.pm today... LightI3ulb, you have to post source, you'll probably get an answer within minutes if you do.
|
# ? Apr 4, 2008 15:27 |
|
German Joey posted:http://search.cpan.org/~davecross/Symbol-Approx-Sub-2.06/ Oh god. Every time I see a module like this I laugh until I realize there are probably people using it in production.
|
# ? Apr 4, 2008 17:15 |
|
German Joey posted:http://search.cpan.org/~davecross/Symbol-Approx-Sub-2.06/ That modules like a disfigured orphan. Horrifying and depressing at the same time.
|
# ? Apr 4, 2008 18:09 |
|
Need halp picking a MVC framework. Wat I'm doing: I'm writing a modpanel for kusuba, the lovely software 7chan.org uses. It already has an existing modpanel of course but it's all in php and I hate php, so to hell with modifying the existing one, I'll just write a new one (it's probably a better idea anyway). So I need to make a dynamic, pretty interface to a database with login/session crap. Your standard fare I guess. I want to keep it lightweight, because it's just a modpanel. This means catalyst is out the window because I installed it about half an hour ago and that poo poo is HUGE. I looked at CGI::Framework on CPAN and it looks real small and I'd like to use it, but it feels kind of limited. I think I have to keep every page callback in a single file, and I have no idea if it works with fastCGI (which I should add, is what I'm going to be using). So what should I use? Think I should just bang out my own custom framework? Also, Sorta Off-Topic: Has anyone had a look at the Continuity module on CPAN? It's freakin awesome! It's the sort of idea that, if implemented properly on a large scale could really change how we approach dynamic database-driven webpages. Or maybe I'm drunk. Or both!
|
# ? Apr 5, 2008 11:39 |
|
TiMBuS posted:Need halp picking a MVC framework. I thought Catalyst was small, and that the functionality is in its plugins.. quote:Think I should just bang out my own custom framework? God no! quote:Also, Sorta Off-Topic: Has anyone had a look at the Continuity module on CPAN? I've been playing with it the last few days. It's really interesting. I'm a Jifty developer but if you want something small I'd recommend Catalyst. Jifty comes with everything you need, so the install is much larger than Catalyst's.
|
# ? Apr 5, 2008 13:32 |
|
Sartak posted:I thought Catalyst was small, and that the functionality is in its plugins.. Sartak posted:God no! Caveats include needing to edit the controller for session management, it uses mod_rewrite to hide page selection, and due to using the index for page selection its not uncommon to mix 'post' and 'get' requests. Yeah okay maybe I'll use Catalyst then.
|
# ? Apr 5, 2008 23:59 |
|
|
# ? May 21, 2024 14:45 |
|
Catalyst started off great, but it has become a gigantic bloated pig. The whole project went into the woods after a while. I've looked at all the perl frameworks at length, and I can't say I like any of them anymore. What I'd really like to see is something that very efficiently processes the HTTP request of an environment (CGI, mod_perl, etc) into some object, and a fast url->action mapper. That's the only parts of a framework I find I actually want. The rest is all crap from CPAN (and I do mean crap). quote:Continuity... Continuity is a neat idea, but it's not extremely useful since its going to have much steeper memory requirements than the traditional approach. That's a bad thing in a perl environment.
|
# ? Apr 6, 2008 18:32 |