[21732] in Perl-Users-Digest
Perl-Users Digest, Issue: 3936 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 8 18:11:00 2002
Date: Tue, 8 Oct 2002 15:10:18 -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, 8 Oct 2002 Volume: 10 Number: 3936
Today's topics:
Perl program sending email to database (Mike)
perl user interface to tar. <dmehler@siscom.net>
Re: Problem with SIG handling on WinNT <goldbb2@earthlink.net>
Re: Problem with SIG handling on WinNT <flavell@mail.cern.ch>
Re: question about speeding perl development (trwww)
Re: question about speeding perl development <goldbb2@earthlink.net>
Read Text Widget into Array (PERL TK) (Miguel)
Re: Read Text Widget into Array (PERL TK) <nibl@onlinehome.de>
Redirecting MS-DOS apps <hal@thresholddigital.com>
Re: Redirecting MS-DOS apps (Malcolm Dew-Jones)
Regexp: Extracting HTML img src <nibl@onlinehome.de>
Re: shell/perl question: how processes get invoked? <goldbb2@earthlink.net>
Slow SCript Execution <carriera@nortelnetworks.com>
Re: Split a string <krahnj@acm.org>
Re: synonymous subroutines <johannes.fuernkranz@t-online.de>
Re: synonymous subroutines <goldbb2@earthlink.net>
Re: synonymous subroutines <bart.lateur@pandora.be>
TM:2 DBI questions (Tavish Muldoon)
Re: TM:2 DBI questions <jeff@vpservices.com>
Re: udp <goldbb2@earthlink.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 8 Oct 2002 14:55:53 -0700
From: csdude@hotmail.com (Mike)
Subject: Perl program sending email to database
Message-Id: <46cdc619.0210081355.377c8561@posting.google.com>
Hey,
I'm wanting to write a program that will let any user register for a
free email address (username@mydomain.com), then send and receive
email. My site is on a remote host, so I only have 5 POP accounts,
which means that most of the programs I've seen won't work for me
since they require a different POP for each user*.
Sending the email is no sweat; I've used Sendmail enough on contact
forms and such that it's pretty much going to be the same thing. But
I've never had to write a program that would receive emails before,
and I'm not sure how to proceed. I saw a module Net::SMTP::Receive
(http://search.cpan.org/author/MUIR/Net-SMTP-Receive-0.2/Receive.pod),
and from what I can tell it would let me receive emails, but I'm not
sure what it does with the emails once it receives them, and I hate to
ask my host to install the module if it's not what I need.
Does anyone know if this module is doing what I'm wanting? If not, is
there a different one I should use? I searched through CPAN, but
didn't see anything that looked even close. In my dream world, I would
simply create a directory (something like /var/mail/username) with
their login info, then any emails sent to that directory would be
saved there as a text file (something like
/var/mail/username/inbox/1.txt). Am I dreaming a little too much?
To be honest, I only have about 15 users, so this is more of a
learning experience for me than anything else. The only experience
I've had with modules has been with Email::Verify and simple things
like that, so I really don't know what to expect.
TIA,
Mike
* Although my host only gives me 5 POP accounts, I can set up
unlimited redirects. For instance, I add a line to my .redirect file
that says something like "username realaddress@theirdomain.com" and
anything sent to username@mydomain.com is redirected to
realaddress@theirdomain.com. I'm thinking it would be cool if I could
just change that line to "username /var/mail/username," then any
emails sent to username@mydomain.com would be saved in the directory
/var/mail/username. My own little dream world, I guess, but any
thoughts?
------------------------------
Date: Tue, 8 Oct 2002 16:48:28 -0400
From: "dave" <dmehler@siscom.net>
Subject: perl user interface to tar.
Message-Id: <3da3467d$0$38592$9a6e19ea@news.newshosting.com>
Hello,
Does anyone have a perl UI to the unix tar program? I'm looking for
something that implements identical functionality to the dump/restore UI but
in perl and for tar and optionally gzip.
Thanks.
Dave.
------------------------------
Date: Tue, 08 Oct 2002 14:32:59 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Problem with SIG handling on WinNT
Message-Id: <3DA324DB.E8BBCC16@earthlink.net>
Nan Wang wrote:
>
> Hi all:
>
> I'm trying to write a script to catch SIG{INT}, the script is as
> follows:
>
> use strict;
>
> $SIG{INT}=\&handler;
>
> for (;;) {
> }
>
> sub handler {
> my $sig=shift;
> print "Caught SIG$sig\n";
> exit 0;
> }
>
> When I ran this and press ctrl-c, I got the "Caught SIGINT" message,
> but also an messagebox saying, "The exception unknown software
> exception (0xc0000029) occurred in the application at location
> 0x77f893e6." And I get the choice to terminate it or debug it.
When the perl interpreter exits, it tries to clean up it's data. When
you call exit from within a signal handler, the perl interpreter is in
an undefined state. Your best bet is to set a flag and then return from
the signal handler (and *not* call exit()) -- even printing may be
dangerous, depending on how your system's C runtime is designed.
my $interrupted = 0;
$SIG{INT} = sub {
syswrite(STDOUT, "Caught SIG");
my ($sig) = @_;
syswrite(STDOUT, $sig);
syswrite(STDOUT, ".\n");
$interrupted = 1;
};
until( $interrupted ) {
}
__END__
[tested, seems to work.]
> I'm using ActivePerl 5.6.1, build 633, on a Windows NT box.
>
> Has anyone seen anything like this?
Yes, I'm on the same system -- exit() or die() from within a $SIG{INT}
handler seems to always fail.
perl -e "$SIG{INT} = sub { exit }; sleep;"
pressing control-C causes a popup window as you described to appear.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Tue, 8 Oct 2002 21:14:03 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Problem with SIG handling on WinNT
Message-Id: <Pine.LNX.4.40.0210082106140.19301-100000@lxplus072.cern.ch>
On Oct 8, Benjamin Goldberg inscribed on the eternal scroll:
> Yes, I'm on the same system -- exit() or die() from within a $SIG{INT}
> handler seems to always fail.
My apologies - I carelessly used the same word, "exit", as was used in
the FAQ answer - my mental picture was of exiting from the subroutine,
i.e returning, but of course when one says "exit", it's obvious that
the reader will think of exit()
Maybe an issue for the wording of the FAQ, then?
------------------------------
Date: 8 Oct 2002 11:39:31 -0700
From: toddrw69@excite.com (trwww)
Subject: Re: question about speeding perl development
Message-Id: <d81ecffa.0210081039.610de474@posting.google.com>
"Hmmm..." <blahblahblah@blah.com> wrote in message news:<St_m9.6638$lV3.655189@newsread1.prod.itd.earthlink.net>...
> I have worked on projects that use perl to access sybase databases, and to
> generate html to display the data. This is in a Sun/Solaris environment.
>
> Does anyone know of a development tool that would accelerate the creation of
> html screen layouts, automatically produce the perl that would display the
> screens, and perhaps have some support for linking database fields to screen
> fields?
A good programmer =0). Seriously, are you looking for a product like
drumbeat or something? Theres nothing generic I know of off hand
written in perl.
You might want to think of your implementation.
I like a mod_perl + perl XML suite for web apps.
I have sucessfully drawn distinct lines between logic | content |
presentation
Logic is handled in modules that depend on the requested filename.
Data is stored in a request object or session object, depending on the
necessity of the information's life.
Content is held in the requested filename as an xml document that has
user, session, and request specific dynamic data appended to it during
a trip through a SAX stream with the help of XML::SAX::Machines and
XML::SAX::Base. Most of it is a dumb filter, blindly dumping the data
in the objects mentioned above into XML format. Theres a hook to
insert per request handlers, that may execute code depending on the
content of the XML document.
The presentation is seperated from the other layers by a template file
that is (often) modified by an XSLT processor, which generates a
template valid for use with HTML::Template::XPath.
At this point the three come together when the (partially) dynamically
generated XML document data is massaged into the template document,
and sent to the user. The visual presentation is determined by
Cascading Stylesheets at the browser.
This makes things like proper language negoation or template selection
(my user may be logged on to thier PDA) nonplussed. I dont even have
to think about it. Also, programmers and web page developers dont even
have to meet, let alone speak to eachother.
All of this is possible in any language, but perl makes it VERY easy.
VERY, VERY easy.
After writing all this, I do believe if you look at AxKit
(http://www.axkit.org/), with XForms, tagLibs, and stuff it may do
everything you asked for in your OP. I may be switching to it soon, as
I built the above just to see how I could tie mod_perl and XML
together starting with a blank notepad screen.
mod_perl definitely speeds perl development (and execution time)
because it enforces - instestead of simply promoting - code reuse.
Writing a subroutine is no longer just a function definition or
class/object method, its an extension to your web server. If you need
a function or method... just call it. It lives in the same mod_perl
process that the currently executing code lives in, so it will always
be there.
> Thanks.
No problem!
Todd W.
------------------------------
Date: Tue, 08 Oct 2002 15:41:30 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: question about speeding perl development
Message-Id: <3DA334EA.93910E4D@earthlink.net>
Hmmm... wrote:
>
> I have worked on projects that use perl to access sybase databases,
> and to generate html to display the data. This is in a Sun/Solaris
> environment.
>
> Does anyone know of a development tool that would accelerate the
> creation of html screen layouts, automatically produce the perl that
> would display the screens, and perhaps have some support for linking
> database fields to screen fields?
You might want to consider some sort of html templating kit, to allow
you to hand off the html generation to a web designer, so that you can
manage the innards of the real programming (database stuff, etc)
yourself.
http://search.cpan.org/search?query=template+toolkit
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: 8 Oct 2002 13:08:31 -0700
From: m_dv@hotmail.com (Miguel)
Subject: Read Text Widget into Array (PERL TK)
Message-Id: <120db37b.0210081208.1796ca24@posting.google.com>
Hello Everyone,
First of all, I tried posting this thread in comp.lang.perl.tk
twice, but it did not work. My last resort was to post it here, I
apologize if it's on the wrong place for any reason. Anyways with that
said, here is the question.
I'm sure this question has been asked before, however I could
not find much related to this subject under archives. Anyways, the
problem is that I'm trying to read all the input lines from a text
widget into an array. So far this is what I have been trying "@array =
$textbox->get(1.0, end);"
It failed. I don't know what else to think about. Any help will be
much appreciated. Thank You.
PS. Here is the actual code.
$frm_body = $mw->Frame() ->pack( -padx => 10, -pady => 5, -side =>
right);
$txt = $frm_body->Text( -width => 60, -height => 23)->pack;
@input_body = $txt->get("1.0", "end"); # IT DOES NOT WORK.
-Miguel Daniel <m_dv@hotmail.com>
------------------------------
Date: Tue, 08 Oct 2002 22:18:34 +0200
From: nibl <nibl@onlinehome.de>
Subject: Re: Read Text Widget into Array (PERL TK)
Message-Id: <o8f6qu811smoha08fnvevu2pqs7qkmvhbt@4ax.com>
On 8 Oct 2002 13:08:31 -0700, m_dv@hotmail.com (Miguel) wrote:
> First of all, I tried posting this thread in comp.lang.perl.tk
>twice, but it did not work.
The Perl/Tk mailing list is a good place to join. Google will find it.
The main authors are present on that list too.
nibl
------------------------------
Date: Tue, 08 Oct 2002 19:14:38 GMT
From: Hal Vaughan <hal@thresholddigital.com>
Subject: Redirecting MS-DOS apps
Message-Id: <y8Go9.14655$ST4.29229@rwcrnsc53>
I don't know if this is even possible under Perl, but I haven't done any
programming in over 10 years until I had to start using Perl recently.
I have a old client who is using a DOS application (I've been trying to get
him to upgrade since '99) on Windows ME. The application does work in the
DOS mode, but there are some problems with output.
Is there any way I can use a Perl wrapper to run this program (it's a binary
.exe file) and redirect or intercept the output to the printer so I can
have the Perl wrapper intercept the data before it goes to the printer,
modify and filter the data, then send the result to the printer instead?
The printer is a Lexmark -- I forgot the model number, but it's using HP
Deskjet control codes and prints text okay -- I just want to intercept the
text and be able to look for certain strings and replace them with control
codes.
Thanks for any info or pointers to sites that discuss this (I've alredy been
searching on Google...).
Hal
------------------------------
Date: 8 Oct 2002 14:29:21 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Redirecting MS-DOS apps
Message-Id: <3da34e31@news.victoria.tc.ca>
Hal Vaughan (hal@thresholddigital.com) wrote:
: I don't know if this is even possible under Perl, but I haven't done any
: programming in over 10 years until I had to start using Perl recently.
: I have a old client who is using a DOS application (I've been trying to get
: him to upgrade since '99) on Windows ME. The application does work in the
: DOS mode, but there are some problems with output.
: Is there any way I can use a Perl wrapper to run this program (it's a binary
: .exe file) and redirect or intercept the output to the printer so I can
: have the Perl wrapper intercept the data before it goes to the printer,
: modify and filter the data, then send the result to the printer instead?
: The printer is a Lexmark -- I forgot the model number, but it's using HP
: Deskjet control codes and prints text okay -- I just want to intercept the
: text and be able to look for certain strings and replace them with control
: codes.
: Thanks for any info or pointers to sites that discuss this (I've alredy been
: searching on Google...).
: Hal
--
Most likely, the DOS application will be printing to the printer port.
The windows printer "intercepts" or "captures" that port and sends it to
the printer.
You can probably modify how that works either via the printer's control
utility or by getting a dos tsr/utility that does this. ( There used to
be various DOS utilities that did this.)
So a "perl" solution would be
1 - configure the DOS printer setups to capture the DOS print
output into a file (using either the printers window utility or a
DOS tsr/utility).
2 - run your program
3 - modify the output file (the output was created in step 2 and
saved in the file configured in step 1)
4 - (perhaps) uncapture the printer port
5 - send the modified data to the printer port.
You could do this using perl in the sense that perl calls system() to run
the first commands (steps 1 and 2) and then modifies the data (that step's
pure perl), and then prints the modified file from within perl in ways
other people have discussed in the past.
------------------------------
Date: Tue, 08 Oct 2002 22:02:34 +0200
From: nibl <nibl@onlinehome.de>
Subject: Regexp: Extracting HTML img src
Message-Id: <u4e6qu0jjofdjn5iasth4pu71j74c6b34u@4ax.com>
I could use some help with this regexp. I'm extracting HTML image
tags. It only gets the last image on each line. Hence, if all are on
one line then only one is returned:
$output = qq{dadasa<IMG SRC="path1"><IMG ALIGN="LEFT"
SRC="path2">asdasds
<IMG ALIGN="LEFT" SRC="path3">
};
my (@images) = ($output =~ m#.*<img\s+.*src="(.*)">.*#gi);
I know I could use HTML or XML::Parser, but that's a lot of bulk just
for this.
Thanks,
nibl
------------------------------
Date: Tue, 08 Oct 2002 16:45:16 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: shell/perl question: how processes get invoked?
Message-Id: <3DA343DC.D87E818C@earthlink.net>
V. Sanath D. Jayasena wrote:
[snip]
> I appreciate expert views on this. I want to run a program
> (an executable, say, "xyz") repeatedly (a different input file
> each time) for experiments. I tried using a Perl script to do
> the looping but due to some reason, a single "xyz" session
> cannot seem to handle it after a few iterations.
Show us the code you had which tried to do this, and we can help you fix
it.
[snip]
> #!/local/all/perl
> #
> # run-xyz.pl
> #
> $INFILE = $ARGV[0];
> open(XYZ,"|xyz") || die "Can't start xyz\n" ;
> printf XYZ "read_dat $INFILE; ";
> # process data here by giving more commands to XYZ
> # each command terminated by ";"
> printf XYZ "write_dat $INFILE.result ; " ;
> printf XYZ "quit; ";
Looking at the code you have for running the program once, I would
suggest something like the following:
#!/local/all/perl -w
$SIG{PIPE} = 'IGNORE';
foreach my $filename (glob "*.dat") {
open( my($xyz), "|-", "xyz" )
or die "Can't start xyz: $!";
local $\ = ";";
print $xyz $_ foreach(
"read_dat $filename",
"write_dat $filename.results",
"quit");
}
__END__
[untested]
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Tue, 8 Oct 2002 15:57:54 -0500
From: "Al C" <carriera@nortelnetworks.com>
Subject: Slow SCript Execution
Message-Id: <anvgti$2tb$1@bcarh8ab.ca.nortel.com>
I've got a script that strips and formats sniffer files. I've noticed that
on long files the script gets slower and slower as it goes deeper into the
file. Can someone explain this to me?
thanks, Al.
------------------------------
Date: Tue, 08 Oct 2002 19:24:14 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Split a string
Message-Id: <3DA330CA.FFCB17CD@acm.org>
Al wrote:
>
> some thing like this .............sorry probably a long way of doing it but
> it might help you
> ----------------------------------------------------------------------------
> -------------------------------------
> #!/usr/bin/perl -w
No strictures.
> $string="abcdefgdlfsdlfdslkfjdslfjds1234567890\n9847598475947598347";
>
> if($string=~/(\w+)\n/){
^^^^^
What if (as in the OP's example) there is whitespace in the string?
> spliter($1);
> spliter($');
> }else{
> spliter($string);
> }
>
> sub spliter{
> $true=1;
> $strg=$_[0];
> if(length($strg)>5){
> $entry=substr($strg,0,5);
> $rem=substr($strg,6,);
> push @list, $entry;
> }else{
> push @list, $strg;
> }
> while ($true){
> if(length($rem)>5){
> $entry=substr($rem,0,5);
> $rem=substr($rem,6,);
> push @list, $entry;
> }else{
> push @list, $rem;
> undef $true;
> }
> }
>
> }
>
> while(<@list>){
^^^^^^^
Why are you using a file glob to iterate over the array? If there are
any special glob characters in the data this will return unexpected
results.
> print "$_\n";
> }
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 08 Oct 2002 20:30:41 +0200
From: Johannes Fürnkranz <johannes.fuernkranz@t-online.de>
Subject: Re: synonymous subroutines
Message-Id: <anv8bu$cm6$01$1@news.t-online.com>
Tassilo v. Parseval wrote:
>
>>What would be the correct way of doing that?
>
>
> *b = \&a;
Wow. That makes me scratch my head.
And after that I'll re-read the typeglob section. :-)
Thanks!
Juffi
------------------------------
Date: Tue, 08 Oct 2002 15:22:00 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: synonymous subroutines
Message-Id: <3DA33058.DACC0AB5@earthlink.net>
Johannes Fürnkranz wrote:
>
> Tassilo v. Parseval wrote:
> >
> >>What would be the correct way of doing that?
> >
> >
> > *b = \&a;
>
> Wow. That makes me scratch my head.
I'm not surprised at your head-scratching. :)
*Any* time a typeglob is used, something slightly magical happens.
*Always*.
When you use a typeglob as the left hand side of an assignment, and the
thing on the right a reference to something other than a typeglob, then,
the thing on the right gets placed in the appropriate slot of the thing
on the left.
When you do:
*a = \&b;
It takes the coderef, \&b, and stores it into the CODE slot of the *a
typeglob. Almost as if you had done:
*a{CODE} = \&b;
or:
*a{CODE} = *b{CODE};
[neither of which work in actuality... they're psuedoperl]
When you assign a ref to a typeglob to a typeglob, then it acts as if
you'd done an assignment of all the parts of the right, to the one on
the left. That is:
*a = \*b;
is vaguely like:
*a{SCALAR} = \$b;
*a{HASH} = \%b;
*a{CODE} = \&b;
etc.
[vaguely... the semantics are a bit stranger than that, but we don't
need to go into that]. If you assign a typeglob to a typeglob, eg:
*a = *b;
Then it acts the same. If you assign a non-ref to a typeglob, it does a
symbolic reference... that is:
*a = "foo";
is like:
*a = *{"foo"};
Note that a typeglob in non left-side-of-assignment context is also a
rather strange, magical thingy. Consider when you do:
$x = *a;
What now is in $x? It's a typeglob... not a *ref* to a typeglob...
well, sorta... it's what's known as a "fakeglob". What happens if you
print out \$x? Under *normal* circumstances (ignoring blessings), you'd
get something like SCALAR(0xdeadbeef). But now, with a glob in $x, you
get GLOB(0x12345678) when you print \$x. Strange, no?
> And after that I'll re-read the typeglob section. :-)
I really wish that there were documents, "perldoc perltypeglob" and
"perldoc perlsymboltable", describing *typeglobs and %symbol::tables::
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Tue, 08 Oct 2002 19:47:37 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: synonymous subroutines
Message-Id: <8cc6qucp7bg6pcli9tgf16qhnaseodsf15@4ax.com>
Johannes Fürnkranz wrote:
>Tassilo v. Parseval wrote:
> >
>>>What would be the correct way of doing that?
>>
>>
>> *b = \&a;
>
>Wow. That makes me scratch my head.
>And after that I'll re-read the typeglob section. :-)
It is mind-bending. It's typeglob magic.
IIRC there's another way as well, using, er, attributes? I'm not sure
baout the name, but the syntax is something like
*foo{CODE}
I found some text around this at
<http://www.perlmonth.com/perlmonth/issue10/cws.html>
The official description is in perlref, point 7 under "Making
References".
But the eventual syntax is no better or less than the one we started
with:
*b = *a{CODE};
It does work, though.
--
Bart.
------------------------------
Date: 8 Oct 2002 12:17:25 -0700
From: tmuldoon@spliced.com (Tavish Muldoon)
Subject: TM:2 DBI questions
Message-Id: <e2470f35.0210081117.25cafce4@posting.google.com>
Hello,
1) Is there a method to get the field name and corresponding field
data from a database - or do you have to manually insert the field
names.
i.e.
43 $sth=$dbh->prepare("select * from people where name=?");
44 $sth->execute($name);
45 my @ar = $sth->fetchrow_array();
46 foreach $ar (@ar) {
47 print "$ar \n";
48 }
49 $sth->finish;
When I do a simple select from a large table it just gives the field
data only
name doug
last mitchell
phone 1234567
address house
colour blue
But if I do a select like this in perl - I just get:
doug
mitchell
1234567
house
blue
Anyway to get the field name with the field data. I would like to
grab this info from many table reusing the code - and some table have
100 field names....
2) I also get Use of uninitialized value at /test/getform.cgi line 47
I think some of the fields in this table are blank. Do I need to put
code to check $ar to see if it is blank or is there some better way to
handle blank/NULL data?
Thanks,
Tmuld.
------------------------------
Date: Tue, 08 Oct 2002 12:37:02 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: TM:2 DBI questions
Message-Id: <3DA333DE.3080901@vpservices.com>
Hi,
[just a personal peeve, but I find the TM: in your subject lines
distracting since it is only relevant to you]
> 1) Is there a method to get the field name and corresponding field
> data from a database - or do you have to manually insert the field
> names.
my $sth = $dbh->prepare($query);
$sth->execute(@params);
my @col_names = @{ $sth->{NAME} };
while( my $row = $sth->fetchrow_hashref ) {
for my $col_name( @col_names ) {
my $val = $row->{$col_name};
$val = '' unless defined $val;
print "$col : $val\n";
}
}
> 49 $sth->finish;
You should only use finish() if your fetch is interrupted, not when it
completes normally.
> 2) I also get Use of uninitialized value at /test/getform.cgi line 47
>
> I think some of the fields in this table are blank. Do I need to put
> code to check $ar to see if it is blank or is there some better way to
> handle blank/NULL data?
Notice that in the code above the line about "unless defined $val". If
the value is NULL it will be undefined and throw an error, you need to
set it to an emptry string. If you want to do that on an entire row you
can use something like this:
my @row = map { defined $_ ? $_ : '' } @row;
--
Jeff
------------------------------
Date: Tue, 08 Oct 2002 16:16:07 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: udp
Message-Id: <3DA33D07.B73A6C03@earthlink.net>
deita wrote:
>
> Hello,
>
> here is one problem i am trying to solve.
> application1 creates udp server and reads messages from it,
> also it creates udp client socket and every 5 sec sends message.
> application2 is a copy of app1 with only swapped server and client
> socket ports.
>
> executing theese two apps within interval 5 sec both applications
> exchanges messages successfuly. execing them with a little larger
> timeout, the first one does not send messages to the second.
>
> so, i need to send messages to server whenever, even the server does
> not exist.
>
> here is my code:
Your posted code only shows recieving data, not sending.
Show your real code, and what you want it to do, and perhaps we can
help.
Furthermore, you have a busy loop that's stopped by an alarm. That's
wasteful and resource-innefficient.
Remove the alarm code, and change the loop stuff to:
my $timeout = 5;
my $svec = pack("b*", "0" x fileno($server) . "1" );
while (1) {
my $rvec = $svec;
(my ($n_ok), $timeout) = select( $rvec, '', '', $timeout );
if( !defined($n_ok) or $n_ok < 0 ) {
die "ERROR calling select: $!";
} elsif( $n_ok == 0 ) {
print "time out\n";
last;
} else {
$server->recv($data, 1024);
print "received: $data";
}
}
[untested]
For some strange reason, select returns -1 instead of undef when it's
passed an illegal argument... I'm not sure why.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
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.
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 3936
***************************************