[12246] in Perl-Users-Digest
Perl-Users Digest, Issue: 5846 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 1 05:07:20 1999
Date: Tue, 1 Jun 99 02:00:21 -0700
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, 1 Jun 1999 Volume: 8 Number: 5846
Today's topics:
Re: Anyone know what is this script line meaning ?? <info@edoc.co.za>
Artistic License <dchrist@dnai.com>
Can I do this with an "if" statement? <portboy@home.com>
Re: Can I do this with an "if" statement? (Larry Rosler)
Compiler Win32 with Borland C++Builder 4 <c.ubell@worldnet.att.net>
E-Commerce Site work needed! (webmaster@film.tierranet.com)
Free PERL - SQL Tutorial w/ live Practice DB - also, Al (FRANK TORRES)
Re: hey p5p! Bug w/proto (\@)? (Ronald J Kimball)
Re: Is split (surprisingly, amazingly) slow? (Andrew Johnson)
Re: Is split (surprisingly, amazingly) slow? <rootbeer@redcat.com>
m// in list context - can't tell if match succeeded or (Joey Hess)
Re: Making Perl Wait (Tim Herzog)
open FILE,$path || open FILE,$altpath; <wolfgang.goetzinger@siemens.at>
Re: open FILE,$path || open FILE,$altpath; <gellyfish@gellyfish.com>
Re: open FILE,$path || open FILE,$altpath; <axc@iname.com>
Re: Perl Newbee (Ronald J Kimball)
Re: Predefined variable for array number? (Andrew Johnson)
problem in perl using the "chroot" command <vincent.rodts@cern.ch>
Serial port question... <portboy@home.com>
Re: Shorter solution ? (Larry Rosler)
Re: Shorter solution ? <uri@sysarch.com>
Re: Shorter solution ? (Larry Rosler)
Re: Slow, or looping? (Ilya Zakharevich)
Re: the unshift function (Larry Rosler)
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 01 Jun 1999 09:20:31 +0200
From: Nico van der Dussen <info@edoc.co.za>
Subject: Re: Anyone know what is this script line meaning ??
Message-Id: <375389BE.64B95D13@edoc.co.za>
I could figure out hte basics of this staement from the manual, but the { $_
!~ m/^\./} still beats me.
I figure it means something such as if $_ does not match a '.' at the start
of the string. But then the manual warns that using $_ will create chaos if
you do not know what you are doing. I will appreciate it if somebody
knowledgeable will explain why it can be used in this instance, and when it
should not be used.
Thanks
Nico
Sam Holden wrote:
> On 31 May 1999 06:44:58 GMT, Austin Ming <austin95002887@yahoo.com> wrote:
> >
> >--> @files = grep { $_ !~ m/^\./} readdir(DIR);
> >
> >Anyone know what is this script line meaning ??
>
> Yes.
>
> Why don't you look up the documentation on readdir and grep and
> then you can know too...
>
> --
> Sam
>
> Remember that the P in Perl stands for Practical. The P in Python
> doesn't seem to stand for anything.
> --Randal Schwartz in <8cemsabtef.fsf@gadget.cscaper.com>
------------------------------
Date: Tue, 1 Jun 1999 00:00:37 -0700
From: "David Christensen" <dchrist@dnai.com>
Subject: Artistic License
Message-Id: <7j010p$bn$1@pollux.dnai.com>
Hello, World!
I am researching confidential disclosure and intellectual property
agreements. An "Artistic License" is mentioned in the documentation for
Perl, and indicates that it can be found with the source files. I don't
think I have this file and can't seem to find it separate from a the whole
tarball on CPAN. Can someone please post a link or send it to me?
TIA,
--
David Christensen
dchrist@dnai.com
------------------------------
Date: Tue, 01 Jun 1999 04:54:44 GMT
From: Mitch <portboy@home.com>
Subject: Can I do this with an "if" statement?
Message-Id: <3752164A.45E9B2D4@home.com>
I would like to check to make sure that the input from the user is
within 1-60 (integer). Can I do something like this with an if
statement. If so how?
if ($ans = [1...60]) {
blah blah
}
else {
print "out of bounds";
}
Thanks,
Mitch
------------------------------
Date: Tue, 1 Jun 1999 00:22:34 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Can I do this with an "if" statement?
Message-Id: <MPG.11bd2a1046992c65989b47@nntp.hpl.hp.com>
In article <3752164A.45E9B2D4@home.com> on Tue, 01 Jun 1999 04:54:44
GMT, Mitch <portboy@home.com> says...
> I would like to check to make sure that the input from the user is
> within 1-60 (integer). Can I do something like this with an if
> statement. If so how?
>
> if ($ans = [1...60]) {
> blah blah
> }
> else {
> print "out of bounds";
> }
if (1 <= $ans && $ans <= 60) {
...
No shorthand available for that.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 31 May 1999 23:13:18 -0700
From: "Chaz Ubell" <c.ubell@worldnet.att.net>
Subject: Compiler Win32 with Borland C++Builder 4
Message-Id: <7ivtft$mm3$1@bgtnsc01.worldnet.att.net>
Has any body gotten perl5.005_03 to build with Borland C++Builder 4?
Any tips gratefully appreciated.
-cdu
------------------------------
Date: Tue, 01 Jun 1999 08:01:30 GMT
From: webmaster@film.tierranet.com (webmaster@film.tierranet.com)
Subject: E-Commerce Site work needed!
Message-Id: <375393eb$0$8462@nntp1.ba.best.com>
Hello,
I need some custom e-commerce site work. I would like to have an e-commerce
site that will do the following. First off, I don't want a dynamic system.
Just a shopping basket that uses cookies. It should have the following.
1) SSL Checkout.
2) Cross-sell. Be able to recommend products that would work with others.
3) Co-branding. Allows people to link to our site and gain a commision.
System doesn't need to compute amount of commision. Just needs to figure out
WHO it came from. Would like it to allow users to link to any page in our
system (all pages will be static).
Since this will obviously be kept in some kind of database I would like to be
able to include SSI includes into my web pages so any pricing changes in the
database will be reflected in the web page.
Orders can be e-mailed to me or displayed on some kind of order web page.
Please e-mail price quotes to me with possible completion time. Thanks.
------------------------------
Date: 1 Jun 1999 04:44:17 GMT
From: ftorres@aztec.asu.edu (FRANK TORRES)
Subject: Free PERL - SQL Tutorial w/ live Practice DB - also, Alaskan PERL Cruise
Message-Id: <7ivof1$o9l$1@news.asu.edu>
As a PERL programmer, I know the importance of being able to access
databases. I put together a FREE SQL Tutorial that features a live
practice database where you can practice everything you learn on-line
- with immediate feedback. It's 100% web based - no downloads! You can
create your own unique tables, perform inserts, updates, deletes, drops,
selects, etc. It's at:
http://www.sqlcourse.com
or http://torresoft.netmegs.com
Also, one of my advertisers/sponsors is putting together a PERL Cruise -
guest speakers include Larry Wall & Tom Christiansen. You can get to the
site from my "other_links" page or it's on one of my banners.
Frank
http://sqlcourse.com
--
------------------------------
Date: Tue, 1 Jun 1999 00:10:26 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: hey p5p! Bug w/proto (\@)?
Message-Id: <1dsp0zm.1o9m4k18v908tN@p199.block1.tc6.state.ma.tiac.com>
Bill Huston <bhuston@eden.com> wrote:
> If this could be made consistant (prototype magically gives the sub
> a reference, even though the sub is called with something list-like),
> it would be wonderous! I could then do something I need to do: create
> a sub() which gets passed multiple lists and keep them straight:
>
>
> mysub ( @a1, @opts ); # array
> mysub ( (1,2,3), @opts); # literal list
> mysub ( returns_list(), @opts); # sub() returns list
> mysub ( keys %h, @opts); # perlfunc returns list
>
> I can't find a way to (cleanly) do this now.
There is no way to cleanly do this. Aside from passing an array to the
prototype \@ (or a hash to \%), the arguments to the sub are flattened
and passed as one big list in the array @_.
> Q: Wouldn't it be more useful to have a prototype of (\@) give the
> sub a generalized list reference, in order to be able to better
> match builtin behavior?
No. There is no such thing as a list reference. There are scalar
references, array references, and hash references (and glob references
and code references and...). But no list references. A reference to a
list is really a list to an anonymous array.
You might expect this to make a reference to a list:
\($x, $y)
but it doesn't. It creates a list of references to scalars:
(\$x, \$y)
> Q: Is it possible to do this??
No. Not even Perl builtins can do this. I'm not even sure what
"builtin behavior" you refer to above.
If you want to keep the lists separate, you have to pass them as array
references -- either named with a \@ prototype, or as actual references
in all other cases.
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Tue, 01 Jun 1999 05:06:37 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: Is split (surprisingly, amazingly) slow?
Message-Id: <xTJ43.36827$tE.263556@news2.rdc1.on.home.com>
In article <7iuu05$fq7$1@news8.svr.pol.co.uk>,
Jonathan <jonathan@meanwhile.freeserve.co.uk> wrote:
! A couple of weeks ago there was a posting on c++ moderated and
! comp.lang.python called "An efficient split function".
! Among other things it contained Perl and Python code to - well, to do this:
!
!
! my $count = 0;
! my @v;
! while (<STDIN>) {
! @v = split(/\|/);
! $count++;
! }
! print "$count\n";
!
!
! In other words, to count the total number of field separated data items in a
! file.
Well, it'll count records, not fields ...
!
! The author of the post was surprised because the Python version ran **4**
! times as fast as the Perl code above on large files. And with fairly
I looked up the original posting and it claimed (for 1 million lines,
9 fields per line) that perl came in just under 40 seconds and python
just under 20 --- not 4 times faster, only 2 times faster.
His tests used perl5.004_04 against python 1.5.2 ... I ran that perl
code on 100,000 lines of data (on a pentium 133) and found that
5.004_04 was significantly slower than 5.003 or 5.005 versions ...
ie, roughly:
5.003 circa 20 seconds
5.004_04 circa 30 seconds
5.005_01 circa 23 seconds
5.005_02 circa 21 seconds
5.005_03 circa 17 seconds
Using python 1.5.1 (maybe 1.5.2 is faster) the time for 100,000 lines
came in at circa 13 seconds. placing perl5.005_03 roughly 1.3 times
slower than python for this test --- I also went up to 1,000,000
lines and the ratio went to 1.4 times faster for python (but on my
piddly 133 system, other factors can influence longer timing runs).
Now, as I understand it, python splits on a character (or string?).
Perl splits on a regex, a more general and more powerful operation.
I think I am content with such a relatively small speed hit when
splitting on a single character in trade for the ability to split on
a more complicated regex when needed (not to mention the fact that
the above program is useless, and it's what you do with @v that's
likely going to have the most impact on your running time).
regards
andrew
------------------------------
Date: Mon, 31 May 1999 18:30:47 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Is split (surprisingly, amazingly) slow?
Message-Id: <Pine.GSO.4.02A.9905311818140.19186-100000@user2.teleport.com>
On 1 Jun 1999, Mark-Jason Dominus wrote:
> In article <Pine.GSO.4.02A.9905311515050.19186-100000@user2.teleport.com>,
> Tom Phoenix <rootbeer@redcat.com> wrote:
> >If you're going to make (or cite) such amazing claims, it would probably
> >be a good idea to back them up with the actual (correct) code and real
> >benchmarks, so that we can all see what you're talking about.
>
> The cited post is only three weeks old. It is probably still in your
> spool. I think Jonathan can be excused for not reproducing it, since
> it was so recent. (<wywvyhvu2u.fsf@wiggum.dejanews.com>, should you
> care. The subject is `An efficient split function')
You're right. I hereby publicly apologize to Jonathan. I didn't realize
that the data were so readily available.
> Summary:
>
> 1. Perl is not designed to be speedy. It is designed to be
> convenient. Comparing convenient Perl against inconvenient C is
> not very enlightening. Convenience is expensive.
Amen!
> 2. If you want C, you know where to find it.
You tell it, preacher!
> 3. There's probably a nice ecological niche for someone to write an
> XS module that provides a super-duper optimized version of split
> that only splits on static strings. Then you'd say
>
> use SSplit;
> while (<>) {
> @fields = ssplit '|';
> # ...
> }
>
> and performance would probably be at least as good as in Java.
Yeah! Yeah! And that would be easy to do, too. Hey, wait....
You know, split should be smart enough to do that all by itself, at least
if the pattern is simple enough. And since many (most?) split patterns are
simple like /\|/ or /::/ are, there should be a big win from incorporating
that optimization into the core.
Hey, listen! Do you hear that noise? A little sound in the distance? It
sounds a little bit like Chip typing.... :-)
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 01 Jun 1999 08:10:44 GMT
From: joey@kite.kitenet.net (Joey Hess)
Subject: m// in list context - can't tell if match succeeded or failed
Message-Id: <slrn7l75c4.teq.joey@kite.kitenet.net>
According to the man page:
If used in a context that requires a list value, a pattern match
returns a list consisting of the subexpressions matched by the
parentheses in the pattern, i.e., ($1, $2, $3...). (Note that here $1
etc. are also set, and that this differs from Perl 4's behavior.) If
the match fails, a null array is returned. If the match succeeds, but
there were no parentheses, a list value of (1) is returned.
This seems badly designed to me. There's no way to differentiate between a
successful match with one set of parens that didn't trap anything, and a
failed match with no parens. For example:
#!/usr/bin/perl
$_="w";
@matches=/^w(ho)?$/;
print "$#matches (@matches)\n";
print "That really matched.\n" if /^w(ho)?$/;
@matches=/^who$/;
print "$#matches (@matches)\n";
print "That didn't.\n" unless /^who$/;
This outputs:
0 ()
That really matched.
0 ()
That didn't.
I'm reduced to using a scaler m// first to make sure I have a match and then
repeating the same m// in list context to get the array I need.
Am I missing something, or is this just not designed well?
--
see shy jo
------------------------------
Date: Tue, 01 Jun 1999 02:14:05 -0500
From: therzog@knotech.com (Tim Herzog)
Subject: Re: Making Perl Wait
Message-Id: <therzog-0106990214050001@therzog-host105.dsl.visi.com>
In article <374d51d1@cs.colorado.edu>, tchrist@mox.perl.com (Tom
Christiansen) wrote:
> [courtesy cc of this posting mailed to cited author]
>
>Bedamned by the evil and rude Mozilla/4.0 (compatible; MSIE 4.01;
>Windows NT), sherifhanna@my-deja.com blathered in comp.lang.perl.misc:
>
>:Is there any way I can make a Perl scripts stop for x number of
>:seconds? Is there a built-in function for that?
>
>I dunno. Maybe you should search in the standard perlfunc manpage
>that comes with each and every distribution of perl and is sitting
>right there on your own system, which is where the standard
>built-in functions are documented. If you can't find it, fire
>your negligent and idiotic system administrator, then proceed to
>http://language.perl.com/admin/whats_new.html and get the newest set
>of docs.
>
>We can't read manpages to you Prisoners of Bill. You have
>to do your own homework.
Although apparently you have plenty of time to dis users who dare to ask a
"simple" question when a two word answer would have done nicely.
The description of "sleep" in perlfunc doesn't contain the words "wait,"
"pause," "delay," or anything that a non-Unix veteran or new user might
think of. It merely says:
"sleep causes the script to sleep for EXPR seconds..."
which of course is plenty for anyone with a Unix or programming
background, but to anyone else sounds like:
circular reference. see also: circular reference.
--
Tim Herzog
------------------------------
Date: Tue, 01 Jun 1999 10:30:49 +0200
From: Wolfgang =?iso-8859-1?Q?G=F6tzinger?= <wolfgang.goetzinger@siemens.at>
Subject: open FILE,$path || open FILE,$altpath;
Message-Id: <37539A39.F90800DA@siemens.at>
Hi!
i want to open and print the file $path to stdout. if the file $path
does not exist i want to open and print $altpath (which always exists).
i tried the following code:
-------------------------------------------------
$path="/home/file_a"
$altpath="/home/default"
open FILE,$path || open FILE,$altpath;
while (<FILE>) {
print;
}
-------------------------------------------------
but if $path does not exist, $altpath is not opened.
what is wrong?
i think the answer is easy, but i just started perl...sorry
thanx for your help!!
------------------------------
Date: 1 Jun 1999 09:35:30 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: open FILE,$path || open FILE,$altpath;
Message-Id: <37539b52@newsread3.dircon.co.uk>
Wolfgang Gvtzinger <wolfgang.goetzinger@siemens.at> wrote:
> Hi!
>
> i want to open and print the file $path to stdout. if the file $path
> does not exist i want to open and print $altpath (which always exists).
>
> i tried the following code:
>
> -------------------------------------------------
> $path="/home/file_a"
> $altpath="/home/default"
>
> open FILE,$path || open FILE,$altpath;
> while (<FILE>) {
> print;
> }
> -------------------------------------------------
>
> but if $path does not exist, $altpath is not opened.
> what is wrong?
> i think the answer is easy, but i just started perl...sorry
>
> thanx for your help!!
precedence: use brackets around the arguments to open or use or instead
of ||
read more about this in the perlop manpage.
/J\
--
Jonathan Stowe <jns@gellyfish.com>
------------------------------
Date: Tue, 1 Jun 1999 11:48:31 -0700
From: "Alex" <axc@iname.com>
Subject: Re: open FILE,$path || open FILE,$altpath;
Message-Id: <7j06rq$g7n$1@news.kolumbus.fi>
Try this:
$path="/home/file_a"
$altpath="/home/default"
unless (open FILE, "<$path") {
open (FILE, "<$altpath");
}
Wolfgang Gvtzinger <wolfgang.goetzinger@siemens.at> wrote in message
news:37539A39.F90800DA@siemens.at...
> Hi!
>
> i want to open and print the file $path to stdout. if the file $path
> does not exist i want to open and print $altpath (which always exists).
>
> i tried the following code:
>
> -------------------------------------------------
> $path="/home/file_a"
> $altpath="/home/default"
>
> open FILE,$path || open FILE,$altpath;
> while (<FILE>) {
> print;
> }
> -------------------------------------------------
>
> but if $path does not exist, $altpath is not opened.
> what is wrong?
> i think the answer is easy, but i just started perl...sorry
>
> thanx for your help!!
------------------------------
Date: Tue, 1 Jun 1999 00:10:28 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Perl Newbee
Message-Id: <1dsp1lj.1xw11x611mp0n0N@p199.block1.tc6.state.ma.tiac.com>
Mike Likvan <mlikvan@home.com> wrote:
> Really? You'd need to see the code even for the
> question of "what needs to be set up/loaded on a
> server in order to make sure Perl scripts run"?
> Isn't there a standard operating environment and
> settings (e.g. setting "GET" AND "POST" on the server)?
> Stuff like that? I can understand the need for code
> for question #1, but number 2...?
All the questions, number 2 included, were about a *specific* CGI
script:
2) What does it take for formmail.pl to run on an Internet server?
Let me clarify. Does the server that the formmail.pl resides on
HAVE to be running UNIX? Can it be running NT? [etc.]
Frankly, I have no way of knowing whether formmail.pl was written to be
cross-platform, nor what external programs it may require, without
seeing the code. And I would be very surprised if you did.
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Tue, 01 Jun 1999 05:19:45 GMT
From: andrew-johnson@home.com (Andrew Johnson)
Subject: Re: Predefined variable for array number?
Message-Id: <R3K43.36882$tE.263556@news2.rdc1.on.home.com>
In article <5FE43.1947$%65.4999@tor-nn1.netcom.ca>,
none@none.ca <none@none.ca> wrote:
! Is there an array equivalent of the $. variable for files. i.e. A variable
! which tells you what array number you are currently at.
[snip]
! I realize this value is simple to figure out using other ways, I am simply
! curious as to whether this variable is already predefined by Perl.
no, it is not ... but when you need to know the index you may as
well use the for(;;) style loop:
for(my $i = 0; $i < @array; $i++){
print "$i: $array[$i]\n";
}
regards
andrew
------------------------------
Date: Tue, 01 Jun 1999 09:57:48 +0200
From: Vincent Rodts <vincent.rodts@cern.ch>
Subject: problem in perl using the "chroot" command
Message-Id: <3753927C.37C06460@cern.ch>
Hello,
I have to use the chroot command in a perl script, but when using it,
most of the commands concerning files do not work anymore. The following
program shows this strange behaviour :
#!/usr/local/bin/perl5
chroot ("/root");
exec("ls");
Without chroot, the ls command works, but with chroot, ls can't find any
files.
The script is run as root, and this behaviour happens on different
systems.
Is there an error in the way I use the chroot command ?
Thanks,
Vincent Rodts
------------------------------
Date: Tue, 01 Jun 1999 05:27:18 GMT
From: Mitch <portboy@home.com>
Subject: Serial port question...
Message-Id: <37521DEC.D6E99D0E@home.com>
I'm writing a script right now, that should allow the user to change the
baud rate on the serial port, how do I do this?
Thanks, Mitch
------------------------------
Date: Mon, 31 May 1999 21:44:04 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Shorter solution ?
Message-Id: <MPG.11bd04df6f406047989b43@nntp.hpl.hp.com>
In article <x71zfwfvye.fsf@home.sysarch.com> on 31 May 1999 23:20:25 -
0400, Uri Guttman <uri@sysarch.com> says...
> >>>>> "FWM" == Fuzzy Warm Moogles <tgy@chocobo.org> writes:
> FWM> my %fh = (
> FWM> X4 => \*DATA ,
> FWM> XY => \*DATA_XY ,
> FWM> UP => \*XY_Z ,
> FWM> DOWN => \*F2_DATA ,
> FWM> MP => \*LS ,
> FWM> C4 => \*XYZ ,
> FWM> );
>
> FWM> if ($in_file_name =~ /(X4|XY|UP|DOWN|MP|C4)/) {
> FWM> my $fh = $fh{$1};
> FWM> print OUTFILE while <$fh>;
> FWM> close $fh;
> FWM> }
>
> why duplicate the tokens in the regex? this is more flexible as you can
> add/delete hash entries without editing the regex.
>
> (untested as per thread)
>
> $token_re = join( '|', keys %fh ) ;
This changes the semantics from those of the original problem (though
perhaps that is OK; who knows?). As these are matches (not equalities),
a filename like 'X4XY' could match either 'X4' or 'XY' depending on the
quasi-random order presented by keys %fh. But the original program
would always match 'X4', because the tests were sequential.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 01 Jun 1999 01:34:31 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Shorter solution ?
Message-Id: <x7n1ykeb6g.fsf@home.sysarch.com>
>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
LR> In article <x71zfwfvye.fsf@home.sysarch.com> on 31 May 1999 23:20:25 -
LR> 0400, Uri Guttman <uri@sysarch.com> says...
>>
FWM> if ($in_file_name =~ /(X4|XY|UP|DOWN|MP|C4)/) {
FWM> my $fh = $fh{$1};
FWM> print OUTFILE while <$fh>;
FWM> close $fh;
FWM> }
>>
>> why duplicate the tokens in the regex? this is more flexible as you can
>> add/delete hash entries without editing the regex.
>>
>> (untested as per thread)
>>
>> $token_re = join( '|', keys %fh ) ;
LR> This changes the semantics from those of the original problem (though
LR> perhaps that is OK; who knows?). As these are matches (not equalities),
LR> a filename like 'X4XY' could match either 'X4' or 'XY' depending on the
LR> quasi-random order presented by keys %fh. But the original program
LR> would always match 'X4', because the tests were sequential.
that can be fixed by putting a ^$ around the list of tokens. also i
notice my code didn't put in the () to grab so here is a more correct
(but still untested) version:
$token_re = '^(' . join( '|', keys %fh ) . ')$' ;
so that should only match exactly.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Tue, 1 Jun 1999 00:15:09 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Shorter solution ?
Message-Id: <MPG.11bd285a9186520f989b46@nntp.hpl.hp.com>
In article <x7n1ykeb6g.fsf@home.sysarch.com> on 01 Jun 1999 01:34:31 -
0400, Uri Guttman <uri@sysarch.com> says...
+ >>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:
+ LR> In article <x71zfwfvye.fsf@home.sysarch.com> on 31 May 1999
+ LR> 23:20:25 -0400, Uri Guttman <uri@sysarch.com> says...
+ >>
+ FWM> if ($in_file_name =~ /(X4|XY|UP|DOWN|MP|C4)/) {
+ FWM> my $fh = $fh{$1};
+ FWM> print OUTFILE while <$fh>;
+ FWM> close $fh;
+ FWM> }
+ >>
+ >> why duplicate the tokens in the regex? this is more flexible as
+ >> you can add/delete hash entries without editing the regex.
+ >>
+ >> $token_re = join( '|', keys %fh ) ;
+
+ LR> This changes the semantics from those of the original problem
+ LR> (though perhaps that is OK; who knows?). As these are matches
+ LR> (not equalities), a filename like 'X4XY' could match either 'X4'
+ LR> or 'XY' depending on the quasi-random order presented by keys
+ LR> %fh. But the original program would always match 'X4', because
+ LR> the tests were sequential.
+
+ that can be fixed by putting a ^$ around the list of tokens. also i
+ notice my code didn't put in the () to grab so here is a more correct
+ (but still untested) version:
+
+ $token_re = '^(' . join( '|', keys %fh ) . ')$' ;
+
+ so that should only match exactly.
Sure. But for exact matches we don't need a regex at all.
if (my $fh = $fh{$in_file_name}) {
print OUTFILE while <$fh>;
close $fh;
}
And the original problem didn't ask for exact matches -- it asked for
pattern matches:
if ($in_file_name =~ /X4/) ...
I think you have lost sight of the problem specification.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 1 Jun 1999 07:42:15 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Slow, or looping?
Message-Id: <7j02sn$jl$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Abigail
<abigail@delanet.com>],
who wrote in article <slrn7l5ruv.fvi.abigail@alexandra.delanet.com>:
> If something is not Omega (n), how can it be Omega (n^e) for e > 1 ?
>
> What kind of definition of Omega are you using???
Hmm, I was meaning "equivalent up to a bounded factor". Indeed, Omega
is not used for this (even if we forget that this post of mine was a
complete nonsense ;-().
Ilya
------------------------------
Date: Mon, 31 May 1999 21:59:43 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: the unshift function
Message-Id: <MPG.11bd087d708cf964989b44@nntp.hpl.hp.com>
In article <Pine.GSO.4.02A.9905311912210.19186-
100000@user2.teleport.com> on Mon, 31 May 1999 19:18:39 -0700, Tom
Phoenix <rootbeer@redcat.com> says...
...
> See the perlfunc manpage for more information on shift and unshift. It can
> be useful to contrast them with push and pop.
Great advice!
I think the submitter's confusion was in relating unshift() to shift()
in terms of the actions they perform. In fact, unshift() is related to
push() (in that they each add their argument lists to the array, albeit
to opposite ends); shift() is related to pop() (in that they remove one
element from the array, albeit from opposite ends).
The similarity of names refers to the fact that shift() and unshift()
both affect the low-index end of the array; they perform opposite
actions. Similarly for push() and pop().
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 5846
**************************************