[17738] in Perl-Users-Digest
Perl-Users Digest, Issue: 5158 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 20 11:05:33 2000
Date: Wed, 20 Dec 2000 08:05:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <977328312-v9-i5158@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 20 Dec 2000 Volume: 9 Number: 5158
Today's topics:
Re: Alternating Prints from Two Files (Anno Siegel)
ANNOUNCE: Text::Iconv 1.1 <mxp@dynalabs.de>
Re: File::Find - meaning of 'symlinks'? <timallen449@coldmail.com>
Re: File::Find - meaning of 'symlinks'? <timallen449@coldmail.com>
Re: File::Find - meaning of 'symlinks'? (Helgi Briem)
Re: Free servers with Perl support? <bart.lateur@skynet.be>
get the version of a Windows DLL <ralf.peine@bch.siemens.de>
Help with PERLCC! Somebody pleaze ... <richly@mpiz-koeln.mpg.de>
Re: Home Directory <iltzu@sci.invalid>
Re: How can I access the checkbox value of a form in Pe <somewhere@planet.earth>
Re: how to invalidate a hash value during a foreach loo <info@jjmackay.ca>
Re: how to invalidate a hash value during a foreach loo (Garry Williams)
Re: how to invalidate a hash value during a foreach loo (Tad McClellan)
Mail::Sendmail and HTML-messages <fb@geo-guide.com>
Re: Mail::Sendmail and HTML-messages <alian@alianwerbserver.com>
MailTools-1.15 <carlo@netverk.net>
Re: No embeding please! <jhelman@wsb.com>
Re: No embeding please! (Tad McClellan)
Re: No embeding please! <alex@hoopsie2.com>
Re: overriding 'print' (Anno Siegel)
Re: overriding 'print' (Tom Christiansen)
Re: perl DBI (Randal L. Schwartz)
Ping CGI Script <ben.turner@e-inbusiness.co.uk>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 20 Dec 2000 13:51:45 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Alternating Prints from Two Files
Message-Id: <91qdhh$mh1$1@lublin.zrz.tu-berlin.de>
Justin McNutt <mcnuttj@nin.iats.missouri.edu> wrote in comp.lang.perl.misc:
>>> while ( <HEAD> ) { # run all lines of HEAD through $_
>>> last if eof TAIL; # ...unless TAIL runs out of data
>>> chomp; # we don't want a newline in the middle, it's
>> confusing
>>> $_ .= <TAIL>; # append line from tail. keep final newline
>>> print; # output the line
>>> }
>
>> If I get a moment today, I'll see what I can do with that. However, one
>> thing I don't want is to stop the copying if one or the other file runs out
>> of lines. It's perfectly normal for them to have different numbers of lines,
>> and all the information needs to be recovered. As I think of it, it's as
>> though the two files were both printed out onto tracing paper and the
>> desired result is the transparent superposition of everything they contain.
>> They have been spliced apart so that they are negatives of eachother, with
>> no two elements ever occupying the same line-column position on both.
>
>Okay, so perhaps something like this:
>
>while ( 1 ) {
> last if ((eof FIRST) && (eof SECOND));
> $line = <FIRST>;
> chomp $line;
> $line .= <SECOND>;
> print OUT $line;
>}
>
>That should stop only after you've hit the end of *both* files.
Yes, though this will move lines from the second file into the first
column if the first file is shorter, which is probably still not
exactly the desired behavior. Below I have appended a complete
script that does column formatting from any number of files.
Anno
----------------------------------------------------------------------
#!/usr/bin/perl
use strict; use warnings; $| = 1;
use Getopt::Std;
# Deal with user input
my ( $default_w, $default_s) = ( 25, ' ');
my %opt = ( w => $default_w, s => $default_s);
getopts( 'w:s:h', \%opt);
my $width = $opt{ w}; # width of each column
my $sep = $opt{ s}; # separator string between columns
if ( $opt{ h} or @ARGV == 0 ) {
warn <<EOT;
Usage: $0 [ -w width -s sep] file...
Print files in columns of width characters with sep blanks between columns.
Default width is $default_w characters with a separator '$default_s'.
EOT
exit;
}
my @handles = map open_read( $_), @ARGV;
die "$0: No files to read\n" unless @handles;
# Build format string for sprintf for the number of handles we got
my $fmt = "%-$width.${width}s"; # print string in field of $width chars
$fmt = join $sep, ( $fmt ) x @handles; # combine with separator
# Combine lines for output
while ( my @in = read_cols( @handles) ) {
my $line = sprintf $fmt, @in;
$line =~ s/\s+$//; # trim trailing blanks
print "$line\n";
}
#######################################################################
# Open a file for reading, warn on failure, return handle or ()
sub open_read {
my $file = shift;
my $handle;
if ( open $handle, $file) {
return $handle;
} else {
warn "Skipping $file: $!\n";
return;
}
}
# Get columns from so many filehandles. return () if all at eof.
sub read_cols {
my $any;
my @cols = map scalar <$_>, @_;
return unless grep defined, @cols; # signal all done
$_ ||= '' for @cols; # replace undef's
chomp @cols;
@cols;
}
__END__
------------------------------
Date: Wed, 20 Dec 2000 13:46:57 -0000
From: Michael Piotrowski <mxp@dynalabs.de>
Subject: ANNOUNCE: Text::Iconv 1.1
Message-Id: <t41e2h8gb9t081@corp.supernews.com>
I've just uploaded a new version of the Text::Iconv module to CPAN.
The main changes are:
- Works with Perl 5.6
- Improved and expanded test script
- Fixes core dumps with aborted conversions
- Adds experimental class attribute/method raise_error
When it has migrated to its final destination, you should be able to
find it via
<http://search.cpan.org/search?dist=Text-Iconv-1.1>
It's also immediately available from
<http://www.dynalabs.de/mxp/perl/Text-Iconv-1.1.tar.gz>
<ftp://ftp.linguistik.uni-erlangen.de/pub/perl/Text-Iconv-1.1.tar.gz>
Here's an excerpt from the README:
This module provides a Perl interface to the iconv() codeset
conversion function, as defined by the Single UNIX Specification.
For more details see the POD documentation embedded in the file
Iconv.pm.
In other words (and if you aren't into terminology), this module lets
you convert text from one character set into another character set
using the iconv library, which is very likely to be already installed
on your system (if it's a UNIX or UNIX-like system). You can also use
this module with a separate iconv implementation, such as Bruno
Haible's (see <http://clisp.cons.org/~haible/packages-libiconv.html>).
--
Michael Piotrowski, M.A. <mxp@dynalabs.de>
------------------------------
Date: Wed, 20 Dec 2000 12:19:47 +0100
From: "tim allen" <timallen449@coldmail.com>
Subject: Re: File::Find - meaning of 'symlinks'?
Message-Id: <91q407$adn$1@diana.bcn.ttd.net>
"Philip Lees" <pjlees@ics.forthcomingevents.gr> wrote in message
news:3a40688a.64867214@news.grnet.gr...
>Is that why my text search algorithm works fine on the HD but can't
>find anything on a CD-ROM?
>(Windows NT, I'm afraid)
Hi Philip,
I'm pretty sure this isn't a problem in NT. Try this code:
# modified from page 891, Programming Perl
# lists sub directories recursively
use File::Find;
find sub { print "$File::Find::name\n" if -d }, "d:";
It works on my 98 machine, where the d: drive is the CD.
--
unmunge?cold=hot
------------------------------
Date: Wed, 20 Dec 2000 12:56:38 +0100
From: "tim allen" <timallen449@coldmail.com>
Subject: Re: File::Find - meaning of 'symlinks'?
Message-Id: <91q64k$dai$1@diana.bcn.ttd.net>
"Philip Lees" <pjlees@ics.forthcomingevents.gr> wrote in message
news:3a40688a.64867214@news.grnet.gr...
>Is that why my text search algorithm works fine on the HD but can't
>find anything on a CD-ROM?
Hi Philip, I was bored and elaborated a bit on that idea for the search.
Try this code to do a search on the D: drive (you could (should?) change it
so the user can choose the drive, directory, etc.
use File::Find;
my $srch;
sub findit {
$infile = $_;
open (INFILE,$infile);
while (<INFILE>) {
if (m/\b$srch\b/) {
print "$File::Find::name contains $srch\n";
last;
}
}
}
print "What word are you looking for? ";
while (chomp($srch = <STDIN>)) {
if ($srch eq 'q') {last};
find \&findit, "d:";
print "What word are you looking for (q to quit)? ";
}
This works on my 98 machine. Hope that helps! cheers. -tim
--
unmunge?cold=hot
------------------------------
Date: Wed, 20 Dec 2000 14:05:55 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: File::Find - meaning of 'symlinks'?
Message-Id: <3a40b0e0.1130847803@news.itn.is>
On Wed, 20 Dec 2000 08:09:49 GMT,
pjlees@ics.forthcomingevents.gr (Philip Lees) wrote:
>The File::Find documentation says, under Bugs:
>
>'There is no way to make find or finddepth follow symlinks.'
>
>Is that why my text search algorithm works fine on the HD but can't
>find anything on a CD-ROM?
>
>(Windows NT, I'm afraid)
>
No, the code below works fine to search for directories
on a CD-ROM under Windows NT, so that is not
your problem. Maybe you don't know the path
to your CD?
Note: the same code works if you use
finddepth in place of find.
Regards,
Helgi Briem
use File::Find;
use strict;
my $dir = "D:/";
my @dirs;
find (\&wanted, $dir);
for (@dirs) { print "$_\n"; }
sub wanted
{
if (-d $_) { push @dirs, $_; }
}
------------------------------
Date: Wed, 20 Dec 2000 11:07:40 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Free servers with Perl support?
Message-Id: <pg414tgee0fmuujmjte91379g86ti34fco@4ax.com>
Navcomp wrote:
>Hello. I'm looking for a free UNIX-Linux server where I can put my CGIs
>written in Perl while I learn the language (just for learning purposes). I
If you do have a Windows PC and don't intend to install Linux (or
FreeBSD) on it, then you might grab the Perl for Windows port from
IndigoSTAR (<http://www.indigostar.com/indigoperl.htm>). This one comes
combined with Apache, so it's really dead easy to install both Perl and
Apache on your own PC. You can have it all working in under five
minutes.
--
Bart.
------------------------------
Date: 20 Dec 2000 15:07:16 GMT
From: Ralf Peine <ralf.peine@bch.siemens.de>
Subject: get the version of a Windows DLL
Message-Id: <91qhv4$6h9$1@news.mch.sbs.de>
Hi,
how can I get the version of a Windows dll with perl? I want to
catalogue all DLL-Versions for troubleshooting ...
Thanks,
Ralf Peine
------------------------------
Date: Wed, 20 Dec 2000 12:33:25 +0100
From: Erik Richly <richly@mpiz-koeln.mpg.de>
Subject: Help with PERLCC! Somebody pleaze ...
Message-Id: <3A409905.5050209@mpiz-koeln.mpg.de>
Hi!
I'm trying to generate a standalone executable from a perl script.
Using perlcc I alway get a warning:
URI has method new: -uURI assumed
URI::WithBase has method new: -uURI::WithBase assumed
URI::URL has method new: -uURI::URL assumed
and after the compilation the program won't run giving me an error:
Can't locate object method "new" via package "LWP::UserAgent".
What does that mean? Any suggestions?
Thanx alot,
Erik
------------------------------
Date: 20 Dec 2000 14:26:16 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Home Directory
Message-Id: <977321910.12751@itz.pp.sci.fi>
[Jeopardectomy performed.]
In article <GhI%5.24878$xW4.192703@news-server.bigpond.net.au>, SuperGumby wrote:
>Tad McClellan wrote in message ...
>>mgrime@my-deja.com <mgrime@my-deja.com> wrote:
>>
>>>Can anyone tell me if there is there any way to reference your home
>>>directory
>>
>>There is code for that in the "C-style Logical Or" section
>>of perlop.pod.
>
>I have to comment on the obviousness of this, just where I'd expect it to
>be.
While I can appreciate your point, I would like to point out that
anyone claiming to know how to program in Perl should be expected to
have read perlop, and therefore to have seen the example. ;-)
Not that many people who have no clue about Perl's operators dont't
keep claiming Perl programming skills, but they shouldn't..
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
"Lo, I am become the ghost in the machine, drinker of coffee."
-- Julie Lim in rec.arts.sf.composition
------------------------------
Date: Wed, 20 Dec 2000 12:45:03 +0100
From: "Dimitri Gunsing" <somewhere@planet.earth>
Subject: Re: How can I access the checkbox value of a form in Perl?
Message-Id: <91q63a$unv$1@list.pbnec.nl>
A checkbox is a boolean, it only returns 'on' or 'off'. What you want you
can do with a radio button (read HTML documentation for the use of radio
buttons). Then in Perl you can read that value (if in this case the name of
the radio button is the same as in your code) with :
use CGI;
my $query = new CGI;
my $data = $query->param("medium");
$data now holds the value the user selected.
Immortal Love <s997659@ee.cuhk.edu.hk> wrote in message
news:Pine.GSO.4.05.10012201301530.24493-100000@sparc53.ee.cuhk.edu.hk...
> I have a form in html and there is a group of checkbox, say
> <input type="checkbox" name="medium" value="internet">Internet<br>
> <input type="checkbox" name="medium" value="friends">Friends<br>
> <input type="checkbox" name="medium" value="itsc">Activities<br>
>
> then how can i know which one is being checked?
>
> in Perl, i know $FORM{' '} can call a value.
>
> thanks
>
------------------------------
Date: Wed, 20 Dec 2000 12:32:54 GMT
From: "Olwynn" <info@jjmackay.ca>
Subject: Re: how to invalidate a hash value during a foreach loop?
Message-Id: <WF106.7$a75.8026@sapphire.mtt.net>
Philip,
Thanks, I tried that, but perl wouldn't compile saying that the empty string
I was testing for was 'not a number', so it seems that if a blank field
comes through on a hash it is automatically received as a number?
TIA for any enlightenment.
Richard
Philip Lees <pjlees@ics.forthcomingevents.gr> wrote in message
news:3a405fda.62643055@news.grnet.gr...
> On Tue, 19 Dec 2000 15:18:45 GMT, "Olwynn" <info@jjmackay.ca> wrote:
>
> >I am sure that the problem lies in the line
> >
> >if(values(%form_results)!='')
>
> For string comparisons, use ne instead of !=.
>
> See perlop for more (Equality Operators).
>
> Phil
> --
> Philip Lees
> ICS-FORTH, Heraklion, Crete, Greece
> Ignore coming events if you wish to send me e-mail
> 'The aim of high technology should be to simplify, not complicate' - Hans
Christian von Baeyer
------------------------------
Date: Wed, 20 Dec 2000 13:10:27 GMT
From: garry@zweb.zvolve.net (Garry Williams)
Subject: Re: how to invalidate a hash value during a foreach loop?
Message-Id: <7d206.485$Kk5.24560@eagle.america.net>
On Wed, 20 Dec 2000 07:32:07 GMT, Philip Lees
<pjlees@ics.forthcomingevents.gr> wrote:
>On Tue, 19 Dec 2000 15:18:45 GMT, "Olwynn" <info@jjmackay.ca> wrote:
>
>>I am sure that the problem lies in the line
>>
>>if(values(%form_results)!='')
>
>For string comparisons, use ne instead of !=.
What makes you think `values(%form_results)' is a string? "values"
returns a list.
if ( values(%form_results) ) {
or just
if ( %form_results ) {
>See perlop for more (Equality Operators).
>
>Phil
>--
That should be `-- '.
--
Garry Williams
------------------------------
Date: Wed, 20 Dec 2000 08:23:14 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: how to invalidate a hash value during a foreach loop?
Message-Id: <slrn941cm2.24o.tadmc@magna.metronet.com>
Philip Lees <pjlees@ics.forthcomingevents.gr> wrote:
>On Tue, 19 Dec 2000 15:18:45 GMT, "Olwynn" <info@jjmackay.ca> wrote:
>
>>I am sure that the problem lies in the line
>>
>>if(values(%form_results)!='')
>
>For string comparisons, use ne instead of !=.
The important part here is that a string comparison should
not be used at all!
values() does not return a string.
>See perlop for more (Equality Operators).
See the description of values() in perlfunc.pod. Note in particular
its behavior in scalar context.
To see if there are any values in the hash:
if( values(%form_results) != 0 )
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 20 Dec 2000 13:53:12 +0100
From: "Frode Bjerkholt" <fb@geo-guide.com>
Subject: Mail::Sendmail and HTML-messages
Message-Id: <QY106.723$uW.34309@news1.oke.nextra.no>
Hi
I am wondering about how to format a mail message, using Mail::Sendmail, so
that it appear as a HTML page in the mail-browser.
Can anyone help me?
Kind Regards
Frode Bjerkholt
------------------------------
Date: Wed, 20 Dec 2000 16:59:45 +0100
From: Alain BARBET <alian@alianwerbserver.com>
Subject: Re: Mail::Sendmail and HTML-messages
Message-Id: <91qkpj$25n3$1@news4.isdnet.net>
Hi,
> I am wondering about how to format a mail message, using Mail::Sendmail,
> so that it appear as a HTML page in the mail-browser.
With mail::Sendmail no clue, but wih MIME::Lite and MIME::Lite::HTML ...
--
Alain BARBET
http://www.alianwebserver.com
------------------------------
Date: Wed, 20 Dec 2000 11:58:39 -0000
From: "carlo costa" <carlo@netverk.net>
Subject: MailTools-1.15
Message-Id: <3a410f97.0@news.isholf.is>
some one can telme where can i find some more material about the module
MailTools-1.15...some esemple..or helpme in some way using it..
I am not heving any succccess at all.
Tx
carlo
------------------------------
Date: Wed, 20 Dec 2000 15:04:46 GMT
From: Jeff Helman <jhelman@wsb.com>
Subject: Re: No embeding please!
Message-Id: <3A40CAEC.EE0EB1DB@wsb.com>
timothy wrote:
>
> Hey out there!
>
> Well, I'm creating my first web enabled database and I would rather
> avoid embeding my PERL in my HTML or my HTML in my PERL.
If I may ask, why not put some HTML into the CGI script? Generating the
HTML on the fly will be much faster and much cleaner than loading in a
template file and doing search and replace.
> I've done forms so I know the basics, but now I'm trying to get some
> nice output. I spent hours designing a good table layout with dummy
> info and I want to use that html code to display my database info.
Okay, so do so. Let's say you want to put $Value1 in the first cell of
a table and $Value2 in the second cell (for simplicity's sake, let's say
that's all the customizing you want to do.) You could then use the
following script to generate the HTML for you...
print "Content-type: text/html\015\012\015\012";
## MAKE THE HEADER OF YOUR PAGE HERE
$Body = qq!<TABLE BORDER="1">\n<TR>\n!;
## PUT IN YOUR VALUES
$Body .= qq!<TD>$Value1</TD>\n<TD>$Value2</TD>\n!;
## PUT THE REST OF THE BODY IN
$Body .= qq!</TR>\n</TABLE>\n!;
## PRINT THE BODY
print $Body or die("Browser closed connection");
> The last time I was doing some form output I just made up my own HTML
> tags which the browsers are nice enough to ignore, then opened and
> parsed the html doc to replace the tags with the appropriate data.
Probably not the best solution. Throwing in random HTML tags and hoping
that the browser ignores them is somewhat less than a perfect solution.
If you want to go the parsing and replacing route, why not just put in
specific junk tags that will be replaced by your values later?
> Even though it worked fine, what I didn't like about this was that 1.
> I had to continually remind the web designer to leave my tags alone
> and 2. I still ended up embeding each HTML container that had my tags
> into the CGI.
>
> Like....
>
> <td mytag></td>
> was in the HTML doc
How about having your template file look like
<td><<<VALUETAG1>>></td>
And then just replacing the <<<VALUETAG1>>> with the appropriate value,
like
$HTML =~ s/<<<VALUETAG1>>>/$ValueTag1/g;
This way, you don't have any artifacts left in the HTML file sent to the
user. Plus, if you read your HTML file into one scalar variable, you
can do global replaces (like the one above) to replace all matching tags
at once (like if you are setting a color in multiple cells). All you
have to do is come up with the appropriate dummy tags to insert.
> <td mytag>$somedata</td>
> was in my CGI
>
> and then I wrote...
> <td mytag>Some Data</td>
> back to the webserver
>
> This is simplified, as I also did the same for changing colors of
> cells if the form wasn't complete, etc, etc.
As I noted above, if you come up with unique tags for each different
variable, you can do as many substitutions as you want.
> I've looked around for some pointers on displaying formatted data and
> haven't really come across anything. Maybe I'm not looking in the
> right places?
There really isn't any magic to it. I think you'll find, though, that
building the return HTML file from within your script is much faster and
uses less resources than reading an external file and doing a bunch of
s/// ops on the file.
> If anyone can give me a few tips, I'd be much abliged.
>
> Thanks!
>
> - tim
Hope this helps,
JH
------------------------------
Date: Wed, 20 Dec 2000 08:34:56 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: No embeding please!
Message-Id: <slrn941dc0.24o.tadmc@magna.metronet.com>
timothy <timothy@no.spam.here.aracnet.com> wrote:
>
>I spent hours designing a good table layout with dummy
>info and I want to use that html code to display my database info.
>2. I still ended up embeding each HTML container that had my tags
>into the CGI.
That is impossible. You cannot "embed" anything in an interface.
I assume you meant "into the program" instead?
>I've looked around for some pointers on displaying formatted data and
>haven't really come across anything. Maybe I'm not looking in the
>right places?
Was CPAN one of the places?
>If anyone can give me a few tips, I'd be much abliged.
There are many modules for doing such things. Search for "Template" at:
http://search.cpan.org/
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 20 Dec 2000 09:54:27 -0600
From: AP <alex@hoopsie2.com>
Subject: Re: No embeding please!
Message-Id: <3A40D633.13A24EA8@hoopsie2.com>
timothy wrote:
> Well, I'm creating my first web enabled database and I would rather
> avoid embeding my PERL in my HTML or my HTML in my PERL.
<snip>
> I had to continually remind the web designer to leave my tags alone
Tim,
I may suggest the HTML::Template module. It let's you do things like this:
<TABLE>
<TMPL_LOOP NAME="items_list">
<TR>
<TD>
<TMPL_VAR NAME="item_name">
</TD>
<TD>
<TMPL_VAR NAME="item_description">
</TD>
</TR>
</TMPL_LOOP>
</TABLE>
This won't solve #1, but, if I remember correctly, you can also use the
TMPL_* tags in this fasion:
<!--TMPL_VAR NAME="foo"-->
So that they are seen as comments by HTML design tools. What those tools
may do to the tags or how they may move them around is another story beyond
my knowledge because I either code HTML by hand or use HMTL editing tools
that are not WYSIWYG.
Anyway, yoru script would process those tags and that way the resulting file
has no funny tags that you're gambling on the browser to ignore. I used to
use CGI.pm exclusively because it had all the nice HTML functions (all other
usefulness aside) but for the projects I've been doing lately, the clients
seem to change their mind the most with the UI rather than functionality
(ehem, like I said, for the projects I've been doing *lately*..that was not
a blanket statement!).
--Alex
--
--------------------------------------------------
alex@hoopsie2.com | http://alex.hoopsie.com
--------- remove the "2" from e-mail -------------
------------------------------
Date: 20 Dec 2000 14:36:46 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: overriding 'print'
Message-Id: <91qg5u$mku$1@lublin.zrz.tu-berlin.de>
B. Thomas Adler <thumper@alumnae.caltech.edu> wrote in comp.lang.perl.misc:
>I'm trying to override the 'print' command with one
>I've written myself. I've had good success with this
>on other commands (like 'open', and 'chdir'), but 'print'
>is not cooperating. Does anyone know what magic it takes
>to override this command?
>
>
>What I tried was creating a module like:
> package MyPrint;
> use Exporter;
> use vars qw(@ISA @EXPORT);
> @ISA = qw(Exporter);
> @EXPORT = qw(chdir print);
>
> sub chdir {
> CORE::print "called chdir\n";
> }
> sub print {
> CORE::print "called print\n";
> }
>
>
>and this works for 'chdir', but not 'print'. I tried using
>prototypes to help it along, but that also fails.
I can only guess that print() is one of the builtins that don't
allow overriding. The operative sentence from perlsub begins
Many built-in functions may be overridden,...
which implies that not all can.
I know of no way do find out if a function can be overridden, short
of trying to override it.
Anno
------------------------------
Date: 20 Dec 2000 08:47:43 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: overriding 'print'
Message-Id: <3a40d49f@cs.colorado.edu>
In article <91qg5u$mku$1@lublin.zrz.tu-berlin.de>,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>I know of no way do find out if a function can be overridden, short
>of trying to override it.
1) In the Perl Cookbook's chapter on modules, one learns that
Not all ``reserved words'' have the same status. Those
that return a negative number in the C-language C<keyword()>
function in the I<toke.c> file in your Perl source kit may
be overridden.
Actually, it's now the Perl_keyword function, but no matter.
% perl -lne 'print $1 if (/^\S*keyword/ .. /^}/)
&& /return\s*-KEY_(\w+)/' /usr/local/src/perl/toke.c | fmt
__FILE__ __LINE__ __PACKAGE__ and abs alarm atan2 accept
bless bind binmode CORE cmp chr cos close chdir chmod chown
crypt chroot caller connect closedir continue die dump
dbmopen dbmclose eq eq eof exp exit exec endgrent endpwent
endnetent endhostent endservent endprotoent fork fcntl flock
fileno formline gt ge getppid getpgrp getpwent getpwnam
getpwuid getpeername getprotoent getpriority getprotobyname
getprotobynumber gethostbyname gethostbyaddr gethostent
getnetbyname getnetbyaddr getnetent getservbyname getservbyport
getservent getsockname getsockopt getgrent getgrnam getgrgid
getlogin getc gt ge gmtime hex int index ioctl join kill
lt le lt le lc log link lock lstat length listen lcfirst
localtime mkdir msgctl msgget msgrcv msgsnd ne ne not or
ord oct open opendir pack pipe quotemeta ref read rand recv
rmdir reset rename rindex require reverse readdir readlink
readline readpipe rewinddir seek send semop select semctl
semget setpgrp seekdir setpwent setgrent setnetent setsockopt
sethostent setservent setpriority setprotoent shmctl shmget
shmread shmwrite shutdown sin sleep socket socketpair sprintf
sqrt srand stat substr system symlink syscall sysopen sysread
sysseek syswrite tell time times telldir truncate uc utime
umask unpack unlink ucfirst values vec warn wait write
2) Check whether you get back a positive-length string from calling
prototype("CORE::...."), where "...." is the function in question.
% perl -le 'print prototype("CORE::socket")'
*$$$
% perl -le 'print prototype("CORE::sort")'
% perl -le 'print prototype("CORE::tie")'
% perl -le 'print prototype("CORE::dbmopen")'
\%$$
% perl -le 'print prototype("CORE::push")'
% perl -le 'print prototype("CORE::pop")'
% perl -le 'print prototype("CORE::frazzle")'
Can't find an opnumber for "frazzle" at -e line 1.
Exit 255
% perl -le 'print prototype("CORE::atan2")'
$$
% perl -le 'print prototype("CORE::print")'
% perl -le 'print prototype("CORE::readline")'
% perl -le 'print prototype("CORE::sprintf")'
$@
% perl -le 'print prototype("CORE::printf")'
% perl -le 'print prototype("CORE::open")'
*;$@
--tom
------------------------------
Date: 20 Dec 2000 06:48:38 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: perl DBI
Message-Id: <m14rzz2lo9.fsf@halfdome.holdit.com>
>>>>> "AvA" == AvA <a.v.a@home.nl> writes:
AvA> i have a little database (12 rows) for testing (mysql) and i would like
AvA> to show its data in 3 rows with each 4 querys in it.
AvA> i get to output it in one row or as a single column, then i am stuck.
AvA> could anyone have a look at the code and point me in the right
AvA> direction?
AvA> #!/usr/bin/perl
AvA> use DBI;
AvA> print "Content-type: text/html\n\n";
AvA> print "<body>";
AvA> $database = "test";
AvA> $username = "*****";
AvA> $password = "*****";
AvA> $dbh = DBI->connect("DBI:mysql:$database", $username, $password) or die
AvA> "unable.....";
AvA> $sth = $dbh->prepare("select * from test");
AvA> $sth->execute or die "Unable....";
AvA> print "<table border=1>";
AvA> while (@ary = $sth->fetchrow_array){
AvA> print "<td> $ary[0] : $ary[1] <br>";
AvA> }
AvA> print "</table>";
AvA> $dbh->disconnect;
Use the CGI shortcuts!
#!/usr/bin/perl
use strict;
use DBI;
use CGI qw(:all);
print header, start_html("My sample"), h1("My sample");
my $dbh = DBI->connect("dbi:mysql:database", "user", "pass",
{ RaiseError => 1 }); # why isn't this the default? :)
my $two_d = $dbh->selectall_arrayref("select * from test");
print table( map { Tr( map { td(escape_HTML($_)) } @$_ ) } @$two_d );
print end_html;
$dbh->disconnect;
Lots of meat in this. Study each piece, and you will be enlightened,
my son.
print "Just another Perl hacker,";
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Wed, 20 Dec 2000 13:18:51 -0000
From: "Ben Turner" <ben.turner@e-inbusiness.co.uk>
Subject: Ping CGI Script
Message-Id: <t41ce160edomaf@corp.supernews.co.uk>
Hi I have written the following script, which I want the generate an HTML
page displaying the status of the machines at IP addresses kept in
@host_array
*******************
use Net::Ping;
$p = Net::Ping->new("icmp") or die "Can't Create New Ping Object: $!\n";
foreach $host (@host_array)
{
print "($host) - is ";
print "NOT " unless $p->ping($host, 3);
print "reachable.<BR>\n";
}
$p->close;
*******************
When I run the script from the command prompt I get the following - which is
good.
EIB-WebOne - (209.67.27.69) - is reachable.<BR>
EIB-Bondi - (216.32.74.51) - is reachable.<BR>
EIB-Fistral - (207.46.190.117) - is reachable.<BR>
QXL - (195.205.201.242) - is reachable.<BR>
The problem comes when I run the script from a web server (in this case Peer
Web Services on Windows 2000). The script takes 12+ seconds to display (the
timeouts level for all for ping targets), and then reports that they are all
'NOT reachable'.
Help
Ben
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 5158
**************************************