<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: file extension code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 18 May 2008 00:09:52 GMT</pubDate>
    <description>DZone Snippets: file extension code</description>
    <item>
      <title>file extension methods</title>
      <link>http://snippets.dzone.com/posts/show/5509</link>
      <description>Allows you to use file extensions as methods&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class File&lt;br /&gt;  # Feel free to add more here, as you need them.&lt;br /&gt;  Extensions = %r=^(txt|rb|markdown|textile|haml|sass|css|html|xhtml)$=i&lt;br /&gt;  &lt;br /&gt;  module Extension&lt;br /&gt;    def method_missing(meth, *args)&lt;br /&gt;      if Extensions =~ meth.to_s&lt;br /&gt;        [self, '.', meth.to_s].join&lt;br /&gt;      else&lt;br /&gt;        super&lt;br /&gt;      end # if&lt;br /&gt;    end # method_missing&lt;br /&gt;  end # Extension&lt;br /&gt;end # File&lt;br /&gt;&lt;br /&gt;class Symbol&lt;br /&gt;  include File::Extension&lt;br /&gt;end&lt;br /&gt;class String&lt;br /&gt;  include File::Extension&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;'myfile'.html&lt;br /&gt;# =&gt; "myfile.html"&lt;br /&gt;&lt;br /&gt;:a_file.rb&lt;br /&gt;# =&gt; "a_file.rb"&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sat, 17 May 2008 02:08:39 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5509</guid>
      <author>elliottcable (elliott cable)</author>
    </item>
    <item>
      <title>basename &amp; dirname in Perl</title>
      <link>http://snippets.dzone.com/posts/show/4268</link>
      <description>These two Perl functions implement approximations of the UNIX utilities `basename` and `dirname`, though basename() automatically strips off the last extension no matter what.&lt;br /&gt;&lt;code&gt;sub basename($) {&lt;br /&gt; my $file = shift;&lt;br /&gt; $file =~ s!^(?:.*/)?(.+?)(?:\.[^.]*)?$!$1!;&lt;br /&gt; return $file;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;sub dirname($) {my $file = shift; $file =~ s!/?[^/]*/*$!!; return $file; }&lt;/code&gt;</description>
      <pubDate>Fri, 06 Jul 2007 05:49:34 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4268</guid>
      <author>Minimiscience (Guildorn Tanaleth)</author>
    </item>
    <item>
      <title>File extension counter</title>
      <link>http://snippets.dzone.com/posts/show/4249</link>
      <description>Produces a count of the frequencies of each file extension in the directories named on the command line&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/perl -w&lt;br /&gt;use strict;&lt;br /&gt;my %exten;&lt;br /&gt;foreach (@ARGV) {&lt;br /&gt; /(\.[^.]+)$/ &amp;&amp; $exten{$1}++ foreach glob "$_/*.*"&lt;br /&gt;}&lt;br /&gt;print "$_: $exten{$_}\n" foreach sort keys %exten;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 05 Jul 2007 02:40:03 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4249</guid>
      <author>Minimiscience (Guildorn Tanaleth)</author>
    </item>
  </channel>
</rss>
