princepawn has asked for the wisdom of the Perl Monks concerning the following question:

Template File

select `in`.date,leads.* from leads left join `in` on `in`.lead_id = leads.id where `in`.date BETWEEN '{$start_date}' AND '{$end_date}'

Output

[tbone@horse1 CPC]$ ./lead-query.pl 2003-10-01 2003-10-03 Text::Template=HASH(0x8111b3c) at ./lead-query.pl line 43. select `in`.date,leads.* from leads left join `in` on `in`.lead_id = leads.id where `in`.date BETWEEN '' AND '' [tbone@horse1 CPC]$

Source Code

#!/usr/bin/perl #===================================================================== # DECLARATIONS #===================================================================== use strict; use Text::Template; #===================================================================== # SUBROUTINES #===================================================================== sub USAGE { " Usage : $0 start_date end_date You passed: $0 @ARGV "; } #===================================================================== # PROGRAM PROPER #===================================================================== @ARGV == 2 or die USAGE; my %data; our ($start_date, $end_date) = @ARGV; my $template = Text::Template->new (TYPE => 'FILE', SOURCE => 'lead-query.tt') or die "$Text::Template::ERROR"; warn $template; print $template->fill_in (PACKAGE => '__PACKAGE__' ); 1;

Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality.

Replies are listed 'Best First'.
Re: Text::Template and the Binding of Package Variables
by broquaint (Abbot) on Oct 03, 2003 at 21:27 UTC
    Drop the quotes around '__PACKAGE__' as it needs to be a bareword for the parser to process it e.g
    print "package is: __PACKAGE__", $/; print "package is: ", __PACKAGE__, $/; __output__ package is: __PACKAGE__ package is: main
    HTH

    _________
    broquaint

Re: Text::Template and the Binding of Package Variables
by perrin (Chancellor) on Oct 03, 2003 at 19:22 UTC
    I never really use our, but as I understand it those are lexical avriables. You need to use globals if you want this to work (i.e. use vars).
      They are lexical variables, but I they are also package lexicals... to contrast: my variables do not have a package assoc'ed with them - they hang off of a piece of code. But our variables are package variables with lexical scope. The manpage talks about my variables as not working, but it may be that what you are saying about my variables applies.

      Carter's compass: I know I'm on the right track when by deleting something, I'm adding functionality.

        Kind of seems like it should work, actually. You are assigning values to $main::start_date and $main::end_date and then your template runs in package main:: and refers to $start_date and $end_date without strict turned on. Maybe there's something special about the use of the main:: package. You could try declaring a package in your program and see if that helps.