Lecar_red's Journal http://use.perl.org/~Lecar_red/journal/ Lecar_red's use Perl Journal en-us use Perl; is Copyright 1998-2006, Chris Nandor. Stories, comments, journals, and other submissions posted on use Perl; are Copyright their respective owners. 2012-01-25T02:29:30+00:00 pudge pudge@perl.org Technology hourly 1 1970-01-01T00:00+00:00 Lecar_red's Journal http://use.perl.org/images/topics/useperl.gif http://use.perl.org/~Lecar_red/journal/ Why can't you assign a value in ternary operation? http://use.perl.org/~Lecar_red/journal/37031?from=rss <p>I'm sure there is a good reason why this works the way it does. </p><p> If I set a local variable inside a ternary operator like:</p><blockquote><div><p> <tt>print ( my $foo = bar() ? $foo : "unknown" )</tt></p></div> </blockquote><p> It works very closely to my expectations (which I'm sure are off). If bar returns any flavor of false, it will print the "unknown" value. And if bar return true it will call the correct part of the operation. But the local variable assignment will not be set so the output will be an empty string. </p><p> Anyone know why? Is this a scope thing? </p><p> P.S. Yes, I know there are other ways to do this with string printing. In my real world case, I have a much more delicate assignment and would like to cleanly assign and evaluate in one line. Plus I'm curious<nobr> <wbr></nobr>:) </p> Lecar_red 2008-07-28T18:01:02+00:00 journal Ominous cvs log message http://use.perl.org/~Lecar_red/journal/33504?from=rss CVS log message:<blockquote><div><p>I think this adds everything for the XXX into the tree</p></div> </blockquote><p> Unfortunatly, the <i>I</i> thought incorrectly </p> Lecar_red 2007-06-12T19:24:15+00:00 journal Deliberate Practice and Perl http://use.perl.org/~Lecar_red/journal/29570?from=rss I was reading an interesting article in the NY Times in the continuing series of <a href="http://www.freakonomics.com/">Freakonomics</a>. This article was discussing how over 50% of successful soccer players (footballers) were born in the first three months in the year. In it they discussed some research about the effectiveness of "Deliberate Practice". I wasn't aware of it but delibrate practice involves more complex actions than just repeating according to the article it "entails setting specific goals, obtaining immediate feedback, and concentrating as much on technique as on outcome". Perl fits very well into the technique since it provides pretty instant feedback and often Perl coding involves focusing on technique along with results. I'm sure there are other ways as well.<p> It also strikes me as yet another good reason to code test cases. Quick feedback to help cement learning. </p><p> The article is well worth a read over on the <a href="http://www.nytimes.com/2006/05/07/magazine/07wwln_freak.html?ex=1147233600&amp;en=6a3168396c98d5e8&amp;ei=5087%0A">Times</a> site.</p> Lecar_red 2006-05-09T18:45:05+00:00 journal Determing the best tool for the job http://use.perl.org/~Lecar_red/journal/28518?from=rss <p> The other day, a friend and I were having lunch and discussing programming languages and technology. I have been reading a few posts above language advocacy and the problems with any type of advocacy (it turns religous instead of being rational, it leads to the person advocating not being taken seriously, etc.). I have no problem with python (i kind of like the clean syntax), ruby (except the sudden vogue-ness of it), c, java, javascript, etc... I don't mind learning them and using them. But my problem is how to determine what the best tool, language, framework, etc... for the job actually is? Where is this information, CW or ? The experts seem to be in their own camps for their own purposes. </p><p> There doesn't seem to be any studies looking at solving the same problem with different tools. And if there were any studies, how would you determine the effectiveness of each one? Would it be lines of code, ability to scale, speed of development, simplicity to maintain, or ? It seems that we (coders, developers, engineers,<nobr> <wbr></nobr>...) all want to use the most effective tool but we don't have access to information to help us make this choice (beyond folklore, our own experience or that of others, and other social not scientific evaluations). </p><p> How does Perl compare itself with java, python, prolog, etc... ? By language attributes (static typing vs. dynamic) but are these meaningful? By performance? By feature X or Y? Maybe 'compare' isn't the best word here... Maybe we should talk about what Perl is strongest at, or most effective at doing and what Java is most effective at. But what happens when you have three languages at all have the same effectiveness, does it turn to style then?</p><p> I would love to hear peoples thoughts about this. Or information about research projects going on. Or is it time to write a grant? (like I have any idea how to do that<nobr> <wbr></nobr>;) </p><p> Peace </p> Lecar_red 2006-01-30T17:05:43+00:00 journal Irish search engine http://use.perl.org/~Lecar_red/journal/27808?from=rss My friend in Ireland pointed me at <a href="http://www.doogle.org/">Doogle</a>. A funny Irish search engine, it is worth a few minutes of your life. Lecar_red 2005-11-30T22:15:12+00:00 journal Mac IE strikes again... This time select with optgroups. http://use.perl.org/~Lecar_red/journal/27567?from=rss <p> Another very strange Mac IE rendering problem. I know, I know, I know stop supporting Mac IE already. Unfortunatly at $work nothing is quite that easy. </p><p> This time Mac IE's wonderful support (per half the blogs on the planet) for optgroup usage has bit me in the ass. It seems that when you use a multiple select with a size and style height: <code> &lt;select size="6" multiple style="height=6em;" &gt; </code> And then include a (or multiple) optgroups in that select. It cannot figure out what the correct option count to start displaying the scroll bar since it doesn't actually count the 'optgroup' element as a display element. An example:</p><blockquote><div><p> <tt>&lt;select size="6" multiple name="stuff" style="height: 6em;"&gt;<br>&lt;optgroup label="Group 1"&gt;<br>&nbsp; &nbsp;&lt;option value="one"&gt; One &lt;/option&gt;<br>&nbsp; &nbsp;&lt;option value="two"&gt; Two &lt;/option&gt;<br>&nbsp; &nbsp;&lt;option value="three"&gt; Three &lt;/option&gt;<br>&nbsp; &nbsp;&lt;option value="four"&gt; Four &lt;/option&gt;<br>&nbsp; &nbsp;&lt;option value="five"&gt; Five &lt;/option&gt;<br>&lt;/optgroup&gt;</tt></p></div> </blockquote><p>According to Mac IE the size is '5' which is correct (in the javascript DOM) but it doesn't figure out that the display size is six (it seems to use 'select.length') so it never puts the scroll bar there causing the last element to be impossible to select. You have to pad it with blank options to the size of 'size'. Fun...</p> Lecar_red 2005-11-14T15:49:11+00:00 journal Loving outlook email http://use.perl.org/~Lecar_red/journal/27388?from=rss At $work, I need to use the evil that is outlook and all of its associated posse of tools. Today, I was looking for an email from a system and found that I now had a "Junk E-mail" folder. That does not catch the junk mail but only things from mailing lists and systems that create email. It is so good at catching the junk that is seems to catch the virus quarantine reports from the other system... Nice job Outlook! Lecar_red 2005-10-31T16:51:19+00:00 journal J2EE, Mike Park and bad weeks http://use.perl.org/~Lecar_red/journal/27293?from=rss <p>Ah, it was a lovely week. My mac's drive died badly and without warning. My boss indicated that the app I'm in charge of should "consider" (read into that) using JSEE and JSP (I'm a mason, perl, etc... person). And I am dumb enough that I hadn't backed up the mac in fair too long (for my $month = 0; $month </p><p> Perl needs a JSEE like system but it needs to be faster and well less JSEE like. But it needs to dress up like J2EE so managers and CTO and ? think it really is J2EE... I know <a href="http://poe.perl.org/">POE</a> is similar but how do we fight the Java hype? Maybe we don't... Paul Graham did have a nice point about Java in his <a href="http://www.paulgraham.com/ideas.html">Start Up ideas</a> (that people get paid well for it being a dead end...) But is that just wishful thinking? I can do J2EE but do I want to do it? </p><p> I have been listening to <a href="http://www.mikeparkmusic.com/">Mike Park</a> for the last few weeks. He was in Skankin Pickle back in the third wave ska days but now he is writing really good folk music from a new perspective. He is Korean and his music is very enlighting for those of us not Asian. He addresses concerns that I'm sure many young Asian kids have with their own culture in America (and other places in world) like having loves that are not the same race and not having or wanting the same things in life that their parents do (that sounds pretty universal...). It is nice to hear some different voices in the music world. Give him a listen, buy his CD, support someone doing something different. </p><p> Here is a lesson for me. BACKUP your machine! </p> Lecar_red 2005-10-24T14:17:32+00:00 journal resume writing http://use.perl.org/~Lecar_red/journal/26989?from=rss <p>To start off, I'm not looking for a new job but that doesn't stop me from window shopping. </p><p> The other day, I did run across a cool one on <a href="http://jobs.perl.org/">jobs.perl.org</a> which made me think. I want to send them a resume... unfortunately I haven't really kept it up in the last few (when does few turn into many?) years. So this weekend I started to create one. Well, let me tell you, I'm really out of practice with it. I'm trying to distill a big chuck of time into a few sentences. I can understand why you would pay someone. It is a disappointment to take 2+ years of design, coding and such and turn it into "built web application with HTML::Mason, Perl, mod_perl and Javascript".... the blood sweat and curse words are completely lost. The fights over badly complex UI design and crazy marketing ideas are gone. The nice part of it is that I've seen how much I've done in the last few years... that is quite cool and makes me feel warm and fuzzy.<nobr> <wbr></nobr>:) </p> Lecar_red 2005-10-03T15:46:29+00:00 journal finally a meaningful error message http://use.perl.org/~Lecar_red/journal/26928?from=rss <p> Working tonight I received this error message:</p><p> <cite> [Wed Sep 28 23:06:52 2005] [error] Can't locate object method "apache_req" via package "shit" (perhaps you forgot to load "shit"?) at<nobr> <wbr></nobr>/Users/lcarmich/dev/orgwrangler/lib/OrgWrangler/WebApp.pm line 105.\n </cite> </p><p> a bunch of truth in that error message. This is just one time in a million that I forgot to load shit. </p><p> BTW, I mistyped shift....</p> Lecar_red 2005-09-29T04:14:30+00:00 journal ajax and the greek myth http://use.perl.org/~Lecar_red/journal/26723?from=rss It occurred to me today on the way in to work that Ajax as a name for the newest super duper solve all problem technology is kind of odd since the greek myth of Ajax (Greater Ajax) is not very good or postive. I know it is JAA (just another acronym )but will the technology end with the same fate? <br> <br> Here is my synopsis of the myth:<p> Ajax was one of the best Greek fighers in the seige on Troy but according to some accounts (Homer) he wasn't very bright. After Achilles was killed and Troy fell, he and Odysseus both wanted Achilles armor to prove they were the greatest greek warrior. In the end, the armor was awarded to Odysseus, this drove Ajax mad with resentment. He eventually killed himself. </p><p> Is there a Odysseus project out there?<nobr> <wbr></nobr>;) </p> Lecar_red 2005-09-14T21:52:58+00:00 journal Family Values http://use.perl.org/~Lecar_red/journal/25957?from=rss I think it is very funny that America is the (self-proclaimed) land of <i>Family Values</i>. Yet Europeans have may govt regulations helping/enabling them to spend more time with their families. I think in the end America likes the idea of Family Values but doesn't really like their familys or maybe we (I'm american) missed the first stage of the workers revolution. A good read is Paul Krugman's <a href="http://www.nytimes.com/2005/07/29/opinion/29krugman.html?th&amp;emc=th">French Family Values</a> editorial. Lecar_red 2005-07-29T15:14:51+00:00 journal Great ideas at inconvenient times http://use.perl.org/~Lecar_red/journal/25848?from=rss <p> Yesterday, after I started major rewriting of some session, user auth, logging and such in a mason application into the wonderful 'MasonX::WebApp' (Thanks Dave.), I realized that it would be nice to know what the performance impact is/was. Well on my dev system, I had moved the logging initialization and the L10n support into the new library along with already changing the apache configuration and updating the autohandler. After cursing like a good ol' sailor (poor guys get attributed with such things), I wished I was smarted and thought of running performance benchmarks <b>before</b> I had already pretty heavily change the current version... Nothing quite like hide-foresight... Well I broke down and figured out how to reload the old system and then found the very useful WWW::Mechanize::Timed to do some simple page response times (that is really all I care about). But it would have saved an afternoon if I had thought of it before starting to change the software over...</p><p>So as Pilon would say there is a lesson in every story, you can find you own here. </p><p>BTW, if you are writing apps with HTML::Mason check out the <a href="http://search.cpan.org/dist/MasonX-WebApp/lib/MasonX/WebApp.pm">MasonX::WebApp</a> it is a very useful library. </p> Lecar_red 2005-07-22T15:24:18+00:00 journal The sexiest thing http://use.perl.org/~Lecar_red/journal/25106?from=rss To set the stage: My wife is modern dancer. Albeit it is a small stage<p> Last night here in <a href="http://www.ci.stpaul.mn.us/">St Paul</a>, we had a very bad electrical storm. I woke up around 3am to turn off the mac, forgot about the freebsd box. I woke up and left for work. Damn I was tired. The kids and my wife beat me up and I was running late as usually. I thought in the middle of the day, "I forgot to turn on the mac, I wonder if I should call her", then I sat in many meetings and forgot about phoning her to let her know how to do it. Tonight, after dinner I went upstairs to check out the incredible shrinking bank account to find the computer on. WOW! My wife has just figured out how to turn it on (the power button in the IMac G4 is on the back not any of that easy keyboard or front on switch stuff). Man, she is super sexy... </p> Lecar_red 2005-06-09T00:37:14+00:00 journal file transfer quirks http://use.perl.org/~Lecar_red/journal/25034?from=rss Over the the last week, we have had issues with a newly deployed web based file transfer system written in Perl/mod_perl/Mason. To cluster/load balance the web servers we need to run a magic middleware system the receives incoming files with ftp. (Basically web uploads are turned into ftp transfers to central middleware). We run proftpd on the MW and use Net::FTP inside the web app. For the last couple of days we have begun to see data connections start to stall causing the transfers to stop working. Strangely, it seems to happen for only one webserver and the same file will transfer in the next submission is fine. And of course, I cannot replicated it with many sends from my desktop. After pulling hair and not finding anything suspect, in the code, proftp or the network (according to the Ops folk there is nothing in between but a switch no firewall, not extra network problem generator...). Today we switched over to using passive mode to transfer the files and so far so good. I don't really know why this would happen unless there was something about having inbound connections come into a process running as part of apache but I would expect this to cause rejections not stalled sockets after some amount of data transfer. The one thing I really like about this whole deal was to have Net::FTP use passive mode all it took was adding the following line to the apache configuration (No Code Changes, Yeah!)<br> <br> <code> SetEnv FTP_PASSIVE 1 </code> <br> <br> Then we danced and drank beer. Well... there really wasn't any dancing in public. Lecar_red 2005-06-03T20:48:38+00:00 journal M/FF search plugin created, too bad it already existed ;) http://use.perl.org/~Lecar_red/journal/24435?from=rss I went out to <a href="http://mycroft.mozdev.org/download.html">Mozilla Search</a> plugins site, looked under the "Programming" section for a "CPAN" search one (since I seem search for modules all the time) and I don't find one. I think, "great I can learn how to create one and share it". Well I spend a little time learning how to create one, show it to my coworkers with pride (pride before the fall right), and get ready to submit it. Well, before submitting it, I go back to the downloads page and enter "CPAN" into the search input... well lo and behold, there is one already... I'm very disappointed about it. It really isn't that big of a deal (I'm not sure why I thought suddenly that no one had done this), but I would have like to contribute something no matter how small. It was funny writing it. <br> <br> Bummer... Lecar_red 2005-04-28T21:52:28+00:00 journal A very good poem http://use.perl.org/~Lecar_red/journal/24412?from=rss Such a wonderful poem, <a href="http://www.bartleby.com/120/42.html">The Poet in the Nursery</a> by Robert Graves. Everytime I read it I am moved. (I mean really read it) Lecar_red 2005-04-27T20:52:03+00:00 journal I'm digging Class::DBI::mysql http://use.perl.org/~Lecar_red/journal/24307?from=rss I've been really digging Class::DBI and <a href="http://search.cpan.org/~tmtm/Class-DBI-mysql-0.23/lib/Class/DBI/mysql.pm"> Class::DBI::mysql</a>. <br> <br> In a master class (or whatever that main thing would be called), I've been able to do:<blockquote><div><p> <tt>RSSManager::DBI-&gt;table('feeds');<br>RSSManager::DBI-&gt;create_table(q{<br>&nbsp; id MEDIUM INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,<br>&nbsp; userid INT,<br>&nbsp; url varchar(256),<br>});<br> <br>RSSManager::DBI-&gt;set_up_table;</tt></p></div> </blockquote><p> Instead of <code>mysql &lt; setup_my_stuff.sql</code> and other crap... <br> Very cool. This isn't even mention the easy column -&gt; method mapping... <br> <br> <strong>Thanks, Tony!</strong></p> Lecar_red 2005-04-21T20:20:14+00:00 journal Switch Module http://use.perl.org/~Lecar_red/journal/24041?from=rss <p>I've stumbled across the <a href="http://cpan.uwinnipeg.ca/htdocs/perl/Switch.html">Switch</a> module and thinks it's pretty cool (and more importantly useful!). Are there lots of folks using it out there? </p><p> Just Curious.</p> Lecar_red 2005-04-06T18:51:33+00:00 journal Taking an idea and turning it into software http://use.perl.org/~Lecar_red/journal/23594?from=rss I've been frustrated with not being able to take an idea and turn in it to software. I seem to have trouble breaking it into writable (is that a word?) pieces. I guess you could call them requirements... I seem to get spin in the details. Any ideas out there? Lecar_red 2005-03-10T22:25:32+00:00 journal why UTF8 is wonderful http://use.perl.org/~Lecar_red/journal/23554?from=rss <p>I have been writing/supporting a localized and globalized web application that used(still uses) shift jis for japanese character encoding. Our newest webapps uses many better technologies (<a href="masonhq.com">Mason</a> which I really really really like) and UTF8 for character encoding inside both the middleware and web app when handling of text and filenames. We do a lot of file processing (up and down). With that amount of filename processing (including striping off path or renaming when filenames exceed lengths, I ran into many shift jis characters that required special processing to protect them.</p><p> We have a couple of basename (subs, functions, etc. depending upon language) that detect and guard against shift jis slamming. Generally they follow this form: </p><blockquote><div><p> <tt>&nbsp; &nbsp; my $bn; ## basename string<br>&nbsp; &nbsp; while ($loc &lt;= length($path)) {<br>&nbsp; &nbsp; &nbsp; &nbsp; my $chr = substr($path, $loc, 1);<br> <br>&nbsp; &nbsp; &nbsp; &nbsp; ## grab the basename if we match the<br>&nbsp; &nbsp; &nbsp; &nbsp; ## directory sep<br>&nbsp; &nbsp; &nbsp; &nbsp; if ($chr eq $sep) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $bn = substr($path, $loc+1, length($path));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $loc++;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; next;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br> <br>&nbsp; &nbsp; &nbsp; &nbsp; ## it's in the ascii range so it's a single byte<br>&nbsp; &nbsp; &nbsp; &nbsp; ## character, only move forward one character<br>&nbsp; &nbsp; &nbsp; &nbsp; if ($chr =~<nobr> <wbr></nobr>/[\x00-\x7f]/) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $loc++;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; next;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br> <br>&nbsp; &nbsp; &nbsp; &nbsp; ## first is dbl byte, skip following character which<br>&nbsp; &nbsp; &nbsp; &nbsp; ## is part of the dbl character<br>&nbsp; &nbsp; &nbsp; &nbsp; $loc++; $loc++;<br>&nbsp; &nbsp; }</tt></p></div> </blockquote><p>This basically walks each character looking for magic hex pattern before '/' (5C) or '\' (2F) if (815C, 825C, 835C... range), since shift jis uses as part of the character. What A <i>Pain</i> in the ass...</p><p>But the blessed UTF8 does not require any of that crap. Yeah! And now I can use (at least for Perl) standard modules. See: </p><blockquote><div><p> <tt>&nbsp; &nbsp; my $path = shift;<br> <br>&nbsp; &nbsp; ## only change for mac or win. (unix ok)<br>&nbsp; &nbsp; if (isWin) {<br>&nbsp; &nbsp; &nbsp; &nbsp; fileparse_set_fstype("MSWin32");<br>&nbsp; &nbsp; } elsif (isMac) {<br>&nbsp; &nbsp; &nbsp; &nbsp; fileparse_set_fstype("MacOS");<br>&nbsp; &nbsp; }<br> <br>&nbsp; &nbsp; ## default to unix since it rules...<br>&nbsp; &nbsp; my $b = basename($path);<br>&nbsp; &nbsp; fileparse_set_fstype("Unix"); ## reset it to avoid later issues<br>&nbsp; &nbsp; return($b);</tt></p></div> </blockquote><p> Happiness... until the wreslting with content dispositions and utf8, another story for another day.. </p> Lecar_red 2005-03-08T22:59:02+00:00 journal Funky browser evilness (on IE mac users though) http://use.perl.org/~Lecar_red/journal/23464?from=rss As I continue my wandering through the localization and globalization magical land (I want the mushrooms!), I've run into an issue with an older system that just underwent a very cool UI update. <br> <br> It seems that Mac IE while using shift-jis character encoding does not like stylesheets that includes rule that set western style fonts on form inputs. It basically causing the value inside the text input or select to revert to some other encoding (like MacRoman?). Funny enough, we listing a select (a drop down of values) all the values get display as japanese characters. On the other hand, in a more predicible way (much like a horny <a href="http://www.nps.gov/wica/Backcountry_Camping.htm"> American Bison</a>, scroll to Bison section), that setting the same rule for the body does nothing... <br> <br> Here is an example of the offending rule:<br><nobr> <wbr></nobr>.fInput { font-family: Arial, Helvetica, sans-serif; } <br> <br> I've found creating a special sheet (like the small bus), for only IE mac with the font family of 'Osaka' fixes the problem. <br> i.e.<br><nobr> <wbr></nobr>.fInput { font-family: Osaka; } <br> <br> Another one for the Perl (notice Randal) programmer to fix not the UI/web designer (how does this happen?). Lecar_red 2005-03-02T22:01:52+00:00 journal Figuring out if text is UTF8 http://use.perl.org/~Lecar_red/journal/23390?from=rss <p> Well for the last couple of days, I've struggled in figuring out how to have Perl tell me that the current string inside a scalar is actually UTF8 or something else. </p><p> The first thing I tried was using the internal 'utf::valid' command. Well according to this everything (including values I knew where shift jis) was valid utf8. Later, I found (in some very useful documentation) that this will only tell you what Perl is storing it as not if the value is actually UTF8. But thanks to a very nice entry in the <a href="http://cpan.uwinnipeg.ca/htdocs/perl/perluniintro.html#questions_with_answers">perluniintro</a> page, that you can figure out if something is utf8 by simple decoding it. If it doesn't work that the value is not utf8. The <a href="http://cpan.uwinnipeg.ca/htdocs/Encode/Encode.html#perl_encoding_api">Encode</a> module is useful for that. </p><p> One other bit I've learned working with UTF8, shift JIS and other character encodings. It pays to use test values in URI (or HTML escaped) strings, then you can unescape them before your test script (or main application code) messes with the string. Then you can escape them to prevent problems with older (or basic) terms (xterm, my redhat 7.2 machine, etc.). Must better than having to pipe the output to less or xod. Also, it makes it easy to grab a html escape value from a logfile and then pass it as a command line arg to your test script (with unescapes it). </p><p>Just a couple thoughts for the end of the week.</p><p> oops... I meant Perl<nobr> <wbr></nobr>;)</p> Lecar_red 2005-02-25T20:46:38+00:00 journal