[22328] in Perl-Users-Digest
Perl-Users Digest, Issue: 4549 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 11 11:05:52 2003
Date: Tue, 11 Feb 2003 08:05:07 -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 Tue, 11 Feb 2003 Volume: 10 Number: 4549
Today's topics:
Re: building hash (Anno Siegel)
Re: building hash <bigj@kamelfreund.de>
Re: building hash <tassilo.parseval@post.rwth-aachen.de>
Re: building hash <jvandervloet@hotmail.com>
Re: call subroutines from a different file <dbird@no-spam.sghms.ac.uk>
Can you run linux and perl on a floppy ? <andrew.rich@bigpond.com>
Re: Can you run linux and perl on a floppy ? (Jay Tilton)
Re: Can you run linux and perl on a floppy ? <wichmann@uni-wuppertal.de>
Re: Declaring an array member in a object. <perl-dvd@darklaser.com>
Does anyone know if ... <SSEA@SSEAweb.com>
Re: Does anyone know if ... (Helgi Briem)
Insecure Filehandle Dependencies <j.j.konkle-parker@larc.nasa.gov>
Re: Insecure Filehandle Dependencies <tassilo.parseval@post.rwth-aachen.de>
Re: Insecure Filehandle Dependencies <flavell@mail.cern.ch>
Re: iterator in for loop <bart.lateur@pandora.be>
Re: Paging output (Anirban Banerjee)
Re: proxyreq.al? (Anno Siegel)
Re Installing modules from CPAN <brian.smart@blueyonder.co.uk>
Re: Re Installing modules from CPAN (Tad McClellan)
Re: Scope of a global lexical (Greg)
Re: Scope of a global lexical (Greg)
Re: strict and warnings <noreply@gunnar.cc>
Re: strict and warnings <tassilo.parseval@post.rwth-aachen.de>
Re: strict and warnings <bkennedy@hmsonline.com>
Re: unix copy command? <me@privacy.net>
Re: Why won't my for loop work? (Helgi Briem)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 11 Feb 2003 11:17:10 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: building hash
Message-Id: <b2am3m$pjj$1@mamenchi.zrz.TU-Berlin.DE>
joeri <jvandervloet@hotmail.com> wrote in comp.lang.perl.misc:
> Tassilo v. Parseval wrote:
>
> > But still, this is not
> > the problem in your case. It's simply the memory.
>
> I have 512 MB of RAM on a windows 2000 machine. This means that storing
> a file which has a size on disk of 75MB into a hash, will take more than
> 400 MB of memory?
Easily. On my machine I find that a hash built from short strings
occupies about 9 times the space of the raw data. The relation may
look better when the individual entries are larger, but that's the
kind of overhead to expect.
Anno
------------------------------
Date: Tue, 11 Feb 2003 12:43:16 +0100
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: building hash
Message-Id: <pan.2003.02.11.11.06.36.42340@kamelfreund.de>
On Tue, 11 Feb 2003 09:02:32 +0000, joeri wrote:
> I have a 75 MB file consisting of lines that look like:
>
> S0973708 Other operation on meninges OS
> S0873517 Excision of lesion of brain meninges
> S0873177 Excision brain meninges lesion
> S1295875 Removal of lesion of brain meninge
>
> The first element on each line is some sort of ID, followed by a tab,
> followed by some string.
> I want to load these into a hash like so, assuming that IN is the filehandle
> associated with the above file:
>
> while(<IN>) {
> $string{$1}={$2} if $_ =~ /(.*)\t(.*)\n/;
> }
Perl wastes too much memory for normal hashes to gain speed and
flexibility. In your case, you'll need probably a module using other
methods to handle hashes.
As your strings seems to have more or less fixed lengths,
Tie::SubstrHash
could be an idea.
Another is to use the quick Berkeley DB via the Perl module
Tie::DB_File
(Both available on CPAN).
Best Wishes,
Janek
------------------------------
Date: 11 Feb 2003 13:37:01 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: building hash
Message-Id: <b2au9t$gme$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Janek Schleicher:
> Perl wastes too much memory for normal hashes to gain speed and
> flexibility. In your case, you'll need probably a module using other
> methods to handle hashes.
> As your strings seems to have more or less fixed lengths,
> Tie::SubstrHash
> could be an idea.
> Another is to use the quick Berkeley DB via the Perl module
> Tie::DB_File
> (Both available on CPAN).
The thread reminds me of an idea I had been mind-toying with lately.
Writing a module (with a tie() interface) that makes all Perl data-types
store the data zlib-compressed. It could be done in XS to gain some
speed but it's probably less trivial than it sounds since on a an
ordinary FETCH the data would need to be decompressed and could thusly
explode your memory.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Tue, 11 Feb 2003 15:39:23 GMT
From: "joeri" <jvandervloet@hotmail.com>
Subject: Re: building hash
Message-Id: <LO82a.44083$Jd.5516@afrodite.telenet-ops.be>
"Janek Schleicher" <bigj@kamelfreund.de> wrote
> Perl wastes too much memory for normal hashes to gain speed and
> flexibility. In your case, you'll need probably a module using other
> methods to handle hashes.
> As your strings seems to have more or less fixed lengths,
> Tie::SubstrHash
> could be an idea.
Unfortunately, that is not the case, although that did not show in the
example lines
I posted. My apologies. But I will have a look to see if that is sth I can
use.
> Another is to use the quick Berkeley DB via the Perl module
> Tie::DB_File
> (Both available on CPAN).
Will have a look. Thanks,
J
------------------------------
Date: Tue, 11 Feb 2003 11:24:21 +0000
From: Daniel Bird <dbird@no-spam.sghms.ac.uk>
Subject: Re: call subroutines from a different file
Message-Id: <3E48DD65.4050403@no-spam.sghms.ac.uk>
Thanks,
All I need is a place to start.
Regards,
Anno Siegel wrote:
> Daniel Bird <dbird@no-spam.sghms.ac.uk> wrote in comp.lang.perl.misc:
>
>>Dear all,
>>I wish to call subroutines from a 'file'. eg:
>>
>>script1.pl calls subroutine 'printlogo' from the file 'subroutines'. Can
>>anybody assist me in what is probably quite simple?
>
>
> See perldoc perlmod.
>
> Anno
------------------------------
Date: Tue, 11 Feb 2003 22:12:47 +1000
From: "Andrew Rich" <andrew.rich@bigpond.com>
Subject: Can you run linux and perl on a floppy ?
Message-Id: <Rw52a.45379$jM5.113860@newsfeeds.bigpond.com>
Can you run linux and perl on a floppy ?
------------------------------
Date: Tue, 11 Feb 2003 12:26:04 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Can you run linux and perl on a floppy ?
Message-Id: <3e48ebb6.161820214@news.erols.com>
"Andrew Rich" <andrew.rich@bigpond.com> wrote:
: Can you run linux and perl on a floppy ?
Anybody else smell an X-Y problem?
Why would you want to do this?
------------------------------
Date: Tue, 11 Feb 2003 13:37:12 +0100
From: Ingo Wichmann <wichmann@uni-wuppertal.de>
Subject: Re: Can you run linux and perl on a floppy ?
Message-Id: <b2ar26$i9h$01$1@news.t-online.com>
Andrew Rich schrieb:
> Can you run linux and perl on a floppy ?
http://trinux.sourceforge.net/
maybe.
Ingo
------------------------------
Date: Tue, 11 Feb 2003 16:00:21 GMT
From: "David" <perl-dvd@darklaser.com>
Subject: Re: Declaring an array member in a object.
Message-Id: <p692a.7$Ob4.2706@news-west.eli.net>
"manj dodda" <dmanjunath@yahoo.com> wrote in message
news:VzW1a.377$Q73.40153338@newssvr14.news.prodigy.com...
> How do i set the array portlist to be an array in the
> object below ?.
>
> I want the portlist to be an array. Please take a look
> and comment on what i have done.
>
> Thanks in advance.
>
> ma
>
>
> package myModel
> sub new {
> my ($class) = shift;
> bless {
> "modelname" => 0,
> "@portlist" => undef
> }, $class ;
> }
>
> sub setPortlist {
> my($self) = shift;
> my(@m_portlist) = @_ ;
>
> $self->{portlist} = @m_portlist ;
> }
>
>
> sub main {
>
> @myarr = qw( tom henry jack peter) ;
> $list[$i] = myModel->new() ;
> $list[$i]->setPortList(@myArray) ;
> ## This is not working.
> }
This is untested, but I believe this should do the trick
sub setPortlist {
my($self) = shift;
$self->{portlist} = [(@_)] ;
}
Regards,
David
------------------------------
Date: Tue, 11 Feb 2003 15:16:14 GMT
From: "Basil Skordinski" <SSEA@SSEAweb.com>
Subject: Does anyone know if ...
Message-Id: <2t82a.11170$1q2.1084433@newsread2.prod.itd.earthlink.net>
Hello Everyone,
Does anyone know if there are any Perl modules out there somewhere that
could make it possible and easy to program a desired interaction with a
remote web site? I am looking to do this on the Windows NT platform. If
the modules need to work through a browser -- that's fine to.
More specifically, this is what I'm looking to do. Monitor a real-time
display of 10 to 50 numbers and when a certain combination of numbers is
displayed, establish a link with a remote web site (different from the one
that's supplying the real-time display) and automatically fill out a form on
that web site and submit it.
Any suggestions or thoughts on how to do this would be appreciated.
Thanks.
------------------------------
Date: Tue, 11 Feb 2003 15:50:45 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Does anyone know if ...
Message-Id: <3e49192e.359347734@news.cis.dfn.de>
On Tue, 11 Feb 2003 15:16:14 GMT, "Basil Skordinski"
<SSEA@SSEAweb.com> wrote:
>Hello Everyone,
>
>Does anyone know if there are any Perl modules out there somewhere that
>could make it possible and easy to program a desired interaction with a
>remote web site? I am looking to do this on the Windows NT platform. If
>the modules need to work through a browser -- that's fine to.
>
>More specifically, this is what I'm looking to do. Monitor a real-time
>display of 10 to 50 numbers and when a certain combination of numbers is
>displayed, establish a link with a remote web site (different from the one
>that's supplying the real-time display) and automatically fill out a form on
>that web site and submit it.
LWP::UserAgent;
See perldoc LWP::UserAgent for details or if you
haven't installed it yet,
http://www.perldoc.com/perl5.8.0/lib/LWP/UserAgent.html
Here is one way I have used it in the past:
#!perl
use warnings;
use strict;
use LWP::UserAgent;
use HTTP::Request::Common;
my $ua = new LWP::UserAgent;
my $server = 'server.domain.com';
my $cgipath = 'cgi-bin/path/program.cgi';
my $var = 'foo';
my $url = "http://$server/$cgipath?VAR=$var";
my $req = HTTP::Request->new(GET => $url);
my $response = $ua->request($req);
if ($response->is_error())
{ print $response->status_line; }
else
{ print $response->content(); }
__END__
--
Regards, Helgi Briem
helgi AT decode DOT is
------------------------------
Date: Tue, 11 Feb 2003 08:52:57 -0500
From: Joel Konkle-Parker <j.j.konkle-parker@larc.nasa.gov>
Subject: Insecure Filehandle Dependencies
Message-Id: <3E490039.5070804@larc.nasa.gov>
I've attached the beginning of my script. It's giving me an error at
line 95, the last line I've included. "Insecure dependency". How do I
fix this?
- Joel
----------
#!/bin/perl -wT
################################################################
# #
# NACA 0012-34 Airfoil Processor #
# #
# By: Joel Konkle-Parker #
# j.j.konkle-parker@larc.nasa.gov #
# 01/28/2003 #
# #
# Requires: #
# - Perl #
# - Getopt::Long #
# - Pro/ENGINEER 2001 #
# - Gridgen 14 #
# #
# Inputs: #
# $rawfilename - output file name (no extension) #
# $span - span of wing as multiple of chord #
# $outboard_chord - chord of outboard end of wing #
# $grid_type - structured surface, structured volume, #
# unstructured volume #
# #
# Outputs: #
# - IGES file of geometry (filename.igs) #
# - Plot3D file of structured surface grids (filename.grd) #
# - Plot3D file of structured volume grids (filename.dat) #
# - Gridgen file of unstructured volume grids (filename.gg) #
# #
################################################################
use strict;
use Getopt::Long;
my ($filename, $rawfilename, $span, $outboard_chord, $grid_type,);
$ENV{PATH} = "/bin:/usr/local/bin";
#####################
# Argument handling
#####################
GetOptions ("filename|f=s" => \$rawfilename,
"span|s=f" => \$span,
"outboard_chord|oc=f" => \$outboard_chord,
"grid_type|gt=s" => \$grid_type,
);
unless (defined $rawfilename) {
print "Enter output file name (no extension): ";
$rawfilename = <STDIN>;
chomp ($rawfilename);
}
unless (defined $span) {
print "Enter span of wing, as multiple of chord: ";
$span = <STDIN>;
chomp ($span);
}
unless (defined $outboard_chord) {
print "Enter chord at tip of wing (root chord is 1.0000): ";
$outboard_chord = <STDIN>;
chomp ($outboard_chord);
}
unless (defined $grid_type) {
print "Enter type of grid to generate (u for unstructured, s for
structured): ";
$grid_type = <STDIN>;
chomp ($grid_type);
}
if ($rawfilename !~ /\W/) {
$filename = $rawfilename;
}
else {
print "Invalid characters in filename (don't include extension).\n";
exit;
}
#########################
# Trail file generation
#########################
rename "config.pro", "config.pro.temp";
open (CONFIG, ">config.pro") || die $!."\n";
print CONFIG<<'CONFIG';
pro_unit_length unit_mm
display hiddenvis
CONFIG
close (CONFIG);
open (TRAIL, ">$filename.txt") || die $!."\n";
----------
------------------------------
Date: 11 Feb 2003 14:08:54 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Insecure Filehandle Dependencies
Message-Id: <b2b05m$ipo$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Joel Konkle-Parker:
> I've attached the beginning of my script. It's giving me an error at
> line 95, the last line I've included. "Insecure dependency". How do I
> fix this?
>
> - Joel
>
> ----------
> #!/bin/perl -wT
^^
This is good. -T is actually the source of your problem. See below.
[...]
> unless (defined $rawfilename) {
> print "Enter output file name (no extension): ";
> $rawfilename = <STDIN>;
> chomp ($rawfilename);
$rawfilename is now tainted.
> }
>
> unless (defined $span) {
> print "Enter span of wing, as multiple of chord: ";
> $span = <STDIN>;
> chomp ($span);
> }
>
> unless (defined $outboard_chord) {
> print "Enter chord at tip of wing (root chord is 1.0000): ";
> $outboard_chord = <STDIN>;
> chomp ($outboard_chord);
> }
>
> unless (defined $grid_type) {
> print "Enter type of grid to generate (u for unstructured, s for
> structured): ";
> $grid_type = <STDIN>;
> chomp ($grid_type);
> }
>
> if ($rawfilename !~ /\W/) {
> $filename = $rawfilename;
> }
This is a sanity check but it is not yet proper untainting of the data.
Currently you make sure that $filename wont contain any characters other
than alphanumericals and _. You have to apply a capturing pattern-match
to untaint the data:
if ($rawfilename !~ /\W/) {
($filename) = $rawfilename =~ /(.*)/;
}
$filename is now an exact copy of $rawfilename but it is no longer
tainted so you can eventually use it as an argument to open():
> open (TRAIL, ">$filename.txt") || die $!."\n";
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Tue, 11 Feb 2003 15:33:14 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Insecure Filehandle Dependencies
Message-Id: <Pine.LNX.4.53.0302111515350.9560@lxplus077.cern.ch>
On Feb 11, Tassilo v. Parseval inscribed on the eternal scroll:
> > #!/bin/perl -wT
> ^^
> This is good.
Yup...
> -T is actually the source of your problem.
Pardon me, but the underlying source of the "problem" could still be
there in the absence of -T, just that it would not be noticed until it
was much too late!
To put it another way, -T is not the "source of the problem", but
merely the cause of the potential problem coming to light.
Sorry if I seem to be nit picking, but this could be an important
point. I've seen too many cases where users have "solved the problem"
by simply removing -T, or strict, or whatever it was that was
provoking the diagnostic that they were getting, without taking any
thought to investigate the underlying cause.
It just so happens that in this case, the hon Usenaut knows for
other reasons that the potentially tainted variable is, in fact,
safe.
> > if ($rawfilename !~ /\W/) {
> > $filename = $rawfilename;
> > }
>
> This is a sanity check but it is not yet proper untainting of the data.
indeed
> You have to apply a capturing pattern-match
> to untaint the data:
...
> ($filename) = $rawfilename =~ /(.*)/;
...
Am I being too much of a perfectionist to suggest it's unwise to
encourage that paradigm?
OK, it _has_ been encapsulated here in some code which, in fact,
renders it safe, but wouldn't it be better general advice to untaint
$filename with an appropriate regexp? (a slight re-casting of the
other statements seems to be all that it needs).
IMHO and YMMV, cheers
------------------------------
Date: Tue, 11 Feb 2003 11:10:26 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: iterator in for loop
Message-Id: <0vlh4vsuk9lq8nsg8gpsge4gepggr6t47s@4ax.com>
squillion wrote:
>how do i tell which iteration i'm on within a for loop?
>
>i can do
>
>for (my $i=0;$i<@array;$i++) {
> print "iteration #: $i item: $array[$i]\n";
>}
>
>but i don't like that C-style idiom. what i need is a system variable
>$X to tell me which item i'm on, like:
>
>print "iteration #: $X item: $_\n" for @array;
Actually, this has been discussed quite some time ago, when desired
features for Perl6 were being discussed. So you're not alone in this
viewpoint. People were thinking of recycling the old $# special variable
for this purpose, since its original purpose is no longer of practical
value. Heck, I don't even know what it is. `perldoc perlvar` to the
rescue... Oh, it's something to do with formats. It's deprecated,
anyway. (Note: that's $#, not $#ARRAY which is something entirely
different.)
Anyway, I don't this works in current day perls, yet, so you have to
find another way, i.e. you have to take care of it for yourself,
explicitely. Two ways from the top of my head:
# Using an array index:
for my $i (0 .. $#array) {
print "iteration #: $i item: $array[$i]\n";
}
# Keep an external counter:
my $i = 0;
foreach (@array) {
print "iteration #: $i item: $array[$i]\n";
} continue {
$i++;
}
There's no easy way to incorporate it in your one-line loop, I think.
--
Bart.
------------------------------
Date: 11 Feb 2003 04:46:28 -0800
From: anerjee@yahoo.com (Anirban Banerjee)
Subject: Re: Paging output
Message-Id: <d31bf943.0302110446.7fff5dbd@posting.google.com>
How do I do it inside the perl script? I mean everything, even
<tab><tab> ( I am using ReadLine ) should give me paged output, and
this should be transparent to the individual functions.
Benjamin Goldberg <goldbb2@earthlink.net> wrote in message news:<3E4737EE.B25AB45F@earthlink.net>...
> Jodyman wrote:
> >
> > "Anirban Banerjee" <anerjee@yahoo.com> wrote in message
> >
> > > I have a written a small interactive query processor for some large
> > > log files. Sometimes a query generates a large amount of text. I
> > > want to be able to page the output whenever the data is more than a
> > > screen-full. How do I do it ?
> >
> > on *nix:
> >
> > cat largelogfile | more
>
> This is a UUoC.
>
> Just do:
> more largelogfile
>
> > or
> > pg largelogfile
>
> or:
>
> less largelogfile
>
> > or on windows:
> >
> > type largelogfile | more
>
> or:
> more < largelogfile
------------------------------
Date: 11 Feb 2003 12:25:34 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: proxyreq.al?
Message-Id: <b2aq3u$pjj$2@mamenchi.zrz.TU-Berlin.DE>
Jonas Nordstrom <jonas.nordstrom@frispar.se> wrote in comp.lang.perl.misc:
> This test code (which is originally a part of a larger program) fails
> after upgrading perl to 5.8.0.
The error is:
"Can't locate > auto/Apache/TestRewriter/proxyreq.al in @INC..."
> the error message puzzles me, where does the reference to proxyreq.al
> come from, and what does it mean?
One of the modules you use presumably defines a function proxyreq()
and then tries to execute it. The ".al" suffix is an artifact from
trying to autoload it and doesn't have to concern you.
The problem is that some Perl modules from before 5.8.0 are not
compatible with 5.8.0, namely those that have an XS component.
You'll have to re-install those.
Anno
------------------------------
Date: Tue, 11 Feb 2003 11:46:53 -0000
From: "Brian Smart" <brian.smart@blueyonder.co.uk>
Subject: Re Installing modules from CPAN
Message-Id: <Tf52a.5070$297.1604@news-binary.blueyonder.co.uk>
Thanks for the help especially from Tad McClellan. I have now managed to
install a module so onwards and upwards!
Regards
Brian Smart
------------------------------
Date: Tue, 11 Feb 2003 07:44:15 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Re Installing modules from CPAN
Message-Id: <slrnb4hvhf.3at.tadmc@magna.augustmail.com>
Brian Smart <brian.smart@blueyonder.co.uk> wrote:
> Thanks for the help especially from Tad McClellan.
You're welcome.
You should have made your followup in the same thread where
the discussion took place though, rather than starting a
new disconnected thread.
And you shouldn't put Re in the Subject when you don't make
reference to any previous post.
And you shouldn't change the Subject unless you are really
changing the subject. :-)
Threading is useful. Please don't break it.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 11 Feb 2003 06:36:37 -0800
From: gdsafford@hotmail.com (Greg)
Subject: Re: Scope of a global lexical
Message-Id: <a8f367ed.0302110636.2b92bf8@posting.google.com>
"eric" <eric.ehlers@btopenworld.com.nospam> wrote in message news:<b2920m$evk$1@knossos.btinternet.com>...
> "Greg" <gdsafford@hotmail.com> wrote in message
> news:a8f367ed.0302101149.700eb516@posting.google.com...
> > use strict;
> > use warnings;
> >
> > smith();
> >
> > my $global = 3;
> >
> > sub smith{
> > print $global || 'undef', "\n";
> > }
> >
> > This prints 'undef' when run in my local Perl 5.6 installation. How
> > can the body of smith() be interpreted without the assignment of 3 to
> > $global having taken place?
>
> the line
> my $global = 3;
> causes $global to be recognized at compile time, and set to 3 at run time.
> the compile-time recognition means that sub smith can access $global without
> generating a compile-time error under strict 'vars'.
> the run-time assignment does not happen until after the call to sub smith,
> so $global is undefined when sub smith runs.
>
> > The funny thing is that I tried running
> > this using a Perl 5.5.3 installation and printed '3'.
>
> i don't have a copy of Perl 5.5.3 to hand, if what you say is true then that
> would suggest that the behavior of "my" has changed under 5.6.
>
> > Any insight or a reference to where information might be found
> > appreciated.
> >
> > TIA
> >
> > Greg
>
> HTH
> -eric
I see. So, the statement my $global = 3; is executed both at compile
time and run time. I should have seen this. I'm used to C behavior.
Thanks much.
Greg
------------------------------
Date: 11 Feb 2003 06:37:57 -0800
From: gdsafford@hotmail.com (Greg)
Subject: Re: Scope of a global lexical
Message-Id: <a8f367ed.0302110637.7954d935@posting.google.com>
"Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de> wrote in message news:<b2942e$t6f$1@nets3.rz.RWTH-Aachen.DE>...
> Also sprach Greg:
>
> > use strict;
> > use warnings;
> >
> > smith();
> >
> > my $global = 3;
> >
> > sub smith{
> > print $global || 'undef', "\n";
> > }
> >
> > This prints 'undef' when run in my local Perl 5.6 installation. How
> > can the body of smith() be interpreted without the assignment of 3 to
> > $global having taken place? The funny thing is that I tried running
> > this using a Perl 5.5.3 installation and printed '3'.
>
> On my machine, 5.8.0, 5.6.1 and 5.00503 all behave identically with
> respect to the above code. That is, they print 'undef'. You possibly ran
> different code on each.
>
> Tassilo
Dunno. I though that I'd copied and pasted the code, but I imagine
that you must be right.
Thanks.
Greg
------------------------------
Date: Tue, 11 Feb 2003 12:12:55 GMT
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: strict and warnings
Message-Id: <bN52a.10548$LY2.628856@newsc.telia.net>
Thanks for your comments, Tassilo.
Tassilo v. Parseval wrote:
> Warnings (that aren't fatal) at least add a little overhead by printing
> something to STDERR:
>
> print undef for 0 .. 10_000;
>
> is likely to be much slower when warnings are on. Ideally, a good
> program doesn't rise warnings.
Do you mean that, provided that you see to it that the program doesn't
generate any warnings, neither 'use warnings;' has any adverse effect on
performance worth mentioning?
>>They are indeed useful when *developing* a program, but should they
>>always be left in a *production* copy?
>
> As for strictures, I think they should.
> ...
> Warnings can be taken out but best is you make sure that during
> production you weed out all of them or be sure that any warnings that
> potentially occur are harmless.
Suppose you mean during development. ;-)
>>As regards 'use warnings;', I never leave it if portability is an issue
>>(doesn't work in the earlier Perl5 versions), but sometimes I include
>>
>> $^W = 1;
>>
>>instead.
>
> Why not use the -w switch on the shebang-line?
Well, my latest program is a module: http://search.cpan.org/author/GUNNAR/
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 11 Feb 2003 13:30:19 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: strict and warnings
Message-Id: <b2attb$gaa$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Gunnar Hjalmarsson:
> Thanks for your comments, Tassilo.
>
> Tassilo v. Parseval wrote:
>> Warnings (that aren't fatal) at least add a little overhead by printing
>> something to STDERR:
>>
>> print undef for 0 .. 10_000;
>>
>> is likely to be much slower when warnings are on. Ideally, a good
>> program doesn't rise warnings.
>
> Do you mean that, provided that you see to it that the program doesn't
> generate any warnings, neither 'use warnings;' has any adverse effect on
> performance worth mentioning?
I would guess so. Warnings are again implemented via a bitmask that must
internally be checked somehow. Perhaps you can try a benchmark,
even though I am not sure whether this can be reliably done. My attempt:
#! /usr/bin/perl
use strict;
use Benchmark qw(cmpthese);
cmpthese( 1000, {
warn => sub { use warnings; for (0 .. 1000) { my $c = $_ * 2 } },
no_warn => sub { no warnings; for (0 .. 1000) { my $c = $_ * 2 } },
});
Result:
Benchmark: timing 1000 iterations of no_warn, warn...
no_warn: 2 wallclock secs ( 0.82 usr + 0.00 sys = 0.82 CPU) @ 1219.51/s (n=1000)
warn: 2 wallclock secs ( 0.81 usr + 0.00 sys = 0.81 CPU) @ 1234.57/s (n=1000)
Rate no_warn warn
no_warn 1220/s -- -1%
warn 1235/s 1% --
After several runs of the above I see that sometimes 'warn' is quicker,
sometimes 'no_warn'.
But it wont matter to you....see below.
>> Warnings can be taken out but best is you make sure that during
>> production you weed out all of them or be sure that any warnings that
>> potentially occur are harmless.
>
> Suppose you mean during development. ;-)
Yes. I must have been thinking of 'production of the code'. :-)
>>>As regards 'use warnings;', I never leave it if portability is an issue
>>>(doesn't work in the earlier Perl5 versions), but sometimes I include
>>>
>>> $^W = 1;
>>>
>>>instead.
>>
>> Why not use the -w switch on the shebang-line?
>
> Well, my latest program is a module: http://search.cpan.org/author/GUNNAR/
In this case please remove the warnings altogether. A module isn't
supposed to produce unexpected output at all. It's not very helpful for
the user of your module, either. It'll rather confuse them.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Tue, 11 Feb 2003 10:42:54 -0500
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: strict and warnings
Message-Id: <75qcnUYhE8sRh9SjXTWcpg@giganews.com>
"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:wQ32a.10539$LY2.628422@newsc.telia.net...
> I'm wondering to which extent
>
> use strict;
> use warnings;
>
> add any overhead when compiling and executing a Perl program.
>
> They are indeed useful when *developing* a program, but should they
> always be left in a *production* copy?
This is really a more general question about optimization - to what extent
should I sacrifice maintainability in order to increase performance? In
this case, turning off 'strict' makes your code less maintainable - you need
some additional code that turns it off if necessary, which needs to be
documented, etc etc. I think it's very important to *not* optimize at the
expense of maintainability unless you have established benchmarks that
justify the change. My point is there is no general rule to answer your
question - you need to benchmark your code with both versions, and see if
performance upgrade justifies the maintainability downgrade. My best guess
is that unless your code needs to save microseconds on startup, you wont see
enough of a 'win' to justify removing them from production code.
--Ben Kennedy
------------------------------
Date: Tue, 11 Feb 2003 23:20:54 +1100
From: "Tintin" <me@privacy.net>
Subject: Re: unix copy command?
Message-Id: <b2apr7$19at1l$1@ID-172104.news.dfncis.de>
"codeWarrior" <GPatnude@adelphia.net> wrote in message
news:MnQ1a.5209$jR3.2786000@news1.news.adelphia.net...
>
> "David Bruno" <dbruno@ucla.edu> wrote in message
> news:b27hu1$ctm$1@zinnia.noc.ucla.edu...
> > Hi,
> >
> > I'm trying to have a perl script copy a file from one directory
> > to another.
> > I tried "cp (/file directory/file, /destination directory)
> > and that didn't work. The error seems to be that the "cp"
> > command is not being recognized.
>>
> use File::Copy;
>
> $SOURCEFILE = "../usr/file1.doc";
> $DESTFILE = "../../file2.doc"
> $result = copy($SOURCEFILE, $DESTFILE);
much better to check the result like
copy('file1','file2') or die "Copy failed $!\n";
------------------------------
Date: Tue, 11 Feb 2003 11:42:16 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Why won't my for loop work?
Message-Id: <3e48e182.345094469@news.cis.dfn.de>
On 11 Feb 2003 10:45:03 GMT,
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>Helgi Briem <helgi@decode.is> wrote in comp.lang.perl.misc:
>> On Tue, 11 Feb 2003 06:01:06 -0000, lofstrom@lava.net (Karen
>> Lofstrom) wrote:
>>
>> >I was using chop instead of chomp because my beginner's Perl book is old;
>> >1996. Chomp must be new and improved.
>>
>> It is. Chomp removes the last character. Chop removes
>> linebreaks from the end.
>
>Correct, except it's the other way 'round :)
Whoops.
--
Regards, Helgi Briem
helgi AT decode DOT is
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 4549
***************************************