<?xml version="1.0" encoding="windows-1252"?>
<node id="1013054" title="Re: Reminder to self: must use Memoize more often!" created="2013-01-12 12:34:14" updated="2013-01-12 12:34:14">
<type id="11">
note</type>
<author id="733061">
flexvault</author>
<data>
<field name="doctext">
&lt;p&gt;Hello &lt;a href="http://www.perlmonks.org/?node_id=757127"&gt;tobyink&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;I use 'Memoize' and it is an &lt;b&gt;awesome&lt;/b&gt; product. But before I knew about it, I did some memorization using a hash. More than 10 years ago I wrote the following code for an editor that I converted from 'traditional C' to Perl:
&lt;code&gt;
 sub ATS
 {  # PyrEdit assumes the HOME is col 1, row 1
    our %CRToutput;
    my $col = int(shift); my $row = int(shift);
    my $Saved = "$col|$row";
    if (exists $CRToutput{$Saved})
    {    return($CRToutput{$Saved}); }
    my $loc;
    if ( $SYS{"ATS"} eq "xterm" )    ## all 'xterm' compatibles 
    { $loc = "\e\[$row\;$col"."H"; }
    else
    {    ## PyrEdit assumes that HOME is col 1, row 1
        if (  $SYS{"ATSDEC"} eq "Y" ) { $row--; $col--; }
        $loc = qx/tput cup $row $col/; chomp($loc);
    }
    $CRToutput{$Saved} = $loc;
    return($loc);
 }
&lt;/code&gt;
&lt;/p&gt;&lt;p&gt;In *nix the 'tput' command is very expensive, and since I had to support lots of different terminal types, I cached the results using a hash. The results were as good as the 'traditional C' after just a few seconds of use.&lt;/p&gt;&lt;p&gt;Just an alternative. 
&lt;/p&gt;&lt;p&gt;
&lt;b&gt;Update:&lt;/b&gt; The original sub didn't have the 'my's. It was only after joining PM and learning of the value of 'use strict; use warnings' that I went back and put the 'my's into the code. I'm sure I've updated it in more than one place. It's currently on my mind since I received a package of xml files on Thursday without any "\n" and I added an '-xml' option the next day. After 2-3 hours of coding, I have a XML formatter that show the proper indention and structure for all(mine) XML files.

&lt;/p&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-733061"&gt;
&lt;p&gt;&lt;b&gt;"Well done is better than well said." - Benjamin Franklin&lt;/b&gt;&lt;/p&gt;

&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
1013033</field>
<field name="parent_node">
1013033</field>
</data>
</node>
