From arocker at vex.net Fri May 1 09:44:52 2009 From: arocker at vex.net (arocker at vex.net) Date: Fri, 1 May 2009 12:44:52 -0400 (EDT) Subject: [tpm] can't deliver a talk tomorrow night In-Reply-To: References: <5bef4baf0904290806u3fb06839h8f945fc90715b5e1@mail.gmail.com> <20090430052018.0c9d51f9@caliope> <49F9B8D7.3040103@softwareprocess.us> Message-ID: Considering the very short notice, I think we did rather well last night, (even if, as one of the presenters, I have a certain bias :-)* ). As usual, in the process of trying to explain something, I probably learnt more than the audience. (Thanks, Mike.) A discussion started about the relative performance of a subustr function and a regex for excising 8 bytes from a string. The difference turns out to be a factor of about 20 (38.5 cpu-seconds vs 1.86) in favour of the substr. However, on a 3Ghz Core Duo box, Benchmark required 10 million iterations to produce a reliable result, so I think it's safe to say it really doesn't matter in most plausible circumstances. From antoniosun001 at gmail.com Fri May 1 10:03:01 2009 From: antoniosun001 at gmail.com (Antonio Sun) Date: Fri, 1 May 2009 13:03:01 -0400 Subject: [tpm] Perl and Unicode Message-ID: Hi Abram, When you talked about the difficulties that Perl has calculating string lengths, I didn't quite understand your explanation because I didn't catch the term that you used. Could you explain it in writing please? AFAIK, how Perl interprets string length depends on encoding, E.g., use encoding utf8; print length("??"); # 2, because there are 2 Chinese characters # However, no encoding; print length("??"); # 6, the 2 Chinese characters take up 6 bytes. I.e., Perl has the capability to return whatever string length you want. Do I miss anything? BTW, Anyone knows how to split an Unicode string into individual characters? E.g., from "??" to '?' & '?'? Thanks Antonio -------------- next part -------------- An HTML attachment was scrubbed... URL: From antoniosun at lavabit.com Fri May 1 10:29:05 2009 From: antoniosun at lavabit.com (Antonio Sun) Date: Fri, 1 May 2009 13:29:05 -0400 Subject: [tpm] Fwd: Perl and Unicode In-Reply-To: References: Message-ID: Hi Abram, When you talked about the difficulties that Perl has calculating string lengths, I didn't quite understand your explanation because I didn't catch the term that you used. Could you explain it in writing please? AFAIK, how Perl interprets string length depends on encoding, E.g., use encoding utf8; print length("??"); # 2, because there are 2 Chinese characters # However, no encoding; print length("??"); # 6, the 2 Chinese characters take up 6 bytes. I.e., Perl has the capability to return whatever string length you want. Do I miss anything? BTW, Anyone knows how to split an Unicode string into individual characters? E.g., from "??" to '?' & '?'? Thanks Antonio -------------- next part -------------- An HTML attachment was scrubbed... URL: From Henry.Baragar at instantiated.ca Fri May 1 11:46:18 2009 From: Henry.Baragar at instantiated.ca (Henry Baragar) Date: Fri, 1 May 2009 14:46:18 -0400 Subject: [tpm] OID sorting Message-ID: <200905011446.19099.Henry.Baragar@instantiated.ca> Hello, There were a couple of suggestions for Fulko about how to improve his sorting of OID's (strings of the form ^\d+([.]\d+)*$). Attached is my suggestion for rebuilding the tree and walking the tree. I would be curious to see how this solution compares to the other solutions, both in terms of readability and performance. Regards, Henry -- Henry Baragar Instantiated Software 416-907-8454 x42 -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: oid_sort Type: application/x-perl Size: 1259 bytes Desc: not available URL: From abram.hindle at softwareprocess.us Fri May 1 11:47:55 2009 From: abram.hindle at softwareprocess.us (Abram Hindle) Date: Fri, 01 May 2009 14:47:55 -0400 Subject: [tpm] Perl and Unicode [do not read this from a terminal] In-Reply-To: (sfid-20090501_131405_671159_599CCA2E) References: (sfid-20090501_131405_671159_599CCA2E) Message-ID: <49FB43DB.2040708@softwareprocess.us> Hi, I did not mean perl in particular. I meant that it is hard to measure string lengths in unicode due to diacritics. It really depends what you mean by string length, whether you mean character, rendering length etc. Apologies to console users: ????????????????????????????a <-- see this character? depending on what you've got you'll get wildling different lengths: TCL says 29 Perl says 61, 29 with use utf8; echo -n ????????????????????????????a | perl -e 'print length(<>).$/' -> prints 61 Where as that character on my screen looks like 9 characters, thunderbird says it is 1. So unicode as a lot of rough edges, try pasting this into an irc channel on freenode and see how people react: ?????????????????????????????????????????????????????????????????????????????????????????????????????o abram Antonio Sun wrote: > Hi Abram, > > When you talked about the difficulties that Perl has calculating string > lengths, I didn't quite understand your explanation because I didn't catch > the term that you used. Could you explain it in writing please? > > AFAIK, how Perl interprets string length depends on encoding, E.g., > > use encoding utf8; > print length("??"); # 2, because there are 2 Chinese characters > # However, > no encoding; > print length("??"); # 6, the 2 Chinese characters take up 6 bytes. > > I.e., Perl has the capability to return whatever string length you want. Do > I miss anything? > > BTW, > > Anyone knows how to split an Unicode string into individual characters? > E.g., from "??" to '?' & '?'? > > Thanks > > Antonio > > > > ------------------------------------------------------------------------ > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 260 bytes Desc: OpenPGP digital signature URL: From uri at stemsystems.com Fri May 1 12:15:19 2009 From: uri at stemsystems.com (Uri Guttman) Date: Fri, 01 May 2009 15:15:19 -0400 Subject: [tpm] OID sorting In-Reply-To: <200905011446.19099.Henry.Baragar@instantiated.ca> (Henry Baragar's message of "Fri\, 1 May 2009 14\:46\:18 -0400") References: <200905011446.19099.Henry.Baragar@instantiated.ca> Message-ID: <87tz448wjc.fsf@quad.sysarch.com> >>>>> "HB" == Henry Baragar writes: HB> #! /usr/bin/perl -w use warnings is better these days. HB> use strict; HB> sub oid_tree_add { HB> my ($tree, $oid, $value) = @_; HB> my @oid = split /\b/, $oid; why are you splitting on \b? you could just split on /\./ and get the oid numbers. then you can simplify (and speed up) the code below. HB> _oid_node_add($tree,$value, at oid); HB> } HB> sub _oid_node_add { HB> my ($tree, $value, $key, @suboid) = @_; HB> die "Expecting integer, got '$key'" unless $key =~/^\d+/; HB> my $node = $tree->{$key}; HB> if (my $dot = shift @suboid) { HB> die "Expecting '.', got '$dot'" unless $dot eq "."; HB> $node->{subtree} = _oid_node_add($node->{subtree}, $value, @suboid); i won't get into detail here but if you split on . as i said above, you can just delete the check for dot. i can't see any reason to keep that logic. HB> } HB> else { HB> $node->{value} = $value; HB> } HB> $tree->{$key} = $node; i don't see $node being modified anywhere. you modify its keys/values but $node is still the same hashref. so that line probably could go. HB> $tree; use explicit return statements vs implicit last value returns. this is a bug waiting to happen if you ever add/modify code in that section. you may forget what was being returned and return some other expression. HB> } HB> sub oid_tree_sorted { HB> my ($tree) = @_; HB> my @sorted; HB> for my $key (sort {$a <=> $b} keys %$tree) { HB> my $node = $tree->{$key}; HB> push @sorted, $node->{value} if $node->{value}; HB> push @sorted, oid_tree_sorted($node->{subtree}) HB> if $node->{subtree}; if a node has a value it won't have a subtree. so you don't need the second test. in general you could have eliminated the need for the value/subtree keys and just used the value or hash ref. then you can tell if it is a value or tree node with ref(). it is a simpler and cleaner data tree design. again, i could be wrong in your details but this is a common design idea in perl. i leave the actual rewrite as an exercise as i am not up for it at the moment. :) thanx, uri -- Uri Guttman ------ uri at stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Free Perl Training --- http://perlhunter.com/college.html --------- --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- From Henry.Baragar at instantiated.ca Fri May 1 13:06:25 2009 From: Henry.Baragar at instantiated.ca (Henry Baragar) Date: Fri, 1 May 2009 16:06:25 -0400 Subject: [tpm] OID sorting In-Reply-To: <87tz448wjc.fsf@quad.sysarch.com> References: <200905011446.19099.Henry.Baragar@instantiated.ca> <87tz448wjc.fsf@quad.sysarch.com> Message-ID: <200905011606.25604.Henry.Baragar@instantiated.ca> On May 1, 2009 03:15:19 pm Uri Guttman wrote: > >>>>> "HB" == Henry Baragar writes: > > HB> #! /usr/bin/perl -w > > use warnings is better these days. > HB> use strict; > > HB> sub oid_tree_add { > HB> my ($tree, $oid, $value) = @_; > HB> my @oid = split /\b/, $oid; > > why are you splitting on \b? you could just split on /\./ and get the > oid numbers. then you can simplify (and speed up) the code below. > You are correct (the code evolved and I did not finish refactoring). See attached with this refactoring. > HB> _oid_node_add($tree,$value, at oid); > HB> } > > HB> sub _oid_node_add { > HB> my ($tree, $value, $key, @suboid) = @_; > HB> die "Expecting integer, got '$key'" unless $key =~/^\d+/; > HB> my $node = $tree->{$key}; > HB> if (my $dot = shift @suboid) { > HB> die "Expecting '.', got '$dot'" unless $dot eq "."; > HB> $node->{subtree} = _oid_node_add($node->{subtree}, $value, @suboid); > > i won't get into detail here but if you split on . as i said above, you > can just delete the check for dot. i can't see any reason to keep that > logic. > > HB> } > HB> else { > HB> $node->{value} = $value; > HB> } > HB> $tree->{$key} = $node; > > i don't see $node being modified anywhere. you modify its keys/values > but $node is still the same hashref. so that line probably could go. It simply reads better (IMHO). > HB> $tree; > > use explicit return statements vs implicit last value returns. this is a > bug waiting to happen if you ever add/modify code in that section. you > may forget what was being returned and return some other expression. > > HB> } > > HB> sub oid_tree_sorted { > HB> my ($tree) = @_; > HB> my @sorted; > HB> for my $key (sort {$a <=> $b} keys %$tree) { > HB> my $node = $tree->{$key}; > HB> push @sorted, $node->{value} if $node->{value}; > HB> push @sorted, oid_tree_sorted($node->{subtree}) > HB> if $node->{subtree}; > > if a node has a value it won't have a subtree. No, a node is allowed to have both (this is not a pure tree). > so you don't need the > second test. in general you could have eliminated the need for the > value/subtree keys and just used the value or hash ref. then you can > tell if it is a value or tree node with ref(). it is a simpler and > cleaner data tree design. again, i could be wrong in your details but > this is a common design idea in perl. > True, if you have a pure tree (which we don't) > i leave the actual rewrite as an exercise as i am not up for it at the > moment. :) > > thanx, > > uri Regards, Henry -- Henry Baragar Instantiated Software 416-907-8454 x42 -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: oid_sort Type: application/x-perl Size: 1212 bytes Desc: not available URL: From abram.hindle at softwareprocess.us Fri May 1 13:11:39 2009 From: abram.hindle at softwareprocess.us (Abram Hindle) Date: Fri, 01 May 2009 16:11:39 -0400 Subject: [tpm] OID sorting In-Reply-To: <87tz448wjc.fsf@quad.sysarch.com> (sfid-20090501_152107_109443_2F5EDB0A) References: <200905011446.19099.Henry.Baragar@instantiated.ca> <87tz448wjc.fsf@quad.sysarch.com> (sfid-20090501_152107_109443_2F5EDB0A) Message-ID: <49FB577B.3080203@softwareprocess.us> Here are my results: > Rate whilecmp henrys_oid_sort packsort swartzpacksort nounpacksort > > whilecmp 0.648/s -- -23% -81% -82% -82% > henrys_oid_sort 0.843/s 30% -- -75% -77% -77% > packsort 3.33/s 414% 295% -- -7% -9% > swartzpacksort 3.59/s 454% 326% 8% -- -2% > nounpacksort 3.66/s 466% 335% 10% 2% -- So the while loop comparison, with no transformation was the slowest. Followed by Henry's OID Tree Sort. Then my packsort, the swartzpacksort and unpacksort did the best. The parameters of the test were that 10000 entries were generated with with a maximum depth of 10 for each entry (e.g. 1.2.3. ... .10). Then we use benchmark to run for each sort routine this test 100 times. Now per each test NEW random data was created. So technically a sort could get a bad roll and get really nasty data to sort, or really easy to sort, but this happened 100 times. The while loop comparison sort just uses sort and uses a routine to compare arrays of numbers. It is just a while loop which chomps on an array til it finds something not equal. It could probably be sped up. henrys_oid_sort is the tree sort that henry posted, relatively unmodified. packsort, swartzpacksort, nounpacksort are sorts where I use pack to convert the numbers into bigendian representations then use cmp to compare the values. I use "pack('C*')" in this case because I said the max value of the integers would be 255. If it was large we'd use another unsigned big endian representation. These 3 sorts differ in how they are implemented, if their intermediate steps are assigned to values or if tuples are created or unpack is used. Currently using tuples seems faster than unpack. So henry might pipe up and say his sort could be faster if there was more depth per entity. Sure. So I reran it again, with 1000 entries, a maxdepth of 1000, and 10 tests per sort: > Rate whilecmp henrys_oid_sort packsort swartzpacksort nounpacksort > whilecmp 0.671/s -- -28% -79% -81% -82% > henrys_oid_sort 0.938/s 40% -- -71% -73% -74% > packsort 3.20/s 377% 241% -- -8% -13% > swartzpacksort 3.46/s 416% 269% 8% -- -6% > nounpacksort 3.67/s 447% 291% 15% 6% -- Similar results, except that Henry's sort shows about 10% better performance than while the other sorts have slightly worse performance. What does this tell us? Yet again relying on C implementations (pack, regexes, cmp etc.) provides better performance than the more perlish solutions. Also pack is faster than mucking around with data structures. Summary: Pack wins, henry's tree sort defeats array cmp. abram Uri Guttman wrote: >>>>>> "HB" == Henry Baragar writes: > > HB> #! /usr/bin/perl -w > > use warnings is better these days. > HB> use strict; > > HB> sub oid_tree_add { > HB> my ($tree, $oid, $value) = @_; > HB> my @oid = split /\b/, $oid; > > why are you splitting on \b? you could just split on /\./ and get the > oid numbers. then you can simplify (and speed up) the code below. > > HB> _oid_node_add($tree,$value, at oid); > HB> } > > HB> sub _oid_node_add { > HB> my ($tree, $value, $key, @suboid) = @_; > HB> die "Expecting integer, got '$key'" unless $key =~/^\d+/; > HB> my $node = $tree->{$key}; > HB> if (my $dot = shift @suboid) { > HB> die "Expecting '.', got '$dot'" unless $dot eq "."; > HB> $node->{subtree} = _oid_node_add($node->{subtree}, $value, @suboid); > > i won't get into detail here but if you split on . as i said above, you > can just delete the check for dot. i can't see any reason to keep that > logic. > > HB> } > HB> else { > HB> $node->{value} = $value; > HB> } > HB> $tree->{$key} = $node; > > i don't see $node being modified anywhere. you modify its keys/values > but $node is still the same hashref. so that line probably could go. > HB> $tree; > > use explicit return statements vs implicit last value returns. this is a > bug waiting to happen if you ever add/modify code in that section. you > may forget what was being returned and return some other expression. > > HB> } > > HB> sub oid_tree_sorted { > HB> my ($tree) = @_; > HB> my @sorted; > HB> for my $key (sort {$a <=> $b} keys %$tree) { > HB> my $node = $tree->{$key}; > HB> push @sorted, $node->{value} if $node->{value}; > HB> push @sorted, oid_tree_sorted($node->{subtree}) > HB> if $node->{subtree}; > > if a node has a value it won't have a subtree. so you don't need the > second test. in general you could have eliminated the need for the > value/subtree keys and just used the value or hash ref. then you can > tell if it is a value or tree node with ref(). it is a simpler and > cleaner data tree design. again, i could be wrong in your details but > this is a common design idea in perl. > > i leave the actual rewrite as an exercise as i am not up for it at the > moment. :) > > thanx, > > uri > -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 260 bytes Desc: OpenPGP digital signature URL: From abram.hindle at softwareprocess.us Fri May 1 13:15:33 2009 From: abram.hindle at softwareprocess.us (Abram Hindle) Date: Fri, 01 May 2009 16:15:33 -0400 Subject: [tpm] OID sorting In-Reply-To: <49FB577B.3080203@softwareprocess.us> (sfid-20090501_161414_357952_41A924EB) References: <200905011446.19099.Henry.Baragar@instantiated.ca> <87tz448wjc.fsf@quad.sysarch.com> (sfid-20090501_152107_109443_2F5EDB0A) <49FB577B.3080203@softwareprocess.us> (sfid-20090501_161414_357952_41A924EB) Message-ID: <49FB5865.1070902@softwareprocess.us> Here is the code. Sorry. abram Abram Hindle wrote: > Here are my results: > >> Rate whilecmp henrys_oid_sort packsort swartzpacksort nounpacksort >> >> whilecmp 0.648/s -- -23% -81% -82% -82% >> henrys_oid_sort 0.843/s 30% -- -75% -77% -77% >> packsort 3.33/s 414% 295% -- -7% -9% >> swartzpacksort 3.59/s 454% 326% 8% -- -2% >> nounpacksort 3.66/s 466% 335% 10% 2% -- > > So the while loop comparison, with no transformation was the slowest. > Followed by Henry's OID Tree Sort. > Then my packsort, the swartzpacksort and unpacksort did the best. > > The parameters of the test were that 10000 entries were generated with > with a maximum depth of 10 for each entry (e.g. 1.2.3. ... .10). Then we > use benchmark to run for each sort routine this test 100 times. Now per > each test NEW random data was created. So technically a sort could get a > bad roll and get really nasty data to sort, or really easy to sort, but > this happened 100 times. > > The while loop comparison sort just uses sort and uses a routine to > compare arrays of numbers. It is just a while loop which chomps on an > array til it finds something not equal. It could probably be sped up. > > henrys_oid_sort is the tree sort that henry posted, relatively unmodified. > > packsort, swartzpacksort, nounpacksort are sorts where I use pack to > convert the numbers into bigendian representations then use cmp to > compare the values. I use "pack('C*')" in this case because I said the > max value of the integers would be 255. If it was large we'd use another > unsigned big endian representation. These 3 sorts differ in how they are > implemented, if their intermediate steps are assigned to values or if > tuples are created or unpack is used. Currently using tuples seems > faster than unpack. > > So henry might pipe up and say his sort could be faster if there was > more depth per entity. Sure. So I reran it again, with 1000 entries, a > maxdepth of 1000, and 10 tests per sort: > >> Rate whilecmp henrys_oid_sort packsort swartzpacksort nounpacksort >> whilecmp 0.671/s -- -28% -79% -81% -82% >> henrys_oid_sort 0.938/s 40% -- -71% -73% -74% >> packsort 3.20/s 377% 241% -- -8% -13% >> swartzpacksort 3.46/s 416% 269% 8% -- -6% >> nounpacksort 3.67/s 447% 291% 15% 6% -- > > Similar results, except that Henry's sort shows about 10% better > performance than while the other sorts have slightly worse performance. > > What does this tell us? Yet again relying on C implementations (pack, > regexes, cmp etc.) provides better performance than the more perlish > solutions. Also pack is faster than mucking around with data structures. > > Summary: Pack wins, henry's tree sort defeats array cmp. > > abram > > Uri Guttman wrote: >>>>>>> "HB" == Henry Baragar writes: >> HB> #! /usr/bin/perl -w >> >> use warnings is better these days. >> HB> use strict; >> >> HB> sub oid_tree_add { >> HB> my ($tree, $oid, $value) = @_; >> HB> my @oid = split /\b/, $oid; >> >> why are you splitting on \b? you could just split on /\./ and get the >> oid numbers. then you can simplify (and speed up) the code below. >> >> HB> _oid_node_add($tree,$value, at oid); >> HB> } >> >> HB> sub _oid_node_add { >> HB> my ($tree, $value, $key, @suboid) = @_; >> HB> die "Expecting integer, got '$key'" unless $key =~/^\d+/; >> HB> my $node = $tree->{$key}; >> HB> if (my $dot = shift @suboid) { >> HB> die "Expecting '.', got '$dot'" unless $dot eq "."; >> HB> $node->{subtree} = _oid_node_add($node->{subtree}, $value, @suboid); >> >> i won't get into detail here but if you split on . as i said above, you >> can just delete the check for dot. i can't see any reason to keep that >> logic. >> >> HB> } >> HB> else { >> HB> $node->{value} = $value; >> HB> } >> HB> $tree->{$key} = $node; >> >> i don't see $node being modified anywhere. you modify its keys/values >> but $node is still the same hashref. so that line probably could go. >> HB> $tree; >> >> use explicit return statements vs implicit last value returns. this is a >> bug waiting to happen if you ever add/modify code in that section. you >> may forget what was being returned and return some other expression. >> >> HB> } >> >> HB> sub oid_tree_sorted { >> HB> my ($tree) = @_; >> HB> my @sorted; >> HB> for my $key (sort {$a <=> $b} keys %$tree) { >> HB> my $node = $tree->{$key}; >> HB> push @sorted, $node->{value} if $node->{value}; >> HB> push @sorted, oid_tree_sorted($node->{subtree}) >> HB> if $node->{subtree}; >> >> if a node has a value it won't have a subtree. so you don't need the >> second test. in general you could have eliminated the need for the >> value/subtree keys and just used the value or hash ref. then you can >> tell if it is a value or tree node with ref(). it is a simpler and >> cleaner data tree design. again, i could be wrong in your details but >> this is a common design idea in perl. >> >> i leave the actual rewrite as an exercise as i am not up for it at the >> moment. :) >> >> thanx, >> >> uri >> > > > > ------------------------------------------------------------------------ > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm -------------- next part -------------- A non-text attachment was scrubbed... Name: fulko.pl Type: application/x-perl Size: 4658 bytes Desc: not available URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 260 bytes Desc: OpenPGP digital signature URL: From uri at stemsystems.com Fri May 1 13:30:51 2009 From: uri at stemsystems.com (Uri Guttman) Date: Fri, 01 May 2009 16:30:51 -0400 Subject: [tpm] OID sorting In-Reply-To: <49FB5865.1070902@softwareprocess.us> (Abram Hindle's message of "Fri\, 01 May 2009 16\:15\:33 -0400") References: <200905011446.19099.Henry.Baragar@instantiated.ca> <87tz448wjc.fsf@quad.sysarch.com> <49FB577B.3080203@softwareprocess.us> <49FB5865.1070902@softwareprocess.us> Message-ID: <87y6tg7eh0.fsf@quad.sysarch.com> >>>>> "AH" == Abram Hindle writes: some comments on the packed sort. i haven't seen this code before. AH> #sort via cmp and packing AH> sub packsort { AH> #this is just a longform swartzian transform AH> my @packed = map { pack("${pack}*",@$_) } @_; AH> @packed == @_ or die "Packed and Data not same size"; why the check for data sizes each time? this is overhead that will kill the speed. if the sort works, the data will be fine. AH> my @sortedpacked = sort { $a cmp $b} @packed; no need for the explicit cmp op as string compare is the default for sort. i think recent perls do optimize this away but it isn't needed anyway. AH> @sortedpacked == @_ or die "SortedPacked and Data not same size"; AH> my @sorted = map { [ unpack("${pack}*",$_) ] } @sortedpacked; AH> return @sorted why don't you do this like you do the schwartzian, as one long expression? the extra vars and size tests are slowing it down quite a bit IMO. this is an untested rewrite as a single expression: sub packsort { return map [ unpack( "$pack*", $_ ) ], sort map pack( "$pack*", @{$_} ), @_ ; } IMO it is much easier to read. i removed some noise but added whitespace too. and you can generate several different sort styles with my Sort::Maker module including a packed sort (called the GRT). AH> sub swartzpacksort { his name is spelled schwartz! :) and it isn't a packed sort as the intermediate values are in anon arrays. thanx, uri -- Uri Guttman ------ uri at stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Free Perl Training --- http://perlhunter.com/college.html --------- --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- From Henry.Baragar at instantiated.ca Fri May 1 13:38:30 2009 From: Henry.Baragar at instantiated.ca (Henry Baragar) Date: Fri, 1 May 2009 16:38:30 -0400 Subject: [tpm] OID sorting In-Reply-To: <87y6tg7eh0.fsf@quad.sysarch.com> References: <200905011446.19099.Henry.Baragar@instantiated.ca> <49FB5865.1070902@softwareprocess.us> <87y6tg7eh0.fsf@quad.sysarch.com> Message-ID: <200905011638.30497.Henry.Baragar@instantiated.ca> On May 1, 2009 04:30:51 pm Uri Guttman wrote: > AH> my @sortedpacked = sort { $a cmp $b} @packed; > > no need for the explicit cmp op as string compare is the default for > sort. i think recent perls do optimize this away but it isn't needed > anyway. I one of the issues from last night was that a numeric comparison was required (not a string one). That is "3" should precede "13". Regards, Henry -- Henry Baragar Instantiated Software 416-907-8454 x42 -------------- next part -------------- An HTML attachment was scrubbed... URL: From antoniosun at lavabit.com Fri May 1 13:43:52 2009 From: antoniosun at lavabit.com (Antonio Sun) Date: Fri, 1 May 2009 16:43:52 -0400 Subject: [tpm] Perl and Unicode [do not read this from a terminal] In-Reply-To: <49FB43DB.2040708@softwareprocess.us> References: <49FB43DB.2040708@softwareprocess.us> Message-ID: Thanks a lot for clarification, Abram. BTW, Anyone knows how to split an Unicode string into individual characters with Perl? E.g., from "??" to '?' & '?'? Thanks On Fri, May 1, 2009 at 2:47 PM, Abram Hindle < abram.hindle at softwareprocess.us> wrote: > Hi, > > I did not mean perl in particular. I meant that it is hard to measure > string lengths in unicode due to diacritics. It really depends what you > mean by string length, whether you mean character, rendering length etc. . > . > -------------- next part -------------- An HTML attachment was scrubbed... URL: From uri at stemsystems.com Fri May 1 13:46:29 2009 From: uri at stemsystems.com (Uri Guttman) Date: Fri, 01 May 2009 16:46:29 -0400 Subject: [tpm] OID sorting In-Reply-To: <200905011638.30497.Henry.Baragar@instantiated.ca> (Henry Baragar's message of "Fri\, 1 May 2009 16\:38\:30 -0400") References: <200905011446.19099.Henry.Baragar@instantiated.ca> <49FB5865.1070902@softwareprocess.us> <87y6tg7eh0.fsf@quad.sysarch.com> <200905011638.30497.Henry.Baragar@instantiated.ca> Message-ID: <87eiv87dqy.fsf@quad.sysarch.com> >>>>> "HB" == Henry Baragar writes: HB> On May 1, 2009 04:30:51 pm Uri Guttman wrote: >> ? AH> ??my @sortedpacked = sort { $a cmp $b} @packed; >> >> no need for the explicit cmp op as string compare is the default for >> sort. i think recent perls do optimize this away but it isn't needed >> anyway. HB> I one of the issues from last night was that a numeric comparison was required HB> (not a string one). That is "3" should precede "13". that makes sense but the code showed string comparisons in the schwartzian too. the packed sort always uses string compares as the packed values are strings. you handle numeric comparisons by doing the proper packing (small values into bytes, etc.). again, sort::maker handles all of this for you. uri -- Uri Guttman ------ uri at stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Free Perl Training --- http://perlhunter.com/college.html --------- --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- From mike at stok.ca Fri May 1 13:58:43 2009 From: mike at stok.ca (Mike Stok) Date: Fri, 1 May 2009 16:58:43 -0400 Subject: [tpm] Fwd: Perl and Unicode In-Reply-To: References: Message-ID: On May 1, 2009, at 1:29 PM, Antonio Sun wrote: > Hi Abram, > > When you talked about the difficulties that Perl has calculating > string > lengths, I didn't quite understand your explanation because I didn't > catch > the term that you used. Could you explain it in writing please? > > AFAIK, how Perl interprets string length depends on encoding, E.g., > > use encoding utf8; > print length("??"); # 2, because there are 2 Chinese characters > # However, > no encoding; > print length("??"); # 6, the 2 Chinese characters take up 6 bytes. > > I.e., Perl has the capability to return whatever string length you > want. Do I miss anything? > > BTW, > > Anyone knows how to split an Unicode string into individual > characters? E.g., from "??" to '?' & '?'? There has to be a better way than this: DB<7> @chars = map { chr } unpack('U*', "??") DB<8> x @chars 0 '\x{9A86}' 1 '\x{9A7C}' DB<9> print "@chars" ? ? DB<10> Mike > Thanks > > Antonio > > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm -- Mike Stok http://www.stok.ca/~mike/ The "`Stok' disclaimers" apply. -------------- next part -------------- An HTML attachment was scrubbed... URL: From liam at holoweb.net Fri May 1 14:21:25 2009 From: liam at holoweb.net (Liam R E Quin) Date: Fri, 01 May 2009 17:21:25 -0400 Subject: [tpm] Perl and Unicode [do not read this from a terminal] In-Reply-To: References: <49FB43DB.2040708@softwareprocess.us> Message-ID: <1241212885.18699.2664.camel@desktop.barefootcomputing.com> On Fri, 2009-05-01 at 16:43 -0400, Antonio Sun wrote: > Thanks a lot for clarification, Abram. > > BTW, > > Anyone knows how to split an Unicode string into individual characters > with Perl? E.g., from "??" to '?' & '?'? #! /usr/bin/perl -w use strict; use utf8; binmode(STDOUT, ":utf8"); my $input = "??"; print join("<->", split(//, $input)), "\n"; -- Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/ Pictures from old books: http://fromoldbooks.org/ Ankh: irc.sorcery.net irc.gnome.org www.advogato.org From antoniosun at lavabit.com Fri May 1 15:17:20 2009 From: antoniosun at lavabit.com (Antonio Sun) Date: Fri, 1 May 2009 18:17:20 -0400 Subject: [tpm] Fwd: Perl and Unicode In-Reply-To: References: Message-ID: Thanks a lot Mike & Liam for the replies. 2009/5/1 Mike Stok > > Anyone knows how to split an Unicode string into individual characters? > E.g., from "??" to '?' & '?'? > > So both unpack 'U*' and split // work. I should have thought that split // would work on Unicode too. > There has to be a better way than this: > > DB<7> @chars = map { chr } unpack('U*', "??") > this teaches me that to pack back 'unpack' is not 'pack' but 'chr'. :-) BTW, "??" means camel in Chinese. cheers -------------- next part -------------- An HTML attachment was scrubbed... URL: From indy at indigostar.com Sat May 2 06:57:57 2009 From: indy at indigostar.com (Indy Singh) Date: Sat, 2 May 2009 09:57:57 -0400 Subject: [tpm] OID sorting References: <200905011446.19099.Henry.Baragar@instantiated.ca> Message-ID: <99923D4218B84137ADA46DF8CA53DA08@ROADKILL> Just trying to understand the problem to be solved. Why does this key and value not match? Is it a typo? In the real application is the key meant to be an OID and the value just some value that we don't cate about? ARe you trying to sort by the hash keys or hash values? "1.2.4.1" => "1.2.4", Indy Singh IndigoSTAR Software -- www.indigostar.com ----- Original Message ----- From: Henry Baragar To: Toronto Perl Mongers Sent: Friday, May 01, 2009 2:46 PM Subject: [tpm] OID sorting Hello, There were a couple of suggestions for Fulko about how to improve his sorting of OID's (strings of the form ^\d+([.]\d+)*$). Attached is my suggestion for rebuilding the tree and walking the tree. I would be curious to see how this solution compares to the other solutions, both in terms of readability and performance. Regards, Henry -- Henry Baragar Instantiated Software 416-907-8454 x42 ------------------------------------------------------------------------------ _______________________________________________ toronto-pm mailing list toronto-pm at pm.org http://mail.pm.org/mailman/listinfo/toronto-pm -------------- next part -------------- An HTML attachment was scrubbed... URL: From indy at indigostar.com Sat May 2 08:58:15 2009 From: indy at indigostar.com (Indy Singh) Date: Sat, 2 May 2009 11:58:15 -0400 Subject: [tpm] OID sorting References: <200905011446.19099.Henry.Baragar@instantiated.ca> Message-ID: <7C9C1C02AF9A46B09F941A93A7E50E18@ROADKILL> Without a real description of the problem, here is my attempt. I used a simple scalar representation of data instead of a tree. If someone would care to do a time comparison, I would be curious to see the results. #!/usr/bin/perl use strict; use warnings; my @list = ( "1.3", "1.2.3", "1.2.3.1", "1.2.4.1", "1.2.30", "1", "1.2", ); # The expected sort order is the same as the order above sub byoid { # convert dot seperated oid digits into a packed character string # suitable for string comparison, e.g. '65.66.67' => 'ABC' my $x; $x .= pack('C', $_) foreach (split(/\./, $a)); my $y; $y .= pack('C', $_) foreach (split(/\./, $b)); return ($x cmp $y); } my @sorted = sort byoid @list; print "Sorted list:\n", join("\n", @sorted), "\n"; sub byoid_slower_more_readable_version { # convert dot seperated oid digits into digits with leading 0's # suitable for string comparison, e.g. '1.2.3' => '001002003' my $x; $x .= sprintf('%03d', $_) foreach (split(/\./, $a)); my $y; $y .= sprintf('%03d', $_) foreach (split(/\./, $b)); return ($x cmp $y); } Indy Singh IndigoSTAR Software -- www.indigostar.com ----- Original Message ----- From: Henry Baragar To: Toronto Perl Mongers Sent: Friday, May 01, 2009 2:46 PM Subject: [tpm] OID sorting Hello, There were a couple of suggestions for Fulko about how to improve his sorting of OID's (strings of the form ^\d+([.]\d+)*$). Attached is my suggestion for rebuilding the tree and walking the tree. I would be curious to see how this solution compares to the other solutions, both in terms of readability and performance. Regards, Henry -- Henry Baragar Instantiated Software 416-907-8454 x42 ------------------------------------------------------------------------------ _______________________________________________ toronto-pm mailing list toronto-pm at pm.org http://mail.pm.org/mailman/listinfo/toronto-pm -------------- next part -------------- An HTML attachment was scrubbed... URL: From fulko.hew at gmail.com Sat May 2 09:05:07 2009 From: fulko.hew at gmail.com (Fulko Hew) Date: Sat, 2 May 2009 12:05:07 -0400 Subject: [tpm] OID sorting In-Reply-To: <7C9C1C02AF9A46B09F941A93A7E50E18@ROADKILL> References: <200905011446.19099.Henry.Baragar@instantiated.ca> <7C9C1C02AF9A46B09F941A93A7E50E18@ROADKILL> Message-ID: <8204a4fe0905020905k5293727ciea1554755340aa47@mail.gmail.com> On Sat, May 2, 2009 at 11:58 AM, Indy Singh wrote: ... snip... > my @list = ( > "1.3", > "1.2.3", > "1.2.3.1", > "1.2.4.1", > "1.2.30", > "1", > "1.2", > ); > # The expected sort order is the same as the order above > The expected order for the above set is: 1 1.2 1.2.3 1.2.3.1 1.2.4.1 1.2.30 1.3 -------------- next part -------------- An HTML attachment was scrubbed... URL: From indy at indigostar.com Sat May 2 09:24:55 2009 From: indy at indigostar.com (Indy Singh) Date: Sat, 2 May 2009 12:24:55 -0400 Subject: [tpm] OID sorting References: <200905011446.19099.Henry.Baragar@instantiated.ca> <7C9C1C02AF9A46B09F941A93A7E50E18@ROADKILL> <8204a4fe0905020905k5293727ciea1554755340aa47@mail.gmail.com> Message-ID: Thanks, I stand corrected. The comment was wrong, but the code works. Indy Singh IndigoSTAR Software -- www.indigostar.com ----- Original Message ----- From: Fulko Hew To: Indy Singh Cc: Toronto Perl Mongers Sent: Saturday, May 02, 2009 12:05 PM Subject: Re: [tpm] OID sorting On Sat, May 2, 2009 at 11:58 AM, Indy Singh wrote: ... snip... my @list = ( "1.3", "1.2.3", "1.2.3.1", "1.2.4.1", "1.2.30", "1", "1.2", ); # The expected sort order is the same as the order above The expected order for the above set is: 1 1.2 1.2.3 1.2.3.1 1.2.4.1 1.2.30 1.3 -------------- next part -------------- An HTML attachment was scrubbed... URL: From fulko.hew at gmail.com Sat May 2 18:40:35 2009 From: fulko.hew at gmail.com (Fulko Hew) Date: Sat, 2 May 2009 21:40:35 -0400 Subject: [tpm] OID sorting In-Reply-To: References: <200905011446.19099.Henry.Baragar@instantiated.ca> <7C9C1C02AF9A46B09F941A93A7E50E18@ROADKILL> <8204a4fe0905020905k5293727ciea1554755340aa47@mail.gmail.com> Message-ID: <8204a4fe0905021840p88c6764gc70b99a2d9b96be8@mail.gmail.com> Thanks all for your ideas. I've coalesced the various suggestions (excluding Uri's comments so far) and present for your amusement, the following results based on my 'real-world' dataset of 24,528 OID strings. s/iter abram_whilecmp 7.30 -- indy_slow_sort 7.11 3% indy_fast_sort 6.53 12% henrys_sort 5.06 44% fulko_sort_optimized 1.77 314% fulko_sort_orig 1.72 323% abram_swartzpacksort 1.60 357% abram_packsort 1.48 392% abram_nounpacksort 0.96 660% Note: I had to alter Indy's 'slow' compare because %3d is not large enough for real data. The numbers can range from 0 to 4 Gig. This also means that Indy's fast compare won't work either. As it turns out, my original code doesn't appear to be all that bad after all. But as I went through and thought I was optimizing it with maps and stuff, it actually gets worse. Both my original code, and my optimized version is provided below for peer review. In the mean time, I may just investigate the 'nounpacksort' version. sub fulko_sort_orig { my @oids = @_; my ($i, @r1, $temp); my $len = scalar(@oids); for ($i = 0; $i < $len; $i++) { $temp = ''; @r1 = split(/\./, $oids[$i]); foreach (@r1) { $temp .= sprintf ("%8d.", $_); } chop($temp); $oids[$i] = $temp; } @oids = sort @oids; for ($i = 0; $i < $len; $i++) { $oids[$i] =~ s/ //g; } @oids; } sub fulko_sort_optimized { my @oids = sort map { join ".", map { sprintf ("%8d", $_); } split /\./; } @_; for (my $i = 0; $i < scalar(@oids); $i++) { $oids[$i] =~ s/ //g; } @oids; } -------------- next part -------------- An HTML attachment was scrubbed... URL: From vvp at cogeco.ca Sat May 2 20:17:12 2009 From: vvp at cogeco.ca (Viktor Pavlenko) Date: Sat, 2 May 2009 23:17:12 -0400 Subject: [tpm] OID sorting In-Reply-To: <8204a4fe0905020905k5293727ciea1554755340aa47@mail.gmail.com> References: <200905011446.19099.Henry.Baragar@instantiated.ca> <7C9C1C02AF9A46B09F941A93A7E50E18@ROADKILL> <8204a4fe0905020905k5293727ciea1554755340aa47@mail.gmail.com> Message-ID: <18941.3256.772493.245880@hetman.ua> >>>>> "FH" == Fulko Hew writes: >> my @list = ( >> "1.3", >> "1.2.3", >> "1.2.3.1", >> "1.2.4.1", >> "1.2.30", >> "1", >> "1.2", >> ); >> # The expected sort order is the same as the order above >> FH> The expected order for the above set is: FH> 1 FH> 1.2 FH> 1.2.3 FH> 1.2.3.1 FH> 1.2.4.1 FH> 1.2.30 FH> 1.3 Following the KISS directive: ----------------------------------------------------------------->8 #!/usr/bin/perl -wl use strict; $, = "\n"; my @list = ( "1.3", "1.2.3", "1.2.3.1", "1.2.4.1", "1.2.30", "1", "1.2", ); sub srt { my ($a1, $a2) = map { [ split /\./ ] } @_; for (my $i = 0; $i <= $#$a1; ++$i) { return 1 unless defined $a2->[$i]; return $a1->[$i] <=> $a2->[$i] unless $a1->[$i] == $a2->[$i]; } return 0; } print sort { srt($a, $b) } @list, "\n"; ----------------------------------------------------------------->8 -- Viktor From vvp at cogeco.ca Sat May 2 20:49:44 2009 From: vvp at cogeco.ca (Viktor Pavlenko) Date: Sat, 2 May 2009 23:49:44 -0400 Subject: [tpm] OID sorting In-Reply-To: <18941.3256.772493.245880@hetman.ua> References: <200905011446.19099.Henry.Baragar@instantiated.ca> <7C9C1C02AF9A46B09F941A93A7E50E18@ROADKILL> <8204a4fe0905020905k5293727ciea1554755340aa47@mail.gmail.com> <18941.3256.772493.245880@hetman.ua> Message-ID: <18941.5208.890195.164354@hetman.ua> VP> print sort { srt($a, $b) } @list, "\n"; Argh, remove that last "\n". -- Viktor From uri at stemsystems.com Sat May 2 20:45:42 2009 From: uri at stemsystems.com (Uri Guttman) Date: Sat, 02 May 2009 23:45:42 -0400 Subject: [tpm] OID sorting In-Reply-To: <8204a4fe0905021840p88c6764gc70b99a2d9b96be8@mail.gmail.com> (Fulko Hew's message of "Sat\, 2 May 2009 21\:40\:35 -0400") References: <200905011446.19099.Henry.Baragar@instantiated.ca> <7C9C1C02AF9A46B09F941A93A7E50E18@ROADKILL> <8204a4fe0905020905k5293727ciea1554755340aa47@mail.gmail.com> <8204a4fe0905021840p88c6764gc70b99a2d9b96be8@mail.gmail.com> Message-ID: <87d4aq3l3t.fsf@quad.sysarch.com> >>>>> "FH" == Fulko Hew writes: FH> I've coalesced the various suggestions (excluding Uri's comments so far) /me feels so hurt!! no more perl help for hew!! :) uri -- Uri Guttman ------ uri at stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Free Perl Training --- http://perlhunter.com/college.html --------- --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- From uri at stemsystems.com Sat May 2 20:58:31 2009 From: uri at stemsystems.com (Uri Guttman) Date: Sat, 02 May 2009 23:58:31 -0400 Subject: [tpm] OID sorting In-Reply-To: <8204a4fe0905021840p88c6764gc70b99a2d9b96be8@mail.gmail.com> (Fulko Hew's message of "Sat\, 2 May 2009 21\:40\:35 -0400") References: <200905011446.19099.Henry.Baragar@instantiated.ca> <7C9C1C02AF9A46B09F941A93A7E50E18@ROADKILL> <8204a4fe0905020905k5293727ciea1554755340aa47@mail.gmail.com> <8204a4fe0905021840p88c6764gc70b99a2d9b96be8@mail.gmail.com> Message-ID: <878wle3kig.fsf@quad.sysarch.com> >>>>> "FH" == Fulko Hew writes: i couldn't resist! FH> sub fulko_sort_optimized { FH> ??? my @oids = sort FH> ??????????????? map { join ".", FH> ??????????????????? map { sprintf ("%8d", $_); } split /\./; FH> ??????????????? } @_; that is a form of packed sort. you just pad each oid to 8 chars with leading blanks. FH> ??? for (my $i = 0; $i < scalar(@oids); $i++) { FH> ??????? $oids[$i] =~ s/ //g; FH> ??? } blech! i hate useless c for loops. actually i hate seeing c for loops in perl in general. they are so rarely needed. and i mean rare as in maybe 10 in 10k lines of code. s/ //g for oids ; and for good measure this may work using the same logic: s/(\d+)/sprintf( '%8s', $1 )/ge for oids ; @oids = sort @oids ; s/ //g for oids ; return @oids ; that is a lot cleaner and easier to read. if there was a decent way for map and s/// to return the modified string and not the result of s/// it would be easy in one expression. this is the way it can work now: return map { s/ //g ; $_ } sort map { s/(\d+)/sprintf( '%8s', $1 )/ge ; $_ } @_ ; note that i use %8s as there is no need to convert any oid part to an integer. that should be a bit faster too. also if the data size is large enough, the first version which mungs @oids directly may be faster than the map version which has to allocate large temp lists. hell, it may be faster for small sets too. you should benchmark these as well. uri -- Uri Guttman ------ uri at stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Free Perl Training --- http://perlhunter.com/college.html --------- --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- From uri at stemsystems.com Sat May 2 21:01:28 2009 From: uri at stemsystems.com (Uri Guttman) Date: Sun, 03 May 2009 00:01:28 -0400 Subject: [tpm] OID sorting In-Reply-To: <18941.3256.772493.245880@hetman.ua> (Viktor Pavlenko's message of "Sat\, 2 May 2009 23\:17\:12 -0400") References: <200905011446.19099.Henry.Baragar@instantiated.ca> <7C9C1C02AF9A46B09F941A93A7E50E18@ROADKILL> <8204a4fe0905020905k5293727ciea1554755340aa47@mail.gmail.com> <18941.3256.772493.245880@hetman.ua> Message-ID: <874ow23kdj.fsf@quad.sysarch.com> >>>>> "VP" == Viktor Pavlenko writes: VP> Following the KISS directive: keep it simple and SLOW?? :) VP> sub srt VP> { VP> my ($a1, $a2) = map { [ split /\./ ] } @_; VP> for (my $i = 0; $i <= $#$a1; ++$i) { VP> return 1 unless defined $a2->[$i]; VP> return $a1->[$i] <=> $a2->[$i] unless $a1->[$i] == $a2->[$i]; VP> } VP> return 0; VP> } VP> print sort { srt($a, $b) } @list, "\n"; you are doing ALL the heavy work inside the sort comparison. that is O( N log N ) whereas with the map/sort/maps the heavy work is O( N ). simple is not necessarily better. a bubble sort is the simplest sort logic but never used on data set sizes above a few dozen. uri -- Uri Guttman ------ uri at stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Free Perl Training --- http://perlhunter.com/college.html --------- --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- From fulko.hew at gmail.com Wed May 6 09:06:51 2009 From: fulko.hew at gmail.com (Fulko Hew) Date: Wed, 6 May 2009 12:06:51 -0400 Subject: [tpm] OID sorting In-Reply-To: <874ow23kdj.fsf@quad.sysarch.com> References: <200905011446.19099.Henry.Baragar@instantiated.ca> <7C9C1C02AF9A46B09F941A93A7E50E18@ROADKILL> <8204a4fe0905020905k5293727ciea1554755340aa47@mail.gmail.com> <18941.3256.772493.245880@hetman.ua> <874ow23kdj.fsf@quad.sysarch.com> Message-ID: <8204a4fe0905060906h417c6596t9b10e8980aa69d93@mail.gmail.com> I just thought I'd follow up on the discussion I started last week. (Thanks to all who participated!) Attached is my current version of the test harness based on Abram's work, and most if not all supplied routines and suggestions (even your's Uri, now that I had the time to look!) My conclusions: 1/ Abram's 'nounpacksort' was the most efficient. 2/ Uri's rehash of my original code wins as the most readable. (I know it had ugly 'C' constructs, but I couldn't think of a better more Perl'ish way (see bonus points below)) 3/ My original code wasn't all that bad :-) 4/ Adding the tuple idea yields noticeable improvements. Uri also gets bonus points for showing me that I could do this kind of in-place substitution... on a list: s/ //g foreach @oids; Uri also gets extra bonus points for teaching me to use regex's with embedded code. I always knew it could be done but never spent the time to learn it, nor recognize when it would be useful. Now (dammit), thanks to Uri, I know. s/(\d+)/sprintf('%8s', $1)/ge foreach @oids; And oh yes... printing the 'number as a string' _is_ faster than printing a 'number as a number'! Here's the benchmark results: s/iter Improvement abram_whilecmp 7.05 -- indy_slow_sort 6.89 2% henrys_sort 5.52 28% fulko_sort_uri 1.79 294% fulko_sort_orig 1.77 299% abram_swartzpacksort 1.55 356% abram_packsort 1.41 400% fulko_sort 1.14 519% abram_nounpacksort 0.905 679% Oh... another thing I learned... When running benchmarks... turn off Centrino auto-CPU-speed-mechanism! I was having a hell of a time trying to figure out why my results were always all over the map. :-( Finally, for those who want to see the (current) winners, without having to look at the attachment, they are: For Readability: sub fulko_sort_uri { my @oids = @_; s/(\d+)/sprintf('%8s', $1)/ge foreach @oids; @oids = sort @oids; s/ //g foreach @oids; return @oids; } For Fastest: sub abram_nounpacksort { my @data = map { [ split(/\./, $_) ] } @_; my @sorted = map { $_->[1] } sort { $a->[0] cmp $b->[0] } map { [pack("N*",@$_),$_] } @data; @sorted = map { join(".",@$_) } @sorted; return @sorted; } -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: fulko.pl Type: application/x-perl Size: 6389 bytes Desc: not available URL: From john at perlwolf.com Wed May 6 10:15:39 2009 From: john at perlwolf.com (John Macdonald) Date: Wed, 6 May 2009 13:15:39 -0400 Subject: [tpm] OID sorting In-Reply-To: <8204a4fe0905060906h417c6596t9b10e8980aa69d93@mail.gmail.com> References: <200905011446.19099.Henry.Baragar@instantiated.ca> <7C9C1C02AF9A46B09F941A93A7E50E18@ROADKILL> <8204a4fe0905020905k5293727ciea1554755340aa47@mail.gmail.com> <18941.3256.772493.245880@hetman.ua> <874ow23kdj.fsf@quad.sysarch.com> <8204a4fe0905060906h417c6596t9b10e8980aa69d93@mail.gmail.com> Message-ID: <20090506171539.GC3924@perlwolf.com> On Wed, May 06, 2009 at 12:06:51PM -0400, Fulko Hew wrote: > I just thought I'd follow up on the discussion I started last week. > (Thanks to all who participated!) > > Attached is my current version of the test harness based on > Abram's work, and most if not all supplied routines and > suggestions (even your's Uri, now that I had the time to > look!) > > My conclusions: > > 1/ Abram's 'nounpacksort' was the most efficient. > 2/ Uri's rehash of my original code wins as the most readable. > (I know it had ugly 'C' constructs, but I couldn't think of a better > more Perl'ish way (see bonus points below)) > 3/ My original code wasn't all that bad :-) > 4/ Adding the tuple idea yields noticeable improvements. > > Uri also gets bonus points for showing me that I could do this > kind of in-place substitution... on a list: > > s/ //g foreach @oids; > > Uri also gets extra bonus points for teaching me to use > regex's with embedded code. I always knew it could be done > but never spent the time to learn it, nor recognize when > it would be useful. Now (dammit), thanks to Uri, I know. > > s/(\d+)/sprintf('%8s', $1)/ge foreach @oids; > > And oh yes... printing the 'number as a string' _is_ faster > than printing a 'number as a number'! > > Here's the benchmark results: > > s/iter Improvement > abram_whilecmp 7.05 -- > indy_slow_sort 6.89 2% > henrys_sort 5.52 28% > fulko_sort_uri 1.79 294% > fulko_sort_orig 1.77 299% > abram_swartzpacksort 1.55 356% > abram_packsort 1.41 400% > fulko_sort 1.14 519% > abram_nounpacksort 0.905 679% > > Oh... another thing I learned... > > When running benchmarks... turn off Centrino auto-CPU-speed-mechanism! > I was having a hell of a time trying to figure out > why my results were always all over the map. :-( > > Finally, for those who want to see the (current) winners, > without having to look at the attachment, they are: > > For Readability: > > sub fulko_sort_uri { > my @oids = @_; > > s/(\d+)/sprintf('%8s', $1)/ge foreach @oids; > @oids = sort @oids; > s/ //g foreach @oids; > return @oids; > } > > For Fastest: > > sub abram_nounpacksort { > my @data = map { [ split(/\./, $_) ] } @_; > my @sorted = map { $_->[1] } > sort { $a->[0] cmp $b->[0] } > map { [pack("N*",@$_),$_] } @data; > @sorted = map { join(".",@$_) } @sorted; > return @sorted; > } Since the numbers are the only significant content of the oid, I wonder whether it would be cheaper to recreate it at the end. Sorting with no sort function is faster than having to do 2 array subscripts for each compare. (Maybe that was what abram_packsort did?) sub jmm { return map { join( '.', unpack('N*', $_) ) } sort map { pack('N*', split(/\./, $_) ) } @_; } Instead of a 2-element array, I sometimes just use a single string, consisting of a leading portion which is directly sortable, if necessary a marker, and finally the original string. The final map just removes the leading string (and the marker). > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm From fulko.hew at gmail.com Wed May 6 10:34:40 2009 From: fulko.hew at gmail.com (Fulko Hew) Date: Wed, 6 May 2009 13:34:40 -0400 Subject: [tpm] OID sorting In-Reply-To: <20090506171539.GC3924@perlwolf.com> References: <200905011446.19099.Henry.Baragar@instantiated.ca> <7C9C1C02AF9A46B09F941A93A7E50E18@ROADKILL> <8204a4fe0905020905k5293727ciea1554755340aa47@mail.gmail.com> <18941.3256.772493.245880@hetman.ua> <874ow23kdj.fsf@quad.sysarch.com> <8204a4fe0905060906h417c6596t9b10e8980aa69d93@mail.gmail.com> <20090506171539.GC3924@perlwolf.com> Message-ID: <8204a4fe0905061034s5c2e0b1ft39f73da5cbbce03e@mail.gmail.com> On Wed, May 6, 2009 at 1:15 PM, John Macdonald wrote: > Since the numbers are the only significant content of the oid, > I wonder whether it would be cheaper to recreate it at the end. > Sorting with no sort function is faster than having to do > 2 array subscripts for each compare. (Maybe that was what > abram_packsort did?) > > sub jmm { > return > map { join( '.', unpack('N*', $_) ) } > sort > map { pack('N*', split(/\./, $_) ) } > @_; > } > > Instead of a 2-element array, I sometimes just use a single > string, consisting of a leading portion which is directly > sortable, if necessary a marker, and finally the original > string. The final map just removes the leading string (and > the marker). > OK... We have a new leader! John is now in the lead and has passed the competition with the fastest, and arguably fairly readable version provided. The benchmark places it (with other versions removed for clarity): s/iter Improvement abram_whilecmp 7.08 -- fulko_sort 1.11 537% abram_nounpacksort 0.907 681% jmm 0.803 782% -------------- next part -------------- An HTML attachment was scrubbed... URL: From uri at stemsystems.com Wed May 6 11:47:11 2009 From: uri at stemsystems.com (Uri Guttman) Date: Wed, 06 May 2009 14:47:11 -0400 Subject: [tpm] OID sorting In-Reply-To: <20090506171539.GC3924@perlwolf.com> (John Macdonald's message of "Wed\, 6 May 2009 13\:15\:39 -0400") References: <200905011446.19099.Henry.Baragar@instantiated.ca> <7C9C1C02AF9A46B09F941A93A7E50E18@ROADKILL> <8204a4fe0905020905k5293727ciea1554755340aa47@mail.gmail.com> <18941.3256.772493.245880@hetman.ua> <874ow23kdj.fsf@quad.sysarch.com> <8204a4fe0905060906h417c6596t9b10e8980aa69d93@mail.gmail.com> <20090506171539.GC3924@perlwolf.com> Message-ID: <878wla3w7k.fsf@quad.sysarch.com> >>>>> "JM" == John Macdonald writes: JM> On Wed, May 06, 2009 at 12:06:51PM -0400, Fulko Hew wrote: >> For Fastest: >> >> sub abram_nounpacksort { >> my @data = map { [ split(/\./, $_) ] } @_; >> my @sorted = map { $_->[1] } >> sort { $a->[0] cmp $b->[0] } >> map { [pack("N*",@$_),$_] } @data; >> @sorted = map { join(".",@$_) } @sorted; >> return @sorted; >> } JM> Since the numbers are the only significant content of the oid, JM> I wonder whether it would be cheaper to recreate it at the end. JM> Sorting with no sort function is faster than having to do JM> 2 array subscripts for each compare. (Maybe that was what JM> abram_packsort did?) that is the whole win over the GRT or packed sort vs the ST. you can read more in my (very old) paper on this at: http://sysarch.com/Perl/sort_paper.html and the Sort::Maker module has plenty of documentation and a benchmark script so you can compare sorting styles. JM> sub jmm { JM> return JM> map { join( '.', unpack('N*', $_) ) } JM> sort JM> map { pack('N*', split(/\./, $_) ) } JM> @_; JM> } JM> Instead of a 2-element array, I sometimes just use a single JM> string, consisting of a leading portion which is directly JM> sortable, if necessary a marker, and finally the original JM> string. The final map just removes the leading string (and JM> the marker). that is probably the fastest style given the input. as someone mentioned if the oid integers are all less than 255 (unlikely) you can pack into unsigned bytes and if they are all less than 16 bits you can pack into short ints (maybe 15 bits as i think pack only does signed shorts). you need the pack N format if you are not sure as it is 32 bits. another trick to save the join/map on the return value is to put the original OID string as is on the end of the compare strings. the issue is how to get back that original string from the compare string. you can put a null byte before the string and use rindex and substr or even a regex. this should be faster than a join but it needs benchmarking. if the original string is a fixed length than a substr can get it back easily from the end. this is why knowing your data and any restrictions is a valuable thing when you want to optimize any algorithm. but those restrictions have to be 100% correct all the time otherwise this can blow up. thanx, uri -- Uri Guttman ------ uri at stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Free Perl Training --- http://perlhunter.com/college.html --------- --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- From fulko.hew at gmail.com Wed May 6 12:13:54 2009 From: fulko.hew at gmail.com (Fulko Hew) Date: Wed, 6 May 2009 15:13:54 -0400 Subject: [tpm] OID sorting In-Reply-To: <878wla3w7k.fsf@quad.sysarch.com> References: <200905011446.19099.Henry.Baragar@instantiated.ca> <7C9C1C02AF9A46B09F941A93A7E50E18@ROADKILL> <8204a4fe0905020905k5293727ciea1554755340aa47@mail.gmail.com> <18941.3256.772493.245880@hetman.ua> <874ow23kdj.fsf@quad.sysarch.com> <8204a4fe0905060906h417c6596t9b10e8980aa69d93@mail.gmail.com> <20090506171539.GC3924@perlwolf.com> <878wla3w7k.fsf@quad.sysarch.com> Message-ID: <8204a4fe0905061213p27859628k1af834014ce8165a@mail.gmail.com> On Wed, May 6, 2009 at 2:47 PM, Uri Guttman wrote: ... snip ... > that is the whole win over the GRT or packed sort vs the ST. you can > read more in my (very old) paper on this at: > > http://sysarch.com/Perl/sort_paper.html > Thank you. An interesting read. It was easier than the Knuth book, and right now... more relevant. ... snip... -------------- next part -------------- An HTML attachment was scrubbed... URL: From rdice at pobox.com Wed May 6 13:48:29 2009 From: rdice at pobox.com (Richard Dice) Date: Wed, 6 May 2009 16:48:29 -0400 Subject: [tpm] anyone have a line on getting in touch with Jim Harris? Message-ID: <5bef4baf0905061348p127c0e7du8a84dc42913f9dc@mail.gmail.com> Hi gang, I've been looking for Jim Harris and haven't been able to poke through by email. Anyone got a phone number (ICBM co-ords, etc.)? Cheers, - Richard -------------- next part -------------- An HTML attachment was scrubbed... URL: From linux at alteeve.com Wed May 6 16:43:03 2009 From: linux at alteeve.com (Madison Kelly) Date: Wed, 06 May 2009 19:43:03 -0400 Subject: [tpm] CPAN install of HTML::Form::ForceValue fails Message-ID: <4A022087.6020305@alteeve.com> Hi all, I've never had much luck with CPAN installs, but now I am facing an issue where I need the mentioned module and, again, I can't install it via cpan. I am installing it as root, but I get the following error with no idea how to proceed. Advice? Thanks! Madi Error: root at T43p:~/.cpan/build/HTML-Form-ForceValue-0.006-mxhZEF# clear; sudo cpan -i HTML::Form::ForceValue CPAN: Storable loaded ok (v2.18) Going to read /root/.cpan/Metadata Database was generated on Wed, 06 May 2009 19:29:59 GMT CPAN: YAML loaded ok (v0.68) Going to read /root/.cpan/build/ ............................................................................DONE Found 5 old builds, restored the state of 5 Running install for module 'HTML::Form::ForceValue' Running make for R/RJ/RJBS/HTML-Form-ForceValue-0.006.tar.gz Has already been unwrapped into directory /root/.cpan/build/HTML-Form-ForceValue-0.006-mxhZEF Has already been made Running make test PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t t/00-load.........ok 1/1# Testing HTML::Form::ForceValue 0.006, Perl 5.010000, /usr/bin/perl t/00-load.........ok t/boilerplate.....ok t/form............NOK 1/8 # Failed test 'can't set select element to invalid option' # at t/form.t line 20. # '' # doesn't match '(?i-xsm:illegal value)' t/form............NOK 2/8 # Failed test 'can't set select element to invalid option' # at t/form.t line 23. # '' # doesn't match '(?i-xsm:illegal value)' t/form............ok 3/8# Looks like you failed 2 tests of 8. t/form............dubious Test returned status 2 (wstat 512, 0x200) DIED. FAILED tests 1-2 Failed 2/8 tests, 75.00% okay t/perl-critic.....skipped all skipped: define PERL_TEST_CRITIC to run these tests t/pod-coverage....ok t/pod.............ok Failed Test Stat Wstat Total Fail List of Failed ------------------------------------------------------------------------------- t/form.t 2 512 8 2 1-2 1 test skipped. Failed 1/6 test scripts. 2/14 subtests failed. Files=6, Tests=14, 0 wallclock secs ( 0.24 cusr + 0.03 csys = 0.27 CPU) Failed 1/6 test programs. 2/14 subtests failed. make: *** [test_dynamic] Error 255 RJBS/HTML-Form-ForceValue-0.006.tar.gz /usr/bin/make test -- NOT OK //hint// to see the cpan-testers results for installing this module, try: reports RJBS/HTML-Form-ForceValue-0.006.tar.gz Running make install make test had returned bad status, won't install without force From samogon at gmail.com Wed May 6 17:09:04 2009 From: samogon at gmail.com (Ilia) Date: Wed, 6 May 2009 20:09:04 -0400 Subject: [tpm] CPAN install of HTML::Form::ForceValue fails In-Reply-To: <4A022087.6020305@alteeve.com> References: <4A022087.6020305@alteeve.com> Message-ID: It failed for me as well with the same result. HTML::Form::ForceValue has a dependency on HTML::Form. It looks like the latter's API has changed and ForceValue unit tests need to be updated. I would report the test output as a bug --> http://rt.cpan.org/Public/Dist/Display.html?Name=HTML-Form-ForceValue ilia. On Wed, May 6, 2009 at 7:43 PM, Madison Kelly wrote: > Hi all, > > ?I've never had much luck with CPAN installs, but now I am facing an issue > where I need the mentioned module and, again, I can't install it via cpan. > > ?I am installing it as root, but I get the following error with no idea how > to proceed. Advice? > > Thanks! > > Madi > > Error: > > root at T43p:~/.cpan/build/HTML-Form-ForceValue-0.006-mxhZEF# clear; sudo cpan > -i HTML::Form::ForceValue > > CPAN: Storable loaded ok (v2.18) > Going to read /root/.cpan/Metadata > ?Database was generated on Wed, 06 May 2009 19:29:59 GMT > CPAN: YAML loaded ok (v0.68) > Going to read /root/.cpan/build/ > ............................................................................DONE > Found 5 old builds, restored the state of 5 > Running install for module 'HTML::Form::ForceValue' > Running make for R/RJ/RJBS/HTML-Form-ForceValue-0.006.tar.gz > ?Has already been unwrapped into directory > /root/.cpan/build/HTML-Form-ForceValue-0.006-mxhZEF > ?Has already been made > Running make test > PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" > "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t > t/00-load.........ok 1/1# Testing HTML::Form::ForceValue 0.006, Perl > 5.010000, /usr/bin/perl > t/00-load.........ok > t/boilerplate.....ok > t/form............NOK 1/8 > # ? Failed test 'can't set select element to invalid option' > # ? at t/form.t line 20. > # ? ? ? ? ? ? ? ? ? '' > # ? ? doesn't match '(?i-xsm:illegal value)' > t/form............NOK 2/8 > # ? Failed test 'can't set select element to invalid option' > # ? at t/form.t line 23. > # ? ? ? ? ? ? ? ? ? '' > # ? ? doesn't match '(?i-xsm:illegal value)' > t/form............ok 3/8# Looks like you failed 2 tests of 8. > t/form............dubious > ? ? ? ?Test returned status 2 (wstat 512, 0x200) > DIED. FAILED tests 1-2 > ? ? ? ?Failed 2/8 tests, 75.00% okay > t/perl-critic.....skipped > ? ? ? ?all skipped: define PERL_TEST_CRITIC to run these tests > t/pod-coverage....ok > t/pod.............ok > Failed Test Stat Wstat Total Fail ?List of Failed > ------------------------------------------------------------------------------- > t/form.t ? ? ? 2 ? 512 ? ? 8 ? ?2 ?1-2 > 1 test skipped. > Failed 1/6 test scripts. 2/14 subtests failed. > Files=6, Tests=14, ?0 wallclock secs ( 0.24 cusr + ?0.03 csys = ?0.27 CPU) > Failed 1/6 test programs. 2/14 subtests failed. > make: *** [test_dynamic] Error 255 > ?RJBS/HTML-Form-ForceValue-0.006.tar.gz > ?/usr/bin/make test -- NOT OK > //hint// to see the cpan-testers results for installing this module, try: > ?reports RJBS/HTML-Form-ForceValue-0.006.tar.gz > Running make install > ?make test had returned bad status, won't install without force > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm > -- Ilia Lobsanov Nurey Networks - http://www.nurey.com New Ideas for a New Economy Python, Perl, Java, Linux & more Toronto +1 647 996 9087 Boston +1 781 328 1162 From samogon at gmail.com Wed May 6 17:11:01 2009 From: samogon at gmail.com (Ilia) Date: Wed, 6 May 2009 20:11:01 -0400 Subject: [tpm] CPAN install of HTML::Form::ForceValue fails In-Reply-To: References: <4A022087.6020305@alteeve.com> Message-ID: You're probably safe to 'force install' the module. ilia. On Wed, May 6, 2009 at 8:09 PM, Ilia wrote: > It failed for me as well with the same result. > > HTML::Form::ForceValue has a dependency on HTML::Form. It looks like > the latter's API has changed and ForceValue unit tests need to be > updated. I would report the test output as a bug --> > http://rt.cpan.org/Public/Dist/Display.html?Name=HTML-Form-ForceValue > > ilia. > > > On Wed, May 6, 2009 at 7:43 PM, Madison Kelly wrote: >> Hi all, >> >> ?I've never had much luck with CPAN installs, but now I am facing an issue >> where I need the mentioned module and, again, I can't install it via cpan. >> >> ?I am installing it as root, but I get the following error with no idea how >> to proceed. Advice? >> >> Thanks! >> >> Madi >> >> Error: >> >> root at T43p:~/.cpan/build/HTML-Form-ForceValue-0.006-mxhZEF# clear; sudo cpan >> -i HTML::Form::ForceValue >> >> CPAN: Storable loaded ok (v2.18) >> Going to read /root/.cpan/Metadata >> ?Database was generated on Wed, 06 May 2009 19:29:59 GMT >> CPAN: YAML loaded ok (v0.68) >> Going to read /root/.cpan/build/ >> ............................................................................DONE >> Found 5 old builds, restored the state of 5 >> Running install for module 'HTML::Form::ForceValue' >> Running make for R/RJ/RJBS/HTML-Form-ForceValue-0.006.tar.gz >> ?Has already been unwrapped into directory >> /root/.cpan/build/HTML-Form-ForceValue-0.006-mxhZEF >> ?Has already been made >> Running make test >> PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" >> "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t >> t/00-load.........ok 1/1# Testing HTML::Form::ForceValue 0.006, Perl >> 5.010000, /usr/bin/perl >> t/00-load.........ok >> t/boilerplate.....ok >> t/form............NOK 1/8 >> # ? Failed test 'can't set select element to invalid option' >> # ? at t/form.t line 20. >> # ? ? ? ? ? ? ? ? ? '' >> # ? ? doesn't match '(?i-xsm:illegal value)' >> t/form............NOK 2/8 >> # ? Failed test 'can't set select element to invalid option' >> # ? at t/form.t line 23. >> # ? ? ? ? ? ? ? ? ? '' >> # ? ? doesn't match '(?i-xsm:illegal value)' >> t/form............ok 3/8# Looks like you failed 2 tests of 8. >> t/form............dubious >> ? ? ? ?Test returned status 2 (wstat 512, 0x200) >> DIED. FAILED tests 1-2 >> ? ? ? ?Failed 2/8 tests, 75.00% okay >> t/perl-critic.....skipped >> ? ? ? ?all skipped: define PERL_TEST_CRITIC to run these tests >> t/pod-coverage....ok >> t/pod.............ok >> Failed Test Stat Wstat Total Fail ?List of Failed >> ------------------------------------------------------------------------------- >> t/form.t ? ? ? 2 ? 512 ? ? 8 ? ?2 ?1-2 >> 1 test skipped. >> Failed 1/6 test scripts. 2/14 subtests failed. >> Files=6, Tests=14, ?0 wallclock secs ( 0.24 cusr + ?0.03 csys = ?0.27 CPU) >> Failed 1/6 test programs. 2/14 subtests failed. >> make: *** [test_dynamic] Error 255 >> ?RJBS/HTML-Form-ForceValue-0.006.tar.gz >> ?/usr/bin/make test -- NOT OK >> //hint// to see the cpan-testers results for installing this module, try: >> ?reports RJBS/HTML-Form-ForceValue-0.006.tar.gz >> Running make install >> ?make test had returned bad status, won't install without force >> _______________________________________________ >> toronto-pm mailing list >> toronto-pm at pm.org >> http://mail.pm.org/mailman/listinfo/toronto-pm >> > > > > -- > Ilia Lobsanov > Nurey Networks - http://www.nurey.com > New Ideas for a New Economy > Python, Perl, Java, Linux & more > Toronto +1 647 996 9087 > Boston +1 781 328 1162 > -- Ilia Lobsanov Nurey Networks - http://www.nurey.com New Ideas for a New Economy Python, Perl, Java, Linux & more Toronto +1 647 996 9087 Boston +1 781 328 1162 From arocker at vex.net Thu May 7 11:43:26 2009 From: arocker at vex.net (arocker at vex.net) Date: Thu, 7 May 2009 14:43:26 -0400 (EDT) Subject: [tpm] Using SFTP to move multiple files Message-ID: <432e8f7fb6ce60cadcbd8066376b2ba5.squirrel@webmail.vex.net> I need to get multiple files, whose names I do not know in advance, from an SFTP site. Net::SFTP will not take wildcards. Has anybody a solution to this? From indy at indigostar.com Thu May 7 11:50:51 2009 From: indy at indigostar.com (Indy Singh) Date: Thu, 7 May 2009 14:50:51 -0400 Subject: [tpm] Using SFTP to move multiple files References: <432e8f7fb6ce60cadcbd8066376b2ba5.squirrel@webmail.vex.net> Message-ID: <34A496EF89F64BE382FBDD2A836E0A64@ROADKILL> You _could_ call the 'ls' method to get a list of files, then apply the filter yourself. This is just of off the top of my head. There may be better ways. Indy Singh IndigoSTAR Software -- www.indigostar.com ----- Original Message ----- From: To: Sent: Thursday, May 07, 2009 2:43 PM Subject: [tpm] Using SFTP to move multiple files > > I need to get multiple files, whose names I do not know in advance, from > an SFTP site. Net::SFTP will not take wildcards. > > Has anybody a solution to this? > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm From arocker at vex.net Thu May 7 12:17:06 2009 From: arocker at vex.net (arocker at vex.net) Date: Thu, 7 May 2009 15:17:06 -0400 (EDT) Subject: [tpm] Using SFTP to move multiple files In-Reply-To: <34A496EF89F64BE382FBDD2A836E0A64@ROADKILL> References: <432e8f7fb6ce60cadcbd8066376b2ba5.squirrel@webmail.vex.net> <34A496EF89F64BE382FBDD2A836E0A64@ROADKILL> Message-ID: > You _could_ call the 'ls' method to get a list of files, then apply the > filter yourself. > I could, but it's ugly, given what Net::SFTP returns. > This is just of off the top of my head. There may be better ways. > And I was hoping somebody would name one. :-)* Thanks, Indy, (and Richard). From arocker at vex.net Mon May 11 06:19:18 2009 From: arocker at vex.net (arocker at vex.net) Date: Mon, 11 May 2009 09:19:18 -0400 (EDT) Subject: [tpm] Who's going to YAPC? Message-ID: <325d444168b7d30481e308911168bdba.squirrel@webmail.vex.net> Is anyone likely to have spare seats? From adam.prime at utoronto.ca Tue May 12 06:51:01 2009 From: adam.prime at utoronto.ca (Adam Prime) Date: Tue, 12 May 2009 09:51:01 -0400 Subject: [tpm] Who's going to YAPC? In-Reply-To: <325d444168b7d30481e308911168bdba.squirrel@webmail.vex.net> References: <325d444168b7d30481e308911168bdba.squirrel@webmail.vex.net> Message-ID: <4A097EC5.2080406@utoronto.ca> According to http://yapc10.org/yn2009/search?country=ca, currently registered are me, Richard, and Michael. As of right this second i'm still not 100% sure how i'm getting down, or for what dates i'm going to be there for. Adam arocker at vex.net wrote: > Is anyone likely to have spare seats? > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm From linux at alteeve.com Tue May 12 09:21:07 2009 From: linux at alteeve.com (Madison Kelly) Date: Tue, 12 May 2009 12:21:07 -0400 Subject: [tpm] Possible future talk? Message-ID: <4A09A1F3.7040402@alteeve.com> Hi all, I posted this to TLUG and it was received... well, it wasn't. Not a reply either way. lol. Maybe TPM would be interested? Perhaps it's too low down though for the TPM crowd? I saw an article the other day about how there isn't all that much in the way of "intermittent" level papers, talks and such on most programming languages. I'm not sure how true this is, but it got me thinking about a possible future talk. Would there be any interest in an intermittent talk about Perl? I was thinking along the lines of "Introduction to Writing Perl Modules", "Introduction to Object Oriented Perl" or something similar/variation of/combination of. I make no claim to be an expert in either of these fields, or in Perl itself, but I do feel confident enough in them to introduce the topics to people who may have an otherwise softer exposure to Perl. If so, I'd be ready later in the summer. Madi From magog at the-wire.com Tue May 12 11:00:46 2009 From: magog at the-wire.com (Michael Graham) Date: Tue, 12 May 2009 14:00:46 -0400 Subject: [tpm] Possible future talk? In-Reply-To: <4A09A1F3.7040402@alteeve.com> References: <4A09A1F3.7040402@alteeve.com> Message-ID: <20090512140046.42ef1070@caliope> I'm not sure what you mean by "intermittent," in this context... But I think it would be a great idea if we prepared a number of beginner talks and rolled them out periodically. Doesn't have to be just you - it would be ideal if a bunch of people each prepared a talk on something they feel they can teach well. Ideally, each talk would have a short version (for giving on a night when there are other talks), and a longer version (for when there's no other talks). Might be a way to get more people out too! Michael On Tue, 12 May 2009 12:21:07 -0400 Madison Kelly wrote: > Hi all, > > I posted this to TLUG and it was received... well, it wasn't. Not > a reply either way. lol. Maybe TPM would be interested? Perhaps it's > too low down though for the TPM crowd? > > I saw an article the other day about how there isn't all that much > in the way of "intermittent" level papers, talks and such on most > programming languages. I'm not sure how true this is, but it got me > thinking about a possible future talk. > > Would there be any interest in an intermittent talk about Perl? I > was thinking along the lines of "Introduction to Writing Perl > Modules", "Introduction to Object Oriented Perl" or something > similar/variation of/combination of. > > I make no claim to be an expert in either of these fields, or in > Perl itself, but I do feel confident enough in them to introduce the > topics to people who may have an otherwise softer exposure to Perl. > > If so, I'd be ready later in the summer. > > Madi > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm -- Michael Graham From arocker at vex.net Tue May 12 11:07:31 2009 From: arocker at vex.net (arocker at vex.net) Date: Tue, 12 May 2009 14:07:31 -0400 (EDT) Subject: [tpm] Bizarre bug or brain fade? Message-ID: A program containing a fairly large "here document" is on a machine I cannot access directly. (Somebody else has to run it for me.) The code was substantially copied from a program that runs successfully there, but it crashes with a complaint that the terminal string was not found before EOF on input. (I can't quote Perl versions today.) I've tried the usual things to ensure that there are no invisible characters lurking on the line, &c., to no avail. The whole program cannot be run on my machine, but when I extracted the relevant portion for autopsy, it worked. This dialogue http://tinyurl.com/ov69dt seems to deal with a similar case, but it's old enough that I would expect it to have been fixed by now. Has anyone seen anything similar? From magog at the-wire.com Tue May 12 11:16:46 2009 From: magog at the-wire.com (Michael Graham) Date: Tue, 12 May 2009 14:16:46 -0400 Subject: [tpm] Bizarre bug or brain fade? In-Reply-To: References: Message-ID: <20090512141646.70c59134@caliope> How about line endings? I don't know how Perl deals with END_OF_STRING^M vs. END_OF_STRING. Michael On Tue, 12 May 2009 14:07:31 -0400 (EDT) arocker at vex.net wrote: > > A program containing a fairly large "here document" is on a machine I > cannot access directly. (Somebody else has to run it for me.) The > code was substantially copied from a program that runs successfully > there, but it crashes with a complaint that the terminal string was > not found before EOF on input. (I can't quote Perl versions today.) > > I've tried the usual things to ensure that there are no invisible > characters lurking on the line, &c., to no avail. The whole program > cannot be run on my machine, but when I extracted the relevant > portion for autopsy, it worked. > > This dialogue http://tinyurl.com/ov69dt seems to deal with a similar > case, but it's old enough that I would expect it to have been fixed > by now. Has anyone seen anything similar? > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm -- Michael Graham From fulko.hew at gmail.com Tue May 12 11:17:11 2009 From: fulko.hew at gmail.com (Fulko Hew) Date: Tue, 12 May 2009 14:17:11 -0400 Subject: [tpm] Bizarre bug or brain fade? In-Reply-To: References: Message-ID: <8204a4fe0905121117m542a9432k305284e0e5720ca1@mail.gmail.com> On Tue, May 12, 2009 at 2:07 PM, wrote: > > A program containing a fairly large "here document" is on a machine I > cannot access directly. (Somebody else has to run it for me.) The code was > substantially copied from a program that runs successfully there, but it > crashes with a complaint that the terminal string was not found before EOF > on input. (I can't quote Perl versions today.) > > I've tried the usual things to ensure that there are no invisible > characters lurking on the line, &c., to no avail. The whole program cannot > be run on my machine, but when I extracted the relevant portion for > autopsy, it worked. > > This dialogue http://tinyurl.com/ov69dt seems to deal with a similar case, > but it's old enough that I would expect it to have been fixed by now. Has > anyone seen anything similar? > I read yr link, and just tried it out on an older perl 5.004_04 and it fails (under warning) with: Can't find string terminator "EOF" anywhere before EOF at t.1 line 1 What I created was: print <> t. to fix the file, and that worked. -------------- next part -------------- An HTML attachment was scrubbed... URL: From uri at PerlOnCall.com Tue May 12 11:11:35 2009 From: uri at PerlOnCall.com (Uri Guttman) Date: Tue, 12 May 2009 14:11:35 -0400 Subject: [tpm] Bizarre bug or brain fade? In-Reply-To: (arocker@vex.net's message of "Tue\, 12 May 2009 14\:07\:31 -0400 \(EDT\)") References: Message-ID: <873abaw5rc.fsf@quad.sysarch.com> >>>>> "a" == arocker writes: a> A program containing a fairly large "here document" is on a machine I a> cannot access directly. (Somebody else has to run it for me.) The code was a> substantially copied from a program that runs successfully there, but it a> crashes with a complaint that the terminal string was not found before EOF a> on input. (I can't quote Perl versions today.) a> I've tried the usual things to ensure that there are no invisible a> characters lurking on the line, &c., to no avail. The whole program cannot a> be run on my machine, but when I extracted the relevant portion for a> autopsy, it worked. it could be line ending issues (cr/lf vs lf). this has been known to break here docs when moved to/from winblows and unix flavors. so check the line ending type on the platform and exactly what is in the file there (use a text dump utility, not an editor). uri -- Uri Guttman ------ uri at stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Free Perl Training --- http://perlhunter.com/college.html --------- --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- From olaf at vilerichard.com Tue May 12 11:56:00 2009 From: olaf at vilerichard.com (Olaf Alders) Date: Tue, 12 May 2009 14:56:00 -0400 Subject: [tpm] Possible future talk? In-Reply-To: <20090512140046.42ef1070@caliope> References: <4A09A1F3.7040402@alteeve.com> <20090512140046.42ef1070@caliope> Message-ID: On 12-May-09, at 2:00 PM, Michael Graham wrote: > > I'm not sure what you mean by "intermittent," in this context... I had sort of thought it was a typo. "Intermediate" perhaps? At any rate, not a bad idea for getting some fresh blood involved. Olaf -- Olaf Alders olaf at vilerichard.com http://www.vilerichard.com -- folk rock http://cdbaby.com/cd/vilerichard From olaf at vilerichard.com Tue May 12 12:08:22 2009 From: olaf at vilerichard.com (Olaf Alders) Date: Tue, 12 May 2009 15:08:22 -0400 Subject: [tpm] Who's going to YAPC? In-Reply-To: <4A097EC5.2080406@utoronto.ca> References: <325d444168b7d30481e308911168bdba.squirrel@webmail.vex.net> <4A097EC5.2080406@utoronto.ca> Message-ID: On 12-May-09, at 9:51 AM, Adam Prime wrote: > According to http://yapc10.org/yn2009/search?country=ca, currently > registered are me, Richard, and Michael. As of right this second > i'm still not 100% sure how i'm getting down, or for what dates i'm > going to be there for. > > Adam Mark Jubenville and I are likely going to register this week as well. Not sure if the travel arrangements yet, though. Olaf -- Olaf Alders olaf at vilerichard.com http://www.vilerichard.com -- folk rock http://cdbaby.com/cd/vilerichard From jkeen at verizon.net Tue May 12 16:39:32 2009 From: jkeen at verizon.net (James E Keenan) Date: Tue, 12 May 2009 19:39:32 -0400 Subject: [tpm] Who's going to YAPC? In-Reply-To: <4A097EC5.2080406@utoronto.ca> References: <325d444168b7d30481e308911168bdba.squirrel@webmail.vex.net> <4A097EC5.2080406@utoronto.ca> Message-ID: <8A56C605-F70E-4F71-9842-AFE37C436A33@verizon.net> On May 12, 2009, at 9:51 AM, Adam Prime wrote: > According to http://yapc10.org/yn2009/search?country=ca, currently > registered are me, Richard, and Michael. As of right this second > i'm still not 100% sure how i'm getting down, or for what dates i'm > going to be there for. > > Adam > > C'mon, you Torontonians have one of the easiest drives to Pittsburgh of anybody: http://preview.tinyurl.com/oeo5xd Hope to see many of you there! Jim Keenan From lyndsey at lizardpoint.com Tue May 12 18:20:08 2009 From: lyndsey at lizardpoint.com (Lyndsey McCollam) Date: Tue, 12 May 2009 20:20:08 -0500 Subject: [tpm] Possible future talk? References: <4A09A1F3.7040402@alteeve.com> <20090512140046.42ef1070@caliope> Message-ID: <002601c9d368$f4a93840$ccdefea9@Geoffrey> I would be interested in beginner or intermediate talks. Lyndsey ----- Original Message ----- From: "Michael Graham" To: Sent: Tuesday, May 12, 2009 1:00 PM Subject: Re: [tpm] Possible future talk? > > I'm not sure what you mean by "intermittent," in this context... > > But I think it would be a great idea if we prepared a number of beginner > talks and rolled them out periodically. Doesn't have to be just you - > it would be ideal if a bunch of people each prepared a talk on something > they feel they can teach well. > > Ideally, each talk would have a short version (for giving on a night > when there are other talks), and a longer version (for when there's no > other talks). > > Might be a way to get more people out too! > > > Michael > > > > On Tue, 12 May 2009 12:21:07 -0400 > Madison Kelly wrote: > >> Hi all, >> >> I posted this to TLUG and it was received... well, it wasn't. Not >> a reply either way. lol. Maybe TPM would be interested? Perhaps it's >> too low down though for the TPM crowd? >> >> I saw an article the other day about how there isn't all that much >> in the way of "intermittent" level papers, talks and such on most >> programming languages. I'm not sure how true this is, but it got me >> thinking about a possible future talk. >> >> Would there be any interest in an intermittent talk about Perl? I >> was thinking along the lines of "Introduction to Writing Perl >> Modules", "Introduction to Object Oriented Perl" or something >> similar/variation of/combination of. >> >> I make no claim to be an expert in either of these fields, or in >> Perl itself, but I do feel confident enough in them to introduce the >> topics to people who may have an otherwise softer exposure to Perl. >> >> If so, I'd be ready later in the summer. >> >> Madi >> _______________________________________________ >> toronto-pm mailing list >> toronto-pm at pm.org >> http://mail.pm.org/mailman/listinfo/toronto-pm > > > -- > Michael Graham > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm > > From linux at alteeve.com Tue May 12 17:27:47 2009 From: linux at alteeve.com (Madison Kelly) Date: Tue, 12 May 2009 20:27:47 -0400 Subject: [tpm] Possible future talk? In-Reply-To: <20090512140046.42ef1070@caliope> References: <4A09A1F3.7040402@alteeve.com> <20090512140046.42ef1070@caliope> Message-ID: <4A0A1403.60909@alteeve.com> Michael Graham wrote: > I'm not sure what you mean by "intermittent," in this context... > > But I think it would be a great idea if we prepared a number of beginner > talks and rolled them out periodically. Doesn't have to be just you - > it would be ideal if a bunch of people each prepared a talk on something > they feel they can teach well. > > Ideally, each talk would have a short version (for giving on a night > when there are other talks), and a longer version (for when there's no > other talks). > > Might be a way to get more people out too! > > > Michael Well, to me, "Modules" was this mystical perl concept that only guru's wrote. It felt like a very advanced topic and that didn't change until I learned about them as a side-effect of trying to learn about DBus. So by "intermittent", I mean to help people who may be familiar with perl get a feeling for something they may otherwise feel is outside their reach. The "short" and "long" version sounds like a good thing, too. Personally, I'd love to hear a talk on writing testable code... Something I am ashamed to say I know little about. Madi From linux at alteeve.com Tue May 12 17:28:15 2009 From: linux at alteeve.com (Madison Kelly) Date: Tue, 12 May 2009 20:28:15 -0400 Subject: [tpm] Possible future talk? In-Reply-To: References: <4A09A1F3.7040402@alteeve.com> <20090512140046.42ef1070@caliope> Message-ID: <4A0A141F.9060705@alteeve.com> Olaf Alders wrote: > > On 12-May-09, at 2:00 PM, Michael Graham wrote: > >> >> I'm not sure what you mean by "intermittent," in this context... > > I had sort of thought it was a typo. "Intermediate" perhaps? At any > rate, not a bad idea for getting some fresh blood involved. > > Olaf I think I double-typo-failed on that. Yes, I meant "Intermediate". Wow, talk about shooting my credibility in the foot. :P Madi From linux at alteeve.com Tue May 12 17:28:40 2009 From: linux at alteeve.com (Madison Kelly) Date: Tue, 12 May 2009 20:28:40 -0400 Subject: [tpm] Possible future talk? In-Reply-To: <002601c9d368$f4a93840$ccdefea9@Geoffrey> References: <4A09A1F3.7040402@alteeve.com> <20090512140046.42ef1070@caliope> <002601c9d368$f4a93840$ccdefea9@Geoffrey> Message-ID: <4A0A1438.60507@alteeve.com> Lyndsey McCollam wrote: > I would be interested in beginner or intermediate talks. > > Lyndsey Encouraging! :) Madi From antoniosun at lavabit.com Tue May 12 18:59:07 2009 From: antoniosun at lavabit.com (Antonio Sun) Date: Tue, 12 May 2009 21:59:07 -0400 Subject: [tpm] Use RE engine in C Message-ID: Hi, How to use the regexp matching and substitution engine in C? Thanks Antonio -------------- next part -------------- An HTML attachment was scrubbed... URL: From liam at holoweb.net Tue May 12 19:15:40 2009 From: liam at holoweb.net (Liam R E Quin) Date: Tue, 12 May 2009 22:15:40 -0400 Subject: [tpm] Use RE engine in C In-Reply-To: References: Message-ID: <1242180940.4052.74.camel@desktop.barefootcomputing.com> On Tue, 2009-05-12 at 21:59 -0400, Antonio Sun wrote: > Hi, > > How to use the regexp matching and substitution engine in C? To some extent, with libpcre. Liam -- Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/ Pictures from old books: http://fromoldbooks.org/ Ankh: irc.sorcery.net irc.gnome.org www.advogato.org From indy at indigostar.com Tue May 12 19:20:56 2009 From: indy at indigostar.com (Indy Singh) Date: Tue, 12 May 2009 22:20:56 -0400 Subject: [tpm] Use RE engine in C References: Message-ID: <67C3A0706CEA4EA0B3750C266FB9651B@ROADKILL> You can find a C library for it here: http://www.regular-expressions.info/pcre.html Indy Singh IndigoSTAR Software -- www.indigostar.com ----- Original Message ----- From: Antonio Sun To: TPM Mongers Sent: Tuesday, May 12, 2009 9:59 PM Subject: [tpm] Use RE engine in C Hi, How to use the regexp matching and substitution engine in C? Thanks Antonio ------------------------------------------------------------------------------ _______________________________________________ toronto-pm mailing list toronto-pm at pm.org http://mail.pm.org/mailman/listinfo/toronto-pm -------------- next part -------------- An HTML attachment was scrubbed... URL: From arocker at vex.net Wed May 13 08:18:16 2009 From: arocker at vex.net (arocker at vex.net) Date: Wed, 13 May 2009 11:18:16 -0400 (EDT) Subject: [tpm] Bizarre bug or brain fade? In-Reply-To: <8204a4fe0905121117m542a9432k305284e0e5720ca1@mail.gmail.com> References: <8204a4fe0905121117m542a9432k305284e0e5720ca1@mail.gmail.com> Message-ID: <1531b57fe59268966e6cda2aebcb7072.squirrel@webmail.vex.net> Thanks for the help, everyone. The problem appears to have been the line-end character. Moving the script around a mixed PC/Unix environment must have left it in the wrong format, but the "here" document was the only place it mattered. Opening the script file in "TextPad" and then saving it with a format forced to PC cured the problem. From fulko.hew at gmail.com Wed May 13 09:34:50 2009 From: fulko.hew at gmail.com (Fulko Hew) Date: Wed, 13 May 2009 12:34:50 -0400 Subject: [tpm] how to delete a list entry from within a foreach Message-ID: <8204a4fe0905130934t78adfef3y55eb6e759be4084e@mail.gmail.com> I know this is probably simple, but I'm having a mental block, and I can't find the 'easy' solution in any book right now... If I'm foreach'ing over a 'pick list', I need to get a positive indication that a match was found and then remove it from the 'pick list'. something like: if requestedvalue is on the picklist { remove it from the list return found } else { return notfound } Being Perl, I'm sure there is an elegant way... If only I knew. -------------- next part -------------- An HTML attachment was scrubbed... URL: From uri at StemSystems.com Wed May 13 09:50:16 2009 From: uri at StemSystems.com (Uri Guttman) Date: Wed, 13 May 2009 12:50:16 -0400 Subject: [tpm] how to delete a list entry from within a foreach In-Reply-To: <8204a4fe0905130934t78adfef3y55eb6e759be4084e@mail.gmail.com> (Fulko Hew's message of "Wed\, 13 May 2009 12\:34\:50 -0400") References: <8204a4fe0905130934t78adfef3y55eb6e759be4084e@mail.gmail.com> Message-ID: <87k54losl3.fsf@quad.sysarch.com> >>>>> "FH" == Fulko Hew writes: FH> I know this is probably simple, but I'm having a mental block, FH> and I can't find the 'easy' solution in any book right now... FH> If I'm foreach'ing over a 'pick list', I need to get a positive indication FH> that a match was found and then remove it from the 'pick list'. you can't delete from a list in a for. you can delete from an array but it could screw up the for loop. FH> something like: FH> if requestedvalue is on the picklist { FH> ?? remove it from the list FH> ?? return found FH> } else { FH> ?? return notfound FH> } sounds like grep to me. grep out the element. compare the old size to the new size of the array and return that boolean. but using an array for deletion is a red flag. that is best done with a hash. unless you need ordering, a hash is the answer and then it becomes a simple call to delete and return the boolean based on that. uri -- Uri Guttman ------ uri at stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Free Perl Training --- http://perlhunter.com/college.html --------- --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- From douglalonde at gmail.com Wed May 13 09:53:22 2009 From: douglalonde at gmail.com (Doug Lalonde) Date: Wed, 13 May 2009 12:53:22 -0400 Subject: [tpm] how to delete a list entry from within a foreach In-Reply-To: <8204a4fe0905130934t78adfef3y55eb6e759be4084e@mail.gmail.com> References: <8204a4fe0905130934t78adfef3y55eb6e759be4084e@mail.gmail.com> Message-ID: Maybe something along these lines: my @list=("1", "2", "3"); my $target = "2"; my $found=false; my $cleanedList; foreach $item(@list){ if($target eq $item){ $found = true; }else{ push (@cleanedList,$item ); } } @list = @cleanedList; print @list; 2009/5/13 Fulko Hew > > I know this is probably simple, but I'm having a mental block, > and I can't find the 'easy' solution in any book right now... > > If I'm foreach'ing over a 'pick list', I need to get a positive indication > that a match was found and then remove it from the 'pick list'. > > something like: > > if requestedvalue is on the picklist { > remove it from the list > return found > } else { > return notfound > } > > Being Perl, I'm sure there is an elegant way... If only I knew. > > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From james.a.graham at gmail.com Wed May 13 10:02:48 2009 From: james.a.graham at gmail.com (Jim Graham) Date: Wed, 13 May 2009 13:02:48 -0400 Subject: [tpm] how to delete a list entry from within a foreach In-Reply-To: <8204a4fe0905130934t78adfef3y55eb6e759be4084e@mail.gmail.com> References: <8204a4fe0905130934t78adfef3y55eb6e759be4084e@mail.gmail.com> Message-ID: <972EB79F-52D3-4159-B86A-FC5B5DC08789@gmail.com> As Uri said, try grep DB<16> @foo = ("jim", "steve", "dave"); DB<18> @bar = grep { $_ ne "jim" } @foo; DB<20> x @bar 0 'steve' 1 'dave' and compare lengths of @foo and @bar to see if something got removed. Or use a hash. - Jim On 13-May-09, at 12:34 PM, Fulko Hew wrote: > > I know this is probably simple, but I'm having a mental block, > and I can't find the 'easy' solution in any book right now... > > If I'm foreach'ing over a 'pick list', I need to get a positive > indication > that a match was found and then remove it from the 'pick list'. > > something like: > > if requestedvalue is on the picklist { > remove it from the list > return found > } else { > return notfound > } > > Being Perl, I'm sure there is an elegant way... If only I knew. > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm From fulko.hew at gmail.com Wed May 13 10:33:45 2009 From: fulko.hew at gmail.com (Fulko Hew) Date: Wed, 13 May 2009 13:33:45 -0400 Subject: [tpm] how to delete a list entry from within a foreach In-Reply-To: <972EB79F-52D3-4159-B86A-FC5B5DC08789@gmail.com> References: <8204a4fe0905130934t78adfef3y55eb6e759be4084e@mail.gmail.com> <972EB79F-52D3-4159-B86A-FC5B5DC08789@gmail.com> Message-ID: <8204a4fe0905131033x57ff25ftbbcf7d758ea61e3c@mail.gmail.com> While awaiting responses, I had already come to the conclusion that hashes were probably the way to go, but... thanks for refreshing my memory on grep! -------------- next part -------------- An HTML attachment was scrubbed... URL: From adam.prime at utoronto.ca Tue May 19 07:23:11 2009 From: adam.prime at utoronto.ca (Adam Prime) Date: Tue, 19 May 2009 10:23:11 -0400 Subject: [tpm] [Fwd: [yapc] YAPC|10 - Dorm room hold ends today May 19th!] Message-ID: <4A12C0CF.9000106@utoronto.ca> fyi -------------- next part -------------- An embedded message was scrubbed... From: Robert Blackwell Subject: [yapc] YAPC|10 - Dorm room hold ends today May 19th! Date: Tue, 19 May 2009 08:51:46 -0400 Size: 3507 URL: From arocker at vex.net Tue May 19 16:23:55 2009 From: arocker at vex.net (arocker at vex.net) Date: Tue, 19 May 2009 19:23:55 -0400 (EDT) Subject: [tpm] Who's talking this month? Message-ID: <54b9f338a12ddf54a0e95fa3d95ae1e9.squirrel@webmail.vex.net> I forget. From antoniosun at lavabit.com Tue May 19 17:05:45 2009 From: antoniosun at lavabit.com (Antonio Sun) Date: Tue, 19 May 2009 20:05:45 -0400 Subject: [tpm] Who's talking this month? In-Reply-To: <54b9f338a12ddf54a0e95fa3d95ae1e9.squirrel@webmail.vex.net> References: <54b9f338a12ddf54a0e95fa3d95ae1e9.squirrel@webmail.vex.net> Message-ID: Shall we let Richard carry on with his aborted talk on NCI (native call interface) in Parrot? On Tue, May 19, 2009 at 7:23 PM, wrote: > > I forget. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rdice at pobox.com Tue May 19 17:40:46 2009 From: rdice at pobox.com (Richard Dice) Date: Tue, 19 May 2009 20:40:46 -0400 Subject: [tpm] Who's talking this month? In-Reply-To: References: <54b9f338a12ddf54a0e95fa3d95ae1e9.squirrel@webmail.vex.net> Message-ID: <5bef4baf0905191740h13dfadbfm803b4a6f3387bbdb@mail.gmail.com> On Tue, May 19, 2009 at 8:05 PM, Antonio Sun wrote: > Shall we let Richard carry on with his aborted talk on NCI (native call > interface) in Parrot? > I'd like to but I don't think I can commit to it. My wife is on a new evening class schedule which includes Thursday evenings now, which means I have to be daddy at home looking after the baby girl. So it could be a while before I'm out to a TPM meeting again. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ilia at nurey.com Tue May 19 20:39:17 2009 From: ilia at nurey.com (Ilia Lobsanov) Date: Tue, 19 May 2009 23:39:17 -0400 Subject: [tpm] Who's talking this month? In-Reply-To: <5bef4baf0905191740h13dfadbfm803b4a6f3387bbdb@mail.gmail.com> References: <54b9f338a12ddf54a0e95fa3d95ae1e9.squirrel@webmail.vex.net> <5bef4baf0905191740h13dfadbfm803b4a6f3387bbdb@mail.gmail.com> Message-ID: <9479493E-686B-4CBA-AB55-397E611B9EF7@nurey.com> We could help you babysit! ilia. On 19-May-09, at 8:40 PM, Richard Dice wrote: > On Tue, May 19, 2009 at 8:05 PM, Antonio Sun > wrote: > Shall we let Richard carry on with his aborted talk on NCI (native > call interface) in Parrot? > > I'd like to but I don't think I can commit to it. My wife is on a > new evening class schedule which includes Thursday evenings now, > which means I have to be daddy at home looking after the baby girl. > So it could be a while before I'm out to a TPM meeting again. > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm -------------- next part -------------- An HTML attachment was scrubbed... URL: From talexb at gmail.com Tue May 19 20:46:13 2009 From: talexb at gmail.com (Alex Beamish) Date: Tue, 19 May 2009 23:46:13 -0400 Subject: [tpm] Who's talking this month? In-Reply-To: <9479493E-686B-4CBA-AB55-397E611B9EF7@nurey.com> References: <54b9f338a12ddf54a0e95fa3d95ae1e9.squirrel@webmail.vex.net> <5bef4baf0905191740h13dfadbfm803b4a6f3387bbdb@mail.gmail.com> <9479493E-686B-4CBA-AB55-397E611B9EF7@nurey.com> Message-ID: Brilliant -- I flashed on the scene where Tom Selleck is reading the rundown of a vicious boxing match to the baby in Three Men and a Baby. Steve Gutenberg comes by and says, "What are you reading?", and Tom Selleck responds, "It doesn't matter what you're reading, all that matters is the tone of your voice." --http://www.imdb.com/title/tt0094137/quotes So, we can drop by Richard's place and be discussing the finer points of Perl 6 or how to build a module, all sitting around Astra (sp?), and as long as we sound like we're telling a story, she'll be absolutely fine with it. I bet she'll be asleep by the time we get to AUTOLOAD. Alex On Tue, May 19, 2009 at 11:39 PM, Ilia Lobsanov wrote: > We could help you babysit! > ilia. > On 19-May-09, at 8:40 PM, Richard Dice wrote: > > On Tue, May 19, 2009 at 8:05 PM, Antonio Sun wrote: >> >> Shall we let Richard carry on with his aborted talk on NCI (native call >> interface) in Parrot? > > I'd like to but I don't think I can commit to it.? My wife is on a new > evening class schedule which includes Thursday evenings now, which means I > have to be daddy at home looking after the baby girl.? So it could be a > while before I'm out to a TPM meeting again. > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm > > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm > > -- Alex Beamish Toronto, Ontario aka talexb From arocker at vex.net Wed May 20 08:03:43 2009 From: arocker at vex.net (arocker at vex.net) Date: Wed, 20 May 2009 11:03:43 -0400 (EDT) Subject: [tpm] Who's talking this month? In-Reply-To: <9479493E-686B-4CBA-AB55-397E611B9EF7@nurey.com> References: <54b9f338a12ddf54a0e95fa3d95ae1e9.squirrel@webmail.vex.net> <5bef4baf0905191740h13dfadbfm803b4a6f3387bbdb@mail.gmail.com> <9479493E-686B-4CBA-AB55-397E611B9EF7@nurey.com> Message-ID: <42fa432f011396442abd5d538d709ef1.squirrel@webmail.vex.net> > We could help you babysit! > Recruit her as the world's youngest Perlmonger. :-)* From alexcapsa at gmail.com Wed May 20 08:13:34 2009 From: alexcapsa at gmail.com (Alexandru Capsa) Date: Wed, 20 May 2009 11:13:34 -0400 Subject: [tpm] Who's talking this month? In-Reply-To: <42fa432f011396442abd5d538d709ef1.squirrel@webmail.vex.net> References: <54b9f338a12ddf54a0e95fa3d95ae1e9.squirrel@webmail.vex.net> <5bef4baf0905191740h13dfadbfm803b4a6f3387bbdb@mail.gmail.com> <9479493E-686B-4CBA-AB55-397E611B9EF7@nurey.com> <42fa432f011396442abd5d538d709ef1.squirrel@webmail.vex.net> Message-ID: Let's make this one "Bring your kid to TPM day" :D On Wed, May 20, 2009 at 11:03 AM, wrote: > > We could help you babysit! > > > Recruit her as the world's youngest Perlmonger. :-)* > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm > -- Alexandru Capsa -------------- next part -------------- An HTML attachment was scrubbed... URL: From arocker at vex.net Wed May 20 10:00:13 2009 From: arocker at vex.net (arocker at vex.net) Date: Wed, 20 May 2009 13:00:13 -0400 (EDT) Subject: [tpm] Net::SFTP Message-ID: <946977f783bd4891a36a0bd4a0fc4f41.squirrel@webmail.vex.net> Has anybody used this module? I'm having a problem with downloading files. From rdice at pobox.com Wed May 20 11:24:57 2009 From: rdice at pobox.com (Richard Dice) Date: Wed, 20 May 2009 14:24:57 -0400 Subject: [tpm] Who's talking this month? In-Reply-To: References: <54b9f338a12ddf54a0e95fa3d95ae1e9.squirrel@webmail.vex.net> <5bef4baf0905191740h13dfadbfm803b4a6f3387bbdb@mail.gmail.com> <9479493E-686B-4CBA-AB55-397E611B9EF7@nurey.com> <42fa432f011396442abd5d538d709ef1.squirrel@webmail.vex.net> Message-ID: <5bef4baf0905201124s22cf33cbtd94996b751c40cb2@mail.gmail.com> Those are some nice sentiments, gang. And I do enjoy bringing her out to meet people. But her bedtime is 8pm, and there's about a 1 hour long ritual we need to go through to get her into bed. And if I were to be at 2 Bloor St. W. it would take me 1/2 hour to get home. The math just doesn't work, sorry. On Wed, May 20, 2009 at 11:13 AM, Alexandru Capsa wrote: > Let's make this one > > "Bring your kid to TPM day" > > :D > > > > On Wed, May 20, 2009 at 11:03 AM, wrote: > >> > We could help you babysit! >> > >> Recruit her as the world's youngest Perlmonger. :-)* >> >> _______________________________________________ >> toronto-pm mailing list >> toronto-pm at pm.org >> http://mail.pm.org/mailman/listinfo/toronto-pm >> > > > > -- > Alexandru Capsa > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave.s.doyle at gmail.com Wed May 20 11:31:27 2009 From: dave.s.doyle at gmail.com (Dave Doyle) Date: Wed, 20 May 2009 14:31:27 -0400 Subject: [tpm] Who's talking this month? In-Reply-To: <5bef4baf0905201124s22cf33cbtd94996b751c40cb2@mail.gmail.com> References: <54b9f338a12ddf54a0e95fa3d95ae1e9.squirrel@webmail.vex.net> <5bef4baf0905191740h13dfadbfm803b4a6f3387bbdb@mail.gmail.com> <9479493E-686B-4CBA-AB55-397E611B9EF7@nurey.com> <42fa432f011396442abd5d538d709ef1.squirrel@webmail.vex.net> <5bef4baf0905201124s22cf33cbtd94996b751c40cb2@mail.gmail.com> Message-ID: ... unless you have a dozen Perl Mongers to help you perform the 1 hour ritual. We could do it in 5 minutes. This does, of course, mean you would have to subscribe to the theory that throwing more programmers at a project at the last minute would make things go faster. Which is, as we all know, true. Yes? :P -- dave.s.doyle at gmail.com On Wed, May 20, 2009 at 2:24 PM, Richard Dice wrote: > Those are some nice sentiments, gang. And I do enjoy bringing her out to > meet people. But her bedtime is 8pm, and there's about a 1 hour long ritual > we need to go through to get her into bed. And if I were to be at 2 Bloor > St. W. it would take me 1/2 hour to get home. The math just doesn't work, > sorry. > > > On Wed, May 20, 2009 at 11:13 AM, Alexandru Capsa wrote: > >> Let's make this one >> >> "Bring your kid to TPM day" >> >> :D >> >> >> >> On Wed, May 20, 2009 at 11:03 AM, wrote: >> >>> > We could help you babysit! >>> > >>> Recruit her as the world's youngest Perlmonger. :-)* >>> >>> _______________________________________________ >>> toronto-pm mailing list >>> toronto-pm at pm.org >>> http://mail.pm.org/mailman/listinfo/toronto-pm >>> >> >> >> >> -- >> Alexandru Capsa >> >> _______________________________________________ >> toronto-pm mailing list >> toronto-pm at pm.org >> http://mail.pm.org/mailman/listinfo/toronto-pm >> >> > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From Mashton at 4All.com Thu May 21 08:00:09 2009 From: Mashton at 4All.com (Mike Ashton) Date: Thu, 21 May 2009 11:00:09 -0400 Subject: [tpm] Net::SFTP In-Reply-To: <946977f783bd4891a36a0bd4a0fc4f41.squirrel@webmail.vex.net> References: <946977f783bd4891a36a0bd4a0fc4f41.squirrel@webmail.vex.net> Message-ID: <4A156C79.9090401@4All.com> We gave up on using Net::SFTP, we ended up using Net::SSH2:SFTP. This module is more up to date and being maintained. It is utilizing the libssh2 of the OS so if you keep your server updated security updates will be there. Hope this helps. Mike arocker at vex.net wrote: > Has anybody used this module? I'm having a problem with downloading files. > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From arocker at vex.net Thu May 21 16:28:57 2009 From: arocker at vex.net (arocker at vex.net) Date: Thu, 21 May 2009 19:28:57 -0400 (EDT) Subject: [tpm] Safe signals Message-ID: <1002ee072184393f4e151827c2c2d964.squirrel@webmail.vex.net> http://www.theregister.co.uk/2009/05/21/perl_safe_signal_handling/ (And we still have to figure out who is speaking next week.) From arocker at vex.net Sun May 24 06:43:37 2009 From: arocker at vex.net (arocker at vex.net) Date: Sun, 24 May 2009 09:43:37 -0400 (EDT) Subject: [tpm] Travel to YAPC Message-ID: <8cd22c37fa21353e6fb57a7a8e90b17c.squirrel@webmail.vex.net> I'm planning to go to Pittsburgh on Friday 19th for the Parrot Workshop, returning on Wednesday 24th after YAPC. If anybody is on the same schedule, has a spare seat, and would like to share expenses, please contact me. From Henry.Baragar at instantiated.ca Sun May 24 17:25:59 2009 From: Henry.Baragar at instantiated.ca (Henry Baragar) Date: Sun, 24 May 2009 20:25:59 -0400 Subject: [tpm] Net::SFTP In-Reply-To: <4A156C79.9090401@4All.com> References: <946977f783bd4891a36a0bd4a0fc4f41.squirrel@webmail.vex.net> <4A156C79.9090401@4All.com> Message-ID: <200905242025.59776.Henry.Baragar@instantiated.ca> We had the same experience as Mike and did the same thing. On May 21, 2009 11:00:09 am Mike Ashton wrote: > We gave up on using Net::SFTP, we ended up using Net::SSH2:SFTP. This > module is more up to date and being maintained. It is utilizing the > libssh2 of the OS so if you keep your server updated security updates > will be there. Hope this helps. > > Mike > > arocker at vex.net wrote: > > Has anybody used this module? I'm having a problem with downloading > > files. > > > > _______________________________________________ > > toronto-pm mailing list > > toronto-pm at pm.org > > http://mail.pm.org/mailman/listinfo/toronto-pm -- Henry Baragar Instantiated Software 416-907-8454 x42 -------------- next part -------------- An HTML attachment was scrubbed... URL: From arocker at vex.net Mon May 25 07:04:58 2009 From: arocker at vex.net (arocker at vex.net) Date: Mon, 25 May 2009 10:04:58 -0400 (EDT) Subject: [tpm] Net::SFTP Message-ID: From: "Henry Baragar" > We had the same experience as Mike and did the same thing. > It turned out to be a PICNIC (Problem In Chair, Not In Computer), in this case. I had assumed the Net::SFTP commands have similar syntax to the shell equivalents. They don't. (For example, the rename required the full filename in the destination, not just a directrory). From antoniosun at lavabit.com Mon May 25 22:20:54 2009 From: antoniosun at lavabit.com (Antonio Sun) Date: Tue, 26 May 2009 01:20:54 -0400 Subject: [tpm] Who's talking this month? In-Reply-To: <54b9f338a12ddf54a0e95fa3d95ae1e9.squirrel@webmail.vex.net> References: <54b9f338a12ddf54a0e95fa3d95ae1e9.squirrel@webmail.vex.net> Message-ID: So, have we decided on anything yet? On Tue, May 19, 2009 at 7:23 PM, wrote: > > I forget. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From samogon at gmail.com Wed May 27 10:13:46 2009 From: samogon at gmail.com (Ilia) Date: Wed, 27 May 2009 13:13:46 -0400 Subject: [tpm] Who's talking this month? In-Reply-To: References: <54b9f338a12ddf54a0e95fa3d95ae1e9.squirrel@webmail.vex.net> Message-ID: I was looking at this today http://rubyjobfair.ca/ and this http://futureruby.eventbrite.com/ Why don't we, the Toronto Perl Community, organize to create something similar? Let's discuss this Thursday. -- Ilia Lobsanov Nurey Networks - http://www.nurey.com New Ideas for a New Economy Python, Perl, Java, Linux & more Toronto +1 647 996 9087 Boston +1 781 328 1162 On Tue, May 26, 2009 at 1:20 AM, Antonio Sun wrote: > So, have we decided on anything yet? > > On Tue, May 19, 2009 at 7:23 PM, wrote: >> >> I forget. > > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm > > From linux at alteeve.com Wed May 27 10:35:28 2009 From: linux at alteeve.com (Madison Kelly) Date: Wed, 27 May 2009 13:35:28 -0400 Subject: [tpm] Job Fair In-Reply-To: References: <54b9f338a12ddf54a0e95fa3d95ae1e9.squirrel@webmail.vex.net> Message-ID: <4A1D79E0.2040006@alteeve.com> Ilia wrote: > I was looking at this today http://rubyjobfair.ca/ and this > http://futureruby.eventbrite.com/ > > Why don't we, the Toronto Perl Community, organize to create something similar? > > Let's discuss this Thursday. Seeing as I won't be able to make it, I'd like to say that I think this would be an amazing idea. Specially at this time with so many people out of work due to the recession. Madi From samogon at gmail.com Wed May 27 16:00:15 2009 From: samogon at gmail.com (Ilia) Date: Wed, 27 May 2009 19:00:15 -0400 Subject: [tpm] disclosed.ca is open sourced Message-ID: While I have everybody's attention, does anyone remember my prezo on disclosed.ca some months ago? I've open sourced the code yesterday. Here's the announcement: http://groups.google.com/group/visiblegovernment-discuss/browse_thread/thread/853777f7cf0872d4 The scraper is all Perl. I would love to see some enthusiasts with free time on their hands contribute to this project. ilia. From arocker at vex.net Thu May 28 06:10:01 2009 From: arocker at vex.net (arocker at vex.net) Date: Thu, 28 May 2009 09:10:01 -0400 (EDT) Subject: [tpm] TPM mtg room Message-ID: Once again, Scott has prevailed upon Nexient to lend us a room. The room allocated is classroom 18 on the 8th floor. It's the "new" one beside the reception desk. (Turn left out of the elevators). Usual arrangements will be in effect. From grof at rogers.com Thu May 28 06:21:26 2009 From: grof at rogers.com (Andrew Ross) Date: Thu, 28 May 2009 09:21:26 -0400 Subject: [tpm] New videos - Perl talks Message-ID: <005501c9df97$3473f480$05000100@rosan01> Hi Everyone, Recently I recorded some great talks. They're available online at the URLs below. Moose: a Perl post-modern object system http://www.fosslc.org/drupal/node/436 By Yanick Champoux Portable Perl Daemons http://www.fosslc.org/drupal/node/437 By Tim Procter Andrew http://fosslc.org From jbl at jbldata.com Thu May 28 06:33:49 2009 From: jbl at jbldata.com (J. Bobby Lopez) Date: Thu, 28 May 2009 09:33:49 -0400 Subject: [tpm] Freemind to Perl Message-ID: Hey all, Not sure if anyone here uses Freemind [ http://freemind.sourceforge.net/wiki/index.php/Main_Page], but I use it quite a bit for brainstorming and as an outliner. One of the better uses of it for me is to hammer an idea for a perl hash tree very quickly. The problem is that once I have the hash tree exactly the way I want it in Freemind, I have to manually re-create the hash tree in perl source, with all the required formatting. This is no longer the case, as I've written a quick and dirty "freemind2perl" script (below) which takes a Freemind mindmap file, and converts it into a perl hash tree automagically. Not sure it will work with all versions of Freemind, but their mindmap files are XML based, and they haven't really changed it across versions. Just run this script with 'freemind2perl.pl file.mm'. It requires the "XML::Simple" perl module to be installed. Again, not sure if anyone here uses Freemind, but I figured I'd share. #-------------------------------------------------------------------------------- #!/usr/bin/perl -w use strict; use XML::Simple; use Data::Dumper; my $xml = new XML::Simple; my $mm_file = shift; my $data = $xml->XMLin("$mm_file"); my $clean; sub prep_clean { my $data = shift; my $clean; foreach my $key ( keys %{ $data } ) { if ( $key eq "TEXT" ) { $clean->{$data->{$key}} = 1; } if ( $key eq "node" ) { if ( ref( $data->{$key} ) eq "HASH" ) { $clean->{$data->{'TEXT'}} = prep_clean(\%{$data->{$key}}); } if ( ref( $data->{$key} ) eq "ARRAY" ) { my $sub_hashes = {}; for ( my $i = 0; $i <= $#{$data->{$key}}; $i++) { foreach my $sub_hash ( \%{ $data->{$key}[$i] } ) { my $subout = prep_clean( $sub_hash ); $sub_hashes = { %$sub_hashes, %$subout }; } } $clean->{$data->{'TEXT'}} = $sub_hashes; } } } return $clean; } $clean = prep_clean( \%{ $data->{'node'} } ); print Dumper(\$clean); exit; #-------------------------------------------------------------------------------- -- J. Bobby Lopez Web: http://jbldata.com/ Twitter: http://www.twitter.com/jbobbylopez -------------- next part -------------- An HTML attachment was scrubbed... URL: From jbl at jbldata.com Thu May 28 11:57:03 2009 From: jbl at jbldata.com (J. Bobby Lopez) Date: Thu, 28 May 2009 14:57:03 -0400 Subject: [tpm] TPM mtg room In-Reply-To: References: Message-ID: I think I'm going to come out and say hello, as I've not met any of you in person, and I think it will do my sanity some good On Thu, May 28, 2009 at 9:10 AM, wrote: > > Once again, Scott has prevailed upon Nexient to lend us a room. > > The room allocated is classroom 18 on the 8th floor. It's the "new" one > beside the reception desk. (Turn left out of the elevators). > > Usual arrangements will be in effect. > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm > -- J. Bobby Lopez Web: http://jbldata.com/ Twitter: http://www.twitter.com/jbobbylopez -------------- next part -------------- An HTML attachment was scrubbed... URL: From abuzarchaudhary at yahoo.com Thu May 28 13:29:44 2009 From: abuzarchaudhary at yahoo.com (Abuzar Chaudhary) Date: Thu, 28 May 2009 13:29:44 -0700 (PDT) Subject: [tpm] TPM mtg room Message-ID: <376888.65492.qm@web52905.mail.re2.yahoo.com> --- On Thu, 5/28/09, J. Bobby Lopez wrote: > I think I'm going to come out and say hello, as I've not met any of you in person, > and I think it will do my sanity some good Awesome, looking forward to seeing you tonight :-) -------------- next part -------------- An HTML attachment was scrubbed... URL: From jbl at jbldata.com Thu May 28 20:42:33 2009 From: jbl at jbldata.com (J. Bobby Lopez) Date: Thu, 28 May 2009 23:42:33 -0400 Subject: [tpm] TPM mtg room In-Reply-To: <376888.65492.qm@web52905.mail.re2.yahoo.com> References: <376888.65492.qm@web52905.mail.re2.yahoo.com> Message-ID: Thank you all for the warm welcome today - very nice to meet those of you who were there. I look forward to the next meet up :) On Thu, May 28, 2009 at 4:29 PM, Abuzar Chaudhary wrote: > > > --- On *Thu, 5/28/09, J. Bobby Lopez * wrote: > > I think I'm going to come out and say hello, as I've not met any of you > in person, > > and I think it will do my sanity some good > > Awesome, looking forward to seeing you tonight :-) > > -- J. Bobby Lopez Web: http://jbldata.com/ Twitter: http://www.twitter.com/jbobbylopez -------------- next part -------------- An HTML attachment was scrubbed... URL: From jbl at jbldata.com Fri May 29 09:17:46 2009 From: jbl at jbldata.com (J. Bobby Lopez) Date: Fri, 29 May 2009 12:17:46 -0400 Subject: [tpm] Bigtable (Hypertable) Message-ID: Last night during our discussion, Abuzar brought up Google's Bigtable database, and the open source Hypertable implementation. I just wanted to follow up on that discussion, as I think anyone who is working with large data-sets may benefit from it. With regards to the tablet implementation - on the surface, its usage looks similar to having multiple tables within a regular RDBMS, but instead of each table within the RDBMS being somewhat "disjointed" from each other (requiring you to "join" rows from multiple tables to get a unique data-set), Hypertable (BigTable) just has each of these tables as sub-tables - part of a bigger main table. Here's the link to the Google research publication regarding BigTable: http://labs.google.com/papers/bigtable.html And Wikipedia's article on BigTable: http://en.wikipedia.org/wiki/BigTable >From what I can see, the benefits include the ability to store extremely large sets of data into a single table, across a distributed file-system (such as GFS), along with having version control "built-in" via another table dimension. All this seems that it is accomplished without the need for a database server of any kind (though I'm not sure about this). Any performance increase, it seems, comes from requiring the client application to cache references to sub-tables within a bigger table. If anyone has a better understanding of how this works, please share! -- J. Bobby Lopez Web: http://jbldata.com/ Twitter: http://www.twitter.com/jbobbylopez -------------- next part -------------- An HTML attachment was scrubbed... URL: From linux at alteeve.com Fri May 29 11:10:38 2009 From: linux at alteeve.com (Madison Kelly) Date: Fri, 29 May 2009 14:10:38 -0400 Subject: [tpm] Is there a three-way version of... Message-ID: <4A20251E.4010906@alteeve.com> my $foo=$bar ? "bing" : "bang"; I am probably trying to extend what the above syntax was designed to address, but I am curious. I've got three strings I want to show based on the viewing user's credentials. I know I can use: my $title=""; if ($a) { $title="bing"; } elsif ($b) { $title="bang"; } else { $title="bong"; } But it's quite a bit more code. Thanks all! Madi From linux at alteeve.com Fri May 29 11:15:26 2009 From: linux at alteeve.com (Madison Kelly) Date: Fri, 29 May 2009 14:15:26 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <4A20251E.4010906@alteeve.com> References: <4A20251E.4010906@alteeve.com> Message-ID: <4A20263E.4030102@alteeve.com> Madison Kelly wrote: > my $foo=$bar ? "bing" : "bang"; > > I am probably trying to extend what the above syntax was designed to > address, but I am curious. I've got three strings I want to show based > on the viewing user's credentials. I know I can use: > > my $title=""; > if ($a) > { > $title="bing"; > } > elsif ($b) > { > $title="bang"; > } > else > { > $title="bong"; > } > > But it's quite a bit more code. > > Thanks all! > > Madi Sorry to reply to my own question, but I did think of: my $title="bong"; $title="bang" if $b; $title="bing" if $a; Though I would still be interested in another way more similar to: my $foo=$bar ? "bing" : "bang"; Madi From dave.s.doyle at gmail.com Fri May 29 11:20:24 2009 From: dave.s.doyle at gmail.com (Dave Doyle) Date: Fri, 29 May 2009 14:20:24 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <4A20263E.4030102@alteeve.com> References: <4A20251E.4010906@alteeve.com> <4A20263E.4030102@alteeve.com> Message-ID: In one line: my $title= $a ? 'bing' : $b ? 'bang' : 'bong'; but more readable as per PBP: my $title = $a ? 'bing' : $b ? 'bang' : 'bong'; D dave.s.doyle at gmail.com On Fri, May 29, 2009 at 2:15 PM, Madison Kelly wrote: > > Madison Kelly wrote: >> >> my $foo=$bar ? "bing" : "bang"; >> >> I am probably trying to extend what the above syntax was designed to address, but I am curious. I've got three strings I want to show based on the viewing user's credentials. I know I can use: >> >> my $title=""; >> if ($a) >> { >> ? ?$title="bing"; >> } >> elsif ($b) >> { >> ? ?$title="bang"; >> } >> else >> { >> ? ?$title="bong"; >> } >> >> But it's quite a bit more code. >> >> Thanks all! >> >> Madi > > Sorry to reply to my own question, but I did think of: > > my $title="bong"; > $title="bang" if $b; > $title="bing" if $a; > > Though I would still be interested in another way more similar to: > > my $foo=$bar ? "bing" : "bang"; > > Madi > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm From talexb at gmail.com Fri May 29 11:23:12 2009 From: talexb at gmail.com (Alex Beamish) Date: Fri, 29 May 2009 14:23:12 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <4A20263E.4030102@alteeve.com> References: <4A20251E.4010906@alteeve.com> <4A20263E.4030102@alteeve.com> Message-ID: On Fri, May 29, 2009 at 2:15 PM, Madison Kelly wrote: > Madison Kelly wrote: >> >> my $foo=$bar ? "bing" : "bang"; >> >> I am probably trying to extend what the above syntax was designed to >> address, but I am curious. I've got three strings I want to show based on >> the viewing user's credentials. I know I can use: >> >> my $title=""; >> if ($a) >> { >> ? ?$title="bing"; >> } >> elsif ($b) >> { >> ? ?$title="bang"; >> } >> else >> { >> ? ?$title="bong"; >> } >> >> But it's quite a bit more code. >> >> Thanks all! >> >> Madi > > Sorry to reply to my own question, but I did think of: > > my $title="bong"; > $title="bang" if $b; > $title="bing" if $a; > > Though I would still be interested in another way more similar to: > > my $foo=$bar ? "bing" : "bang"; How about $title = $aa ? "bing" : ( $bb ? "bang" : "bong" ); I've doubled the variable names, since you should never get into the habit of using $a and $b -- remember that those are special variables for in-place sorting. -- Alex Beamish Toronto, Ontario aka talexb From mike at stok.ca Fri May 29 11:23:41 2009 From: mike at stok.ca (Mike Stok) Date: Fri, 29 May 2009 14:23:41 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <4A20263E.4030102@alteeve.com> References: <4A20251E.4010906@alteeve.com> <4A20263E.4030102@alteeve.com> Message-ID: <04D83EA0-688D-4CEE-AA6B-C00BC98E4A28@stok.ca> On May 29, 2009, at 2:15 PM, Madison Kelly wrote: > Madison Kelly wrote: >> my $foo=$bar ? "bing" : "bang"; >> I am probably trying to extend what the above syntax was designed >> to address, but I am curious. I've got three strings I want to show >> based on the viewing user's credentials. I know I can use: >> my $title=""; >> if ($a) >> { >> $title="bing"; >> } >> elsif ($b) >> { >> $title="bang"; >> } >> else >> { >> $title="bong"; >> } >> But it's quite a bit more code. >> Thanks all! >> Madi > > Sorry to reply to my own question, but I did think of: > > my $title="bong"; > $title="bang" if $b; > $title="bing" if $a; > > Though I would still be interested in another way more similar to: > > my $foo=$bar ? "bing" : "bang"; > You can chain ?: for example in the debugger: main::(-e:1): 1 DB<1> $x = 0; $y = 0 DB<2> print $x ? 'bing' : $y ? 'bang' : 'bong' bong DB<3> $x = 0; $y = 1 DB<4> print $x ? 'bing' : $y ? 'bang' : 'bong' bang DB<5> $x = 1, $y = 0 DB<6> print $x ? 'bing' : $y ? 'bang' : 'bong' bing Layout is left up to you :-) Mike > Madi > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm -- Mike Stok http://www.stok.ca/~mike/ The "`Stok' disclaimers" apply. -------------- next part -------------- An HTML attachment was scrubbed... URL: From dave.s.doyle at gmail.com Fri May 29 11:24:10 2009 From: dave.s.doyle at gmail.com (Dave Doyle) Date: Fri, 29 May 2009 14:24:10 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: References: <4A20251E.4010906@alteeve.com> <4A20263E.4030102@alteeve.com> Message-ID: Addendum: You can chain the ternary operator as much as you want. Laying out in a table-like way is adviced. my $title = $condition1 ? 'result1' : $condition2 ? 'result2' : $condition 3 ? 'result3' # ... more lines here : 'default'; -- dave.s.doyle at gmail.com On Fri, May 29, 2009 at 2:20 PM, Dave Doyle wrote: > In one line: > > my $title= $a ? 'bing' : $b ? 'bang' : 'bong'; > > but more readable as per PBP: > > my $title = $a ? 'bing' > ? ? ? ? ? ? : ?$b ? 'bang' > ? ? ? ? ? ? : ? ? ? ? 'bong'; > > > D > > dave.s.doyle at gmail.com > > > On Fri, May 29, 2009 at 2:15 PM, Madison Kelly wrote: >> >> Madison Kelly wrote: >>> >>> my $foo=$bar ? "bing" : "bang"; >>> >>> I am probably trying to extend what the above syntax was designed to address, but I am curious. I've got three strings I want to show based on the viewing user's credentials. I know I can use: >>> >>> my $title=""; >>> if ($a) >>> { >>> ? ?$title="bing"; >>> } >>> elsif ($b) >>> { >>> ? ?$title="bang"; >>> } >>> else >>> { >>> ? ?$title="bong"; >>> } >>> >>> But it's quite a bit more code. >>> >>> Thanks all! >>> >>> Madi >> >> Sorry to reply to my own question, but I did think of: >> >> my $title="bong"; >> $title="bang" if $b; >> $title="bing" if $a; >> >> Though I would still be interested in another way more similar to: >> >> my $foo=$bar ? "bing" : "bang"; >> >> Madi >> _______________________________________________ >> toronto-pm mailing list >> toronto-pm at pm.org >> http://mail.pm.org/mailman/listinfo/toronto-pm > From liam at holoweb.net Fri May 29 11:30:04 2009 From: liam at holoweb.net (Liam R E Quin) Date: Fri, 29 May 2009 14:30:04 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <4A20263E.4030102@alteeve.com> References: <4A20251E.4010906@alteeve.com> <4A20263E.4030102@alteeve.com> Message-ID: <1243621804.27720.63.camel@desktop.barefootcomputing.com> On Fri, 2009-05-29 at 14:15 -0400, Madison Kelly wrote: > > my $title=""; > > if ($a) > > { > > $title="bing"; > > } > > elsif ($b) > > { > > $title="bang"; > > } > > else > > { > > $title="bong"; > > } Well, if ($a) { $title = "bing"; } elsif ($b) { $title = "bang"; } else { $title = "bong"; } is a considerable improvement :) You can shorten it with, $title = ("bing", "bang", "bong")[ $a ? 0 : $b ? 1 : 2] but now no-one can understand it. > my $title="bong"; > $title="bang" if $b; > $title="bing" if $a; is also more compact. Most likely I'd use the chained if/else with the layout shown, but that's because I have a background in C, and no shoes. :D Liam -- Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/ Pictures from old books: http://fromoldbooks.org/ Ankh: irc.sorcery.net irc.gnome.org www.advogato.org From linux at alteeve.com Fri May 29 12:26:56 2009 From: linux at alteeve.com (Madison Kelly) Date: Fri, 29 May 2009 15:26:56 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: References: <4A20251E.4010906@alteeve.com> <4A20263E.4030102@alteeve.com> Message-ID: <4A203700.80906@alteeve.com> Dave Doyle wrote: > Addendum: > > You can chain the ternary operator as much as you want. Laying out in > a table-like way is adviced. > > my $title = $condition1 ? 'result1' > : $condition2 ? 'result2' > : $condition 3 ? 'result3' > # ... more lines here > : 'default'; > > -- > dave.s.doyle at gmail.com Huh, didn't realize you could chain it like that. Thanks! Madi From matt at starnix.com Fri May 29 13:01:01 2009 From: matt at starnix.com (G. Matthew Rice) Date: 29 May 2009 16:01:01 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <4A203700.80906@alteeve.com> References: <4A20251E.4010906@alteeve.com> <4A20263E.4030102@alteeve.com> <4A203700.80906@alteeve.com> Message-ID: Madison Kelly writes: > > a table-like way is adviced. > > my $title = $condition1 ? 'result1' > > : $condition2 ? 'result2' > > : $condition 3 ? 'result3' > > # ... more lines here Yuch. Looks like C :) Mine looks similar to another one I saw: my $title = {aa => 'bing', bb => 'bang'}->{$key} || 'bong'; -- g. matthew rice starnix care, toronto, ontario, ca phone: 647.722.5301 x242 gpg id: EF9AAD20 http://www.starnix.com professional linux services & products From uri at StemSystems.com Fri May 29 12:32:22 2009 From: uri at StemSystems.com (Uri Guttman) Date: Fri, 29 May 2009 15:32:22 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <4A203700.80906@alteeve.com> (Madison Kelly's message of "Fri\, 29 May 2009 15\:26\:56 -0400") References: <4A20251E.4010906@alteeve.com> <4A20263E.4030102@alteeve.com> <4A203700.80906@alteeve.com> Message-ID: <87vdnjogc9.fsf@quad.sysarch.com> >>>>> "MK" == Madison Kelly writes: MK> Dave Doyle wrote: >> Addendum: >> >> You can chain the ternary operator as much as you want. Laying out in >> a table-like way is adviced. >> >> my $title = $condition1 ? 'result1' >> : $condition2 ? 'result2' >> : $condition 3 ? 'result3' >> # ... more lines here >> : 'default'; >> >> -- >> dave.s.doyle at gmail.com MK> Huh, didn't realize you could chain it like that. Thanks! just to add to that, you can chain ANY expression in perl (as with most any language). chaining is how you build up complex expressions. this is no different that doing $x * $y + $z which is chaining too. thinking you can't chain ?: is like newbies who see print < References: <4A20251E.4010906@alteeve.com> <4A20263E.4030102@alteeve.com> <4A203700.80906@alteeve.com> Message-ID: <45535519-7D9D-42CA-8EE7-98CC75B7DB40@stok.ca> On May 29, 2009, at 4:01 PM, G. Matthew Rice wrote: > Madison Kelly writes: >>> a table-like way is adviced. >>> my $title = $condition1 ? 'result1' >>> : $condition2 ? 'result2' >>> : $condition 3 ? 'result3' >>> # ... more lines here > > Yuch. Looks like C :) > > Mine looks similar to another one I saw: > > my $title = {aa => 'bing', bb => 'bang'}->{$key} || 'bong'; Or even use // there if your perl is recent enough, in case you ever might have cases involving false but defined strings. my $title = { aa => 'bing', bb => 'bang', cc => '0', dd => '' }- >{$key} // 'bong'; Mike -- Mike Stok http://www.stok.ca/~mike/ The "`Stok' disclaimers" apply. From linux at alteeve.com Fri May 29 13:17:14 2009 From: linux at alteeve.com (Madison Kelly) Date: Fri, 29 May 2009 16:17:14 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <45535519-7D9D-42CA-8EE7-98CC75B7DB40@stok.ca> References: <4A20251E.4010906@alteeve.com> <4A20263E.4030102@alteeve.com> <4A203700.80906@alteeve.com> <45535519-7D9D-42CA-8EE7-98CC75B7DB40@stok.ca> Message-ID: <4A2042CA.1030909@alteeve.com> Mike Stok wrote: > > On May 29, 2009, at 4:01 PM, G. Matthew Rice wrote: > >> Madison Kelly writes: >>>> a table-like way is adviced. >>>> my $title = $condition1 ? 'result1' >>>> : $condition2 ? 'result2' >>>> : $condition 3 ? 'result3' >>>> # ... more lines here >> >> Yuch. Looks like C :) >> >> Mine looks similar to another one I saw: >> >> my $title = {aa => 'bing', bb => 'bang'}->{$key} || 'bong'; > > > Or even use // there if your perl is recent enough, in case you ever > might have cases involving false but defined strings. > > my $title = { aa => 'bing', bb => 'bang', cc => '0', dd => '' > }->{$key} // 'bong'; > > Mike > I'm not familiar with the '//' operator. It is ... ? Madi From mike at stok.ca Fri May 29 13:20:48 2009 From: mike at stok.ca (Mike Stok) Date: Fri, 29 May 2009 16:20:48 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <4A2042CA.1030909@alteeve.com> References: <4A20251E.4010906@alteeve.com> <4A20263E.4030102@alteeve.com> <4A203700.80906@alteeve.com> <45535519-7D9D-42CA-8EE7-98CC75B7DB40@stok.ca> <4A2042CA.1030909@alteeve.com> Message-ID: <6A5D7C88-A25B-49F5-A0C1-3DEAEDB87FC1@stok.ca> On May 29, 2009, at 4:17 PM, Madison Kelly wrote: > Mike Stok wrote: >> On May 29, 2009, at 4:01 PM, G. Matthew Rice wrote: >>> Madison Kelly writes: >>>>> a table-like way is adviced. >>>>> my $title = $condition1 ? 'result1' >>>>> : $condition2 ? 'result2' >>>>> : $condition 3 ? 'result3' >>>>> # ... more lines here >>> >>> Yuch. Looks like C :) >>> >>> Mine looks similar to another one I saw: >>> >>> my $title = {aa => 'bing', bb => 'bang'}->{$key} || 'bong'; >> Or even use // there if your perl is recent enough, in case you >> ever might have cases involving false but defined strings. >> my $title = { aa => 'bing', bb => 'bang', cc => '0', dd => '' }- >> >{$key} // 'bong'; >> Mike > > I'm not familiar with the '//' operator. It is ... ? > > Madi As of perl 5.10 (I think) it is the "defined or" operator which only returns the right hand side if the left hand side is undef, from perlop: C?style Logical Defined?Or Although it has no direct equivalent in C, Perl?s "//" operator is related to its C?style or. In fact, it?s exactly the same as "||", except that it tests the left hand side?s definedness instead of its truth. Thus, "$a // $b" is similar to "defined($a) || $b" (except that it returns the value of $a rather than the value of "defined($a)") and is exactly equivalent to "defined($a) ? $a : $b". This is very useful for providing default values for variables. If you actually want to test if at least one of $a and $b is defined, use "defined($a // $b)". The "||", "//" and "&&" operators return the last value evaluated (unlike C?s "||" and "&&", which return 0 or 1). Mike -- Mike Stok http://www.stok.ca/~mike/ The "`Stok' disclaimers" apply. From alexcapsa at gmail.com Fri May 29 13:23:19 2009 From: alexcapsa at gmail.com (Alexandru Capsa) Date: Fri, 29 May 2009 16:23:19 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <6A5D7C88-A25B-49F5-A0C1-3DEAEDB87FC1@stok.ca> References: <4A20251E.4010906@alteeve.com> <4A20263E.4030102@alteeve.com> <4A203700.80906@alteeve.com> <45535519-7D9D-42CA-8EE7-98CC75B7DB40@stok.ca> <4A2042CA.1030909@alteeve.com> <6A5D7C88-A25B-49F5-A0C1-3DEAEDB87FC1@stok.ca> Message-ID: In another words: $a // $b same as defined $a ? $a : $b The operator was added in Perl 5.10.0 http://perldoc.perl.org/perldelta.html On Fri, May 29, 2009 at 4:20 PM, Mike Stok wrote: > > On May 29, 2009, at 4:17 PM, Madison Kelly wrote: > > Mike Stok wrote: >> >>> On May 29, 2009, at 4:01 PM, G. Matthew Rice wrote: >>> >>>> Madison Kelly writes: >>>> >>>>> a table-like way is adviced. >>>>>> my $title = $condition1 ? 'result1' >>>>>> : $condition2 ? 'result2' >>>>>> : $condition 3 ? 'result3' >>>>>> # ... more lines here >>>>>> >>>>> >>>> Yuch. Looks like C :) >>>> >>>> Mine looks similar to another one I saw: >>>> >>>> my $title = {aa => 'bing', bb => 'bang'}->{$key} || 'bong'; >>>> >>> Or even use // there if your perl is recent enough, in case you ever >>> might have cases involving false but defined strings. >>> my $title = { aa => 'bing', bb => 'bang', cc => '0', dd => '' }->{$key} >>> // 'bong'; >>> Mike >>> >> >> I'm not familiar with the '//' operator. It is ... ? >> >> Madi >> > > As of perl 5.10 (I think) it is the "defined or" operator which only > returns the right hand side if the left hand side is undef, from perlop: > > C?style Logical Defined?Or > > Although it has no direct equivalent in C, Perl?s "//" operator is > related to its C?style or. In fact, it?s exactly the same as "||", > except that it tests the left hand side?s definedness instead of its > truth. Thus, "$a // $b" is similar to "defined($a) || $b" (except > that > it returns the value of $a rather than the value of "defined($a)") > and > is exactly equivalent to "defined($a) ? $a : $b". This is very > useful > for providing default values for variables. If you actually want to > test if at least one of $a and $b is defined, use "defined($a // > $b)". > > The "||", "//" and "&&" operators return the last value evaluated > (unlike C?s "||" and "&&", which return 0 or 1). > > Mike > > -- > > Mike Stok > http://www.stok.ca/~mike/ > > The "`Stok' disclaimers" apply. > > > > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm > -- Alexandru Capsa -------------- next part -------------- An HTML attachment was scrubbed... URL: From matt at starnix.com Fri May 29 13:31:42 2009 From: matt at starnix.com (G. Matthew Rice) Date: Fri, 29 May 2009 16:31:42 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <45535519-7D9D-42CA-8EE7-98CC75B7DB40@stok.ca> References: <4A20251E.4010906@alteeve.com> <4A20263E.4030102@alteeve.com> <4A203700.80906@alteeve.com> <45535519-7D9D-42CA-8EE7-98CC75B7DB40@stok.ca> Message-ID: <1243629102.24395.1.camel@hatsya.starnix.com> On Fri, 2009-05-29 at 16:10 -0400, Mike Stok wrote: > > my $title = {aa => 'bing', bb => 'bang'}->{$key} || 'bong'; > > Or even use // there if your perl is recent enough, in case you ever > might have cases involving false but defined strings. > > my $title = { aa => 'bing', bb => 'bang', cc => '0', dd => '' }- > >{$key} // 'bong'; Err :) Yeah, I thought of that but after my C crack I didn't want someone complaining that my sample looked like C++. --matt From john at perlwolf.com Fri May 29 13:43:56 2009 From: john at perlwolf.com (John Macdonald) Date: Fri, 29 May 2009 16:43:56 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <6A5D7C88-A25B-49F5-A0C1-3DEAEDB87FC1@stok.ca> References: <4A20251E.4010906@alteeve.com> <4A20263E.4030102@alteeve.com> <4A203700.80906@alteeve.com> <45535519-7D9D-42CA-8EE7-98CC75B7DB40@stok.ca> <4A2042CA.1030909@alteeve.com> <6A5D7C88-A25B-49F5-A0C1-3DEAEDB87FC1@stok.ca> Message-ID: <20090529204356.GD4363@perlwolf.com> On Fri, May 29, 2009 at 04:20:48PM -0400, Mike Stok wrote: > As of perl 5.10 (I think) it is the "defined or" operator which only > returns the right hand side if the left hand side is undef, from perlop: > > C?style Logical Defined?Or > > Although it has no direct equivalent in C, Perl?s "//" operator is > related to its C?style or. In fact, it?s exactly the same as > "||", > except that it tests the left hand side?s definedness instead of > its > truth. Thus, "$a // $b" is similar to "defined($a) || $b" (except > that > it returns the value of $a rather than the value of > "defined($a)") and > is exactly equivalent to "defined($a) ? $a : $b". This is very > useful > for providing default values for variables. If you actually want > to > test if at least one of $a and $b is defined, use "defined($a // > $b)". > > The "||", "//" and "&&" operators return the last value evaluated > (unlike C?s "||" and "&&", which return 0 or 1). This is especially useful for setting a value that can come from multiple optional locations, and using the first one that was actually provided: $foo = $opt{foo} || $ENV{PROG_FOO} || $rc_opts{foo} || 'default'; and, as Mike said, this will still take the first one found even if the explicitly provided value is 0 or ''. e.g.: prog --foo=0 The || operator would skip this setting (because it's false) and go on to getting the setting of foo from the alternate sources. From jbl at jbldata.com Fri May 29 23:54:13 2009 From: jbl at jbldata.com (J. Bobby Lopez) Date: Sat, 30 May 2009 02:54:13 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <20090529204356.GD4363@perlwolf.com> References: <4A20251E.4010906@alteeve.com> <4A20263E.4030102@alteeve.com> <4A203700.80906@alteeve.com> <45535519-7D9D-42CA-8EE7-98CC75B7DB40@stok.ca> <4A2042CA.1030909@alteeve.com> <6A5D7C88-A25B-49F5-A0C1-3DEAEDB87FC1@stok.ca> <20090529204356.GD4363@perlwolf.com> Message-ID: It basically looks like we're talking about switch statements. An alternate method of doing the same thing would be as follows, though I'm not sure how expensive it is: $a = ""; $a = $b if $a = ""; $a = $c if $a = ""; $a = $d if $a = ""; ... $a = "default" if $a = ""; On Fri, May 29, 2009 at 4:43 PM, John Macdonald wrote: > On Fri, May 29, 2009 at 04:20:48PM -0400, Mike Stok wrote: > > As of perl 5.10 (I think) it is the "defined or" operator which only > > returns the right hand side if the left hand side is undef, from perlop: > > > > C?style Logical Defined?Or > > > > Although it has no direct equivalent in C, Perl?s "//" operator is > > related to its C?style or. In fact, it?s exactly the same as > > "||", > > except that it tests the left hand side?s definedness instead of > > its > > truth. Thus, "$a // $b" is similar to "defined($a) || $b" (except > > that > > it returns the value of $a rather than the value of > > "defined($a)") and > > is exactly equivalent to "defined($a) ? $a : $b". This is very > > useful > > for providing default values for variables. If you actually want > > to > > test if at least one of $a and $b is defined, use "defined($a // > > $b)". > > > > The "||", "//" and "&&" operators return the last value evaluated > > (unlike C?s "||" and "&&", which return 0 or 1). > > This is especially useful for setting a value that can come from > multiple optional locations, and using the first one that was > actually provided: > > $foo = $opt{foo} || $ENV{PROG_FOO} || $rc_opts{foo} || 'default'; > > and, as Mike said, this will still take the first one found even > if the explicitly provided value is 0 or ''. e.g.: > > prog --foo=0 > > The || operator would skip this setting (because it's false) and > go on to getting the setting of foo from the alternate sources. > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm > -- J. Bobby Lopez Web: http://jbldata.com/ Twitter: http://www.twitter.com/jbobbylopez -------------- next part -------------- An HTML attachment was scrubbed... URL: From uri at StemSystems.com Sat May 30 11:09:50 2009 From: uri at StemSystems.com (Uri Guttman) Date: Sat, 30 May 2009 14:09:50 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: (J. Bobby Lopez's message of "Sat\, 30 May 2009 02\:54\:13 -0400") References: <4A20251E.4010906@alteeve.com> <4A20263E.4030102@alteeve.com> <4A203700.80906@alteeve.com> <45535519-7D9D-42CA-8EE7-98CC75B7DB40@stok.ca> <4A2042CA.1030909@alteeve.com> <6A5D7C88-A25B-49F5-A0C1-3DEAEDB87FC1@stok.ca> <20090529204356.GD4363@perlwolf.com> Message-ID: <87bppalaxd.fsf@quad.sysarch.com> >>>>> "JBL" == J Bobby Lopez writes: JBL> It basically looks like we're talking about switch statements. An JBL> alternate method of doing the same thing would be as follows, JBL> though I'm not sure how expensive it is: JBL> $a = ""; JBL> $a = $b if $a = ""; JBL> $a = $c if $a = ""; JBL> $a = $d if $a = ""; JBL> ... JBL> $a = "default" if $a = ""; regardless of expense, it helps to have it correct. if you were to check for numbers then use ==. but for strings use 'eq'. what you have will assign '' to $a and then fail the if each time and never assign anything else to $a. and the chain of if's like that is expensive compared to a chained set of ?: as yours has to test each time whereas the other will break out when it has to. uri -- Uri Guttman ------ uri at stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Free Perl Training --- http://perlhunter.com/college.html --------- --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- From sfryer at sourcery.ca Sat May 30 11:30:37 2009 From: sfryer at sourcery.ca (Shaun Fryer) Date: Sat, 30 May 2009 14:30:37 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <20090529204356.GD4363@perlwolf.com> References: <4A20251E.4010906@alteeve.com> <4A20263E.4030102@alteeve.com> <4A203700.80906@alteeve.com> <45535519-7D9D-42CA-8EE7-98CC75B7DB40@stok.ca> <4A2042CA.1030909@alteeve.com> <6A5D7C88-A25B-49F5-A0C1-3DEAEDB87FC1@stok.ca> <20090529204356.GD4363@perlwolf.com> Message-ID: <982579710905301130t5d45aaa4v71a964f0c62b3f81@mail.gmail.com> >> ? ? ? ?The "||", "//" and "&&" operators return the last value evaluated >> ? ? ? ?(unlike C?s "||" and "&&", which return 0 or 1). > ? ?$foo = $opt{foo} || $ENV{PROG_FOO} || $rc_opts{foo} || 'default'; This is interesting. I learned something new. Now I'm personally curious if there's an operator that instead of doing "or equals", does "equals or". For instance, I find myself doing this alot (particularly in accessors/setters)... $x = $y if defined $y; What would be helpful is to be able to do this instead. $x =|| $y; Or even better... $x =// $y; Shaun Fryer From mike at stok.ca Sat May 30 12:20:22 2009 From: mike at stok.ca (Mike Stok) Date: Sat, 30 May 2009 15:20:22 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <982579710905301130t5d45aaa4v71a964f0c62b3f81@mail.gmail.com> References: <4A20251E.4010906@alteeve.com> <4A20263E.4030102@alteeve.com> <4A203700.80906@alteeve.com> <45535519-7D9D-42CA-8EE7-98CC75B7DB40@stok.ca> <4A2042CA.1030909@alteeve.com> <6A5D7C88-A25B-49F5-A0C1-3DEAEDB87FC1@stok.ca> <20090529204356.GD4363@perlwolf.com> <982579710905301130t5d45aaa4v71a964f0c62b3f81@mail.gmail.com> Message-ID: <58862122-1ABE-4358-A48A-D37A2169E71E@stok.ca> On May 30, 2009, at 2:30 PM, Shaun Fryer wrote: >>> The "||", "//" and "&&" operators return the last value >>> evaluated >>> (unlike C?s "||" and "&&", which return 0 or 1). > >> $foo = $opt{foo} || $ENV{PROG_FOO} || $rc_opts{foo} || 'default'; > > This is interesting. I learned something new. Now I'm personally > curious if there's an operator that instead of doing "or equals", does > "equals or". For instance, I find myself doing this alot (particularly > in accessors/setters)... > > $x = $y if defined $y; > > What would be helpful is to be able to do this instead. > > $x =|| $y; > > Or even better... > > $x =// $y; Maybe $x = $y // $x? If that's in the context of a routine which acts as both a reader and writer of an attribute then it might be safer to count arguments so you can tell the difference between $obj->get_or_set(); and $obj->get_or_set(undef); depending on context and circumstance, of course. Mike -- Mike Stok http://www.stok.ca/~mike/ The "`Stok' disclaimers" apply. From uri at StemSystems.com Sat May 30 12:29:11 2009 From: uri at StemSystems.com (Uri Guttman) Date: Sat, 30 May 2009 15:29:11 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <982579710905301130t5d45aaa4v71a964f0c62b3f81@mail.gmail.com> (Shaun Fryer's message of "Sat\, 30 May 2009 14\:30\:37 -0400") References: <4A20251E.4010906@alteeve.com> <4A20263E.4030102@alteeve.com> <4A203700.80906@alteeve.com> <45535519-7D9D-42CA-8EE7-98CC75B7DB40@stok.ca> <4A2042CA.1030909@alteeve.com> <6A5D7C88-A25B-49F5-A0C1-3DEAEDB87FC1@stok.ca> <20090529204356.GD4363@perlwolf.com> <982579710905301130t5d45aaa4v71a964f0c62b3f81@mail.gmail.com> Message-ID: <87bppajsoo.fsf@quad.sysarch.com> >>>>> "SF" == Shaun Fryer writes: SF> This is interesting. I learned something new. Now I'm personally SF> curious if there's an operator that instead of doing "or equals", does SF> "equals or". For instance, I find myself doing this alot (particularly SF> in accessors/setters)... SF> $x = $y if defined $y; or you can do: $x = $y // $x ; as for accessors/setters i bet you are doing something like this: sub foo { my $self = shift ; my $val = shift ; $self->{foo} = $val if defined $val ; return $self->{foo} ; } that has a minor flaw. you can't tell if val was passed in vs a real undef was passed in. as in which of these will undef the value? foo() ; foo( undef ) ; in the above code, neither will undef it and both do the same thing which is just return the old value. the proper solution (which also eliminates your reverse defined or problem) is to check @_'s length. this way you know if any arg was passed in for val. there are variations on this but this is one simple version: sub foo { my( $self, $val ) = @_ ; # see if any args were passed to foo(). note that the object is first so # don't count it. $self->{foo} = $val if @_ > 1 ; # another variant is: # # $self->{foo} = $_[1] if @_ > 1 ; # and if you shifted out the object then this would work: # $self->{foo} = shift if @_ ; return $self->{foo} ; } uri -- Uri Guttman ------ uri at stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Free Perl Training --- http://perlhunter.com/college.html --------- --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- From sfryer at sourcery.ca Sat May 30 12:49:50 2009 From: sfryer at sourcery.ca (Shaun Fryer) Date: Sat, 30 May 2009 15:49:50 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <87bppajsoo.fsf@quad.sysarch.com> References: <4A20251E.4010906@alteeve.com> <4A203700.80906@alteeve.com> <45535519-7D9D-42CA-8EE7-98CC75B7DB40@stok.ca> <4A2042CA.1030909@alteeve.com> <6A5D7C88-A25B-49F5-A0C1-3DEAEDB87FC1@stok.ca> <20090529204356.GD4363@perlwolf.com> <982579710905301130t5d45aaa4v71a964f0c62b3f81@mail.gmail.com> <87bppajsoo.fsf@quad.sysarch.com> Message-ID: <982579710905301249u5fe355e5x16c8650e9f6dbb44@mail.gmail.com> Thanks Guys, > ? ? ? ?foo() ; > ? ? ? ?foo( undef ) ; Indeed! > # ? ? ? $self->{foo} = shift if @_ ; I like that one. Short and sweet. The reason I was looking for a more compact version is I find myself also often doing this kind of evaluation on one or another type of nested reference. For instance. $$aref[$i][$j][$k] = $$href{foo}{bar}{baz} if defined $$href{foo}{bar}{baz}; Hopefully it's clear the merits of being able to do the following instead. $$aref[$i][$j][$k] =// $$href{foo}{bar}{baz}; Perhaps I'm just being [too] lazy. Or a new trick for Perl 6... Anyway, next question... Seeing you do "@array > 1" made me wonder about a particular style issue. In the past I've done just that, but recently have started explicitly doing "scalar(@array) > 0" alot more often (by default). It's been my understanding that the "$#array" idiom is deprecated. If there are arguments for/against each of the above, what are they? Maybe I'm making a mountain out of a molehill for nothing...? Cheers, Shaun Fryer From uri at StemSystems.com Sat May 30 13:30:51 2009 From: uri at StemSystems.com (Uri Guttman) Date: Sat, 30 May 2009 16:30:51 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <982579710905301249u5fe355e5x16c8650e9f6dbb44@mail.gmail.com> (Shaun Fryer's message of "Sat\, 30 May 2009 15\:49\:50 -0400") References: <4A20251E.4010906@alteeve.com> <4A203700.80906@alteeve.com> <45535519-7D9D-42CA-8EE7-98CC75B7DB40@stok.ca> <4A2042CA.1030909@alteeve.com> <6A5D7C88-A25B-49F5-A0C1-3DEAEDB87FC1@stok.ca> <20090529204356.GD4363@perlwolf.com> <982579710905301130t5d45aaa4v71a964f0c62b3f81@mail.gmail.com> <87bppajsoo.fsf@quad.sysarch.com> <982579710905301249u5fe355e5x16c8650e9f6dbb44@mail.gmail.com> Message-ID: <87tz32ib9g.fsf@quad.sysarch.com> >>>>> "SF" == Shaun Fryer writes: >> ? ? ? ?foo() ; >> ? ? ? ?foo( undef ) ; SF> Indeed! >> # ? ? ? $self->{foo} = shift if @_ ; SF> I like that one. Short and sweet. The reason I was looking for a more SF> compact version is I find myself also often doing this kind of i generally don't like using shift on @_ and prefer to assign it. for accessors it makes a little more sense but i don't write them too often and if i do, i automate creating them somehow. SF> evaluation on one or another type of nested reference. For instance. SF> $$aref[$i][$j][$k] = $$href{foo}{bar}{baz} if defined $$href{foo}{bar}{baz}; SF> Hopefully it's clear the merits of being able to do the following instead. SF> $$aref[$i][$j][$k] =// $$href{foo}{bar}{baz}; you are missing a more important problem there. never duplicate deep access code. use a temp var with the lower level reference and it will be clearer and if you do need multiple uses, faster. also don't use $$aref[...]. instead use $aref-> as it is clearer as well. so i would redo the above as: my $kref = \$aref->[$i][$j][$k] ; my $bazref = \$href->{foo}{bar}{baz}; ${$kref} = ${$bazref} if defined ${$bazref} ; note that when you are doing deep accesses they are usually done multiple times and commonly in loops. so you can factor out the higher level access parts and do them before the loop. then the loop is cleaner and faster as well. it is very hard to read and understand deep access expressions so try to minimize their use with temps and other tricks. SF> Seeing you do "@array > 1" made me wonder about a particular style SF> issue. In the past I've done just that, but recently have started SF> explicitly doing "scalar(@array) > 0" alot more often (by default). SF> It's been my understanding that the "$#array" idiom is deprecated. If SF> there are arguments for/against each of the above, what are they? SF> Maybe I'm making a mountain out of a molehill for nothing...? don't use scalar as it is redundant. arrays in scalar context return their size which is all you need to know. when i see extraneous scalar() calls like that i always mark it and let the author know. as for $#array it is useful in the right context such as 0 .. $#array. it is not deprecated but it is usually clearer to use @array when you want to deal with the size of the array vs the last index. @array > 1 $#array > 0 the former is better and easier to read. also in the bizarre case of someone setting $] which changes the index origin, @array will stay the same but $#array will change. uri -- Uri Guttman ------ uri at stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Free Perl Training --- http://perlhunter.com/college.html --------- --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- From sfryer at sourcery.ca Sat May 30 14:20:56 2009 From: sfryer at sourcery.ca (Shaun Fryer) Date: Sat, 30 May 2009 17:20:56 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <87tz32ib9g.fsf@quad.sysarch.com> References: <4A20251E.4010906@alteeve.com> <45535519-7D9D-42CA-8EE7-98CC75B7DB40@stok.ca> <4A2042CA.1030909@alteeve.com> <6A5D7C88-A25B-49F5-A0C1-3DEAEDB87FC1@stok.ca> <20090529204356.GD4363@perlwolf.com> <982579710905301130t5d45aaa4v71a964f0c62b3f81@mail.gmail.com> <87bppajsoo.fsf@quad.sysarch.com> <982579710905301249u5fe355e5x16c8650e9f6dbb44@mail.gmail.com> <87tz32ib9g.fsf@quad.sysarch.com> Message-ID: <982579710905301420r3b06e833x5b4336e9558a67a7@mail.gmail.com> > i generally don't like using shift on @_ and prefer to assign it. True for complex stuff. My feeling is that when it's a very short method (one liner), like a simple accessor, shift is faster (from benchmarks I've seen) and not unclear/unmaintainable. For instance... sub foo { return shift()->{foo} = shift if @_ } ...seems quite reasonable to me. YMMV > never duplicate deep access code. use a temp var with the lower level > reference and it will be clearer and if you do need multiple uses, faster. Seems reasonable. > ...in the bizarre case of someone setting $] which changes the index origin, > @array will stay the same but $#array will change. Good point. Thanks for the input. Cheers, Shaun From uri at StemSystems.com Sat May 30 18:42:52 2009 From: uri at StemSystems.com (Uri Guttman) Date: Sat, 30 May 2009 21:42:52 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <982579710905301420r3b06e833x5b4336e9558a67a7@mail.gmail.com> (Shaun Fryer's message of "Sat\, 30 May 2009 17\:20\:56 -0400") References: <4A20251E.4010906@alteeve.com> <45535519-7D9D-42CA-8EE7-98CC75B7DB40@stok.ca> <4A2042CA.1030909@alteeve.com> <6A5D7C88-A25B-49F5-A0C1-3DEAEDB87FC1@stok.ca> <20090529204356.GD4363@perlwolf.com> <982579710905301130t5d45aaa4v71a964f0c62b3f81@mail.gmail.com> <87bppajsoo.fsf@quad.sysarch.com> <982579710905301249u5fe355e5x16c8650e9f6dbb44@mail.gmail.com> <87tz32ib9g.fsf@quad.sysarch.com> <982579710905301420r3b06e833x5b4336e9558a67a7@mail.gmail.com> Message-ID: <8763fihwtf.fsf@quad.sysarch.com> >>>>> "SF" == Shaun Fryer writes: >> i generally don't like using shift on @_ and prefer to assign it. SF> True for complex stuff. My feeling is that when it's a very short SF> method (one liner), like a simple accessor, shift is faster (from SF> benchmarks I've seen) and not unclear/unmaintainable. For instance... actually shift isn't faster. shift has to copy the data and also modify a pointer in @_. assigning @_ to a list only needs to do the copy. and multiple assignments with shift is slower than a single list assignment from @_. a general rule of thumb (though easily broken) is that the less perl code the faster. this is because most perl ops take about the same amount of time and the op loop itself is the main overhead. now the extreme case of reducing perl code to an absolute minimum (called golfing) is bad too as it becomes unmaintainable. so there is a happy balance to be found. less code is also easier to see with more real code on the screen as you have fewer lines. my( $foo, $bar, $baz ) = @_ vs my $foo = shift ; my $bar = shift ; my $baz = shift ; so why would you waste valuable vertical spacing on just getting args from @_? those are some of the reasons i don't like shift on @_ (except where it really does help in some interesting cases). uri -- Uri Guttman ------ uri at stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Free Perl Training --- http://perlhunter.com/college.html --------- --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- From sfryer at sourcery.ca Sat May 30 21:30:48 2009 From: sfryer at sourcery.ca (Shaun Fryer) Date: Sun, 31 May 2009 00:30:48 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <8763fihwtf.fsf@quad.sysarch.com> References: <4A20251E.4010906@alteeve.com> <4A2042CA.1030909@alteeve.com> <6A5D7C88-A25B-49F5-A0C1-3DEAEDB87FC1@stok.ca> <20090529204356.GD4363@perlwolf.com> <982579710905301130t5d45aaa4v71a964f0c62b3f81@mail.gmail.com> <87bppajsoo.fsf@quad.sysarch.com> <982579710905301249u5fe355e5x16c8650e9f6dbb44@mail.gmail.com> <87tz32ib9g.fsf@quad.sysarch.com> <982579710905301420r3b06e833x5b4336e9558a67a7@mail.gmail.com> <8763fihwtf.fsf@quad.sysarch.com> Message-ID: <982579710905302130t60068a63se1c95283945f1caf@mail.gmail.com> Well, after taking another look at the "sub { shift()->{foo} = shift if @_ }", I realize my head is full of sand today. *sigh* Trying to be too clever without being careful enough... Anyway... thanks again Uri, etc. Good food for thought. Btw, you're totally right about shift versus copy. bash> perl sub foo { my $this = shift; my $that = shift; my $the_other = shift; my $this_other = shift; my $that_other = shift; } sub bar { my ($this, $that, $the_other, $this_other, $that_other) = @_; } my $iterations = 10000000; # ten million my $start_foo = time; foo() for 0 .. $iterations; my $end_foo = time; my $foo_time = $end_foo - $start_foo; my $start_bar = time; bar() for 0 .. $iterations; my $end_bar = time; my $bar_time = $end_bar - $start_bar; print "foo() took $foo_time seconds\n"; print "bar() took $bar_time seconds\n"; my @times = sort { $a <=> $b } $foo_time, $bar_time; print ( $foo_time == $times[0] ? 'foo()' : 'bar()' ); print ' was faster by ' . ( $times[1] - $times[0] ) . " seconds.\n"; ^D foo() took 26 seconds bar() took 20 seconds bar() was faster by 6 seconds. Cheers, Shaun Fryer > actually shift isn't faster. shift has to copy the data and also modify > a pointer in @_. assigning @_ to a list only needs to do the copy. and > multiple assignments with shift is slower than a single list assignment > from @_. a general rule of thumb (though easily broken) is that the less > perl code the faster. this is because most perl ops take about the same > amount of time and the op loop itself is the main overhead. From uri at StemSystems.com Sat May 30 23:20:05 2009 From: uri at StemSystems.com (Uri Guttman) Date: Sun, 31 May 2009 02:20:05 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <982579710905302130t60068a63se1c95283945f1caf@mail.gmail.com> (Shaun Fryer's message of "Sun\, 31 May 2009 00\:30\:48 -0400") References: <4A20251E.4010906@alteeve.com> <4A2042CA.1030909@alteeve.com> <6A5D7C88-A25B-49F5-A0C1-3DEAEDB87FC1@stok.ca> <20090529204356.GD4363@perlwolf.com> <982579710905301130t5d45aaa4v71a964f0c62b3f81@mail.gmail.com> <87bppajsoo.fsf@quad.sysarch.com> <982579710905301249u5fe355e5x16c8650e9f6dbb44@mail.gmail.com> <87tz32ib9g.fsf@quad.sysarch.com> <982579710905301420r3b06e833x5b4336e9558a67a7@mail.gmail.com> <8763fihwtf.fsf@quad.sysarch.com> <982579710905302130t60068a63se1c95283945f1caf@mail.gmail.com> Message-ID: <87hbz1hjze.fsf@quad.sysarch.com> >>>>> "SF" == Shaun Fryer writes: SF> my $start_foo = time; SF> foo() for 0 .. $iterations; SF> my $end_foo = time; SF> my $foo_time = $end_foo - $start_foo; SF> print "foo() took $foo_time seconds\n"; SF> print "bar() took $bar_time seconds\n"; this is wall clock time which is not a good measure of code efficiency. use the Benchmark.pm module (in core perl) which is the standard way to do this. it measures cpu time, is more accurate, is easier to use and has many options, features and reporting styles. all perl hackers should know the benchmark module. uri -- Uri Guttman ------ uri at stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Free Perl Training --- http://perlhunter.com/college.html --------- --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- From arocker at vex.net Sun May 31 06:42:30 2009 From: arocker at vex.net (arocker at vex.net) Date: Sun, 31 May 2009 09:42:30 -0400 (EDT) Subject: [tpm] Is there a three-way version of... In-Reply-To: <982579710905302130t60068a63se1c95283945f1caf@mail.gmail.com> References: <4A20251E.4010906@alteeve.com> <4A2042CA.1030909@alteeve.com> <6A5D7C88-A25B-49F5-A0C1-3DEAEDB87FC1@stok.ca> <20090529204356.GD4363@perlwolf.com> <982579710905301130t5d45aaa4v71a964f0c62b3f81@mail.gmail.com> <87bppajsoo.fsf@quad.sysarch.com> <982579710905301249u5fe355e5x16c8650e9f6dbb44@mail.gmail.com> <87tz32ib9g.fsf@quad.sysarch.com> <982579710905301420r3b06e833x5b4336e9558a67a7@mail.gmail.com> <8763fihwtf.fsf@quad.sysarch.com> <982579710905302130t60068a63se1c95283945f1caf@mail.gmail.com> Message-ID: <74ae83c07dd369b87ea8860760363873.squirrel@webmail.vex.net> > > my $iterations = 10000000; # ten million > > foo() took 26 seconds > bar() took 20 seconds > bar() was faster by 6 seconds. > You'ld have to do it an awful lot for the difference to matter. From arocker at vex.net Sun May 31 07:08:47 2009 From: arocker at vex.net (arocker at vex.net) Date: Sun, 31 May 2009 10:08:47 -0400 (EDT) Subject: [tpm] Thursday's meeting & future topics Message-ID: <73c72fee53e4f3cfa2e5e434e0860a70.squirrel@webmail.vex.net> We discussed Ilia's suggestion about a Perl job fair inspired by the Ruby one, http://rubyjobfair.ca/ and decided to see what results it produces before doing anything. We also discussed topics and plans for future meetings. Possible topics were: "Cloud computing" and Perl Perl Best Practices (discussions based on Damian's book) Parrot Perl 6 Catalyst http://www.catalystframework.org/ IDEs for Perl programmers VmWare Madison's "Intermittent" (or "Intermediate") talks A tentative schedule was: June No topic (no meeting?) *July YAPC debriefing August VMWare and how to install it *September Lightning talks (Start writing them now) October Parrot & Rakudo November Perl Best Practices *December Social The 3 marked with an * are reasonably fixed, the others are flexible. Anybody who feels passionately about any of the subjects, would like to present, (on the suggested or any other topics), or have any other suggestions, please chime in. If you have something you would like presented, but really don't want to speak, write the presentation and ask one of the usual suspects to deliver it for you. From uri at StemSystems.com Sun May 31 08:44:12 2009 From: uri at StemSystems.com (Uri Guttman) Date: Sun, 31 May 2009 11:44:12 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <74ae83c07dd369b87ea8860760363873.squirrel@webmail.vex.net> (arocker@vex.net's message of "Sun\, 31 May 2009 09\:42\:30 -0400 \(EDT\)") References: <4A20251E.4010906@alteeve.com> <4A2042CA.1030909@alteeve.com> <6A5D7C88-A25B-49F5-A0C1-3DEAEDB87FC1@stok.ca> <20090529204356.GD4363@perlwolf.com> <982579710905301130t5d45aaa4v71a964f0c62b3f81@mail.gmail.com> <87bppajsoo.fsf@quad.sysarch.com> <982579710905301249u5fe355e5x16c8650e9f6dbb44@mail.gmail.com> <87tz32ib9g.fsf@quad.sysarch.com> <982579710905301420r3b06e833x5b4336e9558a67a7@mail.gmail.com> <8763fihwtf.fsf@quad.sysarch.com> <982579710905302130t60068a63se1c95283945f1caf@mail.gmail.com> <74ae83c07dd369b87ea8860760363873.squirrel@webmail.vex.net> Message-ID: <87d49pffar.fsf@quad.sysarch.com> >>>>> "a" == arocker writes: >> >> my $iterations = 10000000; # ten million >> >> foo() took 26 seconds >> bar() took 20 seconds >> bar() was faster by 6 seconds. >> a> You'ld have to do it an awful lot for the difference to matter. as i said, it is as much a style difference as a speed one. assignment from @_ is just better than shifting from it. two reasons are better than one! :) uri -- Uri Guttman ------ uri at stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Free Perl Training --- http://perlhunter.com/college.html --------- --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com --------- From sfryer at sourcery.ca Sun May 31 10:44:11 2009 From: sfryer at sourcery.ca (Shaun Fryer) Date: Sun, 31 May 2009 13:44:11 -0400 Subject: [tpm] Is there a three-way version of... In-Reply-To: <87d49pffar.fsf@quad.sysarch.com> References: <4A20251E.4010906@alteeve.com> <982579710905301130t5d45aaa4v71a964f0c62b3f81@mail.gmail.com> <87bppajsoo.fsf@quad.sysarch.com> <982579710905301249u5fe355e5x16c8650e9f6dbb44@mail.gmail.com> <87tz32ib9g.fsf@quad.sysarch.com> <982579710905301420r3b06e833x5b4336e9558a67a7@mail.gmail.com> <8763fihwtf.fsf@quad.sysarch.com> <982579710905302130t60068a63se1c95283945f1caf@mail.gmail.com> <74ae83c07dd369b87ea8860760363873.squirrel@webmail.vex.net> <87d49pffar.fsf@quad.sysarch.com> Message-ID: <982579710905311044r2c591322k4d2d8adae5502819@mail.gmail.com> On Sun, May 31, 2009 at 11:44 AM, Uri Guttman wrote: > as i said, it is as much a style difference as a speed one. assignment > from @_ is just better than shifting from it. two reasons are better > than one! :) Interesting. I tend to agree, though I have heard the exact opposite argument with regards to the style position. Having real metrics helps though. In alot of cases, things which could be considered premature optimizations, if incorporated as a simple matter of style, save you the trouble of tedious refactoring at later stages of an app's life-cycle. Triviality is a matter of perspective. Cheers, Shaun Fryer