[25624] in Perl-Users-Digest
Perl-Users Digest, Issue: 7866 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 8 14:05:55 2005
Date: Tue, 8 Mar 2005 11:05:23 -0800 (PST)
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, 8 Mar 2005 Volume: 10 Number: 7866
Today's topics:
About tied filehandles limitation: stat operation <alian@cpan.org>
conditional <toylet@hotpop.com>
Re: conditional (Anno Siegel)
Re: conditional <do-not-use@invalid.net>
Re: conditional <toylet@hotpop.com>
Re: conditional <tadmc@augustmail.com>
doubt regarding Symbolic references <rajesh.mr@gmail.com>
Re: doubt regarding Symbolic references <no@email.com>
Re: doubt regarding Symbolic references <mritty@gmail.com>
Re: doubt regarding Symbolic references <jgibson@mail.arc.nasa.gov>
error with variable (nicolas-laurent)
Re: error with variable <tadmc@augustmail.com>
Re: error with variable <jgibson@mail.arc.nasa.gov>
How to view error messages within a function francescomoi@europe.com
Re: How to view error messages within a function <glex_nospam@qwest.invalid>
include external perl program (Alythh)
Re: include external perl program <1usa@llenroc.ude.invalid>
Re: include external perl program <jl_post@hotmail.com>
perlpod/perldoc Q: I want asterisk bullets <jkrugman345@yahbitoo.com>
Re: Q: Only put unique element in a HoL? xhoster@gmail.com
Strange tar behavior with Net::Telnet jimnl69@hotmail.com
Text::Template Question <edwin@webvoip.com>
Re: Text::Template Question <jkeen_via_google@yahoo.com>
Re: Text::Template Question <edwin@webvoip.com>
Re: Text::Template Question <pilkowsk@informatik.uni-marburg.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 08 Mar 2005 14:41:14 +0100
From: Alian <alian@cpan.org>
Subject: About tied filehandles limitation: stat operation
Message-Id: <422dab5e$0$25625$626a14ce@news.free.fr>
Hello,
I work on a module that allow access to windows share from unix world with help
of samba API. This module allow things like:
use Filesys::Smbclient;
my $smb = new Filesys::SmbClient;
my $fd = $smb->open("<smb://jupiter/doc/general.css")
or die "Can't open it:$!\n";
while (my $l= $smb->read($fd,50)) {print $l; }
$smb->close(fd);
but too with the help of the magic tie command:
use Filesys::Smbclient;
use File::Copy;
local *FD;
tie(*FD, 'Filesys::SmbClient',">smb://jupiter/toto/tata", 0755);
copy(\*FD, "/tmp/toto");
But this last one complain with:
stat() on closed filehandle FD at /usr/local/perl-5.8.5/lib/5.8.5/File/Copy.pm
line 82, <F> line 1.
(The copy command work well even I’ve been getting an error code from copy method.)
In perldoc perltie, I can read in BUG section:
Tied filehandles are still incomplete. sysopen(), truncate(), flock(), fcntl(),
stat() and -X can’t currently be trapped.
Is this a "todo" or a "can't" ? Can someone give some reasons about this
restriction and where I must read code to understand this warning ?
Thanks,
--
Alain BARBET
------------------------------
Date: Tue, 08 Mar 2005 19:12:11 +0800
From: man-wai chang <toylet@hotpop.com>
Subject: conditional
Message-Id: <422d888b$1_1@rain.i-cable.com>
what's wrong with this line:
print (($found)? "" : "not")."found\n";
--
.~. Might, Courage, Vision. http://www.linux-sxs.org
/ v \
/( _ )\ Linux 2.4.29
^ ^ 7:11pm up 3 days 9:21 load average: 1.01 1.39 2.30
------------------------------
Date: 8 Mar 2005 11:21:48 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: conditional
Message-Id: <d0k1sc$po2$1@mamenchi.zrz.TU-Berlin.DE>
man-wai chang <toylet@hotpop.com> wrote in comp.lang.perl.misc:
> what's wrong with this line:
>
> print (($found)? "" : "not")."found\n";
Consult the documentation of the functions you're using if they're giving
you trouble. perldoc -f print. See the sentence beginning with "Also
be careful...".
Anno
------------------------------
Date: 08 Mar 2005 12:25:11 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: conditional
Message-Id: <yzd3bv6wfag.fsf@invalid.net>
man-wai chang <toylet@hotpop.com> writes:
> what's wrong with this line:
>
> print (($found)? "" : "not")."found\n";
If you enable warnings, you will get a very long and descriptive
text that tells you what the problem is.
------------------------------
Date: Tue, 08 Mar 2005 20:59:16 +0800
From: man-wai chang <toylet@hotpop.com>
Subject: Re: conditional
Message-Id: <422da1a4$1_1@rain.i-cable.com>
> Consult the documentation of the functions you're using if they're giving
> you trouble. perldoc -f print. See the sentence beginning with "Also
> be careful...".
I see. thanks.
--
.~. Might, Courage, Vision. http://www.linux-sxs.org
/ v \
/( _ )\ Linux 2.4.29
^ ^ 8:59pm up 3 days 11:09 load average: 1.17 1.10 0.91
------------------------------
Date: Tue, 8 Mar 2005 07:40:57 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: conditional
Message-Id: <slrnd2rar9.6s7.tadmc@magna.augustmail.com>
man-wai chang <toylet@hotpop.com> wrote:
> what's wrong with this line:
It has too many parenthesis and a dot instead of a comma. :-)
(ie. precedence)
print $found ? '' : 'not', "found\n";
> print (($found)? "" : "not")."found\n";
You should always enable warnings when developing Perl code!
(Especially when perl is doing something you don't understand.
Especially especially before asking hundreds of people around
the world to help you with it.
)
See also:
Message-Id: <slrnatq036.2q2.tadmc@magna.augustmail.com>
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 8 Mar 2005 09:08:25 -0800
From: "Rajesh" <rajesh.mr@gmail.com>
Subject: doubt regarding Symbolic references
Message-Id: <1110301705.453443.323450@o13g2000cwo.googlegroups.com>
Lets Consider a simple program like this
$i = 'a';
$a = "why is it so boring?";
print "$$i";
Now, the output will be the string "why is it so boring?" because $$i
will now get referenced to $a and hence the string.
Now, instead $i has the value $a . Something like,
$i = '$a';
$a = "why is it so boring?";
print "$i";
In this case, the output will be "$a" and not the string that is
expected.
But, I want the output to be the string. How would I get the value of a
variable if another variable has this variable?
------------------------------
Date: Tue, 08 Mar 2005 17:26:31 +0000
From: Brian Wakem <no@email.com>
Subject: Re: doubt regarding Symbolic references
Message-Id: <3965i9F5rvg2hU1@individual.net>
Rajesh wrote:
> Lets Consider a simple program like this
>
> $i = 'a';
> $a = "why is it so boring?";
> print "$$i";
>
> Now, the output will be the string "why is it so boring?" because $$i
> will now get referenced to $a and hence the string.
>
> Now, instead $i has the value $a . Something like,
>
> $i = '$a';
> $a = "why is it so boring?";
> print "$i";
>
> In this case, the output will be "$a" and not the string that is
> expected.
> But, I want the output to be the string. How would I get the value of a
> variable if another variable has this variable?
You could use:-
print eval $i;
--
Brian Wakem
------------------------------
Date: Tue, 08 Mar 2005 17:49:06 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: doubt regarding Symbolic references
Message-Id: <mAlXd.49355$ya6.15007@trndny01>
"Rajesh" <rajesh.mr@gmail.com> wrote in message
news:1110301705.453443.323450@o13g2000cwo.googlegroups.com...
> Lets Consider a simple program like this
>
> $i = 'a';
> $a = "why is it so boring?";
> print "$$i";
please read:
perldoc -q quoting
What's wrong with always quoting $vars.
>
> Now, the output will be the string "why is it so boring?" because $$i
> will now get referenced to $a and hence the string.
>
> Now, instead $i has the value $a . Something like,
>
> $i = '$a';
> $a = "why is it so boring?";
> print "$i";
>
> In this case, the output will be "$a" and not the string that is
> expected.
> But, I want the output to be the string. How would I get the value of
a
> variable if another variable has this variable?
Another responder already told you about eval(). I will give you the
standard warning - YOU DON'T WANT TO DO THIS! Symbolic references are
bad, evil, and should not be used unless absolutely necessary. They
almost never are. The correct answer is to use a hash:
$i = 'a';
$vars{a} = 'Why is it so boring?';
print $vars{$i};
For a more thorough discussion on why you should not be using symrefs,
please consult the FAQ:
perldoc -q "variable name"
Paul Lalli
------------------------------
Date: Tue, 08 Mar 2005 09:49:48 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: doubt regarding Symbolic references
Message-Id: <080320050949482552%jgibson@mail.arc.nasa.gov>
In article <1110301705.453443.323450@o13g2000cwo.googlegroups.com>,
Rajesh <rajesh.mr@gmail.com> wrote:
> Lets Consider a simple program like this
>
> $i = 'a';
> $a = "why is it so boring?";
> print "$$i";
>
> Now, the output will be the string "why is it so boring?" because $$i
> will now get referenced to $a and hence the string.
>
> Now, instead $i has the value $a . Something like,
>
> $i = '$a';
> $a = "why is it so boring?";
> print "$i";
>
> In this case, the output will be "$a" and not the string that is
> expected.
> But, I want the output to be the string. How would I get the value of a
> variable if another variable has this variable?
>
If you want to use reference variables, use _real_ ones, not bogus
symbolic references:
#!/usr/local/bin/perl
#
use strict;
use warnings;
my $a = 'this is exciting';
my $i = \$a;
$a = 'why is it so boring?';
print "$$i\n";
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
------------------------------
Date: 8 Mar 2005 05:34:57 -0800
From: nicolas_laurent545@hotmail.com (nicolas-laurent)
Subject: error with variable
Message-Id: <97fc9ebc.0503080534.d4049d@posting.google.com>
New to programming, I don't see what wrong with this code. The script
run on /fr/rules/sens1 but not on en/rules/sens1. I suspect something
wrong with
readParams(\$lang);
# ---------------MAIN
BEGIN-------------------------------------------------
my $lang;
readParams(\$lang);
#\$silent, \@rulesFiles, \$base);
printc "lang = ", 'black', ''; printc "$lang", 'green';
my $WORD = "[[:alpha:]'-]";
my @RULES_FILES;
my $exceptFile = "$lang/config/exceptions.txt";
buildRulesSens(1, $exceptFile, $lang);
#buildRulesSens(2, $configFile, $lang);
# -------------------------------------------------------------------
sub buildRulesSens {
my ($sens, $exceptFile, $lang) = @_;
@RULES_FILES = ();
my $rulesPath = "$lang/rules/sens$sens";
find \&lsRuleFiles, "$rulesPath";
my $out = "$lang/rules_sens$sens.txt";
my $conf = readConfFile($exceptFile);
open (OUT, ">$out") or error("Cant open '$out'");
foreach my $ruleF (@RULES_FILES) {
printc "Processing rules file: $ruleF\n";
print OUT "#<FILE>$ruleF<BODY>\n";
my $newRules = buildRules($ruleF, $conf);
foreach my $r (@$newRules) {
print OUT "$r\n";
}
#trc('_rules', $_rules); die;
}
close OUT;
}
# -------------------------------------------------------------------
CODE
sub readParams {
my ($lang) = @_;
my ($help, $version);
GetOptions(
"--lang:s" => $lang,
"v" => \$version, "version" => \$version,
"h" => \$help, "help" => \$help);
error("--lang parameter missing") unless $$lang;
if ($$lang !~ /(fr|en)/) {
error("Invalid value for parameter lang=$$lang");
}
}
------------------------------
Date: Tue, 8 Mar 2005 09:01:46 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: error with variable
Message-Id: <slrnd2rfiq.7a6.tadmc@magna.augustmail.com>
nicolas-laurent <nicolas_laurent545@hotmail.com> wrote:
> I don't see what wrong with this code.
> printc "lang = ", 'black', ''; printc "$lang", 'green';
Perl does not have a printc() function.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 08 Mar 2005 10:00:24 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: error with variable
Message-Id: <080320051000240749%jgibson@mail.arc.nasa.gov>
In article <97fc9ebc.0503080534.d4049d@posting.google.com>,
nicolas-laurent <nicolas_laurent545@hotmail.com> wrote:
> New to programming, I don't see what wrong with this code. The script
> run on /fr/rules/sens1 but not on en/rules/sens1. I suspect something
> wrong with
> readParams(\$lang);
In what language is this program written? The functions find, printc,
and error do not exist in the Perl language, although they can be
supplied by modules. If it is Perl, then you should have the following
at the beginning of your program:
use strict;
use warnings;
You should also tell us why "something is wrong". What is the program
doing that you don't think it should. Please read the guidelines for
posting to this group.
[programm snipped]
Good luck.
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
------------------------------
Date: 8 Mar 2005 10:27:01 -0800
From: francescomoi@europe.com
Subject: How to view error messages within a function
Message-Id: <1110306421.075416.95410@g14g2000cwa.googlegroups.com>
Hi.
I'm trying to call a function:
----------------------
use DBI;
...
do my_function();
...
sub my_function()
{
...
my $q1 = $DB->prepare($sql1) or die ("Error");
...
}
--------------------
But this function's got an error and returns to the line where I call
'my_function', without being able to visualize the Error.
Is it possible to view the error message within the function?
Thank you very much.
------------------------------
Date: Tue, 08 Mar 2005 12:35:50 -0600
From: "J. Gleixner" <glex_nospam@qwest.invalid>
Subject: Re: How to view error messages within a function
Message-Id: <agmXd.26$UW6.1642@news.uswest.net>
francescomoi@europe.com wrote:
> Hi.
>
> I'm trying to call a function:
>
> ----------------------
> use DBI;
> ...
> do my_function();
Why 'do'??? my_function() will suffice.
> ...
>
> sub my_function()
You don't need () there either.
> {
> ...
> my $q1 = $DB->prepare($sql1) or die ("Error");
Don't need ()'s there either.
die "Error" is fine.
> ...
> }
> --------------------
>
> But this function's got an error and returns to the line where I call
> 'my_function', without being able to visualize the Error.
>
> Is it possible to view the error message within the function?
You can 'print' the error, or if you're in the debugger I suppose you
could view the error, regardless it's well documented.
perldoc DBI
Look for the prepare method.
Also, you might want to use RaiseError => 1. See documentation for what
it does.
------------------------------
Date: 8 Mar 2005 09:06:44 -0800
From: alythh@netscape.net (Alythh)
Subject: include external perl program
Message-Id: <6a25ba72.0503080906.11cad2f9@posting.google.com>
I need to use an input file to a main perl program.
Since I'm changing its shape often, and I'd like to add comments here
and there, I was thinking to giving it the shape of a perl program by
itself, like this:
# comment
# ...
$inputvar1=2;
# comment
$inputvar2=2;
...
and to include it some way in the main program.
Problem is, I don't know which command is used to <include> a file.
I heard about "use" and "require", but it seems to me that they're
mostly used for defining big libraries and/or OOprogramming, isnt it?
any hint?
thanks!
Alessandro Magni
------------------------------
Date: Tue, 08 Mar 2005 18:10:13 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: include external perl program
Message-Id: <Xns961385FB9E57Casu1cornelledu@127.0.0.1>
alythh@netscape.net (Alythh) wrote in news:6a25ba72.0503080906.11cad2f9
@posting.google.com:
> I need to use an input file to a main perl program.
> Since I'm changing its shape often, and I'd like to add comments here
> and there, I was thinking to giving it the shape of a perl program by
> itself, like this:
>
> # comment
> # ...
> $inputvar1=2;
> # comment
> $inputvar2=2;
> ...
The design choice depends on the purpose of this file. Is it used to
tune some configuration parameters? In that case, I myself would have
used a regular configuration file format rather than Perl code. There
are many modules on CPAN that deal with configuration files in various
formats. One particularly simple one is Config::Auto.
> and to include it some way in the main program.
> Problem is, I don't know which command is used to <include> a file.
perldoc -f do
perldoc -f require
perldoc -f use
> I heard about "use" and "require", but it seems to me that they're
> mostly used for defining big libraries and/or OOprogramming, isnt it?
A module need not be "big" or OO.
perldoc perlmod
Sinan.
------------------------------
Date: 8 Mar 2005 10:51:23 -0800
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: include external perl program
Message-Id: <1110307883.607504.57240@z14g2000cwz.googlegroups.com>
Alythh wrote:
>
> I was thinking to giving it the shape of a perl program
> by itself, like this:
>
> # comment
> # ...
> $inputvar1=2;
> # comment
> $inputvar2=2;
> ...
>
> and to include it some way in the main program.
Ciao, Alessandro!
If I understand you correctly, you want to be able to have a main
program file, and to be able to specify several variables in a separate
file.
If this is what you want, you can do so like this:
Create a file called "inputvars.pm" that looks like this:
====== START OF "inputvars.pm" =======
# This file is for defining input variables.
use strict;
use warnings;
# $inputvar1 is for ...
our $inputvar1 = 2;
# $inputvar2 is for ...
our $inputvar2 = 2;
1;
====== END OF "inputvars.pm" =======
Then create a main Perl program, like this:
====== START OF "script.pl" =======
#!/usr/bin/perl
use strict;
use warnings;
use inputvars;
our ($inputvar1, $inputvar2);
print "Value of \$inputvar1: $inputvar1\n";
print "Value of \$inputvar2: $inputvar2\n";
__END__
====== END OF "script.pl" =======
Then run script.pl with a command like:
perl script.pl
Ecco fatto! Now the values you defined in inputvars.pm show up in
script.pl !
If you use this approach, there are a few things you need to
remember:
1. DON'T name your module file "vars.pm" (because
there already is a module with that name).
2. The last line of your module file should always
end with the line:
1;
Not doing so may give you an error.
3. Declare any shared variables (variables whose values
are defined in one file and used in another) with
"our" (and not "my").
4. It is recommended that you always "use strict;" and
"use warnings;" in all your files. Doing so will
help you catch many errors that you didn't expect
to have.
Spero di averti aiutato, Alessandro.
-- Jean-Luc Romano
------------------------------
Date: Tue, 8 Mar 2005 13:52:45 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: perlpod/perldoc Q: I want asterisk bullets
Message-Id: <d0kand$f5q$1@reader1.panix.com>
I'm writing a POD page, and I want my itemized lists to use asterisks
for bullets, like this:
* first item
* second item
* etc., etc.
So I write my POD source like this:
=over
=item *
first item
=item *
second item
=item *
etc., etc.
=back
But, when I run perldoc on my POD file, what I see on the screen is
o first item
o second
o etc., etc.
What's really annoying is that all the other POD pages installed
on my system (e.g. perlpod.pod) use the exact same POD source code
(i.e. "=item *", etc.) as what I'm using, and yet when these other
pages are displayed, the lists have asterisks, not o's for bullets.
What's going on here?
TIA!
jill
--
To s&e^n]d me m~a}i]l r%e*m?o\v[e bit from my a|d)d:r{e:s]s.
------------------------------
Date: 08 Mar 2005 16:16:27 GMT
From: xhoster@gmail.com
Subject: Re: Q: Only put unique element in a HoL?
Message-Id: <20050308111627.350$02@newsreader.com>
mpe17@kth.se (Magnus) wrote:
> Hi!
>
> How do I only put unique element into a HoL? I do not want to add
> $element into HoL if it is already there.
If it is already where?
Maybe you want a HoH rather than a HoL.
> push @{ $HoL{$hashkey} }, $element;
$HoL{$hashkey}{$element}=();
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 8 Mar 2005 07:16:15 -0800
From: jimnl69@hotmail.com
Subject: Strange tar behavior with Net::Telnet
Message-Id: <1110294975.912179.143170@g14g2000cwa.googlegroups.com>
I'm having a strange problem I can't figure out. I have a tar file
(sent through gzip) that contains the file
/etc/sysconfig/static-routes, amoung many others. If I telnet to my
Linux box and su to root and untar this file, all the files extract
properly. However, if I telnet to the box via a perl script and have
the script su to root and run the exact same command, the other 30
files extract fine but /etc/sysconfig/static-routes always comes out as
a 0 byte file. I can then manually telnet to the box and extract the
tar file and everything is fine. Any ideas on why my perl script that
is performing the exact same commands fails to properly extract ONLY
this particular file?
*My script exits if it can't su to root so it's not extracting at a
lower level.
*I created the file with tar -czf.
*I'm extracting the file with tar -xzf.
*I've tried using the -i -p nad -U flags just for grins and no help.
------------------------------
Date: 8 Mar 2005 06:42:35 -0800
From: "webvoip" <edwin@webvoip.com>
Subject: Text::Template Question
Message-Id: <1110292955.944707.34930@l41g2000cwc.googlegroups.com>
EHLO,
I'm toying around with Text::Template and have a question for anyone
who may know this out there...
I have a template that has the following code:
<table>
<tr><td colspan="100%">Edwin's Test Table</td></tr>
{
my $sth = $dbh->prepare("select * from t");
$sth->execute;
while (my $h = $sth->fetchrow_hashref)
{
print " <tr><td>$h->{id}</td><td>$h->{stuff}</td></tr>\n";
}
}
</table>
And my calling application exports the $dbh handle via the package
option using fill_in:
$PackageName::dbh =
DBI->connect("DBI:mysql:database=test;host=test1", "username",
"password") || die($!);;
my $t = Text::Template->new(TYPE => 'FILE', SOURCE =>
'../templ/t.tmpl') or die ($Text::Template::Error);
my $text = $t->fill_in(PACKAGE => 'PackageName');
print $text;
It works... somewhat... The problem i am having is that the print order
is wrong. Is there some pre-processing or other simple option i am
missing?
Here's what prints out (notice the table rows print first):
<tr><td>1</td><td>one</td></tr>
<tr><td>2</td><td>two</td></tr>
<tr><td>3</td><td>three</td></tr>
<tr><td>4</td><td>four</td></tr>
<tr><td>5</td><td>five</td></tr>
<html>
<body bgcolor="#ffffff" text="#000000">
<table>
<tr><td colspan="100%">Edwin's Test Table</td></tr>
<!-- table rows should be here -->
</table>
</body>
</html>
Thanks and apologies if i posted this to the wrong newsgroup.
-Edwin
------------------------------
Date: Tue, 08 Mar 2005 14:50:46 GMT
From: Jim Keenan <jkeen_via_google@yahoo.com>
Subject: Re: Text::Template Question
Message-Id: <aZiXd.92211$g16.78355@trndny08>
webvoip wrote:
> EHLO,
>
> I'm toying around with Text::Template and have a question for anyone
> who may know this out there...
>
> I have a template that has the following code:
>
> <table>
> <tr><td colspan="100%">Edwin's Test Table</td></tr>
> {
> my $sth = $dbh->prepare("select * from t");
>
> $sth->execute;
>
> while (my $h = $sth->fetchrow_hashref)
> {
> print " <tr><td>$h->{id}</td><td>$h->{stuff}</td></tr>\n";
> }
> }
> </table>
>
A preliminary question: Have you verified that, independently of
Text::Template, your program prints what you expect as of this point?
(I.e., let's make sure we have clearly sorted out DBI problems from
Text::Template problems.)
Jim Keenan
------------------------------
Date: 8 Mar 2005 07:02:30 -0800
From: "webvoip" <edwin@webvoip.com>
Subject: Re: Text::Template Question
Message-Id: <1110294150.427680.184270@g14g2000cwa.googlegroups.com>
Hi Jim,
The values in the table rows do correctly mirror the data in the
database table. I am of the opinion DBI is doing its job correctly. I
think the problem lies in my Text::Template implementation.
Reading the docs, I see Text::Template scans in the template first, and
interpolates any perl code. I am guessing it is during this phase that
it is expanding my print statements and this is what is causing them to
print before the calling application calls: "print $text";
i guess the table rows are not stored in the $text variable because
they are just print statements in the template.
?,
Edwin
------------------------------
Date: Tue, 8 Mar 2005 19:55:51 +0100
From: Fabian Pilkowski <pilkowsk@informatik.uni-marburg.de>
Subject: Re: Text::Template Question
Message-Id: <MPG.1c98139ddc3c01999898c2@news.individual.de>
* webvoip wrote:
>
> I'm toying around with Text::Template and have a question for anyone
> who may know this out there...
>
> I have a template that has the following code:
>
> <table>
> <tr><td colspan="100%">Edwin's Test Table</td></tr>
> {
> my $sth = $dbh->prepare("select * from t");
> $sth->execute;
> while (my $h = $sth->fetchrow_hashref) {
> print " <tr><td>$h->{id}</td><td>$h->{stuff}</td></tr>\n";
> }
> }
> </table>
Please read this modules docs before asking here. Text::Template will
print the returning value of each code block. As described, you can also
try to use the special variable called $OUT (this is what i would do).
{
my $sth = $dbh->prepare("select * from t");
$sth->execute;
while ( my $h = $sth->fetchrow_hashref ) {
$OUT .= "<tr><td>$h->{id}</td><td>$h->{stuff}</td></tr>\n";
}
}
Please read the docs e.g. at
http://search.cpan.org/~mjd/Text-Template-1.44/lib/Text/Template.pm
and learn why not using prints in your template's code blocks.
regards,
fabian
------------------------------
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:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#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 V10 Issue 7866
***************************************