From rjbs-perl-abe at lists.manxome.org Mon Nov 8 10:04:43 2004 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Mon Nov 8 10:04:46 2004 Subject: [ABE.pm] tonight? Message-ID: <20041108110443.N1901@manxome.org> As I'm sure everyone knows and is anticipating, tonight is the second Monday of the month! Who's down for Perl and beer? -- 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/20041108/c3530985/attachment.bin From faber at linuxnj.com Mon Nov 8 11:08:58 2004 From: faber at linuxnj.com (Faber Fedor) Date: Mon Nov 8 11:09:00 2004 Subject: [ABE.pm] Re: tonight? In-Reply-To: <20041108110443.N1901@manxome.org> References: <20041108110443.N1901@manxome.org> Message-ID: <20041108170858.GA2954@uranus.faber.nom> On 08/11/04 11:04 -0500, Ricardo SIGNES wrote: > As I'm sure everyone knows and is anticipating, tonight is the second > Monday of the month! Who's down for Perl and beer? _Second_ Monday? No wonder I've been missing meetings! Unfortunately, tonight I'm down with Perl and a database. No beer. :-( (If I ever get through this CSS crap, that is.) -- Regards, Faber Linux New Jersey: Open Source Solutions for New Jersey http://www.linuxnj.com From faber at linuxnj.com Tue Nov 9 14:22:28 2004 From: faber at linuxnj.com (Faber Fedor) Date: Tue Nov 9 14:22:31 2004 Subject: [ABE.pm] DBI Q Message-ID: <20041109202228.GA12473@uranus.faber.nom> What's the Proper Way to grab an error from a DBI call? I thought this would work: $dbh->do($stmt); snd_msg("failure in LOAD DATA INFILE command. Error: $DBI::errstr") if defined($dbh->err); but that prints an error to STDOUT and dies, i.e. it never reaches snd_msg(). I tried this: $dbh->do($stmt) or snd_msg("failure in LOAD DATA INFILE command. Error: $DBI::errstr") if defined($dbh->err); but that printed nothing out (presumably since the return of the do() was nonzero) and it didn't die. RaiseError = 0 as well as PrintError. -- Regards, Faber Linux New Jersey: Open Source Solutions for New Jersey http://www.linuxnj.com From rjbs-perl-abe at lists.manxome.org Tue Nov 9 14:41:46 2004 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Tue Nov 9 14:41:48 2004 Subject: [ABE.pm] DBI Q In-Reply-To: <20041109202228.GA12473@uranus.faber.nom> References: <20041109202228.GA12473@uranus.faber.nom> Message-ID: <20041109154146.V1901@manxome.org> * Faber Fedor [2004-11-09T15:22:28] > What's the Proper Way to grab an error from a DBI call? I thought this > would work: > > $dbh->do($stmt); > snd_msg("failure in LOAD DATA INFILE command. Error: $DBI::errstr") > if defined($dbh->err); > > but that prints an error to STDOUT and dies, i.e. it never reaches > snd_msg(). It dies, with RaiseError set to zero? What about this: { local $dbh->{RaiseError} = 0; $dbh->do($stmt) or die("problem: " . $dbh->errstr); } What does that do? > $dbh->do($stmt) or > snd_msg("failure in LOAD DATA INFILE command. Error: $DBI::errstr") > if defined($dbh->err); That is the same as this: if (defined $dbh->err) { $dbh->do($stmt) or snd_msg("..."); } ...which is surely not what you want. -- 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/20041109/d00fe04d/attachment.bin From phil at five-lawrences.com Thu Nov 11 08:46:10 2004 From: phil at five-lawrences.com (Phil Lawrence) Date: Thu Nov 11 08:46:06 2004 Subject: [ABE.pm] virtual membership Message-ID: <6D84F084-33F0-11D9-A3CA-003065C45FE0@five-lawrences.com> Well, I've fought it for a while, but there's no avoiding this: I don't have time to attend ABE.pm! :-( From here on out I've got to be a mailing list member only. Regrets, prl From waltman at pobox.com Mon Nov 29 13:32:40 2004 From: waltman at pobox.com (Walt Mankowski) Date: Mon Nov 29 13:32:45 2004 Subject: [ABE.pm] Mark-Jason Dominus talking about qmail Wednesday night Message-ID: <20041129193240.GE2779@waltman.dnsalias.org> Hi everyone! Sorry that this talk is neither in the Lehigh Valley, nor is it likely to have much to do with Perl. But those of us who've seen Mark in action know what a great speaker he is on just about any topic. So on the chance that someone might be interested in driving an hour or so to hear his talk, I thought I'd crosspost this here. There's likely to be quite a few phl.pm folks there so you'll at least see a few friendly faces. Also, and this is very short notice, but phl.pm is having its November social meeting tonight. We're meeting for dinner at 7 PM at Rangoon, a Burmese restaurant at 112 N. 9th St in Philadelphia's Chinatown. Anyone who can make it down will be welcome. Walt ----- Forwarded message from "Michael C. Toren" ----- Date: Sun, 28 Nov 2004 22:45:56 -0500 From: "Michael C. Toren" To: plug-announce@phillylinux.org Subject: [PLUG] [plug-announce] "Internals of the qmail mail system" - December 1, 2004 /(_________________________________ / ( _____) _a'{ /__( The Philadelphia Area (_____|_______________________)\ `/\\/ __( Linux Users Group (PLUG) | ) \ (/ __( cordially invites you to | our next meeting, Wednesday )__\ }`a_ <_____(___________________________| December 1, 2004, at the )__ \//\' | University of the Sciences )__ \) |_____________________________)_____> The topic of this month's meeting is "Internals of the qmail mail system", presented by Mark Jason Dominus. The meeting will take place from 7-9PM, at: University of the Sciences in Philadelphia (USP) Griffith Hall C 600 South 43rd Street Philadelphia, PA 19104-4495 USP is located in University City. Driving directions are available at , or , both of which have an aerial view of the campus buildings. USP is also easily accessible by public transportation. There will be an open Question & Answer session at 7PM, prior to the main presentation at 8PM. This is an open meeting; all are welcome, and encouraged to attend. Usually, a number of members get together after the meeting at a nearby restaurant for food and perhaps a beer or two. Come join the camaraderie! _______________________________________________ plug-announce mailing list plug-announce@lists.phillylinux.org http://lists.netisland.net/mailman/listinfo/plug-announce ___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug ----- End forwarded message ----- From faber at linuxnj.com Mon Nov 29 17:17:14 2004 From: faber at linuxnj.com (Faber Fedor) Date: Mon Nov 29 17:17:16 2004 Subject: [ABE.pm] Accessing data in an array? Message-ID: <20041129231714.GA6678@uranus.faber.nom> Hi guys, I've got an array of...references? that looks like this: my @indices = ( { index=>"r1", weight=>"r1weight", cap=>"r1_mkt"} { index=>"r2", weight=>"r2weight", cap=>"r2_mkt"} { index=>"r3", weight=>"r3weight", cap=>"r3_mkt"} { index=>"rm", weight=>"rmweight", cap=>"rm_mkt" } ); What I've been doing is looping through them so I could get at the data like this: for(@indices) { print $_->{index} . "\t" . $_->{weight} . "\n"; } but now I need to access each internal reference(?) without looping. IOW, if I have $var = "r3", how do I access the array such that $indices->{weight}="r3weight"? -- Regards, Faber Linux New Jersey: Open Source Solutions for New Jersey http://www.linuxnj.com From rjbs-perl-abe at lists.manxome.org Mon Nov 29 17:24:49 2004 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Mon Nov 29 17:24:53 2004 Subject: [ABE.pm] Accessing data in an array? In-Reply-To: <20041129231714.GA6678@uranus.faber.nom> References: <20041129231714.GA6678@uranus.faber.nom> Message-ID: <20041129182449.G8950@manxome.org> * Faber Fedor [2004-11-29T18:17:14] > my @indices = ( { index=>"r1", weight=>"r1weight", cap=>"r1_mkt"} > { index=>"r2", weight=>"r2weight", cap=>"r2_mkt"} > { index=>"r3", weight=>"r3weight", cap=>"r3_mkt"} > { index=>"rm", weight=>"rmweight", cap=>"rm_mkt" } > ); > > What I've been doing is looping through them so I could get at the data > like this: > > for(@indices) { > print $_->{index} . "\t" . $_->{weight} . "\n"; > } > > but now I need to access each internal reference(?) without looping. > IOW, if I have $var = "r3", how do I access the array such that > $indices->{weight}="r3weight"? This question doesn't seem to make sense to me. If @indices is an array, you can never dereference it as a hash, as you are doing when you say $indices->{weight}. When you say C< for (@indices) > you are getting $_ set, each iteration, to the reference to a hash contained within the next element of the array @indices. Do you mean that you need to know the numerical index of the current iteration? I guess I need you to ask the question differently; maybe give a real-world example? -- 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/20041129/0e185b57/attachment.bin From rjbs-perl-abe at lists.manxome.org Tue Nov 30 10:45:42 2004 From: rjbs-perl-abe at lists.manxome.org (Ricardo SIGNES) Date: Tue Nov 30 10:45:44 2004 Subject: [ABE.pm] Re: Accessing data in an array? In-Reply-To: <20041130162417.GB5757@uranus.faber.nom> References: <20041129231714.GA6678@uranus.faber.nom> <20041129182449.G8950@manxome.org> <20041130162417.GB5757@uranus.faber.nom> Message-ID: <20041130114542.I8950@manxome.org> * Faber Fedor [2004-11-30T11:24:17] > > > > This question doesn't seem to make sense to me. If @indices is an > > array, you can never dereference it as a hash, as you are doing when you > > say $indices->{weight}. > > I kinda figured that and that's why I'm asking youse guys. :-) > > > When you say C< for (@indices) > you are getting $_ set, each iteration, > > to the reference to a hash contained within the next element of the > > array @indices. > > So this is an array of hashes, right? Every array is an array of scalars. The array you created was, too, and the scalars it contained were references to hashes. We'd often call this an "array of hashes" or "list of hashes" (or "LOH") but it's important that, before you call it by a close-enough name, you know the actual nature: it's an array of scalars, each of which is a hashref. > > Do you mean that you need to know the numerical index of the current > > iteration? I guess I need you to ask the question differently; maybe > > give a real-world example? > > What I've been doing is looping through the array and calling functions. > Because of the code (that I did NOT write), I am passing the value of > the index to a function. I need to access the other members of the hash > for that value. > > The only thing I've thought of so far is this pseudo-code: > > sub returnIndicesValues($) { > my ($index) = @_; > > for(@indices) { > return (weight, cap) if $_->{index} eq $index ; > } > } 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/ Also, don't mix tabs and spaces! Was that really your doing? 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. my %hash = ( 102 => { volume => 10, weight => 12 }, 103 => { volume => 9, weight => 91 }, 1 => { volume => 1, weight => 1 } ); 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. 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!) > sub foobar($) { Where "foobar" should be "print_entry" or something? Don't confuse me more than regular life already does! > > 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"; } 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); } -- 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/20041130/2bdd2a0e/attachment.bin