stillhq.com : Mikal, a geek from Canberra living in Silicon Valley (no blather posts) http://www.stillhq.com The life, times, travel and software of Michael Still (no blather posts) en Copyright (c) Michael Still 2000 - 2006 blosxom simplerss20 v20050208hh 180 http://blogs.law.harvard.edu/tech/rss die() in a CGI /perl Tue, 26 Jul 2005 00:43:00 GMT So, I've been battling for a couple of days with how best to die() in a perl script while running a CGI script... The problem is that I really want the user in browser land to know about the error too. Then SJH pointed me at a web page which suggests this: <br/><br/> <ul><pre> use CGI::Carp qw(fatalsToBrowser); </pre></ul> <br/><br/> Which is lovely and just works. Me likey. <br/><br/><i>Tags for this post: perl(<a href="http://www.stillhq.com/perl"><img src="http://www.stillhq.com/tagicon.cgi?post=/perl/000004&tag=perl&format=.png" border="0" alt="S"></a>) </i> <br/><br/> <a href="http://www.stillhq.com/perl/000004.commentform.html">Comment</a> http://www.stillhq.com/perl/000004.html http://www.stillhq.com/perl/000004.html Unique elements in a perl array /perl Sun, 17 Jul 2005 22:04:00 GMT I want to have an array in perl with only unique elements. My current hacky way is to misuse a hash, is there a nicer way of doing this? <br/><br/> <ul><pre> # This function is similar to the above, but returns a list of the # directories containing at least one image. # # Pass in the path to the parent directory sub getdirectories{ my($path) = @_; my(%directories); find(sub{ # Again, this needs to be tweaked if other image formats are # to be supported if($File::Find::name =~ /\/([^\/]*\.jpg)$/i){ # This is a horrible, horrible hack $directories{$File::Find::dir} = "yes"; } }, $path); return keys %directories; } </pre></ul> <br/><br/><i>Technorati tags for this post: <a href="http://technorati.com/tag/perl" rel="tag">perl</a> <a href="http://technorati.com/tag/unique" rel="tag">unique</a> <a href="http://technorati.com/tag/array" rel="tag">array</a> <a href="http://technorati.com/tag/item" rel="tag">item</a> </i> <br/><br/> <a href="http://www.stillhq.com/perl/000003.commentform.html">Comment</a> http://www.stillhq.com/perl/000003.html http://www.stillhq.com/perl/000003.html Welcome to my personal perl help desk /perl Mon, 28 Mar 2005 04:23:00 GMT So far <a href="http://ozlabs.org/~jk/diary/tech/software/pmkdir.diary/">Jeremy</a>, <a href="http://www.flamingspork.com/blog">Stewart</a> and <a href="http://svana.org/sjh/diary">Steven</a> have pointed me at opendir, readdir and closedir. I'm mildly surprised that perl does something as sensible as implementing the syscall interface I was already familiar with. That's cool. <br/><br/> What's cooler is that I appear to have a band of perl helper monkeys at my command. Never again need I google while programming! Oh, and comment display now works because of their assistance. <br/><br/><i>Technorati tags for this post: <a href="http://technorati.com/tag/perl" rel="tag">perl</a> <a href="http://technorati.com/tag/perl" rel="tag">perl</a> <a href="http://technorati.com/tag/helper" rel="tag">helper</a> <a href="http://technorati.com/tag/monkey" rel="tag">monkey</a> </i> <br/><br/> <a href="http://www.stillhq.com/perl/000002.commentform.html">Comment</a> http://www.stillhq.com/perl/000002.html http://www.stillhq.com/perl/000002.html A more efficient way of getting a directory listing? /perl Sun, 27 Mar 2005 23:04:00 GMT You might have noticed no comments are visible yet. I've actually got four to publish, but I'm just finishing off the display side of the system now (there was an afternoon nap that got in the way of that). Anyways, my current problem is that: <br/><br/> <ul><pre> open FH, "ls /home/mikal/blog-comments/$path/$filename/ 2> /dev/null |" or die "Couldn't get a list of files"; </pre></ul> <br/><br/> Is terribly inefficient and slow. Is there a faster way of getting a listing of a directory's contents in perl? <br/><br/><i>Technorati tags for this post: <a href="http://technorati.com/tag/perl" rel="tag">perl</a> <a href="http://technorati.com/tag/directory" rel="tag">directory</a> <a href="http://technorati.com/tag/listing" rel="tag">listing</a> <a href="http://technorati.com/tag/slow" rel="tag">slow</a> </i> <br/><br/> <a href="http://www.stillhq.com/perl/000001.commentform.html">Comment</a> http://www.stillhq.com/perl/000001.html http://www.stillhq.com/perl/000001.html