From faber at linuxnj.com Wed Dec 1 18:21:28 2004 From: faber at linuxnj.com (Faber Fedor) Date: Wed Dec 1 18:21:36 2004 Subject: [ABE.pm] Re: Accessing data in an array? In-Reply-To: <20041130114542.I8950@manxome.org> References: <20041129231714.GA6678@uranus.faber.nom> <20041129182449.G8950@manxome.org> <20041130162417.GB5757@uranus.faber.nom> <20041130114542.I8950@manxome.org> Message-ID: <20041202002128.GA15472@uranus.faber.nom> On 30/11/04 11:45 -0500, Ricardo SIGNES wrote: > * Faber Fedor [2004-11-30T11:24:17] > Don't use prototypes. They don't do what most people think, and they > end up causing a lot of trouble. Take it from Tom C, one of the Camel > authors: > > http://library.n0i.net/programming/perl/articles/fm_prototypes/ IIUC, I should just do a "sub foobar {" instead of a "sub foobar($$) {"? If so, that would allow me the variable arguments I Was looking for earlier tonight. > Also, don't mix tabs and spaces! Was that really your doing? My vi(m) is supposed to replace all tabes with spaces. > So, @incides here is a global, or at least declared in a larger > containing scope? It looks like what you want to do, there, is return > attributes for the hashref with the given value in a specific key. > > My first note would be that you'd be better served by a HOH -- a hash of > hashes or, more properly, a hash in which the values are references to > hashes. That's what I was thinking, but that means going back and changing alot of code. > Failing that: > > my @matches = grep { $_->{key} eq $key } @indices; > return unless @matches; # nothing matched > die "more than one match!!" if @matches > 1; # too many matches! > return ($matches[0]{volume}, $matches[0]{weight}); # the only match > > Note that I have to handle "more than one match" here, because a LOH > can't enforce uniqueness on the index key. A HOH could. I still think > this code is ugly, but it should demonstrate the point. It's just a more Perlish way of doing what I thought to do. > Also note that I'm calling it "key" instead of "index." Index is > usually positional, like in an array, but you're looking for an > unordered match, like a hash key. (Another red flag that you should be > using a HOH!) Sorry. The word "index" refers to the the finacial index that we are using; the S&P 500 index, the NYSE index, etc.. > > sub foobar($) { > > Where "foobar" should be "print_entry" or something? Don't confuse me > more than regular life already does! Actually, "foobar" is generating an SQL statement; how is that any different than a print_entry function for the purpose of the discussion? > > my ($index) = @_; > > my (weight, cap) = returnIndicesValues($index); > > print "index = $index \t weight = $weight \t cap = $cap\n"; > > } > > I just figure there's a nicer, more Perl-ish solution. > > sub display_entry { > my ($key) = @_; > return unless my @values = lookup_values_for($key); > print "key: $key\nvolume: $values[0]\nweight: $values[1]\n"; > } Well, that certainly is more Perl-ish. > Personally, I'd just return the hashref from lookup_values_for, so it > returned { key => x, volume => y, weight => z } (well, really I'd use a > HOH, but...): > > sub display_entry { > my ($key) = @_; > return unless my $entry = lookup_entry_for($key); > printf "%10s: %u\n", $_, $entry->{$_} for qw(key volume weight); > } Returning a hash to a scalar makes the scalar a hashref? Intriguing. -- Regards, Faber Linux New Jersey: Open Source Solutions for New Jersey http://www.linuxnj.com From rjbs-perl-abe at lists.manxome.org Wed Dec 1 18:33:02 2004 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Wed Dec 1 18:33:04 2004 Subject: [ABE.pm] Re: Accessing data in an array? In-Reply-To: <20041202002128.GA15472@uranus.faber.nom> References: <20041129231714.GA6678@uranus.faber.nom> <20041129182449.G8950@manxome.org> <20041130162417.GB5757@uranus.faber.nom> <20041130114542.I8950@manxome.org> <20041202002128.GA15472@uranus.faber.nom> Message-ID: <20041201193301.O8950@manxome.org> * Faber Fedor [2004-12-01T19:21:28] > On 30/11/04 11:45 -0500, Ricardo SIGNES wrote: > > * Faber Fedor [2004-11-30T11:24:17] > > Don't use prototypes. They don't do what most people think, and they > > end up causing a lot of trouble. Take it from Tom C, one of the Camel > > authors: > > > > http://library.n0i.net/programming/perl/articles/fm_prototypes/ > > IIUC, I should just do a "sub foobar {" instead of a "sub foobar($$) > {"? If so, that would allow me the variable arguments I Was looking for > earlier tonight. Right. > > Also, don't mix tabs and spaces! Was that really your doing? > > My vi(m) is supposed to replace all tabes with spaces. That's just sick. Still, better than mixing. :) > > So, @incides here is a global, or at least declared in a larger > > containing scope? It looks like what you want to do, there, is return > > attributes for the hashref with the given value in a specific key. > > > > My first note would be that you'd be better served by a HOH -- a hash of > > hashes or, more properly, a hash in which the values are references to > > hashes. > > That's what I was thinking, but that means going back and changing alot > of code. Could be. You could always do the things below, or create an adapter to let you access the icky stuff via a nicer interface. You might consider this too much work. (You'd use something like a hash tied to the array with an interface class.) > > Also note that I'm calling it "key" instead of "index." Index is > > usually positional, like in an array, but you're looking for an > > unordered match, like a hash key. (Another red flag that you should be > > using a HOH!) > > Sorry. The word "index" refers to the the finacial index that we are > using; the S&P 500 index, the NYSE index, etc.. Ha! Ok. > > > sub foobar($) { > > > > Where "foobar" should be "print_entry" or something? Don't confuse me > > more than regular life already does! > > Actually, "foobar" is generating an SQL statement; how is that any > different than a print_entry function for the purpose of the discussion? Giving it a name that describes what it does helps me quickly understand things. That's all. > > Personally, I'd just return the hashref from lookup_values_for, so it > > returned { key => x, volume => y, weight => z } (well, really I'd use a > > HOH, but...): > > > > sub display_entry { > > my ($key) = @_; > > return unless my $entry = lookup_entry_for($key); > > printf "%10s: %u\n", $_, $entry->{$_} for qw(key volume weight); > > } > > Returning a hash to a scalar makes the scalar a hashref? Intriguing. No, I said "return the hashref." You can't return a hash, only a scalar or a list. If you return a hash, it will be returned as an array. If you assign an array to a scalar, you get the length. That's not what you want! Given a hash %dictionary, it's very easy to C< return \%dictionary > Or, be very Perlish: return wantarray ? %dictionary : \%dictionary; In scalar context, return a ref. Otherwise, the hash. (Well, it's not very Perlish because it's not very useful, but...) -- rjbs -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/archives/abe-pm/attachments/20041201/4ca3db03/attachment.bin From rhkramer at gmail.com Thu Dec 2 10:48:56 2004 From: rhkramer at gmail.com (Randy Kramer) Date: Thu Dec 2 10:48:58 2004 Subject: [ABE.pm] Programming Project, maybe in Ruby Message-ID: Sorry about posting to multiple lists, just wanted to catch a reasonably wide local audience. Is anyone interested in forming a group of some sort to work on a programming project? I have a specific project in mind, but don't want to talk much about it pending assessment of interest and whether we might to consider some form of licensing to make money on the initial sales of the software. (Barring that, I'd probably favor using the GPL, and maybe collecting copyrights in one "legal entity" for possible multi licensing. The project might be described as modeled after askSam, but with the things I've seen since I started my sojourn into Linux, I have quite a few modifications in mind. Since I want to learn Ruby, I have some idea of doing some of the programming in Ruby. On the other hand, iiuc, Ruby can use modules from other languages (C, C++, Python, Perl ???) and I have no basic objection to using existing modules rather than creating our own. (In fact, for an initial version, I prefer that -- for the longer term, I dislike software bloat and would eventually like to write our own modules (or trim existing modules) to minimize the bloat.) (Likewise, eventually we may switch to a compiled vs. interpreted language (if we find a need) -- I just think something interpreted may allow us to more easily (and quickly) create a prototype. The last time I used source control it was Microsoft's source safe. I need to learn CVS or something better (and other modern programming tools) to make the project as "professional" as possible. (The point of this paragraph is that I need help learning how to use and setup such tools.) I've spent some time looking at Python recently and it looks decent. I've requested a Ruby book (the Dave Thomas one, 2nd edition) from a library (BAPL). I looked at Perl a few years ago. I don't think I ever want to try to program in Perl again. Python looks usable, but I've been told Ruby may be better, so I want to look at that. (And, if Ruby can handle modules from other languages, we don't necessarily need to all sing off the same song sheet, at least with respect to programming language.) I'd see starting this project with a specification and a high level design. (I've started a very rough specification that I don't want to share with anyone yet.) I'm going through a copy of Code Complete (on about chapter 3), and I'd like to follow that or something similar to guide the development. What would be helpful is to have both some knowledgable people who can share their knowledge and people who are interested in learning to program. I don't have a place to meet or much else at this point in time. I don't necessarily need to start a new group -- if the abe-pm or lvlug (or both) want to somehow take this on as a project, we can just be a subgroup of those organizations. regards, Randy Kramer From rjbs-perl-abe at lists.manxome.org Thu Dec 2 11:45:13 2004 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Thu Dec 2 11:45:16 2004 Subject: [ABE.pm] Programming Project, maybe in Ruby In-Reply-To: References: Message-ID: <20041202124513.S8950@manxome.org> * Randy Kramer [2004-12-02T11:48:56] > I have a specific project in mind, but don't want to talk much about > it pending assessment of interest and whether we might to consider > some form of licensing to make money on the initial sales of the > software. (Barring that, I'd probably favor using the GPL, and maybe > collecting copyrights in one "legal entity" for possible multi > licensing. I won't work on non-Free software unless I'm paid, fwiw. > The project might be described as modeled after askSam, but with the > things I've seen since I started my sojourn into Linux, I have quite a > few modifications in mind. Can you give a bit of an explanation? I've never used "askSam." > The last time I used source control it was Microsoft's source safe. I > need to learn CVS or something better (and other modern programming > tools) to make the project as "professional" as possible. (The point > of this paragraph is that I need help learning how to use and setup > such tools.) Subversion is a simple, popular solution these days. Free, including its book -- both beerwise and speechwise. -- rjbs -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/archives/abe-pm/attachments/20041202/99637d84/attachment.bin From rhkramer at gmail.com Thu Dec 2 13:28:34 2004 From: rhkramer at gmail.com (Randy Kramer) Date: Thu Dec 2 13:28:37 2004 Subject: [ABE.pm] Programming Project, maybe in Ruby In-Reply-To: <20041202124513.S8950@manxome.org> References: <20041202124513.S8950@manxome.org> Message-ID: On Thu, 2 Dec 2004 12:45:13 -0500, Ricardo SIGNES wrote: > I won't work on non-Free software unless I'm paid, fwiw. Understandable! This would be a project built on spec(ulation), so any form of compensation would have to be based the same way (if we head in the direction of non-open source -- although I keep hearing that GPL software can be commercial and/or proprietary (I get confused trying to follow those conversations)). > > The project might be described as modeled after askSam, but with the > > things I've seen since I started my sojourn into Linux, I have quite a > > few modifications in mind. > > Can you give a bit of an explanation? I've never used "askSam." Quoting from one of my WikiLearn pages about askSam: "askSam is a free format database with excellent search capabilities (and some scripting capabilities, and other stuff I won't mention (like structured data)" See also some or all of these WikiLearn (or TWiki) pages. Some are very incomplete, some are seemingly off topic, but either reflect a tidbit or two about askSam, or in describing good things about, for example, TWiki, describe things that do or should exist in askSam or any Linux workalike: * http://www.asksam.com * http://www.asksam.com/cgi-bin/as_web5.exe?Command=First&File=tutorial.ask * http://twiki.org/cgi-bin/view/Codev/AskSam * http://twiki.org/cgi-bin/view/Wikilearn/AskSamForLinux * http://www.twiki.org/cgi-bin/view/Wikilearn/AskSam * http://twiki.org/cgi-bin/view/Wikilearn/WhatIsATWiki * http://twiki.org/cgi-bin/view/Wikilearn/WhatIsATWikiGoodFor * http://twiki.org/cgi-bin/view/Wikilearn/Rhk200311November * http://twiki.org/cgi-bin/view/Wikilearn/AskSamForLinuxDev * http://twiki.org/cgi-bin/view/Codev/RfcModifiedTWikiHeadingMarkup > > The last time I used source control it was Microsoft's source safe. I > > need to learn CVS or something better (and other modern programming > > tools) to make the project as "professional" as possible. (The point > > of this paragraph is that I need help learning how to use and setup > > such tools.) > > Subversion is a simple, popular solution these days. Free, including > its book -- both beerwise and speechwise. Have you used (or are you familiar with) some of the other similar tools available today -- arch, and the one Linus is using, and others?? Any specific reasons why you'd choose subversion over the others (well, I do know (I think) that neither arch nor the thing Linux uses are free)? regards, Randy Kramer From rhkramer at gmail.com Thu Dec 2 16:42:23 2004 From: rhkramer at gmail.com (Randy Kramer) Date: Thu Dec 2 16:42:28 2004 Subject: [Lvlug] Re: [ABE.pm] Programming Project, maybe in Ruby In-Reply-To: <20041202151138.V8950@manxome.org> References: <20041202124513.S8950@manxome.org> <20041202151138.V8950@manxome.org> Message-ID: On Thu, 2 Dec 2004 15:11:38 -0500, Ricardo SIGNES wrote: > arch is a GNU project, so it's Free: > http://www.gnu.org/software/gnu-arch/ Ok, thanks for the correction! > Linux uses BitKeeper, or did last I checked. BitKeeper is not Free (as > in free software) but at some point (possibly still) had gratis > licensing for smaller projects. > > Subversion does everything CVS does, but most of it is a little better. > Some of it is quite a bit better. Local repostitories, webdav > integration, the ability to reorganize files (you can't move files in a > CVS rep without losing history) and atomic revision numbering. So (reading between the lines), you'd recommend Subversion over BitKeeper? regards, Randy Kramer > I don't know much about arch. From rhkramer at gmail.com Tue Dec 7 10:25:42 2004 From: rhkramer at gmail.com (Randy Kramer) Date: Tue Dec 7 11:49:12 2004 Subject: [ABE.pm] Fwd: [Lvlug] Programming Project, maybe in Ruby In-Reply-To: References: <804dcf9d04120208523c951ad8@mail.gmail.com> <804dcf9d041202110014d87775@mail.gmail.com> Message-ID: Oops, wanted to get to the abe.pm and sig, also (to see if we can drum up additional interest). ---------- Forwarded message ---------- From: Randy Kramer Date: Tue, 7 Dec 2004 11:23:24 -0500 Subject: Re: [Lvlug] Programming Project, maybe in Ruby To: swf001@lvc.edu Cc: lvlug On Thu, 2 Dec 2004 14:00:23 -0500, Scott Ferguson wrote: > Schedule will be tight due to working over vacation, but I'll be home > from the middle of December until the middle of January. Scott, So far you may be the only person who has expressed unqualified interest. (I'm not sure about Ricardo (he said he'd only work on a proprietary project if he got paid, but didn't say whether he wanted to work on this project if GPL'd (or paid)), and Pat merely recommended darcs. Maybe others will get interested as time goes on. Anyway, thought I'd give you a quick update and ask you some questions. Quick update: As I started digging into Ruby, I found Instiki (a wiki) and am (lightly) digging into it (first from a user perspective). Perhaps the code will help me learn or otherwise be useful -- I'll have to dig into the Ruby license to find out whether it is open source or not (I have a hint that you can choose GPL or the Ruby license, so its openness sounds promising). I'd like to know more about your interests and capabilities. If you prefer to write to me offlist (your choice), use rhkramer@gmail.com. Some specific questions: * What are you studying in school (is your major computer related)? * Experience in Ruby? Other languages? * Familiarity with HTML? * Familiarity with http web serving? (One aspect of the project will almost certainly be a wiki like thing, and whether we use Apache or try to roll our own (for good reasons, only) we'll need some knowledge / experience there. * How do you feel about programming in Ruby? Would you prefer to work in a different language? (Which can be OK, but my current preference is Ruby for everything, and, at the very least, Ruby to glue the entire thing together -- but, I might be persuaded otherwise.) * What do you see as motivating you to participate in a project like this? Fame, fortune, experience, ? Does it depend a lot on the particular project? Do you have some itches that might be scratched by something like an askSam clone, based on what you know so far? For anyone else on the lists, although we might start a small group to work on this project, I'm sure we'll be asking questions on abe.pm, the lvlug, and elsewhere. Some initial "tasks" (some things I'm rather sure we'll need -- my preference in all cases is Ruby based stuff): * An (X)HTML renderer, * a text renderer / editor (my favorite in Linux at this time is Nedit (for a lot of reasons, including macro capability (I built some folding macros), GUI approach (although I generally don't like Motif / Lesstif, but it seems when I run it on kde I don't notice the lesstif flavor as much anymore -- not sure whether that's kde's doing or something else) -- I don't know if (or how easily) Nedit can be "wrapped" to serve as a component in a system (and not sure of my vocabulary, read on) * other renderers, determined as the design proceeds * I don't know all the right words, but some widgets (like a tree control) and a "framework" (?) (frame?) to display the tree control, (X)HTML renderer, test renderer/editor, etc. * a (simple) markup language, like that in a typical wiki, but I know there are others out there (Instiki uses Markdown and something else, there are a couple of efforts seemingly at standardization). I want something that is very unobtrusive (marked up text should be readable as plain text) and complete. The TWiki markup language is (obviously?) my first choice, with extensions to deal with some things I know are missing. In a future email, I'll mention some more about text markups that I'm aware of. regards, Randy Kramer From rhkramer at gmail.com Wed Dec 8 09:58:15 2004 From: rhkramer at gmail.com (Randy Kramer) Date: Wed Dec 8 09:58:18 2004 Subject: [ABE.pm] Re: [Lvlug] Programming Project, maybe in Ruby In-Reply-To: <20041207221212.E8950@manxome.org> References: <804dcf9d04120208523c951ad8@mail.gmail.com> <804dcf9d041202110014d87775@mail.gmail.com> <20041207221212.E8950@manxome.org> Message-ID: On Tue, 7 Dec 2004 22:12:12 -0500, Ricardo SIGNES wrote: > I'm still not clear what this is. It looks, to me, like a wildly > over-engineered system for attaching metadata to anything and then > searching for it. > > So, you need: > > a metadata indexing system > for each kind of thing: > a viewer > an indexer > > The system crawls your data, indexing new things when possible. When > you search, it searches the big central database and gives you a big > unified description of what's there, using the plugged in viewers. > > Is that about right? That's closer to a description (perhaps) of ZyIndex, although neither it nor askSam rely on (or even use) a search on metadata. (At least in the way I normally think of metadata--however if a "record" consists primarily of a picture (or some other non-textual thing), I guess the name of the picture (file) is metadata, and any descriptive text in that record could be considered metadata.) I never considered either ZyIndex or askSam (or almost any (mainstream) software application that I can recall) "over-engineered" -- usually they are under-engineered, but perhaps over-featured, over-reaching, or something similar. ;-) I know that the project I'm considering is not over-engineered -- it isn't engineered at all, yet. ;-) > It would be pretty simple in Perl, using, say, Plucene. I imagine there > are indexing systems for other languages, too. I'm sure you're right (even for my application), but I've tried Perl, and just can't / won't hack it. Python gave me some renewed faith in programming languages (and my ability to program), and I'm told that Ruby is even better. regards, Randy Kramer From rhkramer at gmail.com Thu Dec 9 11:47:24 2004 From: rhkramer at gmail.com (Randy Kramer) Date: Thu Dec 9 11:47:26 2004 Subject: [ABE.pm] Re: [Lvlug] Programming Project, maybe in Ruby In-Reply-To: <20041208110922.I8950@manxome.org> References: <804dcf9d04120208523c951ad8@mail.gmail.com> <804dcf9d041202110014d87775@mail.gmail.com> <20041207221212.E8950@manxome.org> <20041208110922.I8950@manxome.org> Message-ID: On Wed, 8 Dec 2004 11:09:22 -0500, Ricardo SIGNES wrote: > Is the difference just that ZyIndex uses metadata? Everything is just > content-searched? So, I search for "foo" and only find documents that > contain the word foo? No, to the best of my knowledge, ZyIndex doesn't (did not 10 years ago) use metadata. I'd like to have you on board somehow at which point I'd answer all your questions. As it is, for the time being, I (we) 'll consider you a potential resource (as is everybody on planet earth with any knowledge that might help us). (Sources on other planets are welcome as well, but you (they)'ll have to contact me to set up a means of communication. ;-) regards, Randy Kraer From rjbs-perl-abe at lists.manxome.org Thu Dec 9 11:51:35 2004 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Thu Dec 9 11:51:37 2004 Subject: [ABE.pm] Re: [Lvlug] Programming Project, maybe in Ruby In-Reply-To: References: <804dcf9d04120208523c951ad8@mail.gmail.com> <804dcf9d041202110014d87775@mail.gmail.com> <20041207221212.E8950@manxome.org> <20041208110922.I8950@manxome.org> Message-ID: <20041209125135.M8950@manxome.org> * Randy Kramer [2004-12-09T12:47:24] > > I'd like to have you on board somehow at which point I'd answer all > your questions. As it is, for the time being, I (we) 'll consider you > a potential resource (as is everybody on planet earth with any > knowledge that might help us). > If this is not an open project that everyone can watch and help with, please stop using the ABE.pm mailing list to advertise it. -- rjbs -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/archives/abe-pm/attachments/20041209/f1312b23/attachment.bin From rhkramer at gmail.com Thu Dec 9 12:28:07 2004 From: rhkramer at gmail.com (Randy Kramer) Date: Thu Dec 9 12:28:09 2004 Subject: [ABE.pm] Re: [Lvlug] Programming Project, maybe in Ruby In-Reply-To: <20041209125135.M8950@manxome.org> References: <804dcf9d04120208523c951ad8@mail.gmail.com> <804dcf9d041202110014d87775@mail.gmail.com> <20041207221212.E8950@manxome.org> <20041208110922.I8950@manxome.org> <20041209125135.M8950@manxome.org> Message-ID: On Thu, 9 Dec 2004 12:51:35 -0500, Ricardo SIGNES wrote: > If this is not an open project that everyone can watch and help with, > please stop using the ABE.pm mailing list to advertise it. No decision has been made on that point yet. I was hoping to gather a group of interested people and let them participate in the decision. (Specifically, as to how to license the resulting software.) regards, Randy Kramer From phil at five-lawrences.com Thu Dec 9 13:24:42 2004 From: phil at five-lawrences.com (Phil Lawrence) Date: Thu Dec 9 13:24:21 2004 Subject: [ABE.pm] Re: Accessing data in an array? In-Reply-To: <20041202002128.GA15472@uranus.faber.nom> References: <20041129231714.GA6678@uranus.faber.nom> <20041129182449.G8950@manxome.org> <20041130162417.GB5757@uranus.faber.nom> <20041130114542.I8950@manxome.org> <20041202002128.GA15472@uranus.faber.nom> Message-ID: Faber, Are you good to go regarding arrays now? Any other questions? prl From faber at linuxnj.com Thu Dec 9 15:54:50 2004 From: faber at linuxnj.com (Faber Fedor) Date: Thu Dec 9 15:54:52 2004 Subject: [ABE.pm] automating FTP in Perl Message-ID: <20041209215450.GA12450@uranus.faber.nom> What is The Proper Way to do that? I thought it was to use Expect.pm, but I can't figure out how to get the $%^ errors from Expect.pm. I do this in my code: my ($matched_pattern_position, $error, $successfully_matching_string, $before_match, $after_match) = $exp->expect($timeout,"Transfer complete."); if ( defined($exp->error()) ) { log_message($tag,"before = $exp->before() \n"); log_message($tag,"error = $error\n"); log_message($tag,"exp_error = $exp->exp_error()\n"); log_message($tag, "FTP Error: $exp->error()"); exit; } And whether I have errors or not (I successfully download the file or the file doesn't exist), I always get this: Dec 9 17:00:40 nycaserver1 forddaily: before = Expect=GLOB(0x862fcc8)->before() Dec 9 17:00:40 nycaserver1 forddaily: error = 1:TIMEOUT Dec 9 17:00:40 nycaserver1 forddaily: exp_error = Expect=GLOB(0x862fcc8)->exp_error() Dec 9 17:00:40 nycaserver1 forddaily: FTP Error: Expect=GLOB(0x862fcc8)->error() If you guys need to automate and test an FTP download in Perl, what do you use? -- Regards, Faber Linux New Jersey: Open Source Solutions for New Jersey http://www.linuxnj.com From jce0 at Lehigh.EDU Thu Dec 9 16:02:48 2004 From: jce0 at Lehigh.EDU (Jim Eshleman) Date: Thu Dec 9 16:02:55 2004 Subject: [ABE.pm] automating FTP in Perl In-Reply-To: <20041209215450.GA12450@uranus.faber.nom> References: <20041209215450.GA12450@uranus.faber.nom> Message-ID: <41B8CB88.6090908@Lehigh.EDU> > What is The Proper Way to do that? I'd use Net::FTP. Jim -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: OpenPGP digital signature Url : http://mail.pm.org/archives/abe-pm/attachments/20041209/41c49aeb/signature.bin From faber at linuxnj.com Thu Dec 9 16:40:28 2004 From: faber at linuxnj.com (Faber Fedor) Date: Thu Dec 9 16:40:31 2004 Subject: [ABE.pm] Re: automating FTP in Perl In-Reply-To: <41B8CB88.6090908@Lehigh.EDU> References: <20041209215450.GA12450@uranus.faber.nom> <41B8CB88.6090908@Lehigh.EDU> Message-ID: <20041209224028.GB12450@uranus.faber.nom> On 09/12/04 17:02 -0500, Jim Eshleman wrote: > >What is The Proper Way to do that? > > I'd use Net::FTP. I saw Net::FTP::Common on CPAN but I didn't see just Net::FTP. Does it have a different package name? I obviously had a brain fart since I can't install it via CPAN, either: [root@root root]# perl -MCPAN -e "install Net::FTP" Can't locate object method "install" via package "Net::FTP" at -e line 1. That's it. I'm walking away from the computer and not looking back until I've drank many beers... -- Regards, Faber Linux New Jersey: Open Source Solutions for New Jersey http://www.linuxnj.com From rjbs-perl-abe at lists.manxome.org Thu Dec 9 17:13:03 2004 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Thu Dec 9 17:13:04 2004 Subject: [ABE.pm] Re: automating FTP in Perl In-Reply-To: <20041209224028.GB12450@uranus.faber.nom> References: <20041209215450.GA12450@uranus.faber.nom> <41B8CB88.6090908@Lehigh.EDU> <20041209224028.GB12450@uranus.faber.nom> Message-ID: <20041209181303.P8950@manxome.org> * Faber Fedor [2004-12-09T17:40:28] > On 09/12/04 17:02 -0500, Jim Eshleman wrote: > > >What is The Proper Way to do that? > > > > I'd use Net::FTP. > > > I saw Net::FTP::Common on CPAN but I didn't see just Net::FTP. Does it > have a different package name? http://search.cpan.org/dist/libnet/ -- rjbs -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/archives/abe-pm/attachments/20041209/5e1b559d/attachment.bin From jce0 at Lehigh.EDU Thu Dec 9 18:29:52 2004 From: jce0 at Lehigh.EDU (Jim Eshleman) Date: Thu Dec 9 18:30:03 2004 Subject: [ABE.pm] Re: automating FTP in Perl In-Reply-To: <20041209181303.P8950@manxome.org> References: <20041209215450.GA12450@uranus.faber.nom> <41B8CB88.6090908@Lehigh.EDU> <20041209224028.GB12450@uranus.faber.nom> <20041209181303.P8950@manxome.org> Message-ID: <41B8EE00.3000006@Lehigh.EDU> >>I saw Net::FTP::Common on CPAN but I didn't see just Net::FTP. Does it >>have a different package name? > > > http://search.cpan.org/dist/libnet/ CPAN can be your friend...sometimes: $ perl -MCPAN -e shell cpan shell -- CPAN exploration and modules installation (v1.7601) ReadLine support enabled cpan> m /ftp/ CPAN: Storable loaded ok Going to read /usr/local/cpan/Metadata Database was generated on Thu, 09 Dec 2004 04:51:03 GMT [...] Module Net::FTP (G/GB/GBARR/libnet-1.19.tar.gz) [...] 70 items found cpan> -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 252 bytes Desc: OpenPGP digital signature Url : http://mail.pm.org/archives/abe-pm/attachments/20041209/04b595f7/signature.bin From rhkramer at gmail.com Thu Dec 9 19:55:11 2004 From: rhkramer at gmail.com (Randy Kramer) Date: Thu Dec 9 19:55:14 2004 Subject: [ABE.pm] The Ruby Dumb Questions Series ;-) Message-ID: I finally got a copy (from the BAPL) of the Pickaxe book, and I'm starting to read it. I'm going to ask some question here as they jump out at me, although in some cases I expect I'll find an answer as I read more. (the smart ass introduction to the question:) If Ruby wants to be so consistent as an object oriented language, with a consistent syntax of object.method, why is it: puts instead of: .puts ? Is there a *logical* explanation? regards, Randy Kramer From rjbs-perl-abe at lists.manxome.org Thu Dec 9 20:23:53 2004 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Thu Dec 9 20:24:13 2004 Subject: [ABE.pm] The Ruby Dumb Questions Series ;-) In-Reply-To: References: Message-ID: <20041209212353.Q8950@manxome.org> * Randy Kramer [2004-12-09T20:55:11] > (the smart ass introduction to the question:) If Ruby wants to be so > consistent as an object oriented language, with a consistent syntax of > object.method, why is it: > > puts > instead of: > .puts puts is a method on Kernel. The Kernel methods are always available without qualifying the object. Read about the Kernel class. -- rjbs -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/archives/abe-pm/attachments/20041209/edfac783/attachment.bin From faber at linuxnj.com Thu Dec 9 21:12:07 2004 From: faber at linuxnj.com (Faber Fedor) Date: Thu Dec 9 21:12:10 2004 Subject: [ABE.pm] Re: automating FTP in Perl In-Reply-To: <41B8EE00.3000006@Lehigh.EDU> References: <20041209215450.GA12450@uranus.faber.nom> <41B8CB88.6090908@Lehigh.EDU> <20041209224028.GB12450@uranus.faber.nom> <20041209181303.P8950@manxome.org> <41B8EE00.3000006@Lehigh.EDU> Message-ID: <20041210031207.GA13923@uranus.faber.nom> On 09/12/04 19:29 -0500, Jim Eshleman wrote: > >>I saw Net::FTP::Common on CPAN but I didn't see just Net::FTP. Does it > >>have a different package name? > > > > > >http://search.cpan.org/dist/libnet/ > > CPAN can be your friend...sometimes: > > $ perl -MCPAN -e shell > > cpan shell -- CPAN exploration and modules installation (v1.7601) > ReadLine support enabled > > cpan> m /ftp/ > CPAN: Storable loaded ok > Going to read /usr/local/cpan/Metadata > Database was generated on Thu, 09 Dec 2004 04:51:03 GMT > [...] > Module Net::FTP (G/GB/GBARR/libnet-1.19.tar.gz) > [...] > 70 items found Oh! THAT'S how you do that! Thanks! (Maybe we need a "how to do useful things other than install modules with CPAN" lecture at one of the meetings.) -- Regards, Faber Linux New Jersey: Open Source Solutions for New Jersey http://www.linuxnj.com From faber at linuxnj.com Fri Dec 10 11:34:43 2004 From: faber at linuxnj.com (Faber Fedor) Date: Fri Dec 10 11:34:46 2004 Subject: [ABE.pm] Re: automating FTP in Perl In-Reply-To: <20041209215450.GA12450@uranus.faber.nom> References: <20041209215450.GA12450@uranus.faber.nom> Message-ID: <20041210173443.GA22594@uranus.faber.nom> Okay, the Net::FTP is alot cleaner than using Expect.pm but I'm still having problems with error logging, specifically, in my code I say: $ftp->get($ftp_cfg{file}, $datafile) or log_message("tag", "get failed $ftp->message") && die; (where log_message is my function that just calls logger) and the error report I get is: Dec 10 12:39:28 myserver tag: get failed Net::FTP=GLOB(0x874b50c)->message But, if I create the log message this way: log_message("tag", "get failed " . $ftp->message) && die; I get the "proper" error message: Dec 10 12:45:46 myserver tag: get failed my20041210.csv: The system cannot find the file specified. I was under the impression that the compiler would interpret everything in the double quotes but here it obviously isn't. Why is that? On another note, I'm assuming thatthe reason the "&& die" isn't executed is because log_message returns nothing, right? -- Regards, Faber Linux New Jersey: Open Source Solutions for New Jersey http://www.linuxnj.com From rjbs-perl-abe at lists.manxome.org Fri Dec 10 11:56:38 2004 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Fri Dec 10 11:56:45 2004 Subject: [ABE.pm] Re: automating FTP in Perl In-Reply-To: <20041210173443.GA22594@uranus.faber.nom> References: <20041209215450.GA12450@uranus.faber.nom> <20041210173443.GA22594@uranus.faber.nom> Message-ID: <20041210125638.S8950@manxome.org> * Faber Fedor [2004-12-10T12:34:43] > $ftp->get($ftp_cfg{file}, $datafile) > or log_message("tag", "get failed $ftp->message") && die; > > (where log_message is my function that just calls logger) and the error > report I get is: > > Dec 10 12:39:28 myserver tag: get failed Net::FTP=GLOB(0x874b50c)->message > ... > I was under the impression that the compiler would interpret everything > in the double quotes but here it obviously isn't. Why is that? You can't interpolate method calls, basically. > On another note, I'm assuming thatthe reason the "&& die" isn't executed > is because log_message returns nothing, right? Presumably, yeah. Those kinds of long chains are one of the things that people think gets too confusing in Perl. I use them now and then, and constantly use short chains, but it's very common to hear "keep flow control on the left." die is flow control, so one would normally write: die "error message" unless $object->can_do_something_important; Once you need multiple things to happen, flip it and use a real block. unless ($obj->can_do) { log_error; die "message"; } Also, don't use die without an error message. Even a single word will make life easier later. -- rjbs -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/archives/abe-pm/attachments/20041210/7bd2493f/attachment-0001.bin From faber at linuxnj.com Fri Dec 10 20:47:28 2004 From: faber at linuxnj.com (Faber Fedor) Date: Fri Dec 10 20:47:34 2004 Subject: [ABE.pm] Got any good data structures handy? Message-ID: <20041211024728.GA29359@uranus.faber.nom> In this mass of programs I'm bothering you guys with, I'm generating a far amount of data. In one section, I'm generating the min, max, avg, and sum of 24 variables. Both the numbers to be generated and the variables to generate from will increase in the future. Well, the client wants to see graphs of this data. I figure I'll just pull the data down, run it through Chart::Graph::Gnuplot, dump the grpahs to separate directies each day and generate an index.html page in each dir. Then I got to thinking about the data structure that needs to hold the title of each graph, the X and Y axes labels of each graph, the style for each graph, etc. I'm thinking of a hashref. You? Then there's the matter of storing the data structure to disk. Should I put it into a MySQL DB? An XML file? I know, I could put everything in an array and store it in a CSV file in Swahili, but I'm looking for something fun and interesting to do. Any cool and fun ideas for this? -- Regards, Faber Linux New Jersey: Open Source Solutions for New Jersey http://www.linuxnj.com From rjbs-perl-abe at lists.manxome.org Fri Dec 10 22:17:02 2004 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Fri Dec 10 22:17:05 2004 Subject: [ABE.pm] Got any good data structures handy? In-Reply-To: <20041211024728.GA29359@uranus.faber.nom> References: <20041211024728.GA29359@uranus.faber.nom> Message-ID: <20041210231702.U8950@manxome.org> * Faber Fedor [2004-12-10T21:47:28] > Then I got to thinking about the data structure that needs to hold the > title of each graph, the X and Y axes labels of each graph, the style > for each graph, etc. I'm thinking of a hashref. You? That certainly sounds reasonable. Hashes are really, really useful for serving as generic catch-all "record" types. > Then there's the matter of storing the data structure to disk. Should I > put it into a MySQL DB? An XML file? MySQL has administrative overhead. XML is a pain, in my experience. I suggest SQLite (q.v. DBD::SQLite) or YAML (q.v. YAML.pm) or maybe Storable. -- rjbs -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/archives/abe-pm/attachments/20041210/b07e12b7/attachment.bin From faber at linuxnj.com Fri Dec 10 23:27:26 2004 From: faber at linuxnj.com (Faber Fedor) Date: Fri Dec 10 23:27:28 2004 Subject: [ABE.pm] Re: Got any good data structures handy? In-Reply-To: <20041210231702.U8950@manxome.org> References: <20041211024728.GA29359@uranus.faber.nom> <20041210231702.U8950@manxome.org> Message-ID: <20041211052726.GC30258@uranus.faber.nom> On 10/12/04 23:17 -0500, Ricardo SIGNES wrote: > > Then there's the matter of storing the data structure to disk. Should I > > put it into a MySQL DB? An XML file? > > MySQL has administrative overhead. True, but I'm already administering a MySQL DB for these guys (although Postgresql would be much better/cooler even if we if we don't need the transactions or ACID). > XML is a pain, in my experience. That's been my experience as well, but I've seen some amazing things done with it. IME, XML is good for data transfers, but I've seen programs (like Japple) change their behavior based on the XML; that looks RFC but I don't get what it is they're doing. -- Regards, Faber Linux New Jersey: Open Source Solutions for New Jersey http://www.linuxnj.com From faber at linuxnj.com Tue Dec 14 15:45:33 2004 From: faber at linuxnj.com (Faber Fedor) Date: Tue Dec 14 15:45:38 2004 Subject: [ABE.pm] perl regex Q Message-ID: <20041214214533.GA7721@uranus.faber.nom> I have a text file that contains lines like 1.2,3.4,,5.67,78.9,,,,,0.01 I want to make the line look like this: 1.2,3.4,\N,5.67,78.9,\N,\N,\N,\N,0.01 so I did this: perl -iBAK -p -e 's/,,/,\\N,/g' foo.txt Unfortunately, that creates a file that looks like this 1.2,3.4,\N,5.67,78.9,\N,,\N,,0.01 It looks like after the replace, the search starts at the next character after the previous search term. How do I get around that? There's prolly a magical switch for that, but I can't find it. Also, is there a way to do a perl "edit in place" inside of a perl program other than using backticks (`perl -iBAK -p -e 's/,,/,\\N,/g' foo.txt`) or the system() call? (No, reading the file in a line at a time is not an option.) -- Regards, Faber Linux New Jersey: Open Source Solutions for New Jersey http://www.linuxnj.com From rjbs-perl-abe at lists.manxome.org Tue Dec 14 16:16:26 2004 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Tue Dec 14 16:16:29 2004 Subject: [ABE.pm] perl regex Q In-Reply-To: <20041214214533.GA7721@uranus.faber.nom> References: <20041214214533.GA7721@uranus.faber.nom> Message-ID: <20041214171626.I14246@manxome.org> * Faber Fedor [2004-12-14T16:45:33] > so I did this: > > perl -iBAK -p -e 's/,,/,\\N,/g' foo.txt > > Unfortunately, that creates a file that looks like this > > 1.2,3.4,\N,5.67,78.9,\N,,\N,,0.01 > > It looks like after the replace, the search starts at the next character > after the previous search term. How do I get around that? There's > prolly a magical switch for that, but I can't find it. You told it: find two commas, replace them with ",\N," and then keep going. Well, it keeps going from the last thing it found: the second comma. What you want to say is: find a comma; if the next thing is a comma, replace the comma you found with ",\N" and keep going. $string =~ s/,(?=,)/,\\N/g The (?= ... ) construct is called a look-ahead assertion. It asserts that something occurs ahead of the current point in the regexp. Understanding how to use look-around is something that many Perl programmers never really get to, which is a bummer, because it's way fun. A less elegant solution would have been: while ($string =~ /,,/) { $string =~ s/,,/,\\N,/g; } This would keep applying the replacement until it found every case. > Also, is there a way to do a perl "edit in place" inside of a perl > program other than using backticks (`perl -iBAK -p -e 's/,,/,\\N,/g' > foo.txt`) or the system() call? No. Well, yes, but you won't like it! Consult "perldoc perlrun" and look under the section about -i; it explains how -i would be implemented in Perl, more or less. > (No, reading the file in a line at a time is not an option.) Why not? It's what perl does when you use -i. Give us more real-world information about what you need to accomplish, and what the limitations are. -- rjbs -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/archives/abe-pm/attachments/20041214/01cf8730/attachment.bin From faber at linuxnj.com Tue Dec 14 16:49:48 2004 From: faber at linuxnj.com (Faber Fedor) Date: Tue Dec 14 16:49:49 2004 Subject: [ABE.pm] Re: perl regex Q In-Reply-To: <20041214171626.I14246@manxome.org> References: <20041214214533.GA7721@uranus.faber.nom> <20041214171626.I14246@manxome.org> Message-ID: <20041214224948.GA8295@uranus.faber.nom> On 14/12/04 17:16 -0500, Ricardo SIGNES wrote: > The (?= ... ) construct is called a look-ahead assertion. And that is the Perl magic I was looking for. > > Also, is there a way to do a perl "edit in place" inside of a perl > > program other than using backticks (`perl -iBAK -p -e 's/,,/,\\N,/g' > > foo.txt`) or the system() call? > > No. I guess that's why (different regex) perl -iBAK -p -e 's/ *NA */\\N/g' foo.txt works from the command line but doing it from inside a perl program generates the error: Missing braces on \N{} at -e line 1, within string Execution of -e aborted due to compilation errors. It doesn't matter how many slashes I put in front of the N! :-) > Consult "perldoc perlrun" and look under the section about -i; it > explains how -i would be implemented in Perl, more or less. I'll go read it forthwith. > > (No, reading the file in a line at a time is not an option.) > Why not? It's what perl does when you use -i. Seems a helluva lot faster than when I tried it in a while loop a while back. > Give us more real-world information about what you need to accomplish, > and what the limitations are. I need to replace "NA" with "\N" (no quotes around either). The file is 900K+ lines long and 136 columns wide and will continue growing lengthwise. Limitation: time. If I can do the "edit-in-place" from inside my program, the whole process takes a minute or two. Everything thing else I've tried (except a while loop) takes 40 minutes or longer. -- Regards, Faber Linux New Jersey: Open Source Solutions for New Jersey http://www.linuxnj.com From faber at linuxnj.com Tue Dec 14 16:53:51 2004 From: faber at linuxnj.com (Faber Fedor) Date: Tue Dec 14 16:53:53 2004 Subject: [ABE.pm] Re: perl regex Q In-Reply-To: <20041214171626.I14246@manxome.org> References: <20041214214533.GA7721@uranus.faber.nom> <20041214171626.I14246@manxome.org> Message-ID: <20041214225351.GB8295@uranus.faber.nom> On 14/12/04 17:16 -0500, Ricardo SIGNES wrote: > > (No, reading the file in a line at a time is not an option.) > > Why not? It's what perl does when you use -i. Now I remember the details: I'm reading the data into a MySQL database. Reading the file a line at a time and INSERTing takes days. Doing a LOAD DATA INFILE takes seconds. So I need to massage the data before LOADing it. -- Regards, Faber Linux New Jersey: Open Source Solutions for New Jersey http://www.linuxnj.com From rjbs-perl-abe at lists.manxome.org Tue Dec 14 17:36:53 2004 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Tue Dec 14 17:36:56 2004 Subject: [ABE.pm] Re: perl regex Q In-Reply-To: <20041214232422.GA8757@uranus.faber.nom> References: <20041214214533.GA7721@uranus.faber.nom> <20041214171626.I14246@manxome.org> <20041214224948.GA8295@uranus.faber.nom> <20041214232422.GA8757@uranus.faber.nom> Message-ID: <20041214183653.J14246@manxome.org> * Faber Fedor [2004-12-14T18:24:22] > Turns out I need 4, count 'em four, backslashes in front of the N, e.g. > perl -iBAK -p -e 's/ *NA */\\\\N/g' foo.txt perl needs 2, and then you have to escape them for the shell :) -- rjbs -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/archives/abe-pm/attachments/20041214/949f203a/attachment.bin From jce0 at Lehigh.EDU Tue Dec 14 19:08:44 2004 From: jce0 at Lehigh.EDU (Jim Eshleman) Date: Tue Dec 14 19:08:52 2004 Subject: [ABE.pm] perl regex Q In-Reply-To: <20041214214533.GA7721@uranus.faber.nom> References: <20041214214533.GA7721@uranus.faber.nom> Message-ID: <41BF8E9C.70806@Lehigh.EDU> > I have a text file that contains lines like > > 1.2,3.4,,5.67,78.9,,,,,0.01 > > I want to make the line look like this: > > 1.2,3.4,\N,5.67,78.9,\N,\N,\N,\N,0.01 This: perl -ne 'chomp;print join(",",map {$_ or "\\N"} split ",",$_,-1), "\n"' should work and handle the corner cases of leading and/or trailing commas. Likely not as fast as a regex but *maybe* easier to understand. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 252 bytes Desc: OpenPGP digital signature Url : http://mail.pm.org/archives/abe-pm/attachments/20041214/22c76404/signature.bin From rjbs-perl-abe at lists.manxome.org Tue Dec 14 19:15:09 2004 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Tue Dec 14 19:15:11 2004 Subject: [ABE.pm] perl regex Q In-Reply-To: <41BF8E9C.70806@Lehigh.EDU> References: <20041214214533.GA7721@uranus.faber.nom> <41BF8E9C.70806@Lehigh.EDU> Message-ID: <20041214201508.K14246@manxome.org> * Jim Eshleman [2004-12-14T20:08:44] > This: > > perl -ne 'chomp;print join(",",map {$_ or "\\N"} split ",",$_,-1), "\n"' > > should work and handle the corner cases of leading and/or trailing > commas. Likely not as fast as a regex but *maybe* easier to understand. I think you mean: perl -ne 'chomp;print join(",",map {defined $_ ? $_ : "\\N"} split ",",$_,-1), "\n"' Otherwise, a 0 will become a \N :) -- rjbs -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.pm.org/archives/abe-pm/attachments/20041214/18e8c2b8/attachment.bin From faber at linuxnj.com Tue Dec 14 19:31:27 2004 From: faber at linuxnj.com (Faber Fedor) Date: Tue Dec 14 19:31:31 2004 Subject: [ABE.pm] Re: perl regex Q In-Reply-To: <41BF8E9C.70806@Lehigh.EDU> References: <20041214214533.GA7721@uranus.faber.nom> <41BF8E9C.70806@Lehigh.EDU> Message-ID: <20041215013127.GA9785@uranus.faber.nom> On 14/12/04 20:08 -0500, Jim Eshleman wrote: > Likely not as fast as a regex but *maybe* easier to understand. That's a joke, right? :-) (Someday I'll learn what map does too!) -- Regards, Faber Linux New Jersey: Open Source Solutions for New Jersey http://www.linuxnj.com From jce0 at Lehigh.EDU Tue Dec 14 19:33:21 2004 From: jce0 at Lehigh.EDU (Jim Eshleman) Date: Tue Dec 14 19:33:32 2004 Subject: [ABE.pm] perl regex Q In-Reply-To: <20041214201508.K14246@manxome.org> References: <20041214214533.GA7721@uranus.faber.nom> <41BF8E9C.70806@Lehigh.EDU> <20041214201508.K14246@manxome.org> Message-ID: <41BF9461.8080807@Lehigh.EDU> >>This: >> >>perl -ne 'chomp;print join(",",map {$_ or "\\N"} split ",",$_,-1), "\n"' >> >>should work and handle the corner cases of leading and/or trailing >>commas. Likely not as fast as a regex but *maybe* easier to understand. > > > I think you mean: > perl -ne 'chomp;print join(",",map {defined $_ ? $_ : "\\N"} split ",",$_,-1), "\n"' > > Otherwise, a 0 will become a \N :) Heh heh. Oops. Well, a zero will always be input as 0.0, right? ;) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 252 bytes Desc: OpenPGP digital signature Url : http://mail.pm.org/archives/abe-pm/attachments/20041214/aa307f94/signature.bin From jce0 at Lehigh.EDU Tue Dec 14 19:51:31 2004 From: jce0 at Lehigh.EDU (Jim Eshleman) Date: Tue Dec 14 19:51:41 2004 Subject: [ABE.pm] Re: perl regex Q In-Reply-To: <20041215013127.GA9785@uranus.faber.nom> References: <20041214214533.GA7721@uranus.faber.nom> <41BF8E9C.70806@Lehigh.EDU> <20041215013127.GA9785@uranus.faber.nom> Message-ID: <41BF98A3.2050203@Lehigh.EDU> >>Likely not as fast as a regex but *maybe* easier to understand. > > > That's a joke, right? :-) > > (Someday I'll learn what map does too!) Well, yeah, in this case that's a joke I guess. Map isn't really hard. You're doing something with each element of a list (in an expression or code block where $_ is set to each element of the list) and it returns a list of the results. You can always code a for loop instead, the map is just more concise. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 252 bytes Desc: OpenPGP digital signature Url : http://mail.pm.org/archives/abe-pm/attachments/20041214/363c882b/signature.bin From jce0 at Lehigh.EDU Tue Dec 14 21:56:23 2004 From: jce0 at Lehigh.EDU (Jim Eshleman) Date: Tue Dec 14 21:56:33 2004 Subject: [ABE.pm] perl regex Q In-Reply-To: <20041214201508.K14246@manxome.org> References: <20041214214533.GA7721@uranus.faber.nom> <41BF8E9C.70806@Lehigh.EDU> <20041214201508.K14246@manxome.org> Message-ID: <41BFB5E7.8070407@Lehigh.EDU> >>This: >> >>perl -ne 'chomp;print join(",",map {$_ or "\\N"} split ",",$_,-1), "\n"' >> >>should work and handle the corner cases of leading and/or trailing >>commas. Likely not as fast as a regex but *maybe* easier to understand. > > > I think you mean: > perl -ne 'chomp;print join(",",map {defined $_ ? $_ : "\\N"} split ",",$_,-1), "\n"' > > Otherwise, a 0 will become a \N :) Actually, that doesn't work at all (just reproduces the input string) because when there's no value between delimiters split returns the empty string ('') and that *is* defined. What we really meant is: perl -ne 'chomp; print join(",", map { $_ eq "" ? "\\N" : $_ } split ",", $_, -1), "\n"' Now we can process zeros (0) and zeros (0.0) :) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 252 bytes Desc: OpenPGP digital signature Url : http://mail.pm.org/archives/abe-pm/attachments/20041214/d8e1bcaa/signature-0001.bin From faber at sedna.linuxnj.com Tue Dec 14 22:32:51 2004 From: faber at sedna.linuxnj.com (faber@sedna.linuxnj.com) Date: Tue Dec 14 22:22:40 2004 Subject: [ABE.pm] perl regex Q In-Reply-To: <41BFB5E7.8070407@Lehigh.EDU> References: <20041214214533.GA7721@uranus.faber.nom> <41BF8E9C.70806@Lehigh.EDU> <20041214201508.K14246@manxome.org> <41BFB5E7.8070407@Lehigh.EDU> Message-ID: <20041215043251.GA1118@sedna.linuxnj.com> On Tue, Dec 14, 2004 at 10:56:23PM -0500, Jim Eshleman wrote: > >>This: > >> > >>perl -ne 'chomp;print join(",",map {$_ or "\\N"} split ",",$_,-1), "\n"' > >> > >>should work and handle the corner cases of leading and/or trailing > >>commas. Likely not as fast as a regex but *maybe* easier to understand. > > > > > >I think you mean: > >perl -ne 'chomp;print join(",",map {defined $_ ? $_ : "\\N"} split > >",",$_,-1), "\n"' > > > >Otherwise, a 0 will become a \N :) > > Actually, that doesn't work at all (just reproduces the input string) > because when there's no value between delimiters split returns the empty > string ('') and that *is* defined. > > What we really meant is: > > perl -ne 'chomp; print join(",", map { $_ eq "" ? "\\N" : $_ } split > ",", $_, -1), "\n"' > > Now we can process zeros (0) and zeros (0.0) :) Either of you boys wanna explain this to us mere mortals? From jce0 at Lehigh.EDU Wed Dec 15 00:35:49 2004 From: jce0 at Lehigh.EDU (Jim Eshleman) Date: Wed Dec 15 00:36:04 2004 Subject: [ABE.pm] perl regex Q In-Reply-To: <20041215043251.GA1118@sedna.linuxnj.com> References: <20041214214533.GA7721@uranus.faber.nom> <41BF8E9C.70806@Lehigh.EDU> <20041214201508.K14246@manxome.org> <41BFB5E7.8070407@Lehigh.EDU> <20041215043251.GA1118@sedna.linuxnj.com> Message-ID: <41BFDB45.3070607@Lehigh.EDU> >>>>This: >>>> >>>>perl -ne 'chomp;print join(",",map {$_ or "\\N"} split ",",$_,-1), "\n"' >>>> >>>>should work and handle the corner cases of leading and/or trailing >>>>commas. Likely not as fast as a regex but *maybe* easier to understand. >>> >>> >>>I think you mean: >>>perl -ne 'chomp;print join(",",map {defined $_ ? $_ : "\\N"} split >>>",",$_,-1), "\n"' >>> >>>Otherwise, a 0 will become a \N :) >> >>Actually, that doesn't work at all (just reproduces the input string) >>because when there's no value between delimiters split returns the empty >>string ('') and that *is* defined. >> >> What we really meant is: >> >>perl -ne 'chomp; print join(",", map { $_ eq "" ? "\\N" : $_ } split >>",", $_, -1), "\n"' >> >> Now we can process zeros (0) and zeros (0.0) :) > > > Either of you boys wanna explain this to us mere mortals? Ok, gotta read from right to left. First the split: @valuesin = split ",", $_, -1; This returns a list (to be used by map) that contains the comma delimited fields. The delimiters are thrown away. Where the field is null (between two consecutive commas, or between the beginning of the string and a leading comma, or between a trailing comma and the end of the string) the list element will be the empty string (''), or null. Note that by default split doesn't return trailing nulls (like if your input string ended in one or more consectutive commas) so you'll need to specify a negative LIMIT, -1 in this case. So using your example the list returned by split is: (1.2, 3.4, '', 5.67, 78.9, '', '', '', '', 0.01) Now we feed that list to map: @valuesout = map { $_ eq "" ? "\\N" : $_ } @valuesin; The map function iterates over @valuesin, internally setting $_ to each element and evaluating the code block. The output of map is a list of the result of each of these evaluations. The code block evaluates to "\\N" if the list element is null, otherwise it evaluates to the list element itself. So the list returned by map is: (1.2, 3.4, '\N', 5.67, 78.9, '\N', '\N', '\N', '\N', 0.01) Now we join the list elements returned by map together, delimited by commas: join ",", @valuesout; which returns a string: '1.2,3.4,\N,5.67,78.9,\N,\N,\N,\N,0.01' Just add a newline and you're done. My first attempt used the map code block: {$_ or "\\N"} which would evaluate to $_ if $_ was true (not null), else '\N'. The problem pointed out by Ric was that if the list element was zero (0) it evaluates to '\N', because zero is false. Interestingly a different zero ('0.0') here is true :-) Ric suggested: {defined $_ ? $_ : "\\N"} which evaluates to $_ if $_ is defined, else '\N'. However split returns a list element of '' for a null, not the value undef. With this block map just returns the same list it was fed by split. Finally, this block should work as intended: { $_ eq "" ? "\\N" : $_ } as it evaluates to '\N' if the list element is null, else $_. Anyway, this approach might be needed, rather than the regex, if you need to do some processing on those comma delimited values. Like maybe you want to round them to one digit after the decimal, you could use this code block for the map: { $_ eq "" ? "\\N" : sprintf "%.1f", $_ } -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 252 bytes Desc: OpenPGP digital signature Url : http://mail.pm.org/archives/abe-pm/attachments/20041215/c91c0b19/signature.bin From phil at five-lawrences.com Wed Dec 15 09:49:49 2004 From: phil at five-lawrences.com (Phil Lawrence) Date: Wed Dec 15 09:50:14 2004 Subject: [ABE.pm] Re: automating FTP in Perl In-Reply-To: <20041210125638.S8950@manxome.org> References: <20041209215450.GA12450@uranus.faber.nom> <20041210173443.GA22594@uranus.faber.nom> <20041210125638.S8950@manxome.org> Message-ID: On Dec 10, 2004, at 12:56, Ricardo SIGNES wrote: > ... it's very common to hear "keep flow control on the > left." die is flow control, so one would normally write: > > die "error message" > unless $object->can_do_something_important; > > Once you need multiple things to happen, flip it and use a real block. > > unless ($obj->can_do) { > log_error; > die "message"; > } Nice... I like that "flow control to the left" bit. > > Also, don't use die without an error message. Even a single word will > make life easier later. In prod code, yes... but when writing new code, die()'s habit of spitting out line numbers when not given a \n -terminated argument is handy on its own. prl From phil at five-lawrences.com Wed Dec 15 09:58:10 2004 From: phil at five-lawrences.com (Phil Lawrence) Date: Wed Dec 15 09:57:33 2004 Subject: [ABE.pm] Re: perl regex Q In-Reply-To: <20041215013127.GA9785@uranus.faber.nom> References: <20041214214533.GA7721@uranus.faber.nom> <41BF8E9C.70806@Lehigh.EDU> <20041215013127.GA9785@uranus.faber.nom> Message-ID: <1E50811A-4EB2-11D9-9F59-003065C45FE0@five-lawrences.com> On Dec 14, 2004, at 20:31, Faber Fedor wrote: > On 14/12/04 20:08 -0500, Jim Eshleman wrote: >> Likely not as fast as a regex but *maybe* easier to understand. > > That's a joke, right? :-) > > (Someday I'll learn what map does too!) I felt the same until that day finally came for me. Really, now I don't know what kept me from grokking map! map rules, and i use it all the time when manipulating nested hashrefs. Why? because it's otherwise hard to code clean and simple "look at and understand" hashref data structure manipulation. map is a good tool for doing complex transformations on the fly, i.e. as you iterate/sort/whatever through hash keys and data. prl From rhkramer at gmail.com Wed Dec 15 16:21:12 2004 From: rhkramer at gmail.com (Randy Kramer) Date: Wed Dec 15 16:21:16 2004 Subject: [ABE.pm] HTML Widget in Ruby Message-ID: Not sure I'm using the right words, but I want to find an HTML widget, i.e., that part of a (web) browser that displays (renders) the HTML in a window. Haven't found anything yet at RAA (the Ruby Application Archive??), but I'm not done looking. Pickaxe2 points me to Tk, I suspect Qt would have something as well (but possible licensing issues)--my first choice would be to find something "purely" in Ruby. Randy Kramer From rhkramer at gmail.com Sun Dec 19 15:12:56 2004 From: rhkramer at gmail.com (Randy Kramer) Date: Sun Dec 19 15:12:58 2004 Subject: [ABE.pm] Ruby IDEs, Object Browser Message-ID: Any recommendations for (simple to install) IDEs or similar tools for Ruby? The first thing I'd like to find is probably called an object browser--something to let me jump from an object reference to its definition. Randy Kramer