scratchpad fenLisesi I am happily employed (5+ years by the same employer) but I would consider offers in and around livable cities (Vancouver, Toronto, Amsterdam, London, Adelaide, Perth, Sydney, Melbourne and your city, too :) that match my interests and strengths. Nano resume: Penn graduate, mix of electrical engineering and physics, summa cum laude. Other than Perl: C/C++, postgres, telecommunication industry, software development process. <hr /> <i>[fenLisesi] swings a live chicken around the Monastery in a demonstration of black magic while it clucks <c>Useless use of a chicken in void context at -e line 1</c></i> <br /> [Corion]: [fenLisesi]: You have to <i>hit</i> somebody or something with the chicken! <hr /> [marto]: /msf corion yes, g0n told me you had taken over the secret node stash :) Cheers. <br /><i>[McDarren] slips [marto] a <c>s/f/g/</c>, to go with his mug of tea</i> <br />[marto] : sweet Craven <br />[marto] : looks like I picked a bad week to quit caffeine <br /><i>[fenLisesi] busts the secret node stash gig: "All right, who's the brains of this here operation?"</i> <br /><i>[fenLisesi] points at [Corion] and tells the boys: "Book this clown!"</i> <br /><i>[clinton] .oO( You can hire him for shows? )</i> <br /><i>[Corion] hides the wig, shoes and red nose.</i> <br /><i>[marto] can do some balloon modeling</i> <br /><i>[graq] hears about a 'secret node stash' rumour, and quickly pays attention.</i> <hr /> from Abigail: <code> > $ perl -wle 'print 2**99' > 6.33825300114115e+29 > > $ ruby -wle 'print 2**99' > 633825300114114700748351602688 > > $ perl -wle 'print 9**9**5' > inf > > $ ruby -wle 'print 9**9**5' > 1163964896171447645003711273838351370118119528741870708047727598123267112930 > 6111037903049760060898121238296130301019497278726966272049388713194128225979 > 0233081290924196740856977261251272318881097024932788534895797954088979392032 > 7738428577367953596166126106831822401524421292985114258127612235972114773252 > 5778322807185432006841500874332599997098613753825177560964766837277637864923 > 8576839226487925173752881910807257686606441838099952474016813167775933784942 > and so on [1] > > Though even Ruby gives up after a while. > > $ ruby -wle 'print 9**9**9' > -e:1: warning: in a**b, b may be too big > Infinity > > > [1] Worth noting that Ruby gets this done in about 2.5 seconds while perl with > bigint takes 30. They're probably using gmp. </code> <p>The following took about 2.2 seconds (using 5.8.0; I couldn't install Inline::BC on 5.10): <code> #!/usr/bin/perl use strict; use warnings; no warnings 'syntax'; use Inline 'BC'; print x(); __DATA__ __BC__ define x(){ return (9^9^5) } </code> 9^9^9 takes more than 350 million digits to write down, and bc refuses to calculate it. <hr /> This is about [id://652466], where [swampyankee] recommends <i>"Don't make the mistake of writing a recursive routine to calculate factorials; they are easily, and much more efficiently, calculated by a for loop"</i>; <p> I think that is good advice in general and even good advice in this particular case, for small N. But I don't think that it is good advice for this problem and large N. The reason is that this problem requires calculating factorials from 1 through N. <p> With memoized recursion, you need of order N function calls, N memoize lookups and N multiplications. With a straigtfowrawd <c>for</c> loop, you need of order N<sup>2</sup> multiplications. Here is some code to demonstrate (I have replaced multiplication with addition to avoid big numbers. That's a change against the recursion camp, as addition is a cheaper operation than multiplication): <p> <code> use strict; use warnings; use Memoize; $| = 1; memoize('f_fenLisesi'); my $LARGE_N = shift || 10_000; time_this( \&f_fenLisesi, 'fenLisesi' ); time_this( \&f_swampyankee, 'swampyankee'); exit( 0 ); #--------------------------------------------------+ sub time_this { my ($cref, $test_name) = @_; my $start = time(); print "testing $test_name: "; for (1 .. $LARGE_N) { $cref->( $_ ); } printf "%d second(s)\n", time() - $start; } #--------------------------------------------------+ sub f_swampyankee { my ($n) = @_; my $sum = 0; for my $i (1 .. $n) { $sum += $i; } $sum; } ##--------------------------------------------------+ sub f_fenLisesi { my ($n) = @_; return 1 if $n == 1; $n + f_fenLisesi( $n - 1 ); } </code> <hr /> <code> On 7/1/07, Mark Jason Dominus <mjd@plover.com> wrote: > >Dave Mitchell: >> NB - It has traditionally been the case that 'local $_' >> was unsafe, and that it was better to do 'local *_' >> instead. Can anyone remind me why this is, and I'm >> wondering whether the assorted local() fixes have made >> this point moot. > > tie $x, "DO_NOT_MODIFY"; > sub DO_NOT_MODIFY::TIESCALAR { bless [] => $_[0] } > sub DO_NOT_MODIFY::FETCH { return rand; } > sub DO_NOT_MODIFY::STORE { > # system("do-bad-stuff"); > die("I told you not to modify this!") > } > > for ($x) { > use_dollar_underbar(); > } > > sub use_dollar_underbar { > local $_; > print "okay...\n"; > $_ = 1; > } > > > use_dollar_underbar() wants to operate on $_ without > tampering with its global value and without causing > any strange action-at-a-distance. So it uses "local $_" > to try to do this. But "local $_" *itself* tampers > with the global value and causes a strange > action-at-a-distance. And more specifically... Changing it to confess() instead of die shows that local $_; calls DO_NOT_MODIFY::STORE(). Yves -- perl -Mre=debug -e "/just|another|perl|hacker/" </code> <hr> from a msg by Tels: <code> # perl -wle 'print 2 ** 128' 3.40282366920938e+38 # perl -Mbigint -wle 'print 2 ** 128' 340282366920938463463374607431768211456 # perl -wle 'print sqrt(2)' 1.4142135623731 # perl -Mbignum -wle 'print sqrt(2)' 1.41421356237309504880168872420969807857 # perl -wle 'print 3/7 ** 77' 2.53847080898319e-65 # perl -Mbigrat -wle 'print 3/7 ** 77' 3/118181386580595879976868414312001964434038548836769923458287039207 </code> <hr /> <code> ... In my current project, I needed to extend the 'convert' functionality of SQL-Abstract-1.22 in order to support two kinds of behavior: 1) convert procedures that take multiple parameters, such as: locale_upper( name, 'en_US' ) 2) convert procedures that apply to some columns only, as in the following snippet: WHERE locale_upper(name,'en_US') LIKE locale_upper($1,'en_US') AND age = 32 The simplest interface extension that I could came up with that supports these requirements was as follows: $criteria->{convert} = ['locale_upper', q('en_US') ]; OR $criteria->{convert} = { proc => ['locale_upper', q('en_US') ], labels => [qw( name description )], }; I was able to hack SQL-Abstract-1.22 today by introducing changes to sub _convert($) {...} only, as you can see in the following patch. After applying this patch, SQL-Abstract-1.22 passes the four tests that come with the distribution, which I hope means that I have not balatantly broken major existing behavior. I am likely to have introduced some new bugs, however, as I have just sewn the patch today and the code has not been reviewed. ... --- SQL-Abstract-1.22-orig.pm 2006-11-30 19:12:14.000000000 +0200 +++ SQL-Abstract-1.22-fenL.pm 2007-03-15 17:53:57.000000000 +0200 @@ -209,10 +209,78 @@ sub _quote { # Conversion, if applicable sub _convert ($) { - my $self = shift; - return @_ unless $self->{convert}; - my $conv = $self->_sqlcase($self->{convert}); - my @ret = map { $conv.'('.$_.')' } @_; + my ($self, @args) = @_; + + return @args unless $self->{convert}; + + if (! $self->{convert_has_been_init}) { + $self->{convert_has_been_init} = 1; + + my $conv = $self->{convert}; + my ($params, $labels) = ([], []); + + if (ref( $conv ) eq 'ARRAY') { + if (! @$conv) { + die q(convert arrayref refers to an empty array); + return @args; + } + ($conv, @$params) = @$conv; + } + elsif (ref( $conv ) eq 'HASH') { + my $proc = $conv->{proc}; + if (defined $conv->{labels}) { + if (ref( $conv->{labels} ) ne 'ARRAY') { + die q(val for key 'labels' must be an arrayref); + ## return @args; + } + $labels = $conv->{labels}; + } + if (! $proc) { + die q(required elem 'proc' missing in convert hash); + ## return @args; + } + if (! ref( $proc )) { + $conv = $proc; + } + elsif (ref( $proc ) eq 'ARRAY') { + if (! @$proc) { + die q(convert proc aref refers to an empty arr); + ## return @args; + } + ($conv, @$params) = @$proc; + } + else { + die q(convert hash elem 'proc' must be scalar/aref); + ## return @args; + } + } + $self->{convert} = $conv; + $self->{convert_params} = $params; + $self->{convert_labels} = { map { uc( $_ ) => 1 } @$labels }; + } + my $conv = $self->{convert}; + $conv = $self->_sqlcase( $conv ); + my @ret = (); + + ARG: + for my $arg (@args) { + if ($arg eq '?') { + if (not defined $self->{convert_current_label}) { + die q(request to convert '?' when no label has been seen yet); + } + } + else { + $self->{convert_current_label} = $arg; + } + if (keys %{ $self->{convert_labels} }) { + if (not $self->{convert_labels}->{uc $self->{convert_current_label}}) { + warn 'Ignoring _convert() for label ' . $self->{convert_current_label}; + push @ret, $arg; + next ARG; + } + } + push @ret, sprintf '%s(%s%s)', $conv, $arg, map { ",$_" } @{ $self->{convert_params} }; + } return wantarray ? @ret : $ret[0]; } </code> <hr> Recently seen in the CB: <ul> <li>Glamis hath snorted [ liquid], and therefore Cawdor shall sleep no more</li> <li>Segmentation fault (vendor dumped)</li> <li><code> Do you know me, my lord? Excellent well; you are a Perl Monger. </code></li> <li><code> Imperious Bill Gates, dead and turn'd to clay, Might stop a hole to keep the wind away: O, that that earth, which kept the world in awe, Should patch a Wall to expel the Windows' flaw! </code></li> <li><code> $words, @words, %words. </code></li> </ul> <hr/> <code> my $class_name = 'Foo' . '::' . 'Bar'; eval "require $class_name"; if ($@) { warn $@; } $class_name =~ s|::|/|g; eval { require "$class_name.pm"; }; if ($@) { warn $@; } </code> <hr /> [Moron] I once lost a pile of XP by suggesting negative levels with a demonic flavour ;) was fun though <p> <i>[fenLisesi] imagines a damned negative-XP soul, logging in to PM and reading "You have -4 votes left today" Before turn-of-the-day, he has to convince some positive-XP folks to donate votes to him -- which he cannot use -- just to go up to 0 votes, or he gets it</i> <p> [clinton] ...condemned forever to being the NodeReaper's assistant... <p> [Moron]: "you lost 10 XP, you have another 992 votes to lose before reaching the next level, succubus" <p> [fenLisesi] <i>.oO( condemned to read documentation till sunrise, when he "to sulphurous and tormenting flames" must render himself )</i> <hr /> [fenLisesi]: Is there, or are there plans for, that you are aware of, a heroku for catalyst, I have been asked. Heroku seems to be a "deploy your rails/ruby app onto the cloud in ten minutes" kind of service. <br />[bart]: If I were you, I'd ask that on the Catalyst IRC chat channel. <br />[bart]: first on the list <br />moritz wonders if the Cloud was invented at the Clyde <br />[Corion]: I think local::lib together with App::moduleshere is close. There also is ShipWright. None of those are Catalyst specific, but I see that as a plus