<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Sort by Library of Congress call number in Perl</title>
	<atom:link href="http://www.mcgees.org/2001/08/08/sort-by-library-of-congress-call-number-in-perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mcgees.org/2001/08/08/sort-by-library-of-congress-call-number-in-perl/</link>
	<description>Website of Joshua McGee</description>
	<lastBuildDate>Fri, 19 Mar 2010 15:56:04 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Joshua <i>(Site Owner)</i></title>
		<link>http://www.mcgees.org/2001/08/08/sort-by-library-of-congress-call-number-in-perl/comment-page-1/#comment-54838</link>
		<dc:creator>Joshua <i>(Site Owner)</i></dc:creator>
		<pubDate>Fri, 22 May 2009 20:25:58 +0000</pubDate>
		<guid isPermaLink="false">http://mcgees.org/wordpress/?p=131#comment-54838</guid>
		<description>Well, &lt;b&gt;Josh&lt;/b&gt;, I &lt;i&gt;suppose&lt;/i&gt; if you wanted to be &quot;efficient&quot; or &quot;elegant&quot; or &quot;clever&quot; about it, you could use your method.

(Thanks.  I&#039;m feeling a bit foolish for my original solution.)</description>
		<content:encoded><![CDATA[<p>Well, <b>Josh</b>, I <i>suppose</i> if you wanted to be &#8220;efficient&#8221; or &#8220;elegant&#8221; or &#8220;clever&#8221; about it, you could use your method.</p>
<p>(Thanks.&nbsp; I&#8217;m feeling a bit foolish for my original solution.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Purinton</title>
		<link>http://www.mcgees.org/2001/08/08/sort-by-library-of-congress-call-number-in-perl/comment-page-1/#comment-54535</link>
		<dc:creator>Josh Purinton</dc:creator>
		<pubDate>Mon, 18 May 2009 06:04:27 +0000</pubDate>
		<guid isPermaLink="false">http://mcgees.org/wordpress/?p=131#comment-54535</guid>
		<description>An LC Call No.is composed of a &quot;call letter&quot; [A-Z]+ followed optionally by a call number [0-9]+(\.[0-9]+)?, followed by zero or more cutter numbers ([A-Z]+[0-9]+). Everything is sorted ASCII-betically except the integer part of the call number, which is sorted numerically. Therefore, you can just zero-pad the integer part of the call number, and sort the resulting strings using Perl&#039;s built-in cmp operator. (The code below does some extra work to strip non-letters and non-digits, but this shouldn&#039;t matter if all your LC numbers are properly formatted to begin with.)

my @lc_list = (&#039;DK602.3.B76 1996&#039;, &#039;Q335.P416 1994&#039;, &#039;DK602.3.B76 1996a -text&#039;, &#039;QA76.73.P22W35 1991&#039;, &#039;RS75.P5&#039;, &#039;DA870.F64&#039;, &#039;DK602.3.B76 1996b -disc&#039;);

@lc_list = lc_sort(@lc_list);

print map &quot;$_\n&quot;, @lc_list;

sub lc_sort {
  my @sorted = sort map make_sortable_lc($_).&quot;=&quot;.$_, @_;
  foreach (@sorted) {
    s/^[^=]*=//;
  }
  return @sorted;
}

sub make_sortable_lc {
  local ($_) = @_;

  s/([0-9])[.]([0-9])/$1:$2/;
  s/[^:A-Z0-9]//g;
  s/(.):(.)/$1.$2/;
  s/^([A-Z]*)([0-9]+)/sprintf &quot;%s%09d&quot;, $1, $2/e;

  return $_;
}</description>
		<content:encoded><![CDATA[<p>An LC Call No.is composed of a &#8220;call letter&#8221; [A-Z]+ followed optionally by a call number [0-9]+(\.[0-9]+)?, followed by zero or more cutter numbers ([A-Z]+[0-9]+). Everything is sorted ASCII-betically except the integer part of the call number, which is sorted numerically. Therefore, you can just zero-pad the integer part of the call number, and sort the resulting strings using Perl&#8217;s built-in cmp operator. (The code below does some extra work to strip non-letters and non-digits, but this shouldn&#8217;t matter if all your LC numbers are properly formatted to begin with.)</p>
<p>my @lc_list = (&#8217;DK602.3.B76 1996&#8242;, &#8216;Q335.P416 1994&#8242;, &#8216;DK602.3.B76 1996a -text&#8217;, &#8216;QA76.73.P22W35 1991&#8242;, &#8216;RS75.P5&#8242;, &#8216;DA870.F64&#8242;, &#8216;DK602.3.B76 1996b -disc&#8217;);</p>
<p>@lc_list = lc_sort(@lc_list);</p>
<p>print map &#8220;$_\n&#8221;, @lc_list;</p>
<p>sub lc_sort {<br />
&nbsp; my @sorted = sort map make_sortable_lc($_).&#8221;=&#8221;.$_, @_;<br />
&nbsp; foreach (@sorted) {<br />
&nbsp; &nbsp; s/^[^=]*=//;<br />
&nbsp; }<br />
&nbsp; return @sorted;<br />
}</p>
<p>sub make_sortable_lc {<br />
&nbsp; local ($_) = @_;</p>
<p>&nbsp; s/([0-9])[.]([0-9])/$1:$2/;<br />
&nbsp; s/[^:A-Z0-9]//g;<br />
&nbsp; s/(.):(.)/$1.$2/;<br />
&nbsp; s/^([A-Z]*)([0-9]+)/sprintf &#8220;%s%09d&#8221;, $1, $2/e;</p>
<p>&nbsp; return $_;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Library of Congress Call Number Sort in PHP</title>
		<link>http://www.mcgees.org/2001/08/08/sort-by-library-of-congress-call-number-in-perl/comment-page-1/#comment-48533</link>
		<dc:creator>Library of Congress Call Number Sort in PHP</dc:creator>
		<pubDate>Tue, 12 Aug 2008 20:36:20 +0000</pubDate>
		<guid isPermaLink="false">http://mcgees.org/wordpress/?p=131#comment-48533</guid>
		<description>&lt;!--%kramer-ref-pre%--&gt;[...] needed a function that will compare Library of Congress call numbers. I found a function in PERL to do this on Joshua McGees&#039;s site, but I needed it in PHP and our call numbers use a space instead of a period for some of the [...]&lt;!--%kramer-ref-post%--&gt;</description>
		<content:encoded><![CDATA[<p><!--%kramer-ref-pre%-->[...] needed a function that will compare Library of Congress call numbers. I found a function in PERL to do this on Joshua McGees&#8217;s site, but I needed it in PHP and our call numbers use a space instead of a period for some of the [...]<!--%kramer-ref-post%--></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Clark</title>
		<link>http://www.mcgees.org/2001/08/08/sort-by-library-of-congress-call-number-in-perl/comment-page-1/#comment-25154</link>
		<dc:creator>Tom Clark</dc:creator>
		<pubDate>Mon, 30 Jul 2007 13:11:09 +0000</pubDate>
		<guid isPermaLink="false">http://mcgees.org/wordpress/?p=131#comment-25154</guid>
		<description>I get it...sorry...like I said, a newbie.  Thanks for responding.

TC</description>
		<content:encoded><![CDATA[<p>I get it&#8230;sorry&#8230;like I said, a newbie.&nbsp; Thanks for responding.</p>
<p>TC</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joshua <i>(Site Owner)</i></title>
		<link>http://www.mcgees.org/2001/08/08/sort-by-library-of-congress-call-number-in-perl/comment-page-1/#comment-25071</link>
		<dc:creator>Joshua <i>(Site Owner)</i></dc:creator>
		<pubDate>Sun, 29 Jul 2007 01:37:55 +0000</pubDate>
		<guid isPermaLink="false">http://mcgees.org/wordpress/?p=131#comment-25071</guid>
		<description>Tom, I don&#039;t think so.  The first line, commented out, shows what was &quot;passed&quot; into the script.  The second line, also commented out, shows what one gets after the line is chopped up, or &quot;parsed&quot;.  But that&#039;s Geoff&#039;s modification of my code, not mine.</description>
		<content:encoded><![CDATA[<p>Tom, I don&#8217;t think so.&nbsp; The first line, commented out, shows what was &#8220;passed&#8221; into the script.&nbsp; The second line, also commented out, shows what one gets after the line is chopped up, or &#8220;parsed&#8221;.&nbsp; But that&#8217;s Geoff&#8217;s modification of my code, not mine.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Clark</title>
		<link>http://www.mcgees.org/2001/08/08/sort-by-library-of-congress-call-number-in-perl/comment-page-1/#comment-24934</link>
		<dc:creator>Tom Clark</dc:creator>
		<pubDate>Fri, 27 Jul 2007 14:53:26 +0000</pubDate>
		<guid isPermaLink="false">http://mcgees.org/wordpress/?p=131#comment-24934</guid>
		<description>I&#039;m a newbie looking forward to making this work.  If it does it&#039;ll save me a ton of time at my library.

Question:  Shouldn&#039;t the phrase:

       # print “A passed: $a\nB passed: $b\n”;

use &#039;parsed&#039; instead of &#039;passed&#039; ?  

or conversely for the subsequent phrase

       # print “A parsed: $resultA\nB parsed: $resultB\n”;

Perhaps I don&#039;t yet understand enough about Perl.

TC</description>
		<content:encoded><![CDATA[<p>I&#8217;m a newbie looking forward to making this work.&nbsp; If it does it&#8217;ll save me a ton of time at my library.</p>
<p>Question:&nbsp; Shouldn&#8217;t the phrase:</p>
<p>&nbsp; &nbsp; &nbsp;  # print “A passed: $a\nB passed: $b\n”;</p>
<p>use &#8216;parsed&#8217; instead of &#8216;passed&#8217; ?&nbsp; </p>
<p>or conversely for the subsequent phrase</p>
<p>&nbsp; &nbsp; &nbsp;  # print “A parsed: $resultA\nB parsed: $resultB\n”;</p>
<p>Perhaps I don&#8217;t yet understand enough about Perl.</p>
<p>TC</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joshua <i>(Site Owner)</i></title>
		<link>http://www.mcgees.org/2001/08/08/sort-by-library-of-congress-call-number-in-perl/comment-page-1/#comment-268</link>
		<dc:creator>Joshua <i>(Site Owner)</i></dc:creator>
		<pubDate>Mon, 14 Aug 2006 23:10:31 +0000</pubDate>
		<guid isPermaLink="false">http://mcgees.org/wordpress/?p=131#comment-268</guid>
		<description>Yes, it sure did.  It stripped out the backslashes before the dots, too.  Thanks for catching that.</description>
		<content:encoded><![CDATA[<p>Yes, it sure did.&nbsp; It stripped out the backslashes before the dots, too.&nbsp; Thanks for catching that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Geoff Sinclair</title>
		<link>http://www.mcgees.org/2001/08/08/sort-by-library-of-congress-call-number-in-perl/comment-page-1/#comment-267</link>
		<dc:creator>Geoff Sinclair</dc:creator>
		<pubDate>Mon, 14 Aug 2006 21:58:21 +0000</pubDate>
		<guid isPermaLink="false">http://mcgees.org/wordpress/?p=131#comment-267</guid>
		<description>Here&#039;s an example with a little more context. Hopefully it&#039;s useful for newbies! I&#039;ve added one more element to the sort, because our library sometimes makes additions after the year.

&gt;&gt;&gt;&gt;

my @lcList = (&#039;DK602.3.B76 1996&#039;, &#039;Q335.P416 1994&#039;, &#039;DK602.3.B76 1996a -text&#039;, &#039;QA76.73.P22W35 1991&#039;, &#039;RS75.P5&#039;, &#039;DA870.F64&#039;, &#039;DK602.3.B76 1996b -disc&#039;);

$beforeList = join (&quot;\n&quot;, @lcList);
print &quot;Before:\n$beforeList\n\n&quot;;

my @result = sort by_lc_number @lcList;
$afterList = join (&quot;\n&quot;, @result);

print &quot;\nAfter:\n$afterList\n\n&quot;;

sub by_lc_number {

	# print &quot;A passed: $a\nB passed: $b\n&quot;;
	
	$a =~ /^([A-Z]+)(\d+(?:\.\d+)?)\.?([A-Z]*)(\d*)\.?([A-Z]*)(\d*)( (?:\d{4})?)?(.*)?/;
	@a = ($1,$2,$3,$4,$5,$6,$7,$8);
	$b =~ /^([A-Z]+)(\d+(?:\.\d+)?)\.?([A-Z]*)(\d*)\.?([A-Z]*)(\d*)( (?:\d{4})?)?(.*)?/;
	@b = ($1,$2,$3,$4,$5,$6,$7,$8);

	# $resultA = join (&quot;::&quot;, @a);
	# $resultB = join (&quot;::&quot;, @b);
	# print &quot;A parsed: $resultA\nB parsed: $resultB\n&quot;;

	return
	$a[0] cmp $b[0]
	    &#124;&#124;
	$a[1] &lt;=&gt; $b[1]
	    &#124;&#124;
	$a[2] cmp $b[2]
	    &#124;&#124;
	&quot;0.$a[3]&quot; &lt;=&gt; &quot;0.$b[3]&quot;
	    &#124;&#124;
	$a[4] cmp $b[4]
	    &#124;&#124;
	&quot;0.$a[5]&quot; &lt;=&gt; &quot;0.$b[5]&quot;
	    &#124;&#124;
	$a[6] &lt;=&gt; $b[6]
	    &#124;&#124;
	$a[7] cmp $b[7]
	    ;
}</description>
		<content:encoded><![CDATA[<p>Here&#8217;s an example with a little more context. Hopefully it&#8217;s useful for newbies! I&#8217;ve added one more element to the sort, because our library sometimes makes additions after the year.</p>
<p>&gt;&gt;&gt;&gt;</p>
<p>my @lcList = (&#8217;DK602.3.B76 1996&#8242;, &#8216;Q335.P416 1994&#8242;, &#8216;DK602.3.B76 1996a -text&#8217;, &#8216;QA76.73.P22W35 1991&#8242;, &#8216;RS75.P5&#8242;, &#8216;DA870.F64&#8242;, &#8216;DK602.3.B76 1996b -disc&#8217;);</p>
<p>$beforeList = join (&#8221;\n&#8221;, @lcList);<br />
print &#8220;Before:\n$beforeList\n\n&#8221;;</p>
<p>my @result = sort by_lc_number @lcList;<br />
$afterList = join (&#8221;\n&#8221;, @result);</p>
<p>print &#8220;\nAfter:\n$afterList\n\n&#8221;;</p>
<p>sub by_lc_number {</p>
<p>	# print &#8220;A passed: $a\nB passed: $b\n&#8221;;</p>
<p>	$a =~ /^([A-Z]+)(\d+(?:\.\d+)?)\.?([A-Z]*)(\d*)\.?([A-Z]*)(\d*)( (?:\d{4})?)?(.*)?/;<br />
	@a = ($1,$2,$3,$4,$5,$6,$7,$8);<br />
	$b =~ /^([A-Z]+)(\d+(?:\.\d+)?)\.?([A-Z]*)(\d*)\.?([A-Z]*)(\d*)( (?:\d{4})?)?(.*)?/;<br />
	@b = ($1,$2,$3,$4,$5,$6,$7,$8);</p>
<p>	# $resultA = join (&#8221;::&#8221;, @a);<br />
	# $resultB = join (&#8221;::&#8221;, @b);<br />
	# print &#8220;A parsed: $resultA\nB parsed: $resultB\n&#8221;;</p>
<p>	return<br />
	$a[0] cmp $b[0]<br />
	&nbsp; &nbsp; ||<br />
	$a[1] &lt;=&gt; $b[1]<br />
	&nbsp; &nbsp; ||<br />
	$a[2] cmp $b[2]<br />
	&nbsp; &nbsp; ||<br />
	&#8220;0.$a[3]&#8221; &lt;=&gt; &#8220;0.$b[3]&#8221;<br />
	&nbsp; &nbsp; ||<br />
	$a[4] cmp $b[4]<br />
	&nbsp; &nbsp; ||<br />
	&#8220;0.$a[5]&#8221; &lt;=&gt; &#8220;0.$b[5]&#8221;<br />
	&nbsp; &nbsp; ||<br />
	$a[6] &lt;=&gt; $b[6]<br />
	&nbsp; &nbsp; ||<br />
	$a[7] cmp $b[7]<br />
	&nbsp; &nbsp; ;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Geoff Sinclair</title>
		<link>http://www.mcgees.org/2001/08/08/sort-by-library-of-congress-call-number-in-perl/comment-page-1/#comment-266</link>
		<dc:creator>Geoff Sinclair</dc:creator>
		<pubDate>Mon, 14 Aug 2006 21:55:15 +0000</pubDate>
		<guid isPermaLink="false">http://mcgees.org/wordpress/?p=131#comment-266</guid>
		<description>Thanks!! You&#039;re missing the backslashes before the d&#039;s. Did WordPress strip them out?</description>
		<content:encoded><![CDATA[<p>Thanks!! You&#8217;re missing the backslashes before the d&#8217;s. Did WordPress strip them out?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Geoff Sinclair</title>
		<link>http://www.mcgees.org/2001/08/08/sort-by-library-of-congress-call-number-in-perl/comment-page-1/#comment-265</link>
		<dc:creator>Geoff Sinclair</dc:creator>
		<pubDate>Mon, 14 Aug 2006 21:52:46 +0000</pubDate>
		<guid isPermaLink="false">http://mcgees.org/wordpress/?p=131#comment-265</guid>
		<description>Thanks for posting this code!! I had a little trouble getting it to work, but then I figured out that the backslashes before the d&#039;s didn&#039;t show up in your code sample. In any case, here&#039;s the script as I got it to work, with a little extra context. I added another element to the sort, because sometimes our LC numbers have additions after the year. I&#039;ve included some of these in the example. Now...will the backslashes show?

Geoff
&gt;&gt;&gt;&gt;

my @lcList = (&#039;DK602.3.B76 1996&#039;, &#039;Q335.P416 1994&#039;, &#039;DK602.3.B76 1996a -text&#039;, &#039;QA76.73.P22W35 1991&#039;, &#039;RS75.P5&#039;, &#039;DA870.F64&#039;, &#039;DK602.3.B76 1996b -disc&#039;);

$beforeList = join (&quot;\n&quot;, @lcList);
print &quot;Before:\n$beforeList\n\n&quot;;

my @result = sort by_lc_number @lcList;
$afterList = join (&quot;\n&quot;, @result);

print &quot;\nAfter:\n$afterList\n\n&quot;;

sub by_lc_number {

	# print &quot;A passed: $a\nB passed: $b\n&quot;;
	
	$a =~ /^([A-Z]+)(\d+(?:\.\d+)?)\.?([A-Z]*)(\d*)\.?([A-Z]*)(\d*)( (?:\d{4})?)?(.*)?/;
	@a = ($1,$2,$3,$4,$5,$6,$7,$8);
	$b =~ /^([A-Z]+)(\d+(?:\.\d+)?)\.?([A-Z]*)(\d*)\.?([A-Z]*)(\d*)( (?:\d{4})?)?(.*)?/;
	@b = ($1,$2,$3,$4,$5,$6,$7,$8);

	# $resultA = join (&quot;::&quot;, @a);
	# $resultB = join (&quot;::&quot;, @b);
	# print &quot;A parsed: $resultA\nB parsed: $resultB\n&quot;;

	return
	$a[0] cmp $b[0]
	    &#124;&#124;
	$a[1] &lt;=&gt; $b[1]
	    &#124;&#124;
	$a[2] cmp $b[2]
	    &#124;&#124;
	&quot;0.$a[3]&quot; &lt;=&gt; &quot;0.$b[3]&quot;
	    &#124;&#124;
	$a[4] cmp $b[4]
	    &#124;&#124;
	&quot;0.$a[5]&quot; &lt;=&gt; &quot;0.$b[5]&quot;
	    &#124;&#124;
	$a[6] &lt;=&gt; $b[6]
	    &#124;&#124;
	$a[7] cmp $b[7]
	    ;
}</description>
		<content:encoded><![CDATA[<p>Thanks for posting this code!! I had a little trouble getting it to work, but then I figured out that the backslashes before the d&#8217;s didn&#8217;t show up in your code sample. In any case, here&#8217;s the script as I got it to work, with a little extra context. I added another element to the sort, because sometimes our LC numbers have additions after the year. I&#8217;ve included some of these in the example. Now&#8230;will the backslashes show?</p>
<p>Geoff<br />
&gt;&gt;&gt;&gt;</p>
<p>my @lcList = (&#8217;DK602.3.B76 1996&#8242;, &#8216;Q335.P416 1994&#8242;, &#8216;DK602.3.B76 1996a -text&#8217;, &#8216;QA76.73.P22W35 1991&#8242;, &#8216;RS75.P5&#8242;, &#8216;DA870.F64&#8242;, &#8216;DK602.3.B76 1996b -disc&#8217;);</p>
<p>$beforeList = join (&#8221;\n&#8221;, @lcList);<br />
print &#8220;Before:\n$beforeList\n\n&#8221;;</p>
<p>my @result = sort by_lc_number @lcList;<br />
$afterList = join (&#8221;\n&#8221;, @result);</p>
<p>print &#8220;\nAfter:\n$afterList\n\n&#8221;;</p>
<p>sub by_lc_number {</p>
<p>	# print &#8220;A passed: $a\nB passed: $b\n&#8221;;</p>
<p>	$a =~ /^([A-Z]+)(\d+(?:\.\d+)?)\.?([A-Z]*)(\d*)\.?([A-Z]*)(\d*)( (?:\d{4})?)?(.*)?/;<br />
	@a = ($1,$2,$3,$4,$5,$6,$7,$8);<br />
	$b =~ /^([A-Z]+)(\d+(?:\.\d+)?)\.?([A-Z]*)(\d*)\.?([A-Z]*)(\d*)( (?:\d{4})?)?(.*)?/;<br />
	@b = ($1,$2,$3,$4,$5,$6,$7,$8);</p>
<p>	# $resultA = join (&#8221;::&#8221;, @a);<br />
	# $resultB = join (&#8221;::&#8221;, @b);<br />
	# print &#8220;A parsed: $resultA\nB parsed: $resultB\n&#8221;;</p>
<p>	return<br />
	$a[0] cmp $b[0]<br />
	&nbsp; &nbsp; ||<br />
	$a[1] &lt;=&gt; $b[1]<br />
	&nbsp; &nbsp; ||<br />
	$a[2] cmp $b[2]<br />
	&nbsp; &nbsp; ||<br />
	&#8220;0.$a[3]&#8221; &lt;=&gt; &#8220;0.$b[3]&#8221;<br />
	&nbsp; &nbsp; ||<br />
	$a[4] cmp $b[4]<br />
	&nbsp; &nbsp; ||<br />
	&#8220;0.$a[5]&#8221; &lt;=&gt; &#8220;0.$b[5]&#8221;<br />
	&nbsp; &nbsp; ||<br />
	$a[6] &lt;=&gt; $b[6]<br />
	&nbsp; &nbsp; ||<br />
	$a[7] cmp $b[7]<br />
	&nbsp; &nbsp; ;<br />
}</p>
]]></content:encoded>
	</item>
</channel>
</rss>
