[26757] in Perl-Users-Digest
Perl-Users Digest, Issue: 8834 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 6 14:05:43 2006
Date: Fri, 6 Jan 2006 11:05:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 6 Jan 2006 Volume: 10 Number: 8834
Today's topics:
Re: calling subroutine , name derived from variable <noreply@gunnar.cc>
Re: calling subroutine , name derived from variable <sdn.girths00869@zoemail.net>
Re: calling subroutine , name derived from variable <sdn.girths00869@zoemail.net>
Re: calling subroutine , name derived from variable <matthew.garrish@sympatico.ca>
Re: calling subroutine , name derived from variable <madhuram@nortel.com>
Re: calling subroutine , name derived from variable axel@white-eagle.invalid.uk
Re: calling subroutine , name derived from variable <dha@panix.com>
Re: calling subroutine , name derived from variable <jgibson@mail.arc.nasa.gov>
Re: FAQ 6.5 How do I substitute case insensitively on t <ebohlman@omsdev.com>
Re: globbing files with spaces in the path <tadmc@augustmail.com>
Re: How to get image size in these conditions ? <.@.>
Re: How to get image size in these conditions ? <jgibson@mail.arc.nasa.gov>
IO::Pty - reads/writes fail *only* with system() <ahuxley@gmx.net>
Re: Line gives syntax error <mdudley@king-cart.com>
Re: Line gives syntax error <scobloke2@infotop.co.uk>
Re: Using system Commands In threads xhoster@gmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 06 Jan 2006 12:14:47 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: calling subroutine , name derived from variable
Message-Id: <4271lfF1gtbqaU1@individual.net>
Bernard El-Hagin wrote:
> Gunnar Hjalmarsson wrote:
>>Tad McClellan wrote:
>>>Madhu Ramachandran wrote:
>>>>{
>>>> my ($arg1) = @_;
>>>
>>>I think not.
>>
>>Why not?
>
> You snipped the bit that answers your question. :)
Yeah, I see that now. Thanks!
Tad, would you like a lesson on applying an effective followup style? ;-)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 06 Jan 2006 06:05:31 -0600
From: "Eric J. Roode" <sdn.girths00869@zoemail.net>
Subject: Re: calling subroutine , name derived from variable
Message-Id: <Xns974348B477679sdn.comcast@216.196.97.136>
robic0 wrote in news:j6srr15ililu8mndits4ut51o1999t6lu1@4ax.com:
>
> Whats a "jump" table? Whats pesuedo-code?
Look, if you don't understand anything about elementary computer science,
that's fine, but you don't have to boast about it.
--
Eric
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`
------------------------------
Date: Fri, 06 Jan 2006 06:06:56 -0600
From: "Eric J. Roode" <sdn.girths00869@zoemail.net>
Subject: Re: calling subroutine , name derived from variable
Message-Id: <Xns974348F2A3A6Asdn.comcast@216.196.97.136>
robic0 wrote in news:1ttrr1dn4lhunfsu8nvpve6gkqesur5jjf@4ax.com:
> Why in hell would you use it in the context of a hash of "subroutines"
> ? Get off your micro-analysis and look at it from a design point of
> reference. Don't ever, ever take any class I teach...
You.... *teach*?!?
Wow. Just... wow.
--
Eric
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`
------------------------------
Date: Fri, 6 Jan 2006 08:31:22 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: calling subroutine , name derived from variable
Message-Id: <Ciuvf.3066$H37.465003@news20.bellglobal.com>
"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:4268tmF1gt0mbU1@individual.net...
> Gunnar Hjalmarsson wrote:
>> Madhu Ramachandran wrote:
>>> I want to call subroutine, but the name of the subroutine itself is in a
>>> variable. I was able to do this. However, i also want to pass arguments
>>> ..
>>
>> my $method = 'aSub';
>> my $aa = 'bla';
>> my $subref = \&$method;
>> my $ret = $subref->($aa);
>> print "ret = $ret\n";
>>
>> sub aSub {
>> my ($arg1) = @_;
>> print "inside aSub, arg1=$arg1\n";
>> return 1;
>> }
>
> The above solution 'works', but I'd better admit that it's actually a
> symref, even if it passes strict. Matt's solution was criticized by that
> robic0 character, which proves that Matt provided a better answer.
>
ROTFL! I'll take the compliment... : )
Matt
------------------------------
Date: Fri, 6 Jan 2006 09:21:22 -0500
From: "Madhu Ramachandran" <madhuram@nortel.com>
Subject: Re: calling subroutine , name derived from variable
Message-Id: <dplud4$d1o$1@zcars129.ca.nortel.com>
Thank you very much for the help.
"Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
news:n1jvf.41090$X25.916828@news20.bellglobal.com...
>
> "Madhu Ramachandran" <madhuram@nortel.com> wrote in message
> news:dpkck1$g8b$1@zcars129.ca.nortel.com...
>> all:
>>
>> I want to call subroutine, but the name of the subroutine itself is in a
>> variable. I was able to do this. However, i also want to pass arguments
>> .. not able to do this.
>
> You're looking for symbolic references, but it's not good practice to use
> them. For example:
>
> $subRef = 'this_sub';
> $arg1 = 'first argument';
> $arg2 = 'second argument';
>
> &{$subRef}($arg1, $arg2);
>
> sub this_sub {
> print "$_[0] : $_[1]\n";
> }
>
>
> It's better practice to use a hash as you won't break the strictures
> pragma that way, which should make your code easier to maintain:
>
> my %subRefs = ( this_sub => \&this_sub );
>
> my $subRef = 'this_sub';
>
> my $arg1 = 'first argument';
> my $arg2 = 'second argument';
>
> $subRefs{$subRef}($arg1, $arg2);
>
> sub this_sub {
> print "$_[0] : $_[1]\n";
> }
>
> Matt
>
------------------------------
Date: Fri, 06 Jan 2006 17:08:03 GMT
From: axel@white-eagle.invalid.uk
Subject: Re: calling subroutine , name derived from variable
Message-Id: <Ttxvf.21305$iz3.6947@text.news.blueyonder.co.uk>
Madhu Ramachandran <madhuram@nortel.com> wrote:
> I want to call subroutine, but the name of the subroutine itself is in a
> variable. I was able to do this. However, i also want to pass arguments ..
> not able to do this.
> eg: if $sub has the subroutine name, and $arg has the arg to the subroutine.
> How can i call this from my perl main program? i tried eval() and it worked
> if i dont have any arguments.
> #!/usr/local/bin/perl
>
> $method="aSub";
> $aa="\"bla\"";
> $mm = "$method" . "($aa)";
> print ("mm = $mm\n");
> $ret = eval($mm);
> print ("ret = $ret\n");
> $ret=eval($method);
> print ("ret = $ret\n");
>
> sub aSub()
> {
> my ($arg1) = @_;
> print ("inside aSub, arg1=$arg1\n");
> return 1;
> }
Try:
#!/usr/local/bin/perl
use strict;
use warnings;
my $method="aSub";
my $aa= 'bla';
no strict;
my $ret = eval(&$method ($aa));
use strict;
print "ret = ", $ret "\n";
sub aSub() {
my $arg1 = shift;
print "inside aSub, arg1=", $arg1, "\n");
return 1;
}
------------------------------
Date: Fri, 6 Jan 2006 17:44:45 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: calling subroutine , name derived from variable
Message-Id: <slrndrtb4e.5lq.dha@panix2.panix.com>
On 2006-01-06, Eric J. Roode <sdn.girths00869@zoemail.net> wrote:
> robic0 wrote in news:1ttrr1dn4lhunfsu8nvpve6gkqesur5jjf@4ax.com:
>
>> Why in hell would you use it in the context of a hash of "subroutines"
>> ? Get off your micro-analysis and look at it from a design point of
>> reference. Don't ever, ever take any class I teach...
>
> You.... *teach*?!?
>
> Wow. Just... wow.
In the words of Robert Downey Jr., actually, that clears up a lot of
things...
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
Don't you remember High School? I know, for myself, I was a walking
hormone.
- Alyson Hannigan
------------------------------
Date: Fri, 06 Jan 2006 09:55:46 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: calling subroutine , name derived from variable
Message-Id: <060120060955466066%jgibson@mail.arc.nasa.gov>
In article <Xns974348F2A3A6Asdn.comcast@216.196.97.136>, Eric J. Roode
<sdn.girths00869@zoemail.net> wrote:
> robic0 wrote in news:1ttrr1dn4lhunfsu8nvpve6gkqesur5jjf@4ax.com:
>
> > Why in hell would you use it in the context of a hash of "subroutines"
> > ? Get off your micro-analysis and look at it from a design point of
> > reference. Don't ever, ever take any class I teach...
>
> You.... *teach*?!?
>
> Wow. Just... wow.
There are a lot of bad programmers in this world (many of them post
articles on clpm). Do you think they were just born that way? Somebody
has to teach them to program badly. There is a niche for everyone in
this world. :)
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
Date: 6 Jan 2006 14:30:48 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: FAQ 6.5 How do I substitute case insensitively on the LHS while preserving case on the RHS?
Message-Id: <Xns974356229C46Debohlmanomsdevcom@130.133.1.4>
PerlFAQ Server <comdog@pair.com> wrote in
news:dplip6$gvr$1@reader2.panix.com:
> 6.5: How do I substitute case insensitively on the LHS while
> preserving case on the RHS?
>
>
>
> Here's a lovely Perlish solution by Larry Rosler. It exploits
> properties of bitwise xor on ASCII strings.
Given that Perl now supports Unicode, do we really still want to be
offering something that works only for ASCII as the first option?
------------------------------
Date: Fri, 6 Jan 2006 08:53:35 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: globbing files with spaces in the path
Message-Id: <slrndrt13f.e0i.tadmc@magna.augustmail.com>
robic0 <> wrote:
> I'ts hard to cut and past
> with ratioanal.
^^^^^^^^^
^^^^^^^^^ ?
Is that when someone is only fractionally an asshole?
(if so, then it wouldn't be applying to you, so what's the problem?)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 6 Jan 2006 14:54:17 +0100
From: BlinKol <.@.>
Subject: Re: How to get image size in these conditions ?
Message-Id: <MPG.1e2894f9e7a517f798972b@news.tiscali.fr>
In article <WtDuf.12214$vH5.616211@news.xtra.co.nz>,
tintin@invalid.invalid says...
>
> "BlinKol" <.@.> wrote in message
> news:MPG.1e24ecf16b4b812e989729@news.tiscali.fr...
> > How to get width and height of an image file (GIF or JPEG), knowing my
> > hosting provider has just the Perl 5.00503 stock modules (i.e. without
> > things like Image::Info or Image::Size) and doesn't allow any new module
> > install out of my own cgi-bin directory ?
>
> Well, just install Image::Size under your cgi-bin directory. It's a very
> simple module.
>
>
>
Well, thanks, I think this is the right way. Nevertheless, never
isntalled in own cgi-bin : do I simply have to upload, chmod 755 and
indicate "use lib path-to-image-info-module" in my own script ?
------------------------------
Date: Fri, 06 Jan 2006 10:16:38 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: How to get image size in these conditions ?
Message-Id: <060120061016381235%jgibson@mail.arc.nasa.gov>
In article <MPG.1e2894f9e7a517f798972b@news.tiscali.fr>, BlinKol <.@.>
wrote:
> In article <WtDuf.12214$vH5.616211@news.xtra.co.nz>,
> tintin@invalid.invalid says...
> >
> > "BlinKol" <.@.> wrote in message
> > news:MPG.1e24ecf16b4b812e989729@news.tiscali.fr...
> > > How to get width and height of an image file (GIF or JPEG), knowing my
> > > hosting provider has just the Perl 5.00503 stock modules (i.e. without
> > > things like Image::Info or Image::Size) and doesn't allow any new module
> > > install out of my own cgi-bin directory ?
> >
> > Well, just install Image::Size under your cgi-bin directory. It's a very
> > simple module.
> >
>
> Well, thanks, I think this is the right way. Nevertheless, never
> isntalled in own cgi-bin : do I simply have to upload, chmod 755 and
> indicate "use lib path-to-image-info-module" in my own script ?
See the instructions given by 'perldoc -q "own module"'.
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
------------------------------
Date: Fri, 6 Jan 2006 17:01:38 +0100
From: Alexis Huxley <ahuxley@gmx.net>
Subject: IO::Pty - reads/writes fail *only* with system()
Message-Id: <slrndrt531.2ml.ahuxley@dione.no-ip.org>
Starting from the example in the IO::Pty man page I've now got a
perl script which forks, the child reopens stdin/stdout on the
slave side of the pty, and the parent reopens on the master side.
The child writes to STDOUT using 'print', the parent reads from
STDIN using 'while (<>) ...'. This works fine.
I changed the child to write using 'system("echo ...")' and later
I changed the parent to read using 'sed' or 'cat'. This fails,
and I can't see why.
Using only the child using 'system()' the output simply never
appears on the parent side. Using only the parent using 'system()'
results in:
sed: read error on stdin: Bad file descriptor
I tried various combinations of the set_raw() and setting the
controlling terminal of the child using the documented methods,
but still no dice. Googling brings up plenty of pre-OO examples
of pty but nothing besides what's in the FAQ and the perlipc
man page.
Judging by the sed error message, I guess somehow my plumbing
of file handles has gone wrong, but I just can't see it, especially
as it works when - as mentioned above - I use 'print' for the
output and 'while (<>) ..." for the input. Has anybody any ideas?
The script is short and reproduced below. As it is it works, but
with either of the current write/read lines replaced by the
system() equivalents, it will fail:
#!/usr/bin/perl
use IO::Pty;
$pty = new IO::Pty;
$slave = $pty->slave;
(defined($pid = fork)) || die "fork failed";
# Child
if ($pid == 0) {
$pty->make_slave_controlling_terminal() || die;
close($pty);
# Remap stdin and stdout to slave side of pty
close(STDOUT);
open(STDOUT, ">&=" . $slave->fileno) || die;
close(STDIN);
open(STDIN, "<&=" . $slave->fileno) || die;
# -- write options: print works, system doesn't!
print "To be or not to be, that is the question.\n";
#system("echo \"To be or not to be, that is the question.\"");
# Tidy up
close($slave);
# Parent
} else {
$pty->close_slave();
# Remap stdin and stdout to master side of pty
close(STDOUT);
open(STDOUT, ">&=" . $pty->fileno) || die;
close(STDIN);
open(STDIN, "<&=" . $pty->fileno) || die;
# -- read options: print (<>), system doesn't!
while (<>) { chomp; print STDERR "parent read from slave: $_\n"; }
#system("sed 's/^/parent read from slave: /'");
# Tidy up
close($pty);
}
In case it's relevent:
This is perl, v5.8.4 built for i386-linux-thread-multi, running on
Debian Linux.
(Ultimately what I'm trying to do is rewrite a script I googled called
ssh-ppp, which runs 'ssh <host> pppd' in one half, and 'pppd' in
the other. Yes, I know that pppd has a 'pty' directive, but that just
doesn't cut the mustard for what I want ,which is to do
'su -c "ssh -t <first-hop> ssh -t <second-hop> slogin <third-hop>"'
where my shell on <third-hop> is pppd, and all hops require inputting
password, and avoiding entering passwords by using RSA authentication
is neither possible nor desirable.)
Thanks for reading so far :-) and any advice you can offer; the
results of this labour will be google-able.
Alexis
------------------------------
Date: Fri, 06 Jan 2006 11:04:19 -0500
From: Marshall Dudley <mdudley@king-cart.com>
Subject: Re: Line gives syntax error
Message-Id: <43BE9503.E75BD53D@king-cart.com>
Anno Siegel wrote:
> You don't have to *echo* the passcode to get it into gpg's stdin. Untested:
>
> open my $gpg, "| gpg $options $filename" or die;
> print $gpg $passcode;
> close $gpg or die;
>
> is much safer.
That does work, except I had to take the die out of the close statement. I had
changed it to 'close $gpg or die print "$! closing gpg";'
gpg is returning a status saying it was using such and such a key for decryption and
making the script die when it was actually successful.
Thanks,
Marshall
------------------------------
Date: Fri, 6 Jan 2006 17:01:09 +0000 (UTC)
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: Re: Line gives syntax error
Message-Id: <dpm7oj$43m$1@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com>
Marshall Dudley wrote:
> Anno Siegel wrote:
>
>
>>You don't have to *echo* the passcode to get it into gpg's stdin. Untested:
>>
>> open my $gpg, "| gpg $options $filename" or die;
>> print $gpg $passcode;
>> close $gpg or die;
>>
>>is much safer.
>
>
> That does work, except I had to take the die out of the close statement. I had
> changed it to 'close $gpg or die print "$! closing gpg";'
Wrong syntax, that should be
close $gpg or die "$! closing gpg";
>
> gpg is returning a status saying it was using such and such a key for decryption and
> making the script die when it was actually successful.
>
Are you sure? It seems implausible to me. Surely gpg prints out details
of the key used to STDOUT (or less likely, to STDERR). I'd expect that
any status or return code from gpg should be zero or non-zero indicating
success or failure respectively.
------------------------------
Date: 06 Jan 2006 17:09:59 GMT
From: xhoster@gmail.com
Subject: Re: Using system Commands In threads
Message-Id: <20060106120959.513$9K@newsreader.com>
"ukmay" <darronm@model.com> wrote:
> Hello,
>
> I'm new to PERL and have just completed a script that does some process
> using an external program. The script is working great but I want to make
> use of multi-threading to run multiple copies of the external program and
> gather the output. I can get the following code to work with the system
> command ;
>
> use strict;
> use warnings;
> use Env;
> use POSIX;
> use Thread;
>
> my $thr1 = new Thread \&sub1, "vsim_1133390003.fcdb";
> my $thr2 = new Thread \&sub1, "vsim_1133390008.fcdb";
> my $thr3 = new Thread \&sub1, "vsim_1133390025.fcdb";
>
> foreach my $thr (threads->list) {
> my @ReturnData = $thr->join;
> print "Thread returned @ReturnData\n";
> }
>
> sub sub1 {
> my @InboundParameters = @_;
> my $FileName = $InboundParameters[0];
> print "Processing $FileName\n";
> #my $sys = system "vcover stats $FileName";
> return 1 ;
> }
>
> However I need to get hold of the return information from the command
> that I run from system. system() itself doesn't return the stdout so I
> have to use the ' method I believe. However as soon as I change the line
> above in sub1 to be
>
> my @value = `vcover stats $FileName `;
>
> The script hangs. Can someone help me with this as I have tried all kinds
> of things and I'm getting nowhere :)
I cannot reproduce your results. What OS and what version of perl are you
using?
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
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 8834
***************************************