Content here is by:
Michael Still
mikal@stillhq.com

All my Open Source projects
Extracted view of CVS
Home
Site map

See recent comments. RSS feed of all comments. Raw dump of all comments for research purposes.

ImageMagick book
MythTV book








Tue, 26 Jul 2005



die() in a CGI

    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:

      use CGI::Carp qw(fatalsToBrowser); 
      


    Which is lovely and just works. Me likey.

    Tags for this post: perl(S)
    Related posts: The dangers of bad automated translation; Please don't; Bad server, no donut for you

posted at: 00:43 | path: /perl | permanent link to this entry


Sun, 17 Jul 2005



Unique elements in a perl array

    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?

      # 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;
      }
      


    Technorati tags for this post:

posted at: 22:04 | path: /perl | permanent link to this entry


Mon, 28 Mar 2005



Welcome to my personal perl help desk

    So far Jeremy, Stewart and Steven 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.

    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.

    Technorati tags for this post:

posted at: 04:23 | path: /perl | permanent link to this entry


Sun, 27 Mar 2005



A more efficient way of getting a directory listing?

    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:

      open FH, "ls /home/mikal/blog-comments/$path/$filename/ 2> /dev/null |" or die "Couldn't get a list of files";
      


    Is terribly inefficient and slow. Is there a faster way of getting a listing of a directory's contents in perl?

    Technorati tags for this post:

posted at: 23:04 | path: /perl | permanent link to this entry