[32983] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4259 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 5 05:17:16 2014

Date: Tue, 5 Aug 2014 02:17:04 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 5 Aug 2014     Volume: 11 Number: 4259

Today's topics:
    Re: knocking rough edges off template project: issue2:  <cal@example.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 05 Aug 2014 02:00:32 -0700
From: Cal Dershowitz <cal@example.invalid>
Subject: Re: knocking rough edges off template project: issue2: re-writing similar functions
Message-Id: <c4bkpmF718mU1@mid.individual.net>

On 07/26/2014 01:52 AM, Cal Dershowitz wrote:

> Something here clobbers cyrillic....

I was basically one line of code short with the encodings:

$ustring = decode_utf8( $ustring );

sub schmintf{
use strict;
use warnings;
use 5.010;
use Text::Template;
use Encode;

my $rvars = shift;
my $reftoAoA = shift;
my %vars = %$rvars;
my @AoA = @$reftoAoA;
say "in schmint ";
my $body = $vars{"body"};
my $template = Text::Template->new(
     ENCODING => 'utf8',
     SOURCE => $body)
     or die "Couldn't construct template: $!";
my $return;
for my $i ( 0 .. $#AoA ){
$vars{"file"} = $AoA[$i][0];
$vars{"english"} = $AoA[$i][1];
my $ustring = $AoA[$i][2];
$ustring = decode_utf8( $ustring );
$vars{"russian"} = $ustring;

my $result = $template->fill_in(HASH => \%vars);

$return = $return.$result;
}
#say "return is $return";
return \$return;
}

It works:

http://merrillpjensen.com/pages/basketball5.html

so I'm looking at other issues...

Issue2: re-writing similar functions

I'm constantly re-writing the functions and modules and really like 
having all the flexibility of passing a reference to the hash that is 
the main data structure.  But I seem to have a lot of close to identical 
functions, well 3 at any rate, and I have them segregated in their own 
module:

package football2;
require Exporter;
use config1;
use utils1;

our @ISA = qw(Exporter);
our @EXPORT = qw(
   write_bottom
  write_header
    write_footer );


sub write_bottom  {
use strict;
use Text::Template;
my ($rvars) = shift;
my %vars = %$rvars;
my $footer = $vars{"bottom"};
my $template = Text::Template->new(SOURCE => $footer)
           or die "Couldn't construct template: $!";
my $result = $template->fill_in(HASH => $rvars);
return \$result;
}

sub write_header {
use strict;
use Text::Template;
my $rvars = shift;
my %vars = %$rvars;
# get time
my $now_string = localtime;
$vars{"date"} = $now_string;
my $header = $vars{"header"};
my $template2 = Text::Template->new(SOURCE => $header)
           or die "Couldn't construct template: $!";
my $result2 = $template2->fill_in(HASH => \%vars);
return \$result2;
}

sub write_footer  {
use strict;
use Text::Template;
my ($rvars) = shift;
my %vars = %$rvars;
my $footer = $vars{"footer"};
my $template = Text::Template->new(SOURCE => $footer)
           or die "Couldn't construct template: $!";
my $result = $template->fill_in(HASH => $rvars);
return \$result;
}

1;

What I want to do is call these with something like

my $ref = write_header($rvars, "footer")

, but I've had a terrible time passing things at the same time that of 
differing datatypes.

Q2) What would you do to economize this function space?

Thanks for your comment
-- 
Cal Dershowitz


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 4259
***************************************


home help back first fref pref prev next nref lref last post