[23100] in Perl-Users-Digest
Perl-Users Digest, Issue: 5321 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 5 18:05:40 2003
Date: Tue, 5 Aug 2003 15: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 Tue, 5 Aug 2003 Volume: 10 Number: 5321
Today's topics:
Re: [regex] Can't get it to be ungreedy <jane.doe@acme.com>
Re: Brand New to Perl <cwilbur@mithril.chromatico.net>
Re: Brand New to Perl <bart.lateur@pandora.be>
Re: Brand New to Perl <flavell@mail.cern.ch>
Re: Bug or feature: using array references (Tad McClellan)
Re: Command or script to get a list of email addresses <Uniball@gmx.net>
Re: Cplex hangs in Perl system command (Wei)
Re: Final "Flocking" Script <mpapec@yahoo.com>
How do I detect if input is from a pipe or not? <badbob@somewhere.com>
Re: How do I detect if input is from a pipe or not? <grazz@pobox.com>
Re: Perl Math Syntax <jaspax@u.washington.edu>
Re: Perl Math Syntax <krahnj@acm.org>
Re: Perl Math Syntax <grazz@pobox.com>
Re: Perl Math Syntax <REMOVEsdnCAPS@comcast.net>
Re: Renaming Files inside a GZ Zip File <mikeflan@earthlink.net>
Re: Term::ANSIColor How can I print the color directly <gregs@trawna.com>
Variables Definition File (Schaltung)
Re: Variables Definition File <shawn@magma.ca>
Re: Why, oh why have I read "Perl 6 essentials"??? <dha@panix.com>
Re: Why, oh why have I read "Perl 6 essentials"??? <bigj@kamelfreund.de>
Re: Why, oh why have I read "Perl 6 essentials"??? (Tad McClellan)
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 05 Aug 2003 21:17:37 +0200
From: Jane Doe <jane.doe@acme.com>
Subject: Re: [regex] Can't get it to be ungreedy
Message-Id: <2k00jvk8eopcsnb49bkgffjt43rv4156hp@4ax.com>
On Mon, 4 Aug 2003 19:39:21 -0400, "Matt Garrish"
<matthew.garrish@sympatico.ca> wrote:
>I offer this up only as a kludge and not as an elegant solution.
Thank you very much for your help :-) Unfortunately, since the regex
engine in Privoxy doesn't seem to allow running an external program to
handle a given filter entry, I'm stuck. Bah, I can live with this :-)
Thx
JD.
------------------------------
Date: Tue, 05 Aug 2003 18:10:32 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: Brand New to Perl
Message-Id: <87vftcnfga.fsf@mithril.chromatico.net>
Eric Schwartz <emschwar@pobox.com> writes:
> Charlton Wilbur <cwilbur@mithril.chromatico.net> writes:
> > Seconded! Though I'd point out that, for someone learning, you can
> > get pretty far with the Llama book, and you don't need the Camel book
> > until you've worked your way through the Llama -- one way to spread
> > the financial pain out. You certainly don't need to buy all the books
> > at once.
>
> I'd counter that you don't need the Camel at all once you've gotten
> through the Llama. The Camel, handy as it was for learning the
> language (I'm a masochist, and went with it, albeit the perl4 version,
> when I first learned the language), isn't really very much more than
> some commentary on top of the perldocs; I found that nearly every time
> I was confused between the Camel and Perl, it was because the book was
> out-of-date.
Right, but that only applies once you know your way around Perl and
the perldocs well. The Camel book is the perldocs, plus commentary,
*with an index*. That index alone is worth the cover price of the
book for new programmers.
> > I'd add _Programming the Perl DBI_ to this as well, since a lot of
> > useful dynamic web stuff interfaces with databases.
>
> I guess; I can't imagine what's in it that wouldn't be in the DBI
> perldocs, but whatever floats your boat, hey.
Tutorial approach rather than "here are the methods; have fun"
approach. I'm not recommending books to an experienced programmer who
wants a quick reference, in which case I'd agree; I'm recommending
books to a novice who wants to learn how to program in Perl, and for
that a little bit more explanation is helpful.
Charlton
------------------------------
Date: Tue, 05 Aug 2003 20:03:20 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Brand New to Perl
Message-Id: <nb30jv0ka9ne9a256omcafks9krhne6oe2@4ax.com>
Charlton Wilbur wrote:
>The Camel book is the perldocs, plus commentary,
>*with an index*. That index alone is worth the cover price of the
>book for new programmers.
Say what?!? I can search for anything I want in perldoc, without an
index.
--
Bart.
------------------------------
Date: Tue, 5 Aug 2003 22:13:58 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Brand New to Perl
Message-Id: <Pine.LNX.4.53.0308052208450.8886@lxplus005.cern.ch>
On Tue, Aug 5, Charlton Wilbur inscribed on the eternal scroll:
> Right, but that only applies once you know your way around Perl and
> the perldocs well. The Camel book is the perldocs, plus commentary,
> *with an index*. That index alone is worth the cover price of the
> book for new programmers.
Do you think so? I'd value a book as an organised approach to
learning something - i.e organised in the way that the experienced
author chose to present it - to me as a disorganised beginner.
The problem with using the documentation for that is that each is a
piece of the jigsaw, but the beginner has no idea at first just how
the pieces could fit together.
Once that stage is over, I'd have thought that an electronic copy of
the documentation with adequate text search facilities would beat any
dead-trees version with whatever terms the indexer chose to index.
No offence meant to the actual book in question, I must stress - just
a general comment.
> Tutorial approach rather than "here are the methods; have fun"
> approach. I'm not recommending books to an experienced programmer who
> wants a quick reference, in which case I'd agree; I'm recommending
> books to a novice who wants to learn how to program in Perl, and for
> that a little bit more explanation is helpful.
Yup, that's the ticket.
------------------------------
Date: Tue, 5 Aug 2003 16:04:43 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Bug or feature: using array references
Message-Id: <slrnbj06vb.fi6.tadmc@magna.augustmail.com>
Uli Tuerk <ulit_see_signature@fs.tum.de> wrote:
> After more than one year of programming with Perl, there are always
> things to discover. Especially all those "dangerous" things going on in
> the "background" one is normally not aware of....
Being in perlsyn.pod is not the "background".
It is one of the std docs that you should be reading end-to-end
twice a year. I do.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 06 Aug 2003 00:22:33 +0300
From: Mohammed Sameer <Uniball@gmx.net>
Subject: Re: Command or script to get a list of email addresses
Message-Id: <pan.2003.08.05.21.22.32.939834@gmx.net>
On Thu, 31 Jul 2003 18:27:52 +0000, Deboo wrote:
> I tried using grep but then there are some duplicates too and finding
> and removing them would be a big hassle.
>
did you try uniq with grep ?
------------------------------
Date: 5 Aug 2003 15:02:53 -0700
From: wei_zhao2000@hotmail.com (Wei)
Subject: Re: Cplex hangs in Perl system command
Message-Id: <2673a9d5.0308051402.18ff70b@posting.google.com>
Thank you for the suggestion.
I checked the C code, it did close CPLEX env by CPXcloseCPLEX(&env)
command. But I found out some mistakes in my perl code, which didn't
create cplex input files correctly (a file was missed) after first
loop. Therefore cplex hangs.
Although I fixed the problem, I think it's also an issue in cplex
itself, because it didn't show any error message for the missing
input file.
Thanks again,
Wei
"Paul A. Rubin" <rubin@msu.edu> wrote in message news:<Xns93CDAD719809Dquantoid@35.8.2.20>...
> Does your C program close the CPLEX environnment(s) it is using before
> exiting? I wonder if the C program gets stuck waiting for CPLEX's
> license manager, which thinks the first program is still running and
> won't issue a second token. (This presumes that you're licensed for only
> one token at a time.)
>
> Don't know about the Unix version, but on Win2K you should be able to
> look at the DOS window in which the license manager is running and see
> which tokens it has issued (I think). Also, I believe the license
> manager writes a status file in a temp directory; if you can find that (I
> think it starts with ilm-something), you can maybe see what processes
> have been blessed.
>
> Another thought is to stick a couple of print commands in the code, one
> on either side of the line where the CPLEX environment is opened, and see
> if it gets to (and then past) the environment open command.
>
> Just guessing here, but the fact that it works once and not twice does
> suggest it might be a license problem.
>
> -- Paul
>
> *************************************************************************
> Paul A. Rubin Phone: (517) 432-3509
> Department of Management Fax: (517) 432-1111
> The Eli Broad Graduate School of Management E-mail: rubin@msu.edu
> Michigan State University http://www.msu.edu/~rubin/
> East Lansing, MI 48824-1122 (USA)
> *************************************************************************
> Mathematicians are like Frenchmen: whenever you say something to them,
> they translate it into their own language, and at once it is something
> entirely different. J. W. v. GOETHE
------------------------------
Date: Tue, 05 Aug 2003 21:42:32 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: Final "Flocking" Script
Message-Id: <b020jv4elh9kv242adcgcssb40g8o2cluu@4ax.com>
X-Ftn-To: Tad McClellan
tadmc@augustmail.com (Tad McClellan) wrote:
>> sysopen(FH, "data.txt", O_WRONLY | O_CREAT) or die "can't open filename:
>> $!";
>> flock (FH, LOCK_EX) or die "can't lock filename: $!";
>> truncate (FH, 0) or die "can't truncate filename: $!";
>
>There should be a seek(FH, 0, 0) here in case some other process
>advanced the file pointer between your sysopen() and your flock().
Hi,
isn't a file pointer something that belongs to(and only to) process itself?
--
Matija
------------------------------
Date: Tue, 05 Aug 2003 19:49:44 GMT
From: badbob <badbob@somewhere.com>
Subject: How do I detect if input is from a pipe or not?
Message-Id: <rf10jvk2pljqcpoeem23qova4blksoutuc@4ax.com>
I'm writing a utility that can get input from a file or from a pipe'd
output from another program:
myprogram -infile test.txt
or
type test.txt | myprogram
So for the above two scenarios, I have:
if ($opt_infile)
{
# read from file
}
else
{
while (<>)
{
#read from stdin
}
}
The problem is, if I just run
myprogram
it sits there waiting for input. What I really want is for it to
detect that nothing is coming in from a PIPE so it should complain
that the program was run incorrectly. I've searched and I've seen
stuff on named pipes and getting output by calling a specific program,
but I need a way to get input from any program.
So what I really want is:
if ($opt_infile)
{
# read from file
}
elsif ( pipe_detected() )
{
while (<>)
{
#read from stdin
}
}
else
{
showUsage();
}
Is this possible? Thanks!
badbob001 (at yahoo period com)
------------------------------
Date: Tue, 05 Aug 2003 20:24:48 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: How do I detect if input is from a pipe or not?
Message-Id: <koUXa.10967$mZ6.8174@nwrdny02.gnilink.net>
badbob <badbob@somewhere.com> wrote:
> I'm writing a utility that can get input from a file or from
> a pipe'd output from another program:
The magic ARGV filehandle will do that automatically.
while (<>) {
# reading from file(s) or stdin
}
If you only want to read stdin when it's a pipe (and not, e.g.
a file or socket -- which seems like a silly and potentially
irritating restriction) you could do:
unless (@ARGV or -p STDIN) {
die "Usage: $0 [files]\n";
}
while (<>) {
# reading from file(s) or piped stdin
}
If you just want to avoid reading from the terminal, you could
do this instead:
if (@ARGV == 0 and -t) {
die "Usage: $0 [files]\n";
}
while (<>) {
# reading from file(s) or non-tty stdin
}
But I still don't see the point.
--
Steve
------------------------------
Date: Tue, 5 Aug 2003 11:19:16 -0700
From: JS Bangs <jaspax@u.washington.edu>
Subject: Re: Perl Math Syntax
Message-Id: <Pine.A41.4.56.0308051057140.85394@dante11.u.washington.edu>
Eric J. Roode sikyal:
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> JS Bangs <jaspax@u.washington.edu> wrote in
> news:Pine.A41.4.56.0308042009470.95418@dante18.u.washington.edu:
>
> >
> > It's not incorrect, but the OP is probably better off doing:
> >
> > $opened++;
>
> Why is that "better"? For a simple variable increment, I would say that
> it's just a matter of style. I can't see any real difference between
>
> $opened = $opened + 1;
> $opened += 1;
> $opened++;
Personally, I prefer the last form for brevity and clarity. I also thought
it executed faster, but I was surprised by what happened when I actually
benchmarked this.
At the behest of another poster, I benchmarked these using the following
code:
------------------
#!/usr/bin/perl
use Benchmark qw(cmpthese);
my ($a, $b, $c) = (0, 0, 0);
cmpthese(10000000, {
Plus => sub { $a = $a + 1 },
PlusEq => sub { $b += 1 },
PlusPlus => sub { $c++ }
});
------------------
The results suprised me quite a bit:
-----------------
Benchmark: timing 10000000 iterations of Plus, PlusEq, PlusPlus...
Plus: 2 wallclock secs ( 1.10 usr + 0.00 sys = 1.10 CPU) @
9090909.09/s (n=10000000)
PlusEq: 2 wallclock secs ( 1.31 usr + 0.00 sys = 1.31 CPU) @
7633587.79/s (n=10000000)
PlusPlus: 2 wallclock secs ( 1.49 usr + 0.00 sys = 1.49 CPU) @
6711409.40/s (n=10000000)
Rate PlusPlus PlusEq Plus
PlusPlus 6711409/s -- -12% -26%
PlusEq 7633588/s 14% -- -16%
Plus 9090909/s 35% 19% --
------------------
In other words, $c++ was the *slowest* of the options, while $a = $a + 1
was the fastest. I expected the exact opposite. Actually, I pretty much
expected them to be exactly the same, thinking that the compiler would
recognize all of them as synonymous. For my curiosity I tested a similar c
file against gcc and found that all three forms were indeed reduced to the
same assembler command, even without optimization.
So why doesn't the Perl compiler do this? And why the counter-intuitive
result?
--
Jesse S. Bangs jaspax@u.washington.edu
http://students.washington.edu/jaspax/
http://students.washington.edu/jaspax/blog
------------------------------
Date: Tue, 05 Aug 2003 19:31:03 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Perl Math Syntax
Message-Id: <3F30063B.8A28372F@acm.org>
JS Bangs wrote:
>
> At the behest of another poster, I benchmarked these using the following
> code:
>
> ------------------
> #!/usr/bin/perl
>
> use Benchmark qw(cmpthese);
>
> my ($a, $b, $c) = (0, 0, 0);
>
> cmpthese(10000000, {
> Plus => sub { $a = $a + 1 },
> PlusEq => sub { $b += 1 },
> PlusPlus => sub { $c++ }
> });
> ------------------
>
> The results suprised me quite a bit:
>
> -----------------
> Benchmark: timing 10000000 iterations of Plus, PlusEq, PlusPlus...
> Plus: 2 wallclock secs ( 1.10 usr + 0.00 sys = 1.10 CPU) @
> 9090909.09/s (n=10000000)
> PlusEq: 2 wallclock secs ( 1.31 usr + 0.00 sys = 1.31 CPU) @
> 7633587.79/s (n=10000000)
> PlusPlus: 2 wallclock secs ( 1.49 usr + 0.00 sys = 1.49 CPU) @
> 6711409.40/s (n=10000000)
> Rate PlusPlus PlusEq Plus
> PlusPlus 6711409/s -- -12% -26%
> PlusEq 7633588/s 14% -- -16%
> Plus 9090909/s 35% 19% --
Interesting. I get somewhat different results (isn't benchmarking fun!)
$ perl -e'
use Benchmark qw/cmpthese/;
cmpthese( -60, {
plus => sub { my $x; $x = $x + 1 while $x < 1000; $x },
plusequals => sub { my $x; $x += 1 while $x < 1000; $x },
preplusplus => sub { my $x; ++$x while $x < 1000; $x },
postplusplus => sub { my $x; $x++ while $x < 1000; $x },
} )'
Benchmark: running plus, plusequals, postplusplus, preplusplus, each for at least 60 CPU seconds...
plus: 69 wallclock secs (62.71 usr + 0.39 sys = 63.10 CPU) @ 450.52/s (n=28428)
plusequals: 65 wallclock secs (63.59 usr + 0.24 sys = 63.83 CPU) @ 451.03/s (n=28789)
postplusplus: 64 wallclock secs (62.41 usr + 0.17 sys = 62.58 CPU) @ 561.57/s (n=35143)
preplusplus: 64 wallclock secs (63.06 usr + 0.08 sys = 63.14 CPU) @ 560.86/s (n=35413)
Rate plus plusequals preplusplus postplusplus
plus 451/s -- -0% -20% -20%
plusequals 451/s 0% -- -20% -20%
preplusplus 561/s 24% 24% -- -0%
postplusplus 562/s 25% 25% 0% --
:-)
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 05 Aug 2003 19:44:19 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: Perl Math Syntax
Message-Id: <nOTXa.10391$W%3.10130@nwrdny01.gnilink.net>
John W. Krahn <krahnj@acm.org> wrote:
> Interesting. I get somewhat different results (isn't benchmarking fun!)
>
> preplusplus => sub { my $x; ++$x while $x < 1000; $x },
> postplusplus => sub { my $x; $x++ while $x < 1000; $x },
FWIW: post-increment in void context gets "optimized".
% perl -MO=Concise,foo -e 'sub foo { $x++; $x }'
-e syntax OK
main::foo:
6 <1> leavesub[t1] K/REFC,1 ->(end)
- <@> lineseq KP ->6
1 <;> nextstate(main 1 -e:1) v ->2
3 <1> preinc[t2] vK/1 ->4
- <1> ex-rv2sv sKRM/1 ->3
2 <#> gvsv[*x] s ->3
4 <;> nextstate(main 1 -e:1) v ->5
- <1> ex-rv2sv sK/1 ->-
5 <#> gvsv[*x] s ->6
--
Steve
------------------------------
Date: Tue, 05 Aug 2003 16:57:40 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Perl Math Syntax
Message-Id: <Xns93CEB69B726E5sdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Uri Guttman <uri@stemsystems.com> wrote in
news:x7r84045dx.fsf@mail.sysarch.com:
>>>>>> "EJR" == Eric J Roode <REMOVEsdnCAPS@comcast.net> writes:
>
> EJR> Why is that "better"? For a simple variable increment, I would
> EJR> say that it's just a matter of style. I can't see any real
> EJR> difference between
>
> EJR> $opened = $opened + 1;
> EJR> $opened += 1;
> EJR> $opened++;
>
> run them under the benchmark module. report your results back here.
use Benchmark;
my $o;
timethese (10_000_000,
{
1 => sub { $o = $o + 1 },
2 => sub { $o += 1 },
3 => sub { $o++ },
} );
Result:
Benchmark: timing 10000000 iterations of 1, 2, 3...
1: 2 wallclock secs ( 0.80 usr + 0.01 sys = 0.81 CPU)
@ 12315270.94/s (n=10000000)
2: 4 wallclock secs ( 3.46 usr + 0.00 sys = 3.46 CPU)
@ 2886836.03/s (n=10000000)
3: 2 wallclock secs ( 2.30 usr + 0.00 sys = 2.30 CPU)
@ 4340277.78/s (n=10000000)
Conclusion:
It doesn't make a bit of difference which style one uses. Sure, one
could take the shortsighted view that "$o = $o + 1" is four times faster
than "$o += 1", but at nearly 3 million executions per second, even the
slowest of these will have zero impact on any real program. Ergo, use
whichever style one feels the mosy comfortable with, as I advised.
- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPzAoJmPeouIeTNHoEQK7swCdFI7/JcPBd4FQALijtkaQV0orx5kAoJJq
58XjK+KtUhRmq8Hyz8VL+a5G
=JPjH
-----END PGP SIGNATURE-----
------------------------------
Date: Tue, 05 Aug 2003 20:48:36 GMT
From: Mike Flannigan <mikeflan@earthlink.net>
Subject: Re: Renaming Files inside a GZ Zip File
Message-Id: <3F3018B2.75091272@earthlink.net>
Mike Flannigan wrote:
> On a Win2000 box I have hundreds of files named
> somethingXXX - ZZZZZ.tif.gz
> that are gz zip files that contain a single file named:
> otherfileYYY.tif
>
> I want to write a perl script that will rename the single tif
> file inside each gz file with the first portion of the gz file
> name. So all the "inside" files will be named
> somethingXXX.tif
>
> The gz file name will not be modified. (I could do that
> right now if I wanted to).
>
> Anyway, I assume I need a module or two and would
> appreciate any pointers about what to use.
>
> This module does not look like the right one to me:
> http://search.cpan.org/author/NWCLARK/PerlIO-gzip-0.15/gzip.pm
> but I can't find anything else that would apply.
>
> Mike Flannigan
I tried to use PerlIO::gzip as shown in the code below,
but it gives the error:
Perl v5.8.0 required--this is only v5.6.1 . . .
Guess I need to upgrade.
___________________________
use strict;
use warnings;
use PerlIO::gzip;
open FOO, "<:gzip", "Adr.gz" or die $!;
print while <FOO>; # And it will be uncompressed...
------------------------------
Date: Tue, 05 Aug 2003 18:55:44 GMT
From: Greg Schmidt <gregs@trawna.com>
Subject: Re: Term::ANSIColor How can I print the color directly to a printer
Message-Id: <5tuviv8on1q7juc696q4j5pp0q3dam6dtm@4ax.com>
On Thu, 31 Jul 2003 17:58:50 -0400, "Joe Hasting" <hasting@agere.com>
wrote:
>I have been using Term::ANSIColor to have printed charaters on my screen,
>how can I direct the ANSI escaped code to a color printer directly and have
>it print in color (not print the ANSI escape codes). I tried the simple
>code below. The first page comes out ok, but the second page is printed
>with the escape codes. Thanks J
Does your printer support ANSI escape sequences? Does any printer?
Unless there is another module that handles this, I think you may have
to learn the printer-specific codes or else use PostScript or PCL or
some other standard that your printer understands.
--
Greg Schmidt (gregs@trawna.com)
Trawna Publications (http://www.trawna.com/)
------------------------------
Date: 5 Aug 2003 14:26:38 -0700
From: schaltung@hotmail.com (Schaltung)
Subject: Variables Definition File
Message-Id: <1b56a114.0308051326.e16823b@posting.google.com>
I wrote a perl script to run (among other things) a series of commands
using the 'system()' function.
The goal is to run these commands for different input values.
I have a text file called 'variables.def' where I can change those
values, without actually going to every perl script and change the
variable values.
Currently, my perl scripts read the file 'variables.def' and they
"load" the variable values from there (using brute force parsing).
My question is: is there an easier way to implement this? I wish
'variables.def' file could look like this:
$var1= 23;
$var1= 45;
...
... and I simply imported those variable values to my scripts.
I appreciate any of your hints.
Antonio
------------------------------
Date: Tue, 05 Aug 2003 17:35:24 -0400
From: Shawn Corey <shawn@magma.ca>
Subject: Re: Variables Definition File
Message-Id: <Hb-dnX8fg456v62iXTWJhg@magma.ca>
Hi,
perldoc -f do
This is similar to require but require loads the file once, do does it
very time the statement is encountered.
Schaltung wrote:
> I wrote a perl script to run (among other things) a series of commands
> using the 'system()' function.
>
> The goal is to run these commands for different input values.
>
> I have a text file called 'variables.def' where I can change those
> values, without actually going to every perl script and change the
> variable values.
>
> Currently, my perl scripts read the file 'variables.def' and they
> "load" the variable values from there (using brute force parsing).
>
> My question is: is there an easier way to implement this? I wish
> 'variables.def' file could look like this:
> $var1= 23;
> $var1= 45;
> ...
> ... and I simply imported those variable values to my scripts.
>
> I appreciate any of your hints.
> Antonio
------------------------------
Date: Tue, 5 Aug 2003 20:09:06 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: Why, oh why have I read "Perl 6 essentials"???
Message-Id: <slrnbj03n2.r6o.dha@panix2.panix.com>
In article <Pine.A41.4.56.0308042130210.95418@dante18.u.washington.edu>,
JS Bangs wrote:
> Now I'm looking at my code and thinking, "If only this were Perl6, I
> could say 'any @foo' here and my life would be so much easier . . .".
Can't you just use Quantum::Superpositions for that?
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"We Americans stand on the shoulders of freaks." - Doctor Demento
------------------------------
Date: Tue, 05 Aug 2003 23:56:12 +0200
From: "Janek Schleicher" <bigj@kamelfreund.de>
Subject: Re: Why, oh why have I read "Perl 6 essentials"???
Message-Id: <pan.2003.08.05.21.55.16.484321@kamelfreund.de>
David H. Adler wrote at Tue, 05 Aug 2003 20:09:06 +0000:
>> Now I'm looking at my code and thinking, "If only this were Perl6, I
>> could say 'any @foo' here and my life would be so much easier . . .".
>
> Can't you just use Quantum::Superpositions for that?
Yes you can (and I personal often do), but it has two disadvantages.
First, it's very slow.
The junctions are built in in Perl 6 and thus I assume they will be very
quick. Indeed, it's very probably that e.g.
if ($x eq any @foo) {
# ...
}
will be much quicker than the nowadays idiom
if (grep {$x eq $_} @foo) {
# ...
}
as it can break when the first equal element of @foo is found.
Of course that could be also done with
use List::Util qw/first/;
if (first {$x eq $_} @foo) { ... }
# or
use Quantum::Superpositions;
if ($x eq any(@foo)) { ... }
but they are in most cases slower (O.K. the List::Util method is on the
long run avarage quicker than the grep method, but you'll need a lot of
elements in @foo to find it)
The second main advantage of the Perl 6 junctions are that they have their
own operator.
Instead of the long and boring
if ($x eq any($a,$b,$c,$d)) { ... }
you can write the more naturally
if ($x eq $a | $b | $c | $d) { ... }
Similar, instead of the all method, you can use the & operator.
Greetings,
Janek
------------------------------
Date: Tue, 5 Aug 2003 16:58:44 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Why, oh why have I read "Perl 6 essentials"???
Message-Id: <slrnbj0a4k.fk5.tadmc@magna.augustmail.com>
Uri Guttman <uri@stemsystems.com> wrote:
>>>>>> "GS" == Garry Short <g4rry_sh0rt@zw4llet.com> writes:
>
>
> GS> Just on a casual note, because the more I read, the more impatient
> GS> I get, are there any estimated timescales on when Perl6 will be
> GS> available?
>
> next christmas (for some definition of christmas).
So then, that would be:
any('christmas')
?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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 5321
***************************************