<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Nilesh's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Wed, 23 Jul 2008 16:37:30 GMT</pubDate>
    <description>DZone Snippets: Nilesh's Code Snippets</description>
    <item>
      <title>Perl: Dirify string</title>
      <link>http://snippets.dzone.com/posts/show/3057</link>
      <description>Clean up a string for creation of a directory named using the string.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;my $dir = dirify('The s^#%@$!#! &lt;b&gt;title&lt;/b&gt; ever');     # outputs 'The-S-Title-Ever'&lt;br /&gt;&lt;br /&gt;sub dirify {&lt;br /&gt;    my $s = shift;&lt;br /&gt;&lt;br /&gt;    $s =~ s!&lt;[^&gt;]+&gt;!!gs;            # Remove HTML tags.&lt;br /&gt;    $s =~ s!&lt;!&amp;lt;!gs;&lt;br /&gt;&lt;br /&gt;    $s =~ s!&amp;[^;\s]+;!!g;           # Remove HTML entities.&lt;br /&gt;    $s =~ s![^A-Za-z0-9-_ ]! !g;    # Allow only alphanumeric chars.&lt;br /&gt;    $s =~ s!\s+! !g;                # Remove extra spaces.&lt;br /&gt;    $s =~ s!\s$!!g;         &lt;br /&gt;    $s =  lc $s;                    # Convert to lower-case.   &lt;br /&gt;    $s =~ s!(\b.)!\U$1!g;           # Capitalize words (Comment out if you don't need this)&lt;br /&gt;    $s =~ tr! !-!s;                 # Finally, change space chars to dashes.&lt;br /&gt;&lt;br /&gt;    return $s;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 29 Nov 2006 13:28:35 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3057</guid>
      <author>nilesh (Nilesh)</author>
    </item>
    <item>
      <title>Perl: Sorted union of two arrays</title>
      <link>http://snippets.dzone.com/posts/show/3056</link>
      <description>Create a union of two arrays and sort the array.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;my @union = array_union_sort(\@first, \@second);&lt;br /&gt;&lt;br /&gt;sub array_union_sort {&lt;br /&gt;    my $aa = shift;&lt;br /&gt;    my $bb = shift;&lt;br /&gt;    my %union;&lt;br /&gt;    my $e;&lt;br /&gt;    foreach $e (@$aa) { $union{$e} = 1; }&lt;br /&gt;    foreach $e (@$bb) { $union{$e} = 1; }&lt;br /&gt;    my @union = keys %union;&lt;br /&gt;    @union = sort { $a &lt;=&gt; $b } @union;&lt;br /&gt;    return @union;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 29 Nov 2006 12:45:19 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3056</guid>
      <author>nilesh (Nilesh)</author>
    </item>
  </channel>
</rss>
