[24598] in Perl-Users-Digest
Perl-Users Digest, Issue: 6774 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 7 11:05:42 2004
Date: Wed, 7 Jul 2004 08:05:08 -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 Wed, 7 Jul 2004 Volume: 10 Number: 6774
Today's topics:
Re: Auto die on failed sys calls? <krahnj@acm.org>
Re: console print issue <krahnj@acm.org>
Injecting variables after the import subroutine has bee (Daniel S.)
Re: Injecting variables after the import subroutine has <mritty@gmail.com>
Re: looping through IP address range <Eugene.Mikheyev@kiev.cms.com.ua>
Re: Math::BigFloat oddities (J. Romano)
Re: Newbie: How do I filter output to the screen and w <noreply@gunnar.cc>
Re: Newbie: How do I filter output to the screen and w <noreply@gunnar.cc>
Re: Perl and modems <mritty@gmail.com>
Perl IDEs <merman@snafu.de>
Re: Perl IDEs <mritty@gmail.com>
Re: Perl IDEs <bernard.el-haginDODGE_THIS@lido-tech.net>
Re: Perl IDEs <tadmc@augustmail.com>
problem with a script in perl. <NOTMe@ailleur.com>
Re: uninitialized? <matthew.garrish@sympatico.ca>
Re: Why is $ENV{COLUMNS} undefined inside the Perl prog <a24061@yahoo.munged>
Re: Why use dollar sign $ for variables <rene.nyffenegger@gmx.ch>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 07 Jul 2004 11:46:37 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Auto die on failed sys calls?
Message-Id: <40EBE293.CB5490A6@acm.org>
J Krugman wrote:
>
> Is there any way to instruct perl to die whenever a system call
> (e.g. through open, opendir, backticks, system, etc.) fails?
>
> The aim is to be able to enclose a series of such calls in a single
> eval block, and catch any failures at the end, instead of checking
> for them after each system call.
perldoc Fatal
John
--
use Perl;
program
fulfillment
------------------------------
Date: Wed, 07 Jul 2004 11:49:44 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: console print issue
Message-Id: <40EBE34E.BAA7F595@acm.org>
Bigus wrote:
>
> "Eugene Mikheyev" <Eugene.Mikheyev@kiev.cms.com.ua> wrote in message
> news:ccegiv$2ek1$1@news.univ.kiev.ua...
> > > that should cause an angle bracket to be printed on the commandline
> every
> > 2
> > > seconds, but instead all 5 are printed at the same time when it's
> finished
> > > the loop. Can anyone shed any light on why?
> >
> > Sure, just turn on the autoflash.
> > $| = 1;
>
> that's odd, because I've never used $| before and in some of my previous
> scripts where I've looped through a folder of log files I've included a
> progress-bar style thing, like:
>
> >>>>>>>>>>>>>>>>>>>>>
> >>>>>
>
> where the first row of brackets is the number of log files and on the second
> row a bracket is printed after each file has been processed.. and it's
> worked fine. I guess something else must have forced a flush of teh print
> statements in those cases.
You could have been printing to STDERR which isn't buffered.
John
--
use Perl;
program
fulfillment
------------------------------
Date: 7 Jul 2004 07:13:26 -0700
From: lachinois@hotmail.com (Daniel S.)
Subject: Injecting variables after the import subroutine has been called?
Message-Id: <bdcf9711.0407070613.3852eb13@posting.google.com>
Hi!
I'm the author of the Regexp::Extended module and I'm trying to inject
variables into the main perl module (like the Exporter module does).
I'm using overload:constant to modify regexp expressions and there is
an extension for named groups (?<var>pattern). However, if I try to
export '$var' at the time overload:constant is being called (after the
import sub has been executed) all I get is a segfault.
Is there a way of exporting variables during the execution of a perl
code short of using $::var?
Thanks for any help, no matter how complex or obscure.
Daniel S.
------------------------------
Date: Wed, 7 Jul 2004 10:31:45 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Injecting variables after the import subroutine has been called?
Message-Id: <20040707102738.N22150@barbara.cs.rpi.edu>
On Wed, 7 Jul 2004, Daniel S. wrote:
> Hi!
>
> I'm the author of the Regexp::Extended module and I'm trying to inject
> variables into the main perl module (like the Exporter module does).
>
> I'm using overload:constant to modify regexp expressions and there is
> an extension for named groups (?<var>pattern). However, if I try to
> export '$var' at the time overload:constant is being called (after the
> import sub has been executed) all I get is a segfault.
>
> Is there a way of exporting variables during the execution of a perl
> code short of using $::var?
Er, is there a reason you can't just use the import function in your main
code?
#!/usr/bin/perl
use strict;
use warnings;
use MyMod('$foo');
print "Module's foo value: $foo\n";
import MyMod ('$bar');
print "Module's bar value: $bar\n";
__END__
Of course, MyMod in this case would still have to have $bar in it's
@EXPORT_OK array.
'use' is nothing more than a call to require and import wrapped in a
BEGIN{} block.
Paul Lalli
------------------------------
Date: Wed, 7 Jul 2004 14:20:19 +0300
From: "Eugene Mikheyev" <Eugene.Mikheyev@kiev.cms.com.ua>
Subject: Re: looping through IP address range
Message-Id: <ccgmbn$d93$1@news.univ.kiev.ua>
use strict;
use Benchmark;
timethese(
10000,
{
Join1 => sub {
my @parts = (10, 10, 10);
for my $last_part (0..255) {
my $ip = join '.', @parts, $last_part;
do_something( $ip );
}
},
Join2 => sub {
my @parts = (10, 10, 10);
for (my $last_part = 0; $last_part <= 255; $last_part++) {
do_something(join '.', @parts, $last_part);
}
},
Join3 => sub {
for my $last_part (0 .. 255) {
do_something("10.10.10.$last_part");
}
},
Exp1 => sub {
for my $ip ( map "10.10.10.$_", 0 .. 255 ) {
do_something( $ip );
}
},
Exp2 => sub {
map do_something("10.10.10.$_"), 0 .. 255
}
}
);
sub do_something {
my $myvar = shift;
}
Results:
------------
Benchmark: timing 10000 iterations of Exp1, Exp2, Join1, Join2, Join3...
Exp1: 5 wallclock secs ( 5.17 usr + 0.00 sys = 5.17 CPU) @
1933.49/s (n=10000)
Exp2: 5 wallclock secs ( 4.75 usr + 0.00 sys = 4.75 CPU) @
2105.26/s (n=10000)
Join1: 6 wallclock secs ( 5.19 usr + 0.00 sys = 5.19 CPU) @
1927.53/s (n=10000)
Join2: 4 wallclock secs ( 4.28 usr + 0.00 sys = 4.28 CPU) @
2335.90/s (n=10000)
Join3: 3 wallclock secs ( 2.88 usr + 0.00 sys = 2.88 CPU) @
3478.26/s (n=10000)
Join3 results show that interpolating and then looping is worse than just
looping and interpolating :)
I bet that's because of foreach cycle.
Strange why Exp2 is worse than Join3... But maybe that's because map needs
to create a list for output.
------------------------------
Date: 7 Jul 2004 07:09:00 -0700
From: jl_post@hotmail.com (J. Romano)
Subject: Re: Math::BigFloat oddities
Message-Id: <b893f5d4.0407070608.3002f3cc@posting.google.com>
jl_post@hotmail.com (J. Romano) wrote in message news:<b893f5d4.0407061706.64cca68e@posting.google.com>...
>
> Using the '-=' operator on a Math::BigInt object calls the bsub()
> method, which subtracts two Math::BigInt objects by doing the
> following:
>
> 1. It flips the sign of the second object (to negate it)
> 2. It adds the two objects together (with the badd() method)
> 3. It flips the sign of the second object again (to restore it)
Let me clarify a bit here. Suppose we had two Math::BigInt
variables:
my $a = Math::BigInt->new(5); # $a equals 5
my $b = Math::BigInt->new(1); # $b equals 1
and we used them together with the '-=' operator, like this:
$a -= $b;
The '-=' operator basically does the following three steps:
1. It temporarily negates $b:
$b = -$b; # $b is now -1
2. It adds $a and $b and puts the result in $a:
$a = $a + $b; # same as: $a = 5 + -1 (which equals 4)
3. It negates $b again to restore its original sign:
$b = -$b; # $b is now back to 1
If $x was declared with a line like:
my $x = Math::BigInt->new(3); # $x equals 3
You can see why the operator '-=' messes up with a line like:
$x -= $x;
by applying the same three steps to $x:
1. It temporarily negates $x:
$x = -$x; # $x is now -3
2. It adds $x and $x and puts the result in $x:
$x = $x + $x; # same as: $x = -3 + -3 (which equals -6)
3. It negates $x again to restore its original sign:
$x = -$x; # $x is now 6 (not zero)!
If you understood that, this should make more sense now:
> Apparently the bsub() method assumes that the first and second object
> are NOT the same. But since they are, when steps 1 and 3 get carried
> out, both the first object AND the second object get their sign
> flipped.
A better fix than the one I suggested last time would be to give
the second object a copy of the first if it's found that they are both
references to the same object:
if (overload::StrVal($x) eq overload::StrVal($y))
{
# The first and second objects are the same,
# so give the second a copy of the first:
$y = Math::BigInt->new($x);
}
This fix should go in the Math::BigInt::bsub() method right before the
sign of $y is flipped. Unlike the previous fix I suggested, this fix
should be able to handle NaN values. It might use a little more
overhead (by creating a new copy of a Math::BigInt), but that's fairly
negligible due to the fact that a line like "$x -= $x" rarely ever
gets called.
So that's the reason for the bug with the '-=' operator in
Math::BigInt. I'm not sure if Math::BigFloat inherits the same bug,
or if it's a different one altogether. Either way, I hope this clears
up some confusion (and some bugs!).
-- Jean-Luc Romano
------------------------------
Date: Wed, 07 Jul 2004 14:58:09 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Newbie: How do I filter output to the screen and writing the orginal output to a file?
Message-Id: <2l2b6vF7qbtbU1@uni-berlin.de>
Anno Siegel wrote:
> Backticks and qx wait until the background process is finished and
> deliver all the output at once. To see the lines of output as they
> appear, open a filehandle to capture the output. Untested:
>
> open my $proc, "@args |";
> /^(\s*--.+)/ and print "$1\n" while <$proc>;
Thanks, Anno!
So, then a solution to the OP's question may be:
open my $log, '>> build.log' or die $!;
open my $proc, "@args |" or die $!;
while (<$proc>) {
print $log $_;
print if /^(\s*--.+)/;
}
close $proc;
close $log;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 07 Jul 2004 15:17:22 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Newbie: How do I filter output to the screen and writing the orginal output to a file?
Message-Id: <2l2cb4F7qappU1@uni-berlin.de>
Gunnar Hjalmarsson wrote:
>
> print if /^(\s*--.+)/;
That can obviously be shortened to:
print if /^\s*--/;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 7 Jul 2004 09:34:52 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Perl and modems
Message-Id: <20040707093217.F22150@barbara.cs.rpi.edu>
On Wed, 7 Jul 2004, timgerr wrote:
> I want to write a script that will send information to the modem to
> automate a phone queue that I have to call every say. I heard that this
> can be done in perl but I am net to perl. Can someone point me in a
> direction?
How new to Perl are you? If you need to learn the basics, I point you to
http://learn.perl.org
If you are comfortable with the language, I point you to CPAN. This is
the place you go when you wonder "Has anyone already done ____" in Perl?
You start your search of CPAN at http://search.cpan.org.
In this case, a search for "Modem" turned up this likely candidate:
http://search.cpan.org/~cosimo/Device-Modem-1.36/docs/Modem.pod
Paul Lalli
------------------------------
Date: Wed, 07 Jul 2004 15:20:18 +0200
From: Thomas Kaufmann <merman@snafu.de>
Subject: Perl IDEs
Message-Id: <40EBF892.3060206@snafu.de>
Hi there,
I'm a Perl-Newbie and I looking for good and modern Perl-IDEs. Can you help me?
o-o
Thomas
------------------------------
Date: Wed, 7 Jul 2004 09:13:15 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Perl IDEs
Message-Id: <20040707091226.Y22150@barbara.cs.rpi.edu>
On Wed, 7 Jul 2004, Thomas Kaufmann wrote:
> Hi there,
>
> I'm a Perl-Newbie and I looking for good and modern Perl-IDEs. Can you help me?
This topic has been covered about 4 times in the past 2 months of this
group. Go to groups.google.com, and search the archives of this group for
"IDE" or "editor".
Paul Lalli
------------------------------
Date: Wed, 7 Jul 2004 15:14:06 +0200
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: Perl IDEs
Message-Id: <Xns951F9B54EE7CCelhber1lidotechnet@62.89.127.66>
Thomas Kaufmann <merman@snafu.de> wrote:
> Hi there,
>
> I'm a Perl-Newbie and I looking for good and modern Perl-IDEs. Can
> you help me?
Console + screen + vim. Oh wait, you said modern. xterm + screen + vim.
--
Cheers,
Bernard
------------------------------
Date: Wed, 7 Jul 2004 09:25:33 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Perl IDEs
Message-Id: <slrnceo1ut.31f.tadmc@magna.augustmail.com>
Thomas Kaufmann <merman@snafu.de> wrote:
> I'm a Perl-Newbie
Please check the Perl FAQ *before* posting to the Perl newsgroup.
> and I looking for good and modern Perl-IDEs. Can you help me?
perldoc -q IDE
Is there an IDE or Windows Perl Editor?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 7 Jul 2004 13:21:51 +0200
From: "Andre" <NOTMe@ailleur.com>
Subject: problem with a script in perl.
Message-Id: <ccgm55$eur$1@bemesrrs011.be.eds.com>
Hello,
not too sure if this is a perl 5.8 or a sendmail (8.12.9).
I have made a script that extract, and save the attachment. I work well but.
if a line, in the attachemant is longer than 139 characteres, the complet
output is screwed with line of differnet lenght, containing aditionnal
characters (like "=" ) even outside the attachment.
a loop like
LOG="/tmp/mail";
while (<>) {
print LOG $_;
}
contains the errors if the attachemnt contains long lines.
Any idea ??
Many thanks in advances.
Andre
------------------------------
Date: Wed, 7 Jul 2004 09:41:13 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: uninitialized?
Message-Id: <Y3TGc.38455$JG5.743020@news20.bellglobal.com>
"Paul Lalli" <mritty@gmail.com> wrote in message
news:20040706223018.V22150@barbara.cs.rpi.edu...
> On Tue, 6 Jul 2004, Matt Garrish wrote:
>
> > "Ken Sington" <ken_sington@nospam_abcdefg.com> wrote in message
> > news:EuudnYiVgJi-xXbdRVn_iw@speakeasy.net...
> > > uninitialized? Isn't it already?
> > >
> > > #!/usr/bin/perl -T
> > >
> > > use warnings;
> > > use strict;
> > >
> > > my $a=1;
> > >
> > > unless ($a eq undef|| $a eq 0){
> > > print "\$a = $a\n";
> > > }
> > >
> > >
> >
> > Because "undef" is a bareword
>
> No it's not. No more than print or push or pop are barewords.
>
D'oh! I meant function. Barewords don't cause undefined errors, of course...
: )
Matt
------------------------------
Date: Wed, 07 Jul 2004 13:50:24 GMT
From: Adam <a24061@yahoo.munged>
Subject: Re: Why is $ENV{COLUMNS} undefined inside the Perl program?
Message-Id: <AcTGc.200$zG7.2039977@news-text.cableinet.net>
On Monday 05 July 2004 12:55, Joe Smith wrote:
> You can catch errors using eval{}.
>
> use Term::ReadKey;
> my ($wchar, $hchar, $wpixels, $hpixels);
> eval { ($wchar, $hchar, $wpixels, $hpixels) = GetTerminalSize() };
> if (defined $wchar) {
> print "Width and height = $wchar, $hchar\n";
> } else {
> print "Terminal size is undefined\n";
> }
Thanks! I'd forgotten about using eval for error-catching.
------------------------------
Date: 7 Jul 2004 11:06:55 GMT
From: Rene Nyffenegger <rene.nyffenegger@gmx.ch>
Subject: Re: Why use dollar sign $ for variables
Message-Id: <slrncenm0j.3lk.rene.nyffenegger@zhnt60m34.netarchitects.com>
> Unlike /bin/sh, bash, tcsh, etc, perl does not interpret (parse and
> execute) the script a line at a time as you implied.
>
> In the absence of any 'use' statements or BEGIN{} blocks, perl parses
> the entire program before executing any code. It does this every time
> the perl script is invoked, vaguely like an interpreter, but perl
> definitely has a compile phase and a run phase.
> -Joe
Just out of curiosity: would it be possible to store the compiled/parsed
script away and load it later so that a script doesn't have to be
compiled again if it hasn't changed?
Rene
--
Rene Nyffenegger
http://www.adp-gmbh.ch/
------------------------------
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 6774
***************************************