[27936] in Perl-Users-Digest
Perl-Users Digest, Issue: 9300 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 15 09:06:01 2006
Date: Thu, 15 Jun 2006 06:05:06 -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 Thu, 15 Jun 2006 Volume: 10 Number: 9300
Today's topics:
Auto flush doesn't work as expected <leifwessman@hotmail.com>
Re: Auto flush doesn't work as expected <tony_curtis32@_NOSPAM_yahoo.com>
Re: Broken Pipe in Network Programming <siegel@zrz.tu-berlin.de>
Re: Broken Pipe in Network Programming <janicehwang1325@yahoo.com>
Re: Broken Pipe in Network Programming <mumia.w.18.spam+nospam.usenet@earthlink.net>
Re: Broken Pipe in Network Programming <benmorrow@tiscali.co.uk>
Re: can I trust on key %hash natural order? <filippo2991@virgilio.it>
Re: Did not return a true value <aukjan@gmail.com>
Re: Did not return a true value <xoxo_davide@yahoo.com>
Re: Doc to PDF using Perl <benmorrow@tiscali.co.uk>
Re: Doc to PDF using Perl <flavell@physics.gla.ac.uk>
Re: Doc to PDF using Perl <rvtol+news@isolution.nl>
Re: Doc to PDF using Perl <benmorrow@tiscali.co.uk>
Re: Doc to PDF using Perl <flavell@physics.gla.ac.uk>
Re: FAQ 3.5 How do I debug my Perl programs? niall.macpherson@ntlworld.com
Re: FAQ 3.5 How do I debug my Perl programs? <benmorrow@tiscali.co.uk>
Re: question installing DBD::mysql <"v.niekerk at hccnet.nl">
Re: reference to object method <noreply@gunnar.cc>
Re: reference to object method <siegel@zrz.tu-berlin.de>
Re: reference to object method <benmorrow@tiscali.co.uk>
Re: Tk bug not fixed in CPAN <zentara@highstream.net>
Unix shell script with Perl one-liner causes error <simonozzy@gmail.com>
Re: Unix shell script with Perl one-liner causes error <someone@example.com>
Re: Unix shell script with Perl one-liner causes error <simonozzy@gmail.com>
Re: Unix shell script with Perl one-liner causes error <rvtol+news@isolution.nl>
Re: Unix shell script with Perl one-liner causes error <mumia.w.18.spam+nospam.usenet@earthlink.net>
Re: Unix shell script with Perl one-liner causes error <someone@example.com>
Re: What is Expressiveness in a Computer Language <pc@p-cos.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 15 Jun 2006 04:43:44 -0700
From: "Leif Wessman" <leifwessman@hotmail.com>
Subject: Auto flush doesn't work as expected
Message-Id: <1150371824.559175.307110@u72g2000cwu.googlegroups.com>
Auto flush doesn't work for me. I've read the FAQ.
#!/usr/local/bin/perl -w
use strict;
$| = 1;
print "Content-type: text/html\n\n";
print "Printed at once<br>";
sleep(3);
print "3 seconds later";
Everything gets printed after 3 seconds. However, when I try it from
the command line it works.
I'm using Apache/2.0.54 and perl 5.8.0.
Leif
------------------------------
Date: 15 Jun 2006 07:58:17 -0400
From: Tony Curtis <tony_curtis32@_NOSPAM_yahoo.com>
Subject: Re: Auto flush doesn't work as expected
Message-Id: <y6zsu06mhbqe.fsf@post.queensu.ca>
>> On 15 Jun 2006 04:43:44 -0700,
>> "Leif Wessman" <leifwessman@hotmail.com> said:
> Auto flush doesn't work for me. I've read the FAQ.
> #!/usr/local/bin/perl -w
> use strict;
> $| = 1;
> print "Content-type: text/html\n\n";
> print "Printed at once<br>";
> sleep(3);
> print "3 seconds later";
> Everything gets printed after 3 seconds. However, when I
> try it from the command line it works.
So there's nothing wrong with the code and autoflush is
actually doing what you expect...
> I'm using Apache/2.0.54 and perl 5.8.0.
This is a question about how a browser renders data
claiming to be HTML.
------------------------------
Date: Thu, 15 Jun 2006 10:02:42 +0200
From: Anno Siegel <siegel@zrz.tu-berlin.de>
Subject: Re: Broken Pipe in Network Programming
Message-Id: <4fcikkF1hva59U1@news.dfncis.de>
janicehwang1325@yahoo.com wrote:
> Hi,
>
> I have server running on localhost and a client is connected to it from
> the same station, which is the localhost. However, when i try to
> connect another client to the server, it gives me Broken pipe error in
> the second client and the server side prompt that there is a
> segmentation fault (core dumped). What is the cause of this problem and
> how can i solve it?
You must be joking! Show your code.
Anno
------------------------------
Date: 15 Jun 2006 02:52:51 -0700
From: "janicehwang1325@yahoo.com" <janicehwang1325@yahoo.com>
Subject: Re: Broken Pipe in Network Programming
Message-Id: <1150365170.972784.290530@c74g2000cwc.googlegroups.com>
here my server code:
use threads;
#!/usr/bin/perl
use POSIX ":sys_wait_h";
use IO::Socket::SSL;
use IO::Handle;
use Time::Local;
use DBI;
my ($sock, $s, $v_mode);
unless (@ARGV == 1) { die "usage: perl $0 <Port Number>" };
($port) = @ARGV;
# Check to make sure that we were not accidentally run in the wrong^M
# directory:^M
unless (-d "certs") {
if (-d "../certs") {
chdir "..";
} else {
die "No CA Certs\n";
}
}
if(!($sock = IO::Socket::SSL->new( Listen => 10,
LocalPort => $port,
Proto => 'tcp',
ReuseAddr => 1,
SSL_verify_mode => 0x01,
SSL_use_cert => 1,
SSL_passwd_cb => sub {return
"haha"},
SSL_key_file =>
'certs/server_key.pem',
)) ) {
warn "unable to create socket: ", &IO::Socket::SSL::errstr, "\n";
exit(0);
}
warn "SSL socket created: $sock.\n";
#run as daemon
chdir '/' or die "Can't chdir to /: $!";
umask 0;
open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
open STDOUT, '>>/dev/null' or die "Can't write to /dev/null: $!";
open STDERR, '>>/dev/null' or die "Can't write to /dev/null: $!";
defined(my $pid = fork) or die "Can't fork: $!";
exit if $pid;
setsid or die "Can't start a new session: $!";
warn "waiting for next connection......\n";
sub handle_connection{
$dbh = DBI->connect("DBI:mysql:testing", "root",
'!@#zxc'),{RaiseError => 1, AutoCommit => 0} || die ("Cannot connect to
database");
$outpath = "/home/extol/heartbeat_testing/alert.log";
$s = shift;
$output = shift || $s;
$exit = 0;
my ($peer_cert, $subject_name, $issuer_name, $date, $str);
if( ! $s ) {
warn "error: ", $s->errstr, "\n";
$exit = 1;
break;
}
while(<$s>){
if( ref($s) eq "IO::Socket::SSL" && $s->connected()) {
$subject_name =
$s->peer_certificate("subject");
$issuer_name = $s->peer_certificate("issuer");
if($_ =~ /MRTG ([\d.]+) (\w+) (\d+) (\d+) (\d+)
(\d+) (\d+) (\d+)/)
{
# here the program wil process the
log and save into database
...................
}
else{
$exit = 1;
}
last if $exit;
}
$dbh->disconnect;
}
while(1){
while(($s = $sock->accept())) {
$s->autoflush(1);
$thread = threads->create(\&handle_connection, $s);
$id = $thread->tid();
print "the thread id is $id\n";
$thread->detach;
}
}
------------------------------
Date: Thu, 15 Jun 2006 12:28:11 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: Broken Pipe in Network Programming
Message-Id: <vnckg.6148$o4.3033@newsread2.news.pas.earthlink.net>
janicehwang1325@yahoo.com wrote:
> here my server code:
> [...]
>
> #run as daemon
> chdir '/' or die "Can't chdir to /: $!";
> umask 0;
> open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
> open STDOUT, '>>/dev/null' or die "Can't write to /dev/null: $!";
> open STDERR, '>>/dev/null' or die "Can't write to /dev/null: $!";
> [...]
You should close these file handles before you open them with different
targets.
------------------------------
Date: Thu, 15 Jun 2006 13:37:58 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Broken Pipe in Network Programming
Message-Id: <6u08m3-ojt.ln1@osiris.mauzo.dyndns.org>
Quoth "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>:
> janicehwang1325@yahoo.com wrote:
> > here my server code:
> > [...]
> >
> > #run as daemon
> > chdir '/' or die "Can't chdir to /: $!";
> > umask 0;
> > open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
> > open STDOUT, '>>/dev/null' or die "Can't write to /dev/null: $!";
> > open STDERR, '>>/dev/null' or die "Can't write to /dev/null: $!";
> > [...]
>
> You should close these file handles before you open them with different
> targets.
Unless you're particularly concerned to catch errors from close, you
don't need to. Perl will close them for you (and drop any error on the
floor).
Ben
--
The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching.
Assyrian stone tablet, c.2800 BC benmorrow@tiscali.co.uk
------------------------------
Date: 15 Jun 2006 05:59:40 -0700
From: "filippo" <filippo2991@virgilio.it>
Subject: Re: can I trust on key %hash natural order?
Message-Id: <1150376379.922276.29430@y41g2000cwy.googlegroups.com>
John Bokma ha scritto:
> Better: do the comparision with SQL. It can compare dates.
this would be the best. Is is possible to embed this
get TIMESTAMP from database (current local date)
get DATE from a database table
compare DATE to TIMESTAMP
return the result of comparison
as an SQL query?
Thanks,
Filippo
------------------------------
Date: 15 Jun 2006 00:32:38 -0700
From: "aukjan@gmail.com" <aukjan@gmail.com>
Subject: Re: Did not return a true value
Message-Id: <1150356758.652336.253600@i40g2000cwc.googlegroups.com>
narra.madan@gmail.com wrote:
> hi,
> i am getting the follwing error when ever i call a module from my pgm..
> #################################################################
> [Thu Jun 15 12:04:29 2006] [error] [client 127.0.0.1] Premature end of
> script headers: Register.pl
> Thu Jun 15 12:04:29 2006] [error] [client 127.0.0.1] Reg_Display.pm did
> not return a true value at W:/cgi-bin/new/Register.pl line 13.
Every module needs to return a 'true' value, and it seems that
Reg_Display.pm does not do this. Check the end of this module to see if
it has the following statement '1;'.. Else add this at the end of the
module (before any pod documentation).
This should fix the problem
Aukjan.
------------------------------
Date: 15 Jun 2006 04:35:51 -0700
From: "The Doc on The Rocks" <xoxo_davide@yahoo.com>
Subject: Re: Did not return a true value
Message-Id: <1150371351.477639.157690@c74g2000cwc.googlegroups.com>
> #################################################################
> [Thu Jun 15 12:04:29 2006] [error] [client 127.0.0.1] Premature end of
> script headers: Register.pl
> Thu Jun 15 12:04:29 2006] [error] [client 127.0.0.1] Reg_Display.pm did
> not return a true value at W:/cgi-bin/new/Register.pl line 13.
> [Thu Jun 15 12:04:29 2006] [error] [client 127.0.0.1] BEGIN
> failed--compilation aborted at W:/cgi-bin/new/Register.pl line 13.
> ################################################################
possible causes:
1) Did you end your package with "1;" (without quotes) ? Packages need
to return a true value...
2) /cgi-bin usually are web relative paths, you should use system
relative path (/home/web/www/cgi-bin/...) but it seems it's found, so i
guess it's there.
3) Just a suggestions.. pay attention on case-sensitive filesystems...
( unshift(@INC,"/cgi-bin/lib/Register")
Have a nice drink
------------------------------
Date: Thu, 15 Jun 2006 06:02:47 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Doc to PDF using Perl
Message-Id: <n867m3-b4r.ln1@osiris.mauzo.dyndns.org>
Quoth "Scott R. Prelewicz" <scottp@noein.com>:
> Can anyone suggest a good solution to convert MS Word docs to PDF
> programatically, using perl?
>
> I tried installing and using abiword but I am having too many issues with
> the program, and I am looking for a different solution.
> I searched CPAN and can only find Win32 mosules for doing something close,
> but I'm not on windows.
I don't know of any program which can read Word files except Word (this
is one of the main reasons I hate M$ :) ). If you have access to a Win32
machine Word is (relatively) easy to script using Win32::OLE. Otherwise,
find some program that can read the files decently and we can probably
find a way for you to drive it in Perl (that is, the currently hard part
of your problem is not a Perl problem... sorry).
Ben
--
I've seen things you people wouldn't believe: attack ships on fire off
the shoulder of Orion; I watched C-beams glitter in the dark near the
Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
Time to die. benmorrow@tiscali.co.uk
------------------------------
Date: Thu, 15 Jun 2006 12:47:04 +0100
From: "Alan J. Flavell" <flavell@physics.gla.ac.uk>
Subject: Re: Doc to PDF using Perl
Message-Id: <Pine.LNX.4.64.0606151240230.6873@ppepc20.ph.gla.ac.uk>
On Thu, 15 Jun 2006, Ben Morrow wrote:
> I don't know of any program which can read Word files except Word
Hmmm. I've several times encountered MS Word files which could not be
read by the then-current version of MS Word, but were happily read by
openoffice.
> (this is one of the main reasons I hate M$ :) ).
...and all those who insist on putting their substantive content into
MS Word email attachments, without offering any clue to its content in
the Subject header (which typically reads "Important", "Please read",
or similar vacuous sentiments), nor in their covering plaintext note
(which typically contains instructions on how to read MS Word
documents, implying that the misbegotten sender is already aware that
there is a problem, but hasn't got the sense to solve that problem)...
</rant>
> If you have access to a Win32 machine Word is (relatively) easy to
> script using Win32::OLE.
Indeed. MS recommend RTF as a more portable format, by the way.
all the best
------------------------------
Date: Thu, 15 Jun 2006 13:56:06 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Doc to PDF using Perl
Message-Id: <e6rp1p.8o.1@news.isolution.nl>
Scott R. Prelewicz schreef:
> Can anyone suggest a good solution to convert MS Word docs to PDF
> programatically, using perl?
Why use perl? I would use a PostScript-printer that prints to file, and
then ps2pdf.
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Thu, 15 Jun 2006 13:36:14 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Doc to PDF using Perl
Message-Id: <uq08m3-ojt.ln1@osiris.mauzo.dyndns.org>
Quoth "Alan J. Flavell" <flavell@physics.gla.ac.uk>:
> On Thu, 15 Jun 2006, Ben Morrow wrote:
>
> > I don't know of any program which can read Word files except Word
>
> Hmmm. I've several times encountered MS Word files which could not be
> read by the then-current version of MS Word, but were happily read by
> openoffice.
Fair enough... I presume you mean old versions of Word files in newer
versions of Word? I was assuming the files were all from Word 2k/2k+3,
as I don't know of anyone who doesn't use one of those two now.
> > (this is one of the main reasons I hate M$ :) ).
>
> <rant snipped>
:)
> > If you have access to a Win32 machine Word is (relatively) easy to
> > script using Win32::OLE.
>
> Indeed. MS recommend RTF as a more portable format, by the way.
They do; but as of Word2k I would recommend Word's 'HTML' export, which
(while it is not HTML, or XHTML) is a perfectly decent XML format
(...plus M$ conditional comments, IIRC, but those can be stripped fairly
easily, or ignored) which preserves all but everything in the original
Word document.
I read the OP as having a collection of Word files on a Unix machine and
no way to proceed from there... not a situation I envy.
Ben
--
I must not fear. Fear is the mind-killer. I will face my fear and
I will let it pass through me. When the fear is gone there will be
nothing. Only I will remain.
benmorrow@tiscali.co.uk Frank Herbert, 'Dune'
------------------------------
Date: Thu, 15 Jun 2006 14:04:05 +0100
From: "Alan J. Flavell" <flavell@physics.gla.ac.uk>
Subject: Re: Doc to PDF using Perl
Message-Id: <Pine.LNX.4.64.0606151350210.6873@ppepc20.ph.gla.ac.uk>
On Thu, 15 Jun 2006, Ben Morrow wrote:
> Quoth "Alan J. Flavell" <flavell@physics.gla.ac.uk>:
> > Hmmm. I've several times encountered MS Word files which could
> > not be read by the then-current version of MS Word, but were
> > happily read by openoffice.
>
> Fair enough... I presume you mean old versions of Word files in
> newer versions of Word?
Right.
> I was assuming the files were all from Word 2k/2k+3,
We have at least one academic who insists on using an obsolete Mac
version of MS Word on his obsolete Mac...
As far as he's concerned, it ain't broke, so he sees no reason to fix
it. His usage of Mac Symbol fonts produces some quite exotic displays
on Windows.[0]
> > MS recommend RTF as a more portable format, by the way.
>
> They do; but as of Word2k I would recommend Word's 'HTML' export,
> which (while it is not HTML, or XHTML) is a perfectly decent XML
> format (...plus M$ conditional comments, IIRC, but those can be
> stripped fairly easily, or ignored) which preserves all but
> everything in the original Word document.
Fair comment. Pity they try to call it HTML, though.
> I read the OP as having a collection of Word files on a Unix machine
> and no way to proceed from there... not a situation I envy.
In earlier times, I would pipe the .doc attachment to "strings"[1]
But with current Word versions, it doesn't seem to work at all.
Sorry, this is drifting offtopic - I guess I should stop.
best regards
[0] Word still seems to make no attempt to replace Symbol font
characters by their proper Unicode equivalents, meaning that their
resulting HTML is rubbish on specification-conforming browsers. But I
guess you've seen me ranting about that before (since around 1997-8,
at least!).
[1] which sometimes had the side effect of revealing interesting
snippets that they had deleted before sending the attachment,
------------------------------
Date: 15 Jun 2006 04:16:04 -0700
From: niall.macpherson@ntlworld.com
Subject: Re: FAQ 3.5 How do I debug my Perl programs?
Message-Id: <1150370164.783552.173740@u72g2000cwu.googlegroups.com>
>
> The "Data::Dumper" module can pretty-print Perl data structures:
>
> use Data::Dumper( Dump );
> print STDERR "The hash is " . Dump( \%hash ) . "\n";
>
I've only ever used the Data::Dumper module to print to STDOUT as
follows
print Dumper %testhash
which works fine. I thought I would use the format suggested above so
that I can dump output to a logfile , but it fails under Active Perl
since the Dump module isn't exported
-##---------------------------------------------------
use strict;
use warnings;
use Data::Dumper( Dump );
my %testhash = ( 1 => 'arf' ,
2 => 'wibble' ,
3 => 'wobble' );
print STDERR "\nThe hash is " . Dump (\%testhash) . "\n";
exit(0);
##--------------------------------------------------
This produces the following output
C:\develop\NiallPerlScripts>clpm24.pl
Bareword "Dump" not allowed while "strict subs" in use at
C:\develop\NiallPerlSc
ripts\clpm24.pl line 3.
"Dump" is not exported by the Data::Dumper module
Can't continue after import errors at
C:\develop\NiallPerlScripts\clpm24.pl line
3
BEGIN failed--compilation aborted at
C:\develop\NiallPerlScripts\clpm24.pl line
3.
C:\develop\NiallPerlScripts>
Any suggestions as to what I can do to get this to work ?
Thanks in advance
------------------------------
Date: Thu, 15 Jun 2006 12:30:10 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: FAQ 3.5 How do I debug my Perl programs?
Message-Id: <2vs7m3-i4t.ln1@osiris.mauzo.dyndns.org>
Quoth niall.macpherson@ntlworld.com:
> >
> > The "Data::Dumper" module can pretty-print Perl data structures:
> >
> > use Data::Dumper( Dump );
> > print STDERR "The hash is " . Dump( \%hash ) . "\n";
> >
>
> I've only ever used the Data::Dumper module to print to STDOUT as
> follows
>
> print Dumper %testhash
>
> which works fine. I thought I would use the format suggested above so
> that I can dump output to a logfile , but it fails under Active Perl
> since the Dump module isn't exported
^^^^^^
You mean 'function'.
> C:\develop\NiallPerlScripts>clpm24.pl
> Bareword "Dump" not allowed while "strict subs" in use at
> C:\develop\NiallPerlSc
> ripts\clpm24.pl line 3.
> "Dump" is not exported by the Data::Dumper module
There are (apparently) two bugs in the FAQ. Firstly, import arguments
need quoting, so it should be
use Data::Dumper qw(Dump);
and secondly, Data::Dumper indeed doesn't export a 'Dump' function, so
it should be
use Data::Dumper qw(Dumper);
print STDERR "The hash is " . Dumper(\%hash) . "\n";
This will work fine printing to a logfile, or wherever: print FOO can
always be replaced with print STDERR FOO.
Ben
--
If I were a butterfly I'd live for a day, / I would be free, just blowing away.
This cruel country has driven me down / Teased me and lied, teased me and lied.
I've only sad stories to tell to this town: / My dreams have withered and died.
benmorrow@tiscali.co.uk (Kate Rusby)
------------------------------
Date: Thu, 15 Jun 2006 14:54:32 +0200
From: Huub <"v.niekerk at hccnet.nl">
Subject: Re: question installing DBD::mysql
Message-Id: <4491588d$0$30232$e4fe514c@dreader17.news.xs4all.nl>
>
> What I like to do in situations like this is issue a "look DBD::mysql" in
> the CPAN shell. That will go through the download and unzip steps, and open
> up a subshell in the build directory. From that point you can run the other
> steps manually.
>
> sherm--
>
OK, thank you. I now got these results:
<snip>
Checking if your kit is complete...
Looks good
Using DBI 1.50 (for perl 5.008007 on i686-linux) installed in
/usr/local/lib/perl5/site_perl/5.8.7/i686-linux/auto/DBI/
Writing Makefile for DBD::mysql
[root@Paarl DBD-mysql-3.0006]#
From the IDE (Eclipse):
#!/usr/bin/perl
use DBI;
(6) $dbh = DBI->connect('dbi:mysql:10.0.0.9:hvw','root','password')
or die "Connection Error: $DBI::errstr\n";
And the error:
install_driver(mysql) failed: Can't locate DBD/mysql.pm in @INC (@INC
contains: /apps/eclipse/plugins/org.epic.debug_0.2.0/
/usr/local/lib/perl5/5.8.7/i686-linux /usr/local/lib/perl5/5.8.7
/usr/local/lib/perl5/site_perl/5.8.7/i686-linux
/usr/local/lib/perl5/site_perl/5.8.7 /usr/local/lib/perl5/site_perl .)
at (eval 3) line 3.
Perhaps the DBD::mysql perl module hasn't been fully installed,
or perhaps the capitalisation of 'mysql' isn't right.
Available drivers: DBM, ExampleP, File, Proxy, Sponge.
at /home/huub/workspace/AcceptGiros/AcceptGiros.pl line 6
Could you tell me what I'm doing wrong?
Thank you
Huub
------------------------------
Date: Thu, 15 Jun 2006 09:46:18 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: reference to object method
Message-Id: <4fcheiF1i50lvU1@individual.net>
Uri Guttman wrote:
> xhoster <xhoster@gmail.com> writes:
>> "Hobo Salesman" <hobosalesman@gmail.com> wrote:
>>> Can I store a reference to an object method in a scalar and use that to
>>> call the method?
>>
>> my $ref = sub { $object->method(@_) };
>>
>> $ref->($argument);
>
> much better to use UNIVERSAL::can:
^^^^^^^^^^^
> my $meth = $obj->can( 'method_name' ) ;
>
> $meth->( $arg ) ;
Why?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 15 Jun 2006 10:14:11 +0200
From: Anno Siegel <siegel@zrz.tu-berlin.de>
Subject: Re: reference to object method
Message-Id: <4fcja5F1ilcr8U1@news.dfncis.de>
Uri Guttman wrote:
>>>>>> "x" == xhoster <xhoster@gmail.com> writes:
>
> x> "Hobo Salesman" <hobosalesman@gmail.com> wrote:
> >> Can I store a reference to an object method in a scalar and use that
> >> to call the method? Something like (and I'm sure this is wrong):
> >>
> >> $methodRef = \$object->method();
> >> &{$methodRef}($argument);
>
>
> x> my $ref = sub { $object->method(@_) };
>
> x> $ref->($argument);
>
> much better to use UNIVERSAL::can:
>
> my $meth = $obj->can( 'method_name' ) ;
>
> $meth->( $arg ) ;
Ah, but these are not the same. The way I read the OP, the idea is to
freeze both the object and the method in a scalar, and that's what Xhos
solution does. Yours only catches the method, the object would still
have to be supplied as an argument.
Anno
------------------------------
Date: Thu, 15 Jun 2006 06:08:12 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: reference to object method
Message-Id: <si67m3-b4r.ln1@osiris.mauzo.dyndns.org>
Quoth Uri Guttman <uri@stemsystems.com>:
> >>>>> "x" == xhoster <xhoster@gmail.com> writes:
>
> x> "Hobo Salesman" <hobosalesman@gmail.com> wrote:
> >> Can I store a reference to an object method in a scalar and use that to
> >> call the method? Something like (and I'm sure this is wrong):
> >>
> >> $methodRef = \$object->method();
> >> &{$methodRef}($argument);
>
> x> my $ref = sub { $object->method(@_) };
Note that $object must be a lexical here, or the anon sub won't close
over it. (But it was anyway, of course... :) )
> x> $ref->($argument);
>
> much better to use UNIVERSAL::can:
>
> my $meth = $obj->can( 'method_name' ) ;
>
> $meth->( $arg ) ;
...except that just calls the method as a sub, i.e. the invocant is not
preserved. For that you need another closure, hence Xho's answer is the
simplest possible.
Ben
--
I touch the fire and it freezes me, [benmorrow@tiscali.co.uk]
I look into it and it's black.
Why can't I feel? My skin should crack and peel---
I want the fire back... Buffy, 'Once More With Feeling'
------------------------------
Date: Thu, 15 Jun 2006 11:15:32 GMT
From: zentara <zentara@highstream.net>
Subject: Re: Tk bug not fixed in CPAN
Message-Id: <h6g2925tbhflcv260l9apqoqcjjpo53car@4ax.com>
On 14 Jun 2006 22:35:40 -0700, "Larry" <larry.grant.dc@gmail.com> wrote:
>I experiencing a Tk bug, whereby starting another program would crash
>my Tk program. I found a description of the bug here:
>http://tinyurl.com/zbej3 and installed the patch it recommended
>(http://m19s28.vlinux.de/estel/debian/perl-tk.deb), and it seems to
>have worked.
>
>My question is: why hasn't Tk been updated in CPAN to include this fix?
> The bug description describes the severity as "Critical" (and rightly
>so!), and the patch file is dated Jan. 2006. The Tk I used was just
>installed from CPAN a few days ago.
Yeah, I notice the same thing. Nick will say he has made the changes
to his sources to reflect the bug-fix, but it is never updated in the
latest download.
Maybe you can re-post this question in comp.lang.perl.tk, where
Nick Ing-Simmons frequently responds.
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
------------------------------
Date: 15 Jun 2006 03:44:35 -0700
From: "Simon O" <simonozzy@gmail.com>
Subject: Unix shell script with Perl one-liner causes error
Message-Id: <1150368275.549602.286200@p79g2000cwp.googlegroups.com>
Hi there
I have this Unix Borne shell script that does something like this in a
loop :
for FILE in *
do
ROW_COUNT_HEADER=`...`
if [ ${ROW_COUNT_HEADER} -ne 0 ]
then
...
# 1) OLD Option with Sed :
# cat ${FILE} | cut -f1-32 | sed "s/$/ ${FILE}/g" >> file.dat
# 2) NEW Option with Perl :
cat ${FILE} | cut -f1-32 | perl -ple "s/$/\t${FILE}/g" >>
file.dat
fi
bzip2 ${FILE}
mv ${FILE}.bz2 ${LATEST_ARCHIVE}/IGCPDATA/
done
I was having problems with using sed, so changed to option 2) using
perl which then gave a really weird error. It does what it's supposed
to but when it gets to the bzip / move section, it gives an error as
though it's still busy with ${FILE} ?? - being driving me MAD ! Almost
as though Perl is has said it's finished but is not ?
The error is this :
bzip2: I/O or other error, bailing out. Possible reason follows.
bzip2: No such file or directory
Input file = ABS_MTM_By_Trade, output file =
ABS_MTM_By_Trade.bz2
bzip2: Deleting output file ABS_MTM_By_Trade.bz2, if it exists.
bzip2: WARNING: deletion of output file (apparently) failed.
and of the 29 files in *, this error occurs randomly for only say five
of the files and the others are ok ??! The files are definitely there.
Any ideas ?
Thanks
Simon
------------------------------
Date: Thu, 15 Jun 2006 11:12:06 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Unix shell script with Perl one-liner causes error
Message-Id: <agbkg.62568$JX1.13259@edtnps82>
Simon O wrote:
>
> I have this Unix Borne shell script that does something like this in a
> loop :
>
> for FILE in *
> do
> ROW_COUNT_HEADER=`...`
> if [ ${ROW_COUNT_HEADER} -ne 0 ]
> then
> ...
> # 1) OLD Option with Sed :
> # cat ${FILE} | cut -f1-32 | sed "s/$/ ${FILE}/g" >> file.dat
> # 2) NEW Option with Perl :
> cat ${FILE} | cut -f1-32 | perl -ple "s/$/\t${FILE}/g" >>
> file.dat
You don't need the /g option because /$/ only occurs once in every line.
Or you could do that like:
perl -F'\t' -lane'splice @F, 32; print join "\t", @F, $ARGV' ${FILE}
>> file.dat
> fi
> bzip2 ${FILE}
> mv ${FILE}.bz2 ${LATEST_ARCHIVE}/IGCPDATA/
> done
>
> I was having problems with using sed, so changed to option 2) using
> perl which then gave a really weird error. It does what it's supposed
> to but when it gets to the bzip / move section, it gives an error as
> though it's still busy with ${FILE} ?? - being driving me MAD ! Almost
> as though Perl is has said it's finished but is not ?
>
> The error is this :
>
> bzip2: I/O or other error, bailing out. Possible reason follows.
> bzip2: No such file or directory
> Input file = ABS_MTM_By_Trade, output file =
> ABS_MTM_By_Trade.bz2
> bzip2: Deleting output file ABS_MTM_By_Trade.bz2, if it exists.
> bzip2: WARNING: deletion of output file (apparently) failed.
I don't know enough about bzip to be able to diagnose its errors.
John
--
use Perl;
program
fulfillment
------------------------------
Date: 15 Jun 2006 04:24:48 -0700
From: "Simon O" <simonozzy@gmail.com>
Subject: Re: Unix shell script with Perl one-liner causes error
Message-Id: <1150370688.609385.164320@r2g2000cwb.googlegroups.com>
Thanks John for the alternatives.
Not sure that would solve the problem as the error seems to be in the
way the shell passes data to Perl and get's it back.
Bzip - could be any other command - gzip or mv, for that matter - seems
as though the file is locked by Perl ?
I thought that because it's unix | perl | unix I thought the file
handling would all be done by Unix ?
Simon
John W. Krahn wrote:
> Simon O wrote:
> >
> > I have this Unix Borne shell script that does something like this in a
> > loop :
> >
> > for FILE in *
> > do
> > ROW_COUNT_HEADER=`...`
> > if [ ${ROW_COUNT_HEADER} -ne 0 ]
> > then
> > ...
> > # 1) OLD Option with Sed :
> > # cat ${FILE} | cut -f1-32 | sed "s/$/ ${FILE}/g" >> file.dat
> > # 2) NEW Option with Perl :
> > cat ${FILE} | cut -f1-32 | perl -ple "s/$/\t${FILE}/g" >>
> > file.dat
>
> You don't need the /g option because /$/ only occurs once in every line.
>
> Or you could do that like:
>
> perl -F'\t' -lane'splice @F, 32; print join "\t", @F, $ARGV' ${FILE}
> >> file.dat
>
>
> > fi
> > bzip2 ${FILE}
> > mv ${FILE}.bz2 ${LATEST_ARCHIVE}/IGCPDATA/
> > done
> >
> > I was having problems with using sed, so changed to option 2) using
> > perl which then gave a really weird error. It does what it's supposed
> > to but when it gets to the bzip / move section, it gives an error as
> > though it's still busy with ${FILE} ?? - being driving me MAD ! Almost
> > as though Perl is has said it's finished but is not ?
> >
> > The error is this :
> >
> > bzip2: I/O or other error, bailing out. Possible reason follows.
> > bzip2: No such file or directory
> > Input file = ABS_MTM_By_Trade, output file =
> > ABS_MTM_By_Trade.bz2
> > bzip2: Deleting output file ABS_MTM_By_Trade.bz2, if it exists.
> > bzip2: WARNING: deletion of output file (apparently) failed.
>
> I don't know enough about bzip to be able to diagnose its errors.
>
>
>
> John
> --
> use Perl;
> program
> fulfillment
------------------------------
Date: Thu, 15 Jun 2006 13:51:24 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Unix shell script with Perl one-liner causes error
Message-Id: <e6rons.174.1@news.isolution.nl>
Simon O schreef:
> for FILE in *
> do
> cat ${FILE} | cut -f1-32 | perl -ple "s/$/\t${FILE}/g"
> >> file.dat
> done
Probably unrelated to your problem, but the /g modifier is not right.
Same with the sed command. In both cases, the substitution is done per
line.
You don't need cut:
for FILE in *
do
perl -ple "s/^([^\t]*(?:\t[^\t]*){0,31}).*$/\$1\t$FILE/" \
"$FILE" >> file.dat
done
You can of course also do that shell-for-loop in Perl (the language).
You can even get rid of the shell-script and do it all with perl (the
implementation), which would give you better control over what goes
wrong. :)
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Thu, 15 Jun 2006 12:28:09 GMT
From: "Mumia W." <mumia.w.18.spam+nospam.usenet@earthlink.net>
Subject: Re: Unix shell script with Perl one-liner causes error
Message-Id: <tnckg.6147$o4.4661@newsread2.news.pas.earthlink.net>
Simon O wrote:
> Hi there
>
> I have this Unix Borne shell script that does something like this in a
> loop :
>
> for FILE in *
> do
> ROW_COUNT_HEADER=`...`
> if [ ${ROW_COUNT_HEADER} -ne 0 ]
> then
> ...
> # 1) OLD Option with Sed :
> # cat ${FILE} | cut -f1-32 | sed "s/$/ ${FILE}/g" >> file.dat
> # 2) NEW Option with Perl :
> cat ${FILE} | cut -f1-32 | perl -ple "s/$/\t${FILE}/g" >>
> file.dat
Perhaps you need to backslash escape that first '$':
s/\$/\t${FILE}/g
Or you could just print:
perl -nle "print; print q[ ${FILE}]"
> [...]
------------------------------
Date: Thu, 15 Jun 2006 13:02:14 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Unix shell script with Perl one-liner causes error
Message-Id: <qTckg.42979$771.12175@edtnps89>
Simon O wrote:
> Thanks John for the alternatives.
>
> Not sure that would solve the problem as the error seems to be in the
> way the shell passes data to Perl and get's it back.
>
> Bzip - could be any other command - gzip or mv, for that matter - seems
> as though the file is locked by Perl ?
No, Perl does not lock the file, and even if you had explicitly flock()ed the
file, locking files in Unix is only advisory. Besides which, in your example,
there is no physical file to lock because the data is being piped to perl from
another program.
> I thought that because it's unix | perl | unix I thought the file
> handling would all be done by Unix ?
Each process in the pipe, be it cut or sed or awk or tr or perl, etc., treats
the data the same way.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 15 Jun 2006 09:26:29 +0200
From: Pascal Costanza <pc@p-cos.net>
Subject: Re: What is Expressiveness in a Computer Language
Message-Id: <4fcgd5F1hv9ilU1@individual.net>
Neelakantan Krishnaswami wrote:
> In article <4fb97sF1if8l6U1@individual.net>, Pascal Costanza wrote:
>> Torben Ęgidius Mogensen wrote:
>>
>>> On a similar note, is a statically typed langauge more or less
>>> expressive than a dynamically typed language? Some would say less, as
>>> you can write programs in a dynamically typed language that you can't
>>> compile in a statically typed language (without a lot of encoding),
>>> whereas the converse isn't true.
>> It's important to get the levels right here: A programming language
>> with a rich static type system is more expressive at the type level,
>> but less expressive at the base level (for some useful notion of
>> expressiveness ;).
>
> This doesn't seem obviously the case to me. If you have static
> information about your program, the compiler can use this information
> to automate a lot of grunt work away.
>
> Haskell's system of typeclasses work this way. If you tell the
> compiler how to print integers, and how to print lists, then when you
> call a print function on a list of list of integers, then the compiler
> will automatically figure out the right print function using your base
> definitions. This yields an increase in Felleisen-expressiveness over
> a dynamically typed language, because you would need to globally
> restructure your program to achieve a similar effect.
>
> More dramatic are the "polytypic" programming languages, which let you
> automate even more by letting you write generic map, fold, and print
> functions which work at every type.
Yes, but these decisions are taken at compile time, without running the
program.
Pascal
--
3rd European Lisp Workshop
July 3 - Nantes, France - co-located with ECOOP 2006
http://lisp-ecoop06.bknr.net/
------------------------------
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 9300
***************************************