From linux at alteeve.com Fri Jul 3 11:47:11 2009 From: linux at alteeve.com (Madison Kelly) Date: Fri, 03 Jul 2009 14:47:11 -0400 Subject: [tpm] regex problem Message-ID: <4A4E522F.7090807@alteeve.com> Could someone riddle me why this isn't working? #---------------------- #!/usr/bin/perl use strict; use warnings; my $search_word="*4766"; my $joined_string="905-555-4766#:#jane die#:##:#1#:#18#:#2009-06-14 13:44:33.617008#:#"; my $match=0; if ($search_word=~/^\*(.*?)\*$/) { # Match anywhere. my $local_search_word=$1; print __LINE__.": local_search_word: [$local_search_word]\n"; $match++ if $joined_string =~ /$local_search_word/; } elsif ($search_word=~/^\*(.*?)/) { # Match the end of the strings. my $local_search_word=$1; print __LINE__.": local_search_word: [$local_search_word]\n"; $match++ if $joined_string =~ /$local_search_word#:#/; } elsif ($search_word=~/(.*?)\*$/) { # Match the start of the strings. my $local_search_word=$1; print __LINE__.": local_search_word: [$local_search_word]\n"; $match++ if $joined_string =~ /#:#$local_search_word/; } else { # Match the strings exactly. $match++ if $joined_string =~ /#:#$search_word#:#/; } exit; #---------------------- When I run, I see that the second conditional matches because if '22: ' being printed, but the $1 seems to be empty. According to 'perldoc perlre' I seem to be doing it right... Results say otherwise though. :) Thanks! Madi From linux at alteeve.com Fri Jul 3 11:53:27 2009 From: linux at alteeve.com (Madison Kelly) Date: Fri, 03 Jul 2009 14:53:27 -0400 Subject: [tpm] Solved: Re: regex problem In-Reply-To: <4A4E522F.7090807@alteeve.com> References: <4A4E522F.7090807@alteeve.com> Message-ID: <4A4E53A7.6020908@alteeve.com> Why is always that, once I give up and ask for help, I find the answer just minutes later? I was banging my head for an hour before posting this question... Of course, '(.*?)' matches anything, 0 or more times. Take the '?' out or adding and end of string anchor fixed it. Sorry for the line noise. Madi Madison Kelly wrote: > Could someone riddle me why this isn't working? > > #---------------------- > #!/usr/bin/perl > > use strict; > use warnings; > > my $search_word="*4766"; > my $joined_string="905-555-4766#:#jane die#:##:#1#:#18#:#2009-06-14 > 13:44:33.617008#:#"; > my $match=0; > > if ($search_word=~/^\*(.*?)\*$/) > { > # Match anywhere. > my $local_search_word=$1; > print __LINE__.": local_search_word: [$local_search_word]\n"; > $match++ if $joined_string =~ /$local_search_word/; > } > elsif ($search_word=~/^\*(.*?)/) > { > # Match the end of the strings. > my $local_search_word=$1; > print __LINE__.": local_search_word: [$local_search_word]\n"; > $match++ if $joined_string =~ /$local_search_word#:#/; > } > elsif ($search_word=~/(.*?)\*$/) > { > # Match the start of the strings. > my $local_search_word=$1; > print __LINE__.": local_search_word: [$local_search_word]\n"; > $match++ if $joined_string =~ /#:#$local_search_word/; > } > else > { > # Match the strings exactly. > $match++ if $joined_string =~ /#:#$search_word#:#/; > } > > exit; > #---------------------- > > When I run, I see that the second conditional matches because if '22: > ' being printed, but the $1 seems to be empty. According to 'perldoc > perlre' I seem to be doing it right... Results say otherwise though. :) > > Thanks! > > Madi From jkeen at verizon.net Tue Jul 7 19:36:14 2009 From: jkeen at verizon.net (James E Keenan) Date: Tue, 07 Jul 2009 22:36:14 -0400 Subject: [tpm] The Times turns its gaze northwestward Message-ID: <3BF9790F-A490-4727-B227-0A193EDD84B1@verizon.net> http://travel.nytimes.com/2009/07/05/travel/05surfacing.html?8dpc Of course, there's an old rule of thumb: If the NY Times says a neighborhood is hip, it's oh-vuh, baby! From fulko.hew at gmail.com Thu Jul 9 17:56:23 2009 From: fulko.hew at gmail.com (Fulko Hew) Date: Thu, 9 Jul 2009 20:56:23 -0400 Subject: [tpm] recommendations for a perl web server Message-ID: <8204a4fe0907091756p2f15fbdhb8d1ba5b7eadfd17@mail.gmail.com> Who has any recommendations for a simple web server, written in Perl of course, that has the fewest dependencies and supports CGI.pm so I can put some functionality behind the requests. I'm not looking for anything fast, complicated, or otherwise, just basic and functional. (It doesn't even have to handle multiple connections.) Fulko From sfryer at sourcery.ca Thu Jul 9 18:19:28 2009 From: sfryer at sourcery.ca (Shaun Fryer) Date: Thu, 9 Jul 2009 21:19:28 -0400 Subject: [tpm] recommendations for a perl web server In-Reply-To: <8204a4fe0907091756p2f15fbdhb8d1ba5b7eadfd17@mail.gmail.com> References: <8204a4fe0907091756p2f15fbdhb8d1ba5b7eadfd17@mail.gmail.com> Message-ID: <982579710907091819i4ed4e147v757f02cb0394fa4@mail.gmail.com> If you don't need HTTPS, check out HTTP::Daemon. It's *extremely* simple. If you need something a 'little' more complicated, I can probably dig you up a preforking version I wrote a few years ago. http://search.cpan.org/~gaas/libwww-perl-5.829/lib/HTTP/Daemon.pm Unfortunately (last I tried at least), the SSL capable version of this, didn't work. Cheers, -- Shaun Fryer http://sourcery.ca/ 2009/7/9 Fulko Hew : > Who has any recommendations for a simple web server, written in Perl of course, > that has the fewest dependencies and supports CGI.pm so I can put some > functionality > behind the requests. > > I'm not looking for anything fast, complicated, or otherwise, just > basic and functional. > > (It doesn't even have to handle multiple connections.) > > Fulko > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm > From fulko.hew at gmail.com Fri Jul 10 09:37:02 2009 From: fulko.hew at gmail.com (Fulko Hew) Date: Fri, 10 Jul 2009 12:37:02 -0400 Subject: [tpm] recommendations for a perl web server In-Reply-To: <982579710907091819i4ed4e147v757f02cb0394fa4@mail.gmail.com> References: <8204a4fe0907091756p2f15fbdhb8d1ba5b7eadfd17@mail.gmail.com> <982579710907091819i4ed4e147v757f02cb0394fa4@mail.gmail.com> Message-ID: <8204a4fe0907100937v4eafe9ffo22a57327f30c482e@mail.gmail.com> On Thu, Jul 9, 2009 at 9:19 PM, Shaun Fryer wrote: > If you don't need HTTPS, check out HTTP::Daemon. It's *extremely* I don't need HTTPS > simple. If you need something a 'little' more complicated, I can > probably dig you up a preforking version I wrote a few years ago. > > http://search.cpan.org/~gaas/libwww-perl-5.829/lib/HTTP/Daemon.pm > > Unfortunately (last I tried at least), the SSL capable version of > this, didn't work. I had found that... thanks for the recommendation. Finding this Perl Monks article sewed it up for me. http://www.perlmonks.org/?node_id=415908 It has an example of everything I wanted: - fork the server - auto-start a browser - integrate with CGI (Simple) ... its missing lots of 'boundary/cleanup' code, but I can start with that! Thanks From rdice at pobox.com Tue Jul 14 07:07:59 2009 From: rdice at pobox.com (Richard Dice) Date: Tue, 14 Jul 2009 10:07:59 -0400 Subject: [tpm] Details on Damian Conway talk, Monday 27 July 2009 Message-ID: <5bef4baf0907140707l2a935661o129b8fad355896fb@mail.gmail.com> Hi everyone, I mentioned a few weeks back that Damian was coming to Toronto to deliver his latest high-energy talk. I've got the details on that sorted out now. Presenter: Dr. Damian Conway, the Mad Scientist of Perl http://damian.conway.org/About_us//Bio_formal.html http://www.googlism.com/index.htm?ism=damian+conway&type=1 Talk Title: The Missing Link Details: What do watching trees grow, debugging debuggers, Greek mythology, code that writes code that writes code that writes code, the hazards of LaTeX, successful failures, the treacherous Vorta, objective syntax, anti-stacks, Danish mind-control, active null statements, synthetic standup, and the prospect of certain death all have in common? Watch as Damian weaves them together into a new and improbably useful module that demonstrates the awesome power and beauty of Perl 5.10. Date: Monday 27 July 2009 Time: 7pm - 9pm show up early to get a seat, find place to park if you're driving, etc. Location: Bahen Centre for IT Room 1160 (i.e. the major lecture theater on the ground floor) University of Toronto St. George (downtown) campus 40 St. George Street (just North of College on the East side of St. George) Parking: See the following URL for information about parking on UofT St. George campus http://tinyurl.com/u-of-t-parking Looks like there is an underground lot directly beneath Bahen Centre (marker #17). I also find it convenient to park on King's College Circle (marker #13). Transit: St. George subway Stn, St. George St. exit, walk south approx. 7 minutes _or_ Queen's Park subway Stn., walk west approx. 5 minutes _or_ College streetcar westbound from either College Stn or Queen's Park Stn (but walking may be faster than waiting for a car, especially if you're at Queen's Park Stn) Hope to see you there! Cheers, - Richard -------------- next part -------------- An HTML attachment was scrubbed... URL: From fulko.hew at gmail.com Wed Jul 15 07:43:54 2009 From: fulko.hew at gmail.com (Fulko Hew) Date: Wed, 15 Jul 2009 10:43:54 -0400 Subject: [tpm] normalizing filespec paths/directories? Message-ID: <8204a4fe0907150743m5a26af86q60b8f62c9f3ea613@mail.gmail.com> OK, my next query for a code/module recommendation is: 'What is the best/easiest way to normalize a directory from what someone may have provided into something thats potentially real.' Ie. eliminate '../' scenarios. For example, something that translates the following (and all other nasties)... If our home directory is '/home/myaccount', and someone provides '../../etc/passwd' whats the easiest way to figure out that the real path will end up being '/etc/passwd' ? TIA Fulko -------------- next part -------------- An HTML attachment was scrubbed... URL: From rdice at pobox.com Wed Jul 15 07:57:00 2009 From: rdice at pobox.com (Richard Dice) Date: Wed, 15 Jul 2009 10:57:00 -0400 Subject: [tpm] normalizing filespec paths/directories? In-Reply-To: <8204a4fe0907150743m5a26af86q60b8f62c9f3ea613@mail.gmail.com> References: <8204a4fe0907150743m5a26af86q60b8f62c9f3ea613@mail.gmail.com> Message-ID: <5bef4baf0907150757k17236314p9eb3b2ab9beced60@mail.gmail.com> On Wed, Jul 15, 2009 at 10:43 AM, Fulko Hew wrote: > OK, my next query for a code/module recommendation is: > > 'What is the best/easiest way to normalize a directory from what > someone may have provided into something thats potentially real.' > > Ie. eliminate '../' scenarios. > Hi Fulko, Please look into *http://search.cpan.org/~smueller/PathTools-3.30/Cwd.pm and http://search.cpan.org/~smueller/PathTools-3.30/lib/File/Spec.pm* Cheers, - Richard -------------- next part -------------- An HTML attachment was scrubbed... URL: From fulko.hew at gmail.com Wed Jul 15 08:01:22 2009 From: fulko.hew at gmail.com (Fulko Hew) Date: Wed, 15 Jul 2009 11:01:22 -0400 Subject: [tpm] normalizing filespec paths/directories? In-Reply-To: References: <8204a4fe0907150743m5a26af86q60b8f62c9f3ea613@mail.gmail.com> Message-ID: <8204a4fe0907150801l6707b1c3n804661862f0ee7d6@mail.gmail.com> On Wed, Jul 15, 2009 at 10:51 AM, Dave Doyle wrote: > although I haven't tested: > > use Cwd; > > my $real_path = abs_path('/home/production/../../etc/password'); > > I THINK it resolves symbolic links to the real path as well but you'd have > to check that. Thanks. I just found it myself too. This is exactly what I needed. -------------- next part -------------- An HTML attachment was scrubbed... URL: From jbl at jbldata.com Wed Jul 15 08:19:16 2009 From: jbl at jbldata.com (J. Bobby Lopez) Date: Wed, 15 Jul 2009 11:19:16 -0400 Subject: [tpm] normalizing filespec paths/directories? In-Reply-To: <8204a4fe0907150801l6707b1c3n804661862f0ee7d6@mail.gmail.com> References: <8204a4fe0907150743m5a26af86q60b8f62c9f3ea613@mail.gmail.com> <8204a4fe0907150801l6707b1c3n804661862f0ee7d6@mail.gmail.com> Message-ID: If you wanted to roll your own, something like this may work: #~~~~~~~~~~~~~~~~~~~ use strict; use warnings; sub testdir { my $path = shift; my $testit = 1; my @dirs = split ('/', $path); my $goodir = ''; foreach my $dir (@dirs) { if ( $dir =~ m{\.\.} && $testit eq 1 ) { next; } $testit = 0; $goodir .= '/' . $dir; } if ( -f $goodir ) { return $goodir; } else { return "dir not exist"; } } my $path = "../../etc/passwd"; my $isgood = testdir($path); print $isgood . "\n"; #~~~~~~~~~~~~~~~~~~~ On Wed, Jul 15, 2009 at 11:01 AM, Fulko Hew wrote: > > > On Wed, Jul 15, 2009 at 10:51 AM, Dave Doyle wrote: > >> although I haven't tested: >> >> use Cwd; >> >> my $real_path = abs_path('/home/production/../../etc/password'); >> >> I THINK it resolves symbolic links to the real path as well but you'd have >> to check that. > > > Thanks. I just found it myself too. > This is exactly what I needed. > > > > > _______________________________________________ > 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 quantum.mechanic.1964 at gmail.com Thu Jul 16 07:59:05 2009 From: quantum.mechanic.1964 at gmail.com (Quantum Mechanic) Date: Thu, 16 Jul 2009 10:59:05 -0400 Subject: [tpm] Details on Damian Conway talk, Monday 27 July 2009 In-Reply-To: <5bef4baf0907140707l2a935661o129b8fad355896fb@mail.gmail.com> References: <5bef4baf0907140707l2a935661o129b8fad355896fb@mail.gmail.com> Message-ID: <77f3972e0907160759o450778fbp470c68d1c9404601@mail.gmail.com> "(just North of College on the East side of St. George)" >From the PDF, BCIT seems to be on the west side of St. George? (Or are these "Aussie Rules"? :D ) Count me in! On Tue, Jul 14, 2009 at 10:07 AM, Richard Dice wrote: > Hi everyone, > > I mentioned a few weeks back that Damian was coming to Toronto to deliver > his latest high-energy talk. I've got the details on that sorted out now. > > Presenter: Dr. Damian Conway, the Mad Scientist of Perl > http://damian.conway.org/About_us//Bio_formal.html > http://www.googlism.com/index.htm?ism=damian+conway&type=1 > Talk Title: The Missing Link > Details: What do watching trees grow, debugging debuggers, > Greek mythology, code that writes code that writes code > that writes code, the hazards of LaTeX, successful failures, > the treacherous Vorta, objective syntax, anti-stacks, > Danish mind-control, active null statements, synthetic > standup, > and the prospect of certain death all have in common? > Watch as Damian weaves them together into a new and improbably > useful module that demonstrates the awesome power and beauty > of Perl 5.10. > Date: Monday 27 July 2009 > Time: 7pm - 9pm > show up early to get a seat, find place to park if you're > driving, etc. > Location: Bahen Centre for IT > Room 1160 (i.e. the major lecture theater on the ground floor) > University of Toronto St. George (downtown) campus > 40 St. George Street > (just North of College on the East side of St. George) > Parking: See the following URL for information about parking on > UofT St. George campus > http://tinyurl.com/u-of-t-parking > Looks like there is an underground lot directly beneath > Bahen Centre (marker #17). I also find it convenient to > park on King's College Circle (marker #13). > Transit: St. George subway Stn, St. George St. exit, > walk south approx. 7 minutes > _or_ Queen's Park subway Stn., walk west approx. 5 minutes > _or_ College streetcar westbound from either College Stn > or Queen's Park Stn (but walking may be faster than waiting > for a car, especially if you're at Queen's Park Stn) > > Hope to see you there! > > Cheers, > - Richard > > > _______________________________________________ > toronto-pm mailing list > toronto-pm at pm.org > http://mail.pm.org/mailman/listinfo/toronto-pm > > -- -QM Quantum Mechanics: The dreams stuff is made of -------------- next part -------------- An HTML attachment was scrubbed... URL: From linux at alteeve.com Mon Jul 20 16:57:53 2009 From: linux at alteeve.com (Madison Kelly) Date: Mon, 20 Jul 2009 19:57:53 -0400 Subject: [tpm] private method call nuances Message-ID: <4A650481.3040100@alteeve.com> Hi all, I was wondering what, if anything, would be different between calling a module's (private) method in these two ways: $self->_count_module(); - vs - &_count_module($self); Of course, '$self' is a (hash) reference 'bless'ed into the current module. Functionally I don't see a difference (yet). Thanks! A curious Madi From talexb at gmail.com Mon Jul 20 18:26:16 2009 From: talexb at gmail.com (Alex Beamish) Date: Mon, 20 Jul 2009 21:26:16 -0400 Subject: [tpm] private method call nuances In-Reply-To: <4A650481.3040100@alteeve.com> References: <4A650481.3040100@alteeve.com> Message-ID: On Mon, Jul 20, 2009 at 7:57 PM, Madison Kelly wrote: > Hi all, > > ?I was wondering what, if anything, would be different between calling a > module's (private) method in these two ways: > > $self->_count_module(); > - vs - > &_count_module($self); > > ?Of course, '$self' is a (hash) reference 'bless'ed into the current module. > Functionally I don't see a difference (yet). Functionally, I don't see a difference either, but I have to admit I squirm whenever I see & in front of a function/method call. Unless you're calling a reference to a sub, it's unnecessary (and possibly mis-leading, because @_ is used as parameters if a function is called with & and no parameters). Second, calling a method by passing $self in as the first parameter is correct, but not OO-Perlish. The method _count_module is a method (albeit a private one), and so should be called in an OO way. -- Alex Beamish Toronto, Ontario aka talexb From uri at stemsystems.com Mon Jul 20 18:34:45 2009 From: uri at stemsystems.com (Uri Guttman) Date: Mon, 20 Jul 2009 21:34:45 -0400 Subject: [tpm] private method call nuances In-Reply-To: (Alex Beamish's message of "Mon\, 20 Jul 2009 21\:26\:16 -0400") References: <4A650481.3040100@alteeve.com> Message-ID: <87iqhmom2y.fsf@quad.sysarch.com> >>>>> "AB" == Alex Beamish writes: AB> On Mon, Jul 20, 2009 at 7:57 PM, Madison Kelly wrote: >> Hi all, >> >> ?I was wondering what, if anything, would be different between calling a >> module's (private) method in these two ways: >> >> $self->_count_module(); >> - vs - >> &_count_module($self); >> >> ?Of course, '$self' is a (hash) reference 'bless'ed into the current module. >> Functionally I don't see a difference (yet). AB> Functionally, I don't see a difference either, but I have to admit I AB> squirm whenever I see & in front of a function/method call. there is a major difference between those. massive in fact. AB> Unless you're calling a reference to a sub, it's unnecessary (and AB> possibly mis-leading, because @_ is used as parameters if a function AB> is called with & and no parameters). that is one very important issue. calling subs with & is bad in general. AB> Second, calling a method by passing $self in as the first parameter is AB> correct, but not OO-Perlish. The method _count_module is a method AB> (albeit a private one), and so should be called in an OO way. actually it is incorrect since it bypasses any inheritance. even private methods can inherit from parent classes. if you want to use a local/private sub then you can pass parts of the object as you would in any other call. you can even pass the object as OP did but it is just bad coding to pass the object as the first arg. 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 linux at alteeve.com Mon Jul 20 19:48:44 2009 From: linux at alteeve.com (Madison Kelly) Date: Mon, 20 Jul 2009 22:48:44 -0400 Subject: [tpm] private method call nuances In-Reply-To: <87iqhmom2y.fsf@quad.sysarch.com> References: <4A650481.3040100@alteeve.com> <87iqhmom2y.fsf@quad.sysarch.com> Message-ID: <4A652C8C.40808@alteeve.com> Uri Guttman wrote: >>>>>> "AB" == Alex Beamish writes: > > AB> On Mon, Jul 20, 2009 at 7:57 PM, Madison Kelly wrote: > >> Hi all, > >> > >> I was wondering what, if anything, would be different between calling a > >> module's (private) method in these two ways: > >> > >> $self->_count_module(); > >> - vs - > >> &_count_module($self); > >> > >> Of course, '$self' is a (hash) reference 'bless'ed into the current module. > >> Functionally I don't see a difference (yet). > > AB> Functionally, I don't see a difference either, but I have to admit I > AB> squirm whenever I see & in front of a function/method call. > > there is a major difference between those. massive in fact. > > AB> Unless you're calling a reference to a sub, it's unnecessary (and > AB> possibly mis-leading, because @_ is used as parameters if a function > AB> is called with & and no parameters). > > that is one very important issue. calling subs with & is bad in general. > > AB> Second, calling a method by passing $self in as the first parameter is > AB> correct, but not OO-Perlish. The method _count_module is a method > AB> (albeit a private one), and so should be called in an OO way. > > actually it is incorrect since it bypasses any inheritance. even private > methods can inherit from parent classes. if you want to use a > local/private sub then you can pass parts of the object as you would in > any other call. you can even pass the object as OP did but it is just > bad coding to pass the object as the first arg. > > uri > Thanks both for replying. I guess I should have re-worded my question some... I'm working on the intro to (oo) modules talk and was trying to understand why using '$self->_some_method' was better than '&_some_method($self)'. The latter might be more comfortable to a coder just getting into modules, and I really don't like saying "just because". :) Can you explain, or point me somewhere to better understand, how inheritance breaks using the '&' method? Also, I was a little unclear... if you pass in '$self', does that restore the inheritance? I just want to be clear so that I can best explain it in my paper. Thanks! Madi From uri at stemsystems.com Mon Jul 20 20:10:10 2009 From: uri at stemsystems.com (Uri Guttman) Date: Mon, 20 Jul 2009 23:10:10 -0400 Subject: [tpm] private method call nuances In-Reply-To: <4A652C8C.40808@alteeve.com> (Madison Kelly's message of "Mon\, 20 Jul 2009 22\:48\:44 -0400") References: <4A650481.3040100@alteeve.com> <87iqhmom2y.fsf@quad.sysarch.com> <4A652C8C.40808@alteeve.com> Message-ID: <873a8qohnx.fsf@quad.sysarch.com> >>>>> "MK" == Madison Kelly writes: MK> Can you explain, or point me somewhere to better understand, how MK> inheritance breaks using the '&' method? Also, I was a little MK> unclear... if you pass in '$self', does that restore the inheritance? MK> I just want to be clear so that I can best explain it in my paper. & doesn't break inheritance, just calling the method as a sub breaks it. only $obj->method or CLASS->method are proper OO calls that will use inheritance. (yes, i skipped indirect method calls for good reason). on top of the lack of inheritance, &sub calls are nasty in another way. if you don't pass in args to them, they call the sub with the existing @_ which can be a nasty surprise as you might have expected the sub to be called with no args. so you are doing two wrong things by calling a method with &method( $self ). the perl docs explain all of this so refer to them as usual. 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 magog at the-wire.com Mon Jul 20 20:17:24 2009 From: magog at the-wire.com (Michael Graham) Date: Mon, 20 Jul 2009 23:17:24 -0400 Subject: [tpm] private method call nuances In-Reply-To: <4A652C8C.40808@alteeve.com> References: <4A650481.3040100@alteeve.com> <87iqhmom2y.fsf@quad.sysarch.com> <4A652C8C.40808@alteeve.com> Message-ID: <20090720231724.5e07b879@caliope> > Can you explain, or point me somewhere to better understand, how > inheritance breaks using the '&' method? Also, I was a little > unclear... if you pass in '$self', does that restore the inheritance? > I just want to be clear so that I can best explain it in my paper. If you call: foo($thingy); you're calling the "foo" sub in the current package. If you call: $thingy->foo; you're saying: - Find the package that $thingy is blessed into. - If there's a "foo" sub in that package, run it. Otherwise, walk the inheritance tree of that package, and run the first "foo" sub found. Michael -- Michael Graham From linux at alteeve.com Mon Jul 20 21:56:41 2009 From: linux at alteeve.com (Madison Kelly) Date: Tue, 21 Jul 2009 00:56:41 -0400 Subject: [tpm] private method call nuances In-Reply-To: <873a8qohnx.fsf@quad.sysarch.com> References: <4A650481.3040100@alteeve.com> <87iqhmom2y.fsf@quad.sysarch.com> <4A652C8C.40808@alteeve.com> <873a8qohnx.fsf@quad.sysarch.com> Message-ID: <4A654A89.9020007@alteeve.com> Uri Guttman wrote: >>>>>> "MK" == Madison Kelly writes: > > MK> Can you explain, or point me somewhere to better understand, how > MK> inheritance breaks using the '&' method? Also, I was a little > MK> unclear... if you pass in '$self', does that restore the inheritance? > MK> I just want to be clear so that I can best explain it in my paper. > > & doesn't break inheritance, just calling the method as a sub breaks > it. only $obj->method or CLASS->method are proper OO calls that will use > inheritance. (yes, i skipped indirect method calls for good reason). on > top of the lack of inheritance, &sub calls are nasty in another way. if > you don't pass in args to them, they call the sub with the existing > @_ which can be a nasty surprise as you might have expected the sub to > be called with no args. so you are doing two wrong things by calling a > method with &method( $self ). > > the perl docs explain all of this so refer to them as usual. > > uri Indeed, and I have been referencing them, but I wasn't able to find an entry on the topic. Wasn't sure what to search for. Thanks. Madi From linux at alteeve.com Mon Jul 20 21:57:09 2009 From: linux at alteeve.com (Madison Kelly) Date: Tue, 21 Jul 2009 00:57:09 -0400 Subject: [tpm] private method call nuances In-Reply-To: <20090720231724.5e07b879@caliope> References: <4A650481.3040100@alteeve.com> <87iqhmom2y.fsf@quad.sysarch.com> <4A652C8C.40808@alteeve.com> <20090720231724.5e07b879@caliope> Message-ID: <4A654AA5.2060009@alteeve.com> Michael Graham wrote: >> Can you explain, or point me somewhere to better understand, how >> inheritance breaks using the '&' method? Also, I was a little >> unclear... if you pass in '$self', does that restore the inheritance? >> I just want to be clear so that I can best explain it in my paper. > > If you call: > > foo($thingy); > > you're calling the "foo" sub in the current package. > > If you call: > > $thingy->foo; > > you're saying: > > - Find the package that $thingy is blessed into. > - If there's a "foo" sub in that package, run it. > Otherwise, walk the inheritance tree of that package, and run the > first "foo" sub found. > > > > Michael Excellent, thank you! Madi From uri at stemsystems.com Mon Jul 20 21:58:58 2009 From: uri at stemsystems.com (Uri Guttman) Date: Tue, 21 Jul 2009 00:58:58 -0400 Subject: [tpm] private method call nuances In-Reply-To: <4A654A89.9020007@alteeve.com> (Madison Kelly's message of "Tue\, 21 Jul 2009 00\:56\:41 -0400") References: <4A650481.3040100@alteeve.com> <87iqhmom2y.fsf@quad.sysarch.com> <4A652C8C.40808@alteeve.com> <873a8qohnx.fsf@quad.sysarch.com> <4A654A89.9020007@alteeve.com> Message-ID: <8763dmmy25.fsf@quad.sysarch.com> >>>>> "MK" == Madison Kelly writes: >> the perl docs explain all of this so refer to them as usual. MK> Indeed, and I have been referencing them, but I wasn't able to find an MK> entry on the topic. Wasn't sure what to search for. consider this a good challenge. you need to learn how to read the docs and also grep for things. and reread them too. and again. it is a skill unto itself beyond coding. the docs cover what &sub does and why indirect method calls are bad. 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 indy at indigostar.com Tue Jul 21 04:55:27 2009 From: indy at indigostar.com (Indy Singh) Date: Tue, 21 Jul 2009 07:55:27 -0400 Subject: [tpm] private method call nuances References: <4A650481.3040100@alteeve.com><87iqhmom2y.fsf@quad.sysarch.com> <4A652C8C.40808@alteeve.com><873a8qohnx.fsf@quad.sysarch.com> <4A654A89.9020007@alteeve.com> <8763dmmy25.fsf@quad.sysarch.com> Message-ID: <9E855B6E69544A1DA4B7FAC12FE5D56F@ROADKILL> > consider this a good challenge. you need to learn how to read the docs > and also grep for things. and reread them too. and again. it is a > skill > unto itself beyond coding. the docs cover what &sub does and why > indirect method calls are bad. I find this site to an excellent way of viewing the perl documentation: http://perldoc.perl.org/ Indy Singh IndigoSTAR Software -- www.indigostar.com From john at perlwolf.com Tue Jul 21 07:58:29 2009 From: john at perlwolf.com (John Macdonald) Date: Tue, 21 Jul 2009 10:58:29 -0400 Subject: [tpm] private method call nuances In-Reply-To: <20090720231724.5e07b879@caliope> References: <4A650481.3040100@alteeve.com> <87iqhmom2y.fsf@quad.sysarch.com> <4A652C8C.40808@alteeve.com> <20090720231724.5e07b879@caliope> Message-ID: <20090721145829.GA5222@perlwolf.com> On Mon, Jul 20, 2009 at 11:17:24PM -0400, Michael Graham wrote: > > > Can you explain, or point me somewhere to better understand, how > > inheritance breaks using the '&' method? Also, I was a little > > unclear... if you pass in '$self', does that restore the inheritance? > > I just want to be clear so that I can best explain it in my paper. > > If you call: > > foo($thingy); > > you're calling the "foo" sub in the current package. > > If you call: > > $thingy->foo; > > you're saying: > > - Find the package that $thingy is blessed into. > - If there's a "foo" sub in that package, run it. > Otherwise, walk the inheritance tree of that package, and run the > first "foo" sub found. So, what breaks when you use the sub call is not the inheritance relation to classes above the current class in which you make the call. Instead you lose the ability to create sub-classes that have their own version of the "method" that you are calling as a sub unless they also have their own version of the methof that invokes the sub. So, it is inheritance by other classes *from* your current class that is being compromised. From dave.s.doyle at gmail.com Wed Jul 22 07:21:47 2009 From: dave.s.doyle at gmail.com (Dave Doyle) Date: Wed, 22 Jul 2009 10:21:47 -0400 Subject: [tpm] russian peasant multiplication Message-ID: I know at least one other monger has seen this: http://thedailywtf.com/Articles/Programming-Praxis-Russian-Peasant-Multiplication.aspx Anyone take a crack at it? I did just for fun... and a desperate need to do something other than PHP right now. It can, of course, be made much shorter. I used a hashref with left and right keys to make it a little easier to read instead of just using arrayrefs. #!/usr/bin/perl use strict; use warnings; use Test::More qw(no_plan); # russian peasant multiplication sub rpm { my @data = ({ left => abs(int(shift)), right => abs(int(shift)), }); return 0 unless $data[0]{left} && $data[0]{right}; # half the left, double the right while (1) { my $row = $data[$#data]; last if $row->{left} == 1; push(@data, { left => int($row->{left} / 2), right => $row->{right} * 2, } ); } # calc total by adding right columns to total where left is odd my $total = 0; $total += ( ($_->{left} % 2) == 0 ? 0 : $_->{right} ) foreach @data; return $total; } my @pairs = ( [11,12], [13,14],[999,1],[4252,5723], [0,1],[1,0],[0,0]); is( rpm(@{$_}), $_->[0] * $_->[1], "$_->[0] * $_->[1] = " . $_->[0] * $_->[1] ) foreach @pairs; -- dave.s.doyle at gmail.com From dave.s.doyle at gmail.com Wed Jul 22 07:38:30 2009 From: dave.s.doyle at gmail.com (Dave Doyle) Date: Wed, 22 Jul 2009 10:38:30 -0400 Subject: [tpm] russian peasant multiplication In-Reply-To: References: Message-ID: and once more recursively: #!/usr/bin/perl use strict; use warnings; use Test::More qw(no_plan); # russian peasant multiplication sub rpm { my $left = abs(int(shift)); my $right = abs(int(shift)); return 0 if !$left || !$right; return $right if $left == 1; return ( ($left % 2) == 0 ? 0 : $right) + rpm(int($left/2),$right*2); } my @pairs = ( [11,12], [13,14],[999,1],[4252,5723], [0,1],[1,0],[0,0]); is( rpm(@{$_}), $_->[0] * $_->[1], "$_->[0] * $_->[1] = " . $_->[0] * $_->[1] ) foreach @pairs; -- dave.s.doyle at gmail.com On Wed, Jul 22, 2009 at 10:21 AM, Dave Doyle wrote: > I know at least one other monger has seen this: > > http://thedailywtf.com/Articles/Programming-Praxis-Russian-Peasant-Multiplication.aspx > > Anyone take a crack at it? ?I did just for fun... and a desperate need > to do something other than PHP right now. ?It can, of course, be made > much shorter. I used a hashref with left and right keys to make it a > little easier to read instead of just using arrayrefs. > > #!/usr/bin/perl > > use strict; > use warnings; > use Test::More qw(no_plan); > > # russian peasant multiplication > sub rpm { > ? ?my @data = ({ > ? ? ? ?left ?=> abs(int(shift)), > ? ? ? ?right => abs(int(shift)), > ? ?}); > > ? ?return 0 unless $data[0]{left} && $data[0]{right}; > > ? ?# half the left, double the right > ? ?while (1) { > ? ? ? ?my $row = $data[$#data]; > ? ? ? ?last if $row->{left} == 1; > ? ? ? ?push(@data, { > ? ? ? ? ? ?left => int($row->{left} / 2), > ? ? ? ? ? ?right => $row->{right} * 2, > ? ? ? ?} ); > ? ?} > > ? ?# calc total by adding right columns to total where left is odd > ? ?my $total = 0; > ? ?$total += ( ($_->{left} % 2) == 0 ? 0 : $_->{right} ) foreach @data; > ? ?return $total; > } > > my @pairs = ( [11,12], [13,14],[999,1],[4252,5723], [0,1],[1,0],[0,0]); > > is( > ? ?rpm(@{$_}), > ? ?$_->[0] * $_->[1], > ? ?"$_->[0] * $_->[1] = " . $_->[0] * $_->[1] > ) foreach @pairs; > > -- > dave.s.doyle at gmail.com > From rick at bort.ca Wed Jul 22 08:35:02 2009 From: rick at bort.ca (Rick Delaney) Date: Wed, 22 Jul 2009 11:35:02 -0400 Subject: [tpm] russian peasant multiplication In-Reply-To: References: Message-ID: <20090722153502.GA14775@bort.ca> On Jul 22 2009, Dave Doyle wrote: > I know at least one other monger has seen this: > > http://thedailywtf.com/Articles/Programming-Praxis-Russian-Peasant-Multiplication.aspx > > Anyone take a crack at it? perl -le '($a,$b)=@ARGV;$s+=$a&1&&$b,$a>>=1,$b<<=1while$a;print$s' 18 23 I guess it won't work for negative numbers. Oh well. -- Rick Delaney rick at bort.ca From dave.s.doyle at gmail.com Wed Jul 22 08:40:34 2009 From: dave.s.doyle at gmail.com (Dave Doyle) Date: Wed, 22 Jul 2009 11:40:34 -0400 Subject: [tpm] russian peasant multiplication In-Reply-To: References: Message-ID: I just meant that ->{left} and ->{right} were easier to read with regard to the than ->[0] and ->[1] in the non-recursive version since the algorithm description used left and right. I do like the use of the bitwise & though. Nifty! -- dave.s.doyle at gmail.com On Wed, Jul 22, 2009 at 11:33 AM, Mike Stok wrote: > I'm not sure why hash refs are easier than array refs, but you can use the > trick that bit 0 of an integer is a conveninet multiplier to get rid of ? : > if you like, and your integers don't overflow and get turned into floats. > > sub rpm { > my $left = abs(int(shift)); > my $right = abs(int(shift)); > > return 0 if !$left || !$right; > return $right if $left == 1; > return (($left & 1) * $right) + rpm(int($left/2),$right*2); > } > > I'd do > > > > > > Mike > From rdice at pobox.com Thu Jul 23 17:21:01 2009 From: rdice at pobox.com (Richard Dice) Date: Thu, 23 Jul 2009 20:21:01 -0400 Subject: [tpm] Reminder - Damian Conway event, Monday 27 July 2009 Message-ID: <5bef4baf0907231721p105728bey57777faa72bd2f17@mail.gmail.com> Hi everyone, A reminder for Damian's talk next Monday evening, details below. (Note that there was a small mistake in the details the last time I sent them; Bahen Centre is really on the /West/ side of St. George.) Presenter: Dr. Damian Conway, the Mad Scientist of Perl http://damian.conway.org/About_us//Bio_formal.html http://www.googlism.com/index.htm?ism=damian+conway&type=1 Talk Title: The Missing Link Details: What do watching trees grow, debugging debuggers, Greek mythology, code that writes code that writes code that writes code, the hazards of LaTeX, successful failures, the treacherous Vorta, objective syntax, anti-stacks, Danish mind-control, active null statements, synthetic standup, and the prospect of certain death all have in common? Watch as Damian weaves them together into a new and improbably useful module that demonstrates the awesome power and beauty of Perl 5.10. Date: Monday 27 July 2009 Time: 7pm - 9pm show up early to get a seat, find place to park if you're driving, etc. Location: Bahen Centre for IT Room 1160 (i.e. the major lecture theater on the ground floor) University of Toronto St. George (downtown) campus 40 St. George Street (just North of College on the West side of St. George) Parking: See the following URL for information about parking on UofT St. George campus http://tinyurl.com/u-of-t-parking Looks like there is an underground lot directly beneath Bahen Centre (marker #17). I also find it convenient to park on King's College Circle (marker #13). Transit: St. George subway Stn, St. George St. exit, walk south approx. 7 minutes _or_ Queen's Park subway Stn., walk west approx. 5 minutes _or_ College streetcar westbound from either College Stn or Queen's Park Stn (but walking may be faster than waiting for a car, especially if you're at Queen's Park Stn) -------------- next part -------------- An HTML attachment was scrubbed... URL: From legrady at gmail.com Thu Jul 23 19:47:50 2009 From: legrady at gmail.com (Tom Legrady) Date: Thu, 23 Jul 2009 22:47:50 -0400 Subject: [tpm] Alex MacKinnon Message-ID: <3c9af5830907231947g33e45edarf2eb24395b0f05da@mail.gmail.com> please contact me thomas.legrady at morganstanley.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From alexmac131 at hotmail.com Thu Jul 23 21:24:58 2009 From: alexmac131 at hotmail.com (Alex Mackinnon) Date: Fri, 24 Jul 2009 04:24:58 +0000 Subject: [tpm] Alex MacKinnon In-Reply-To: <3c9af5830907231947g33e45edarf2eb24395b0f05da@mail.gmail.com> References: <3c9af5830907231947g33e45edarf2eb24395b0f05da@mail.gmail.com> Message-ID: Hehehehhe like a bad scifi novel :) Oh yes, perl subject , anyone hiring ?:) Alex Date: Thu, 23 Jul 2009 22:47:50 -0400 From: legrady at gmail.com CC: tpm at to.pm.org Subject: [tpm] Alex MacKinnon please contact me thomas.legrady at morganstanley.com _________________________________________________________________ Attention all humans. We are your photos. Free us. http://go.microsoft.com/?linkid=9666047 -------------- next part -------------- An HTML attachment was scrubbed... URL: From fulko.hew at gmail.com Fri Jul 24 11:41:29 2009 From: fulko.hew at gmail.com (Fulko Hew) Date: Fri, 24 Jul 2009 14:41:29 -0400 Subject: [tpm] writting dateTime in DBI::CSV Message-ID: <8204a4fe0907241141i72d3433ck19b7eac12b4a571b@mail.gmail.com> Can anyone tell me how to store a 'date/time' in a DBI::CSV file? ie. 01-MAY-2009 00:00:00 Because... if I use something like: $dateTime = "01-MAY-2009 00:00:00"; INSERT INTO table (DATE) values ( '$dateTime' ) then what's written is a quoted dateTime string: "01-MAY-2009 00:00:00" not the value itself: 01-MAY-2009 00:00:00 Let people know what you're up to, or share links to photos, videos, and web pages. <*fulko*.hew at gmail.com> "*Fulko* Hew(w)" "*Fulko* Hew" Ignore Edit Word -------------- next part -------------- An HTML attachment was scrubbed... URL: From mfowle at navicominc.com Fri Jul 24 11:55:05 2009 From: mfowle at navicominc.com (Mark Fowle) Date: Fri, 24 Jul 2009 14:55:05 -0400 Subject: [tpm] writting dateTime in DBI::CSV In-Reply-To: <8204a4fe0907241141i72d3433ck19b7eac12b4a571b@mail.gmail.com> Message-ID: <759E3F14A23281479A85A082BBCFA5426FA74C@sbsa.NavicomInc.local> CSV files are not always comma separated. The DBD::CSV engine can have different field and record separators. >From the man page it seems ":" is a common, if not default field separator, if that is the case your input would need quoting/escaping to encapsulate the ":" in the record. You can adjust the various separators and escape character to control quoting. Mark ________________________________ From: toronto-pm-bounces+mfowle=navicominc.com at pm.org [mailto:toronto-pm-bounces+mfowle=navicominc.com at pm.org] On Behalf Of Fulko Hew Sent: Friday, July 24, 2009 2:41 PM To: TPM Subject: [tpm] writting dateTime in DBI::CSV Can anyone tell me how to store a 'date/time' in a DBI::CSV file? ie. 01-MAY-2009 00:00:00 Because... if I use something like: $dateTime = "01-MAY-2009 00:00:00"; INSERT INTO table (DATE) values ( '$dateTime' ) then what's written is a quoted dateTime string: "01-MAY-2009 00:00:00" not the value itself: 01-MAY-2009 00:00:00 Let people know what you're up to, or share links to photos, videos, and web pages. "Fulko Hew(w)" "Fulko Hew" Ignore Edit Word -------------- next part -------------- An HTML attachment was scrubbed... URL: From fulko.hew at gmail.com Fri Jul 24 12:07:44 2009 From: fulko.hew at gmail.com (Fulko Hew) Date: Fri, 24 Jul 2009 15:07:44 -0400 Subject: [tpm] writting dateTime in DBI::CSV In-Reply-To: <759E3F14A23281479A85A082BBCFA5426FA74C@sbsa.NavicomInc.local> References: <8204a4fe0907241141i72d3433ck19b7eac12b4a571b@mail.gmail.com> <759E3F14A23281479A85A082BBCFA5426FA74C@sbsa.NavicomInc.local> Message-ID: <8204a4fe0907241207o2801bd68g938d05fdc1a6b465@mail.gmail.com> On Fri, Jul 24, 2009 at 2:55 PM, Mark Fowle wrote: > > CSV files are not always comma separated. The DBD::CSV engine can > have different field and record separators. > > From the man page it seems ?:? is a common, if not default field separator, > if that is the case your input would need quoting/escaping to encapsulate > the ?:? in the record. > > You can adjust the various separators and escape character to control quoting. Thanks for the lead... it turns out that I had to 'connect' to the database using an option csv_sep_char=:; csv_quote_char=; csv_escape_char= The 'magic' one was the csv_quote_char which I set to 'no character' and that made the format right. > From: toronto-pm-bounces+mfowle=navicominc.com at pm.org [mailto:toronto-pm-bounces+mfowle=navicominc.com at pm.org] On Behalf Of Fulko Hew > Sent: Friday, July 24, 2009 2:41 PM > To: TPM > Subject: [tpm] writting dateTime in DBI::CSV > > > > Can anyone tell me how to store a 'date/time' in a DBI::CSV file? > > ie. 01-MAY-2009 00:00:00 > > Because... if I use something like: > > $dateTime = "01-MAY-2009 00:00:00"; > INSERT INTO table (DATE) values ( '$dateTime' ) > > then what's written is a quoted dateTime string: > > "01-MAY-2009 00:00:00" > > not the value itself: > > 01-MAY-2009 00:00:00