<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<title>Snipplr</title>
<link>http://snipplr.com/language/perl/tags/one-liners</link>
<description>Recent snippets posted on Snipplr.com</description>
<language>en-us</language>
<pubDate>Sat, 25 May 2013 09:28:08 GMT</pubDate>
<item>
<title>(Perl) Detect PHP files with trailing whitespace, using Perl - noah</title>
<link>http://snipplr.com/view/46218/detect-php-files-with-trailing-whitespace-using-perl/</link>
<description><![CDATA[ <p>The following incantation returns nonzero exit status when the terminating `?>`  of a PHP file, is followed by whitespace.</p> ]]></description>
<pubDate>Wed, 29 Dec 2010 08:25:03 GMT</pubDate>
<guid>http://snipplr.com/view/46218/detect-php-files-with-trailing-whitespace-using-perl/</guid>
</item>
<item>
<title>(Perl) Renumber the files in a directory, or prefix file names with numbers - noah</title>
<link>http://snipplr.com/view/26527/renumber-the-files-in-a-directory-or-prefix-file-names-with-numbers/</link>
<description><![CDATA[ <p>Useful for renumbering frames to feed into `ffmpeg`</p> ]]></description>
<pubDate>Fri, 15 Jan 2010 16:16:57 GMT</pubDate>
<guid>http://snipplr.com/view/26527/renumber-the-files-in-a-directory-or-prefix-file-names-with-numbers/</guid>
</item>
<item>
<title>(Perl) check for broken links (shell one-liner) - noah</title>
<link>http://snipplr.com/view/18344/check-for-broken-links-shell-oneliner/</link>
<description><![CDATA[ <p>Retrieves links from a remote HTML page, then checks the response code of each link.  Duplicated links are only checked once, and anchors are ignored.  That is `http://foo` and `http://foo#bar` are considered to be the same URL, and thus `http://foo` will only be checked once; even if both URLs occur on the page.

Note that if the command produces too much output for you, you can filter down to just the *broken* links (if any) by piping the output of the entire one-liner, to `grep -v "200 OK"`

## Dependencies

These must be installed on your system:

0. [Perl](http://perl.org)
0. [lwp-request](http://search.cpan.org/~gaas/libwww-perl-5.831/bin/lwp-request)
0. [sort](http://www.gnu.org/software/coreutils/manual/html_node/sort-invocation.html 'GNU sort sorts lines in a text file')
0. [uniq](http://www.gnu.org/software/coreutils/manual/html_node/uniq-invocation.html 'GNU uniq filters duplicate items from a list')

## Troubleshooting

**Check the quotes.**  The command below has strings wrapped in *double* quotes (") which is appropriate if you are using a *Windows* shell.

**If you are using a Mac or Linux shell** then you need to change the double quotes around the strings in the command below, to *single* quotes (').  Then all should work fine.

It is good to keep in mind always that the Windows shell wants strings to be double-quoted, while Unix-ish shells want strings to be single-quoted.</p> ]]></description>
<pubDate>Sat, 15 Aug 2009 08:55:19 GMT</pubDate>
<guid>http://snipplr.com/view/18344/check-for-broken-links-shell-oneliner/</guid>
</item>
<item>
<title>(Perl) comparing the checksums of two files with Perl and cksum - noah</title>
<link>http://snipplr.com/view/16660/comparing-the-checksums-of-two-files-with-perl-and-cksum/</link>
<description><![CDATA[ <p>This one-liner helps to determine if two or more files have the same
checksum.  It works by piping the output from `cksum` to Perl, which
takes note of the first checksum and compares each subsequent file's
checksum to that value.

Assume an example session where we have three identical files and two
that are different
      
    >echo bart > bart
    >cp bart bart1
    >cp bart bart2
    >echo milhouse > mvh
    >echo lisa > lisa
      
two files with the same checksum, produce no output
      
    >cksum bart bart1 | perl -ane '$x ||= $F[0]; warn if $x != $F[0];'
      
if a there is a different checksum, the line numbers printed are the
indexes of those files
      
    >cksum bart bart1 mvh bart2 lisa | perl -ane '$x ||= $F[0]; warn if $x != $F[0];'
    Warning: something's wrong at -e line 1,  line 3.
    Warning: something's wrong at -e line 1,  line 5.</p> ]]></description>
<pubDate>Sun, 05 Jul 2009 21:17:39 GMT</pubDate>
<guid>http://snipplr.com/view/16660/comparing-the-checksums-of-two-files-with-perl-and-cksum/</guid>
</item>
<item>
<title>(Perl) grep with Perl - noah</title>
<link>http://snipplr.com/view/11878/grep-with-perl/</link>
<description><![CDATA[ <p>A combination of the instructions in the book _Minimal Perl_ and [this Perl one-liners page](http://sial.org/howto/perl/one-liner/)

The general form of the one-liner is:

    > perl -wnl -e '/REGEX/ and print $ARGV." $.: $_"; close ARGV if eof' 

The example below shows how to print the hex colors that are defined in a [Sass](http://haml.hamptoncatlin.com/docs/rdoc/classes/Sass.html) source tree.</p> ]]></description>
<pubDate>Thu, 05 Feb 2009 13:29:59 GMT</pubDate>
<guid>http://snipplr.com/view/11878/grep-with-perl/</guid>
</item>
<item>
<title>(Perl) Rake routes filtering with Perl - noah</title>
<link>http://snipplr.com/view/9570/rake-routes-filtering-with-perl/</link>
<description><![CDATA[ <p></p> ]]></description>
<pubDate>Sat, 08 Nov 2008 11:29:05 GMT</pubDate>
<guid>http://snipplr.com/view/9570/rake-routes-filtering-with-perl/</guid>
</item>
<item>
<title>(Perl) Generate XHTML on the command line with XML::API::XHTML - noah</title>
<link>http://snipplr.com/view/4971/generate-xhtml-on-the-command-line-with-xmlapixhtml/</link>
<description><![CDATA[ <p>Build a simple XHTML document, format it with Tidy and print the result to "temp.html."

You may first need to `cpan   XML::API::XHTML`, and install Tidy using your favorite package manager, or just [download Tidy by itself](http://tidy.sourceforge.net/#binaries)

### If you can't install XML::API::XHTML

On my system, CPAN complained that "make test had returned bad status" during installation of XML::API::XHTML.  To solve this I started the CPAN shell (just type `cpan`) and then forced the install, like this:
    
    cpan> force XML::API::XHTML</p> ]]></description>
<pubDate>Sun, 10 Feb 2008 02:21:23 GMT</pubDate>
<guid>http://snipplr.com/view/4971/generate-xhtml-on-the-command-line-with-xmlapixhtml/</guid>
</item>
<item>
<title>(Perl) search and replace across multiple files with Perl - noah</title>
<link>http://snipplr.com/view/3145/search-and-replace-across-multiple-files-with-perl/</link>
<description><![CDATA[ <p>A couple of useful snippets from an article I found at Perl.com

**Perl search-and-replace on the command line.**

All of these should be usable under Cygwin as well.  But remember that bash wants single-quoted strings but MS-DOS shell wants strings to be double-quoted.</p> ]]></description>
<pubDate>Wed, 04 Jul 2007 20:00:52 GMT</pubDate>
<guid>http://snipplr.com/view/3145/search-and-replace-across-multiple-files-with-perl/</guid>
</item>
</channel>
</rss>