[16645] in Perl-Users-Digest
Perl-Users Digest, Issue: 4057 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 18 11:05:34 2000
Date: Fri, 18 Aug 2000 08:05:16 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <966611116-v9-i4057@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 18 Aug 2000 Volume: 9 Number: 4057
Today's topics:
Anyone Help??? <solo@u.genie.co.uk>
Re: Anyone Help??? <care227@attglobal.net>
Re: Apache and cgi/perl (NP)
Re: Apache and cgi/perl <rtarpine@hotmail.com>
Re: Apache and cgi/perl <flavell@mail.cern.ch>
Re: close window <sariq@texas.net>
Re: close window (Rafael Garcia-Suarez)
Re: close window (Gwyn Judd)
Does Win32::ODBC use SQL*Net when used on Oracle? yong321@yahoo.com
Re: DOS Batch to PERL Conversion smilesdotcom@my-deja.com
Re: Eval and Regexps Help bluearchtop@my-deja.com
Re: grepping for multiple fields <russ_jones@rac.ray.com>
help with RegExp <samara_biz@hotmail.com>
Re: I have another question <bkennedy99@home.com>
I need help with ffa links script jeffinnc68@my-deja.com
Open Multiple Files <micheal@nospam_usa.net>
Re: Open Multiple Files Frank.Louwers@roots.org.MEEP
Re: Open Multiple Files <bwalton@rochester.rr.com>
Re: Output to printer in Win NT <lr@hpl.hp.com>
Parsing mail messages awr@cpu.com
Re: perl / unix question <guenther.degenfelder@datev.de>
Re: Perl cgi-wrap issues and security problems (Rafael Garcia-Suarez)
Re: Perl for Palm? (Eric Smith)
Re: problems with Tk and NT4 <bhoran@gate.net>
Re: Regex Alternation Question (Teodor Zlatanov)
Re: Regex Alternation Question (Abigail)
Re: Regex Alternation Question <Jonas.Reinsch@ppi.de>
Re: Search and replace character sections (Keith Calvert Ivey)
try & catch <mail@mail.com>
Re: try & catch (Rafael Garcia-Suarez)
Re: Two pipes and only one runs, why? <panderse@us.ibm.com>
Re: Upload file: Apache/perl - PLEASE HELP!!! <milnergroup@usa.net>
Re: version control win32 <eyalb@aks.com>
Win2K; Perl from command line <mweir@jetform.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 18 Aug 2000 15:19:28 +0100
From: Solo <solo@u.genie.co.uk>
Subject: Anyone Help???
Message-Id: <399D45F0.8BB56EB3@u.genie.co.uk>
Hi all,
got an interesting problem that someone might be able to help me
with....
I have a file called aliases which contains a line as follows
# allusers: :include:/usr/home/admin/temp/allusers
What I want to do is to edit the file to remove the hash.
From the command line I can do it with this
perl -p -i -e 's/^(\# allusers: )(.+)/allusers: $2/g' aliases
but if i try this from within a program using
system ("perl -p -i -e 's/^(\# allusers: )(.+)/allusers: $2/g'
aliases");
All I get is
allusers:
For some reason the rest of the line is not added. Am i missing
something here? Does anyone know why this may be occuring?
can this be do anotherway???
Thanks for you tme on this..
Mark
------------------------------
Date: Fri, 18 Aug 2000 10:28:33 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Anyone Help???
Message-Id: <399D4810.6ACA0975@attglobal.net>
Solo wrote:
>
> # allusers: :include:/usr/home/admin/temp/allusers
>
> What I want to do is to edit the file to remove the hash.
> From the command line I can do it with this
>
> perl -p -i -e 's/^(\# allusers: )(.+)/allusers: $2/g' aliases
>
> but if i try this from within a program using
>
> system ("perl -p -i -e 's/^(\# allusers: )(.+)/allusers: $2/g'
> aliases");
>
> All I get is
>
> allusers:
>
> For some reason the rest of the line is not added. Am i missing
> something here? Does anyone know why this may be occuring?
>
> can this be do anotherway???
You are using a system() call from a Perl script to run perl?
Seems a bit silly. Or am I mistaken?
------------------------------
Date: Fri, 18 Aug 2000 13:20:54 GMT
From: nvp@spamnothanks.speakeasy.org (NP)
Subject: Re: Apache and cgi/perl
Message-Id: <WKan5.260191$t91.2642460@news4.giganews.com>
On Fri, 18 Aug 2000 09:55:28 +0100, pete <pete@alphanetcoms.co.uk> wrote:
: Try the following:
:
: #!c:/perl/bin/perl.exe
Does the above line work for you on your Windows machine? Last I
checked, DOS didn't understand shebang paths.
If the person *really* wants to execute Perl programs without executing
'perl.exe program', they can do 1 of 2 things (off the top of my
head). 1. They can make appropriate registry entries (the ActivePerl
installer does this) or 2. they can wrap their Perl program in a batch
script with 'pl2bat'.
--
Nate II
------------------------------
Date: 18 Aug 2000 9:26:19 -0400
From: Ryan Tarpine <rtarpine@hotmail.com>
Subject: Re: Apache and cgi/perl
Message-Id: <8njdn2$2lje$1@newssvr05-en0.news.prodigy.com>
>Ok, here it is, I have an Apache server set up. The only thing is,
>its setup on Windows NT insead of my Linux computer this time.
>After I type a basic Perl Cgi-Script I have no idea on Windows
>what to type for a path at the top of the program.
>ie.
>in Linux I start this way
>#!/usr/local/bin/perl
>In windows, I got no idea what to put there.
>Anyone know?
>-john-
If you put the path to perl in Windows' %PATH% env. variable, you
can make the shebang line a quick-and-easy "#!perl". At least it
worked on my Win98 box.
Ryan
------------------------------
Date: Fri, 18 Aug 2000 16:17:38 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Apache and cgi/perl
Message-Id: <Pine.GHP.4.21.0008181613240.4917-100000@hpplus03.cern.ch>
On Fri, 18 Aug 2000, NP wrote:
> : #!c:/perl/bin/perl.exe
>
> Does the above line work for you on your Windows machine?
Works fine for me, except that I'd have -wT there too. But I put
the shebang line in for the use of Win32 Apache.
> Last I checked, DOS didn't understand shebang paths.
Last I checked, Win32 Apache didn't care about that sort of DOS shell
limitation. :-}
Of course, for the times when I'm invoking Perl from a command shell,
I have a suitable PATH setting too.
------------------------------
Date: Fri, 18 Aug 2000 08:43:53 -0500
From: Tom Briles <sariq@texas.net>
Subject: Re: close window
Message-Id: <399D3D99.DAF88681@texas.net>
Jonathan Stowe wrote:
>
> On Thu, 17 Aug 2000 14:32:53 +0200 Flip wrote:
> > Could anybody tell me what the perl command is to close the current
> > browserwindow
>
> system('/sbin/reboot');
I prefer the more portable:
print $q->h1('Please close the current browserwindow.');
- Tom
------------------------------
Date: Fri, 18 Aug 2000 14:59:17 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: close window
Message-Id: <slrn8pqk4o.pnk.rgarciasuarez@rafael.kazibao.net>
Tom Briles wrote in comp.lang.perl.misc:
>Jonathan Stowe wrote:
>>
>> On Thu, 17 Aug 2000 14:32:53 +0200 Flip wrote:
>> > Could anybody tell me what the perl command is to close the current
>> > browserwindow
>>
>> system('/sbin/reboot');
>
>I prefer the more portable:
>
>print $q->h1('Please close the current browserwindow.');
print $q->h2("(or, if you're using lynx, please quit.)");
--
Rafael Garcia-Suarez
------------------------------
Date: Fri, 18 Aug 2000 14:59:48 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: close window
Message-Id: <slrn8pqjr1.apk.tjla@thislove.dyndns.org>
I was shocked! How could Tom Briles <sariq@texas.net>
say such a terrible thing:
>Jonathan Stowe wrote:
>>
>> On Thu, 17 Aug 2000 14:32:53 +0200 Flip wrote:
>> > Could anybody tell me what the perl command is to close the current
>> > browserwindow
>>
>> system('/sbin/reboot');
>
>I prefer the more portable:
>
>print $q->h1('Please close the current browserwindow.');
Actually I've been thinking and maybe we were *gasp* wrong! I think the
OP is asking this in a CGI context in which case clearly the best way to
close the current browser window is:
system "rsh", "$ENV{REMOTE_ADDR}", "killall", "-9", "netscape"
and die "Cannot close the browser window";
All I can say is phew. I couldn't sleep knowing I had made an error of
such gigantic proportions!
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
ABADDON, n.:
The adversary of Souls, considered under one of his many charming aspects. A
bad one.
------------------------------
Date: Fri, 18 Aug 2000 14:17:49 GMT
From: yong321@yahoo.com
Subject: Does Win32::ODBC use SQL*Net when used on Oracle?
Message-Id: <8njghq$sch$1@nnrp1.deja.com>
This question is raised on an Oracle DBA mailing list. Some people say
the ODBC driver from Oracle uses SQL*Net, the proprietary network
protocol from Oracle; other vendors' drivers may or may not. If that's
true, what about Dave Roth's Win32::ODBC from www.roth.net? Other
people say all ODBC drivers use SQL*Net.
Thanks.
--
Yong Huang
(yong321@yahoo.com)
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 18 Aug 2000 13:52:17 GMT
From: smilesdotcom@my-deja.com
Subject: Re: DOS Batch to PERL Conversion
Message-Id: <8njf29$qis$1@nnrp1.deja.com>
In article <klZm5.108535$A%3.1426584@news1.rdc2.pa.home.com>,
"Ben Kennedy" <bkennedy@hmsonline.com> wrote:
>
> <smilesdotcom@my-deja.com> wrote in message
> news:8nh6ua$9ad$1@nnrp1.deja.com...
> > I am looking for a simple utility that will convert a DOS batch
file to
> > a PERL file. The batch is very simple. I am not looking for
> > perfection, just a starting point.
>
> I haven't heard of anything that does that - are you trying to convert
> simple batch files that run other programs, or convert looping
constructs?
>
> --Ben Kennedy
>
>
I am using it to run other scripts and java programs. I am looking for
a portable script that will set a CLASSPATH, etc.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 18 Aug 2000 14:07:13 GMT
From: bluearchtop@my-deja.com
Subject: Re: Eval and Regexps Help
Message-Id: <8njfu2$rkg$1@nnrp1.deja.com>
> what you're really trying to do is print everything outside of <%%>s
and
> execute everything inside <%%> .. your simple substitution will not
> accomplish this
Yes, that is exactly correct. Can you point me in the right direction
for doing this?
I want everything inside the <% %> to be executed.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 18 Aug 2000 08:58:51 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: grepping for multiple fields
Message-Id: <399D411B.7BE00099@rac.ray.com>
Abe Timmerman wrote:
>
> my(%seen);
> my @final = grep {
> my @n = m(?=[/)])!g;
> /rejected/ || (@n && @seen{ @n }) } map {
> my @n = m(?=[/)])!g;
> /rejected/ and @seen{ @n } = (1) x @n; $_
> } @lines;
>
> print "Final:\n", map "\t$_\n" => @final;
>
There really are some amazing coders in this group! Thanks Abe, Greg
and Ren! My head's spinning! My mind is boggled. I'm itching like a
man on a fuzzy tree. Thanks again.
--
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747
Quae narravi, nullo modo negabo. - Catullus
------------------------------
Date: Fri, 18 Aug 2000 10:29:20 -0400
From: "Alex T." <samara_biz@hotmail.com>
Subject: help with RegExp
Message-Id: <399D4840.9E564069@hotmail.com>
Hi,
I need to remove suffixes from last names.
For example,
WHITE<any number of blanks>JR
should become WHITE
ST<any number of blanks>LOUIS<any number of blanks>III
should become ST LOUIS
I tried this:
$lastname =~ s/([\w|\s]+?)\s+?(\w+?)$/$1/i;
and a few other ways, but I couldn't get it to work. How can I do it?
Thanks!
Alex
------------------------------
Date: Fri, 18 Aug 2000 14:44:58 GMT
From: "Ben Kennedy" <bkennedy99@home.com>
Subject: Re: I have another question
Message-Id: <KZbn5.110538$A%3.1443374@news1.rdc2.pa.home.com>
<pape_98@my-deja.com> wrote in message news:8nhes8$j3l$1@nnrp1.deja.com...
> I have 1 final question.
> Now that I know how to sort correctly how do u implement a function
> calls a file and then sorts its contents.
> would it be something like this:
One thing worth mentioning, there is a standard Unix utility called 'sort' -
its good for a simple numeric or alphanumeric sort on specific fields based
on any delimiter. Check out 'man sort' or 'info sort' for more details.
For smaller files, sorting all the text in memory via perl is fine, but for
arbitrarily large files, command line 'sort' is the way to go since it uses
auxiliarry text files, and uses little memory. For a simple sort on one
delimited field, a sort one liner may be your best bet.
--Ben Kennedy
------------------------------
Date: Fri, 18 Aug 2000 13:52:28 GMT
From: jeffinnc68@my-deja.com
Subject: I need help with ffa links script
Message-Id: <8njf2k$qj2$1@nnrp1.deja.com>
Hi All,
I'm hoping someone can help me. I started a free
for all links page and want to allow automatic
posting with software (FFAblaster, etc.) but
cannot figure out what I have to add to let that
happen. I'm an amateur I admit but no where can
i find this info. Any help would be great if you
can. Email me at jborden@nc.rr.com if you have
any suggestions. Thanks.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 18 Aug 2000 13:27:26 GMT
From: "Micheal" <micheal@nospam_usa.net>
Subject: Open Multiple Files
Message-Id: <2Ran5.164371$Gh.2793413@news20.bellglobal.com>
Hi there,
How would I open two (or more) documents at the same time to save output to
them?
I have
open(OUTPUT, ">$dir/$filename");
...
close OUTPUT;
which works for one file, but I have tried multiple combinations of this to
open to files at once... never works. Any suggestions appreciated
------------------------------
Date: 18 Aug 2000 13:31:09 GMT
From: Frank.Louwers@roots.org.MEEP
Subject: Re: Open Multiple Files
Message-Id: <8njdqt$e5b$1@inf6serv.rug.ac.be>
Micheal <micheal@nospam_usa.net> wrote:
> How would I open two (or more) documents at the same time to save output to
> them?
> I have
> open(OUTPUT, ">$dir/$filename");
> ...
> close OUTPUT;
open(OUTPUT1, ">$dir/file1");
open(OUTPUT2, ">$dir/file2");
...
close OUTPUT;
close OUTPUT2;
Frank
--
Frank Louwers Unix System Administrator
PGP: 1024D/3F6A7EDD D597 566A BDF5 BBFB C308 447A 5E81 1188 3F6A 7EDD
------------------------------
Date: Fri, 18 Aug 2000 14:54:37 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Open Multiple Files
Message-Id: <399D4E5F.C5E9CE7D@rochester.rr.com>
Micheal wrote:
...
> How would I open two (or more) documents at the same time to save output to
> them?
>
> I have
>
> open(OUTPUT, ">$dir/$filename");
> ...
> close OUTPUT;
>
> which works for one file, but I have tried multiple combinations of this to
> open to files at once... never works. Any suggestions appreciated
Hmmmm...you want to output to two or more files from one filehandle with
one set of print statements, right? You could open a pipe to one or
more tee's to do that:
open OUTPUT,"|tee file1>file2" or die "Oops, $!\n";
for example. That assumes you are working on a Unix-like system or have
something like the Unix tee command available on your system. Depending
on your OS, make sure to
close OUTPUT;
when you are done. Windoze 98 SE using Cygwin v20 hangs if you don't
close, for example. Also, Cygwin's tee (v1.16) under Windoze seems to
mangle the output a bit regarding line endings. It should be fine under
Unix-like OS's.
--
Bob Walton
------------------------------
Date: Fri, 18 Aug 2000 07:47:45 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Output to printer in Win NT
Message-Id: <MPG.1406ec6a34a5721e98ac91@nntp.hpl.hp.com>
In article <MPG.1407993347433e99896ce@localhost>,
elephant@squirrelgroup.com says...
> Jonathan Stowe wrote ..
> >On Thu, 17 Aug 2000 15:13:38 GMT hiroshiishii@my-deja.com wrote:
> >> Hi All:
> >>
> >> Would someone give an advice on how to print an ASCII string, "Hello
> >> world," to LaserJet4, which is on local parallel port (LPT1:), from
> >> WinNT or 98?
> >
> >open(PRINTER,'>LPT1:') || die "Can't open printer - $!\n";
> >print "Hello, World\n";
> >
> >print "\f"; # Some printers will require this line feed before producing
> > # a page
> >
> >close PRINTER;
> >
> >On shared printers you can use the UNC name of the printer (\\server\printer).
>
> of course - Jonathan meant to write
>
> print PRINTER "Hello, World\n";
> print PRINTER "\f";
>
> or maybe a select disappeared from my newsfeed ;)
He might also have meantioned that one can write the UNC name with
forward slashes '//server/printer' to avoid having to bounce so many
times on the backslash key.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 18 Aug 2000 14:50:02 GMT
From: awr@cpu.com
Subject: Parsing mail messages
Message-Id: <8njieh$um9$1@nnrp1.deja.com>
I'm on a project where data files will delivered for processing by
email. Sendmail will be configured to hand the message to my script.
Parsing the messages is trivial if everything is in ascii text. However,
I'm afraid the data will be hidden in mime attachments in many of the
messages. I would like to be able to detech and decode any mime
attachments. Could some kind soul tell me which module or modules I
should be looking at to do this? I made a quick perusal of the mail and
news section of the CPAN modules list, but nothing jumped
out at me.
Thanks!
Andrew Robinson
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 18 Aug 2000 15:06:01 +0200
From: "Guenther Degenfelder" <guenther.degenfelder@datev.de>
Subject: Re: perl / unix question
Message-Id: <399d353e$1@news.datev.de>
<arun_rajappa@my-deja.com> schrieb im Newsbeitrag
news:8niv8m$971$1@nnrp1.deja.com...
> hi,
>
> i have this problem that seems impossible to crack ! (with the present
> system !!)
...
> 0) i'm writing a set of perl scripts for tracking defects and co-
> ordinating projects for our particular system. (i.e, it should work
> with the idiosyncracies of the present system)
Perl.
Good choice!
> 1) i work on a unix system where multiple people use the same login id
> (login id is "shared")
Unix.
Good choice too!
> 2) i want to write a program that will find out the specific users name
...
> can this be done ??
>
> or can i tackle the problem in some other way, without changing the
> system (like getting new login id's for everyone)
I think the better way is:
Add as many groups as needed (depends on how many different roles your users
have: system operators, database admins, ...)
Add as many userids as needed and assign them to your groups.
Use sudo for commands, that need root privileges (sudo can also assign lists
of jobs to lists of users...).
rgds
Guenther
------------------------------
Date: Fri, 18 Aug 2000 13:33:07 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Perl cgi-wrap issues and security problems
Message-Id: <slrn8pqf37.pdo.rgarciasuarez@rafael.kazibao.net>
Sandra wrote in comp.lang.perl.misc:
>
>We have a redhat 6.1 dedicated server with 18gb hd,
>php4, perl 5.x and mysql installed.
>We want to give out free /cgi-bin/ space for users
>(something like geocities but only for perl scripts)
I've no idea how you can prevent non-perl CGI programs to be executed.
But you can scan periodically the cgi-bin dirs for files that don't
begin with #!/usr/(local/)?bin/perl.
>We are having a lot of problems setting up the cgi-wrap
>system to avoid malicious users hacking the server through
>perl scripts with system("rm etc...") and things like that.
>We do know there are lots of hackers around, and they
>will try to hack our server, we are sure.
>
>At first we don't want to give private FTP accounts to
>every user (like geocities). At first, users will upload
>through the browser. We can use a parse function to
>reject .cgi files with common words like "system", `xxx`,
>"sendmail", socket functions, rm, etc, etc. but we can't
>figure out all available possibilities of malicious code.
In one word, this is impossible. Even non malicious-looking code can be
used to do malicious things. That's called a security hole. E.g.:
open FILE, (new CGI)->param('file')
can be used to execute any arbitrary command on the server.
>Questions:
>1. CGI-wrap is the only solution?
>2. We would like to have a modified version of Perl
>with exec() disabled, system() disabled, eval disabled,
>and most server/disk access disabled etc, etc.
>is this possible?
You can hack the perl source code to remove those functions.
>3. Is it possible to install background procs through
>a Perl script? system("./malicious_hidden_server &") ???
Yes. With fork, for example.
Can I suggest you something. It appears that you're taking the problem
from the wrong side. Have you ever heard something about 'chrooted
environnments'? See the man page for chroot on your system. Install
apache as chroot so it can access only a limited part of the filesystem.
Install ftpd as chroot too. This will be safer that hacking the perl
source code and scanning all files that are uploaded to your server.
There are plenty of tutorials on the web that will help you.
--
Rafael Garcia-Suarez
------------------------------
Date: 18 Aug 2000 13:55:41 GMT
From: eric@fruitcom.com (Eric Smith)
Subject: Re: Perl for Palm?
Message-Id: <slrn8pqfs7.pdk.eric@plum.fruitcom.com>
matt venn posted
> shame
but father Larry talks about a microperl for realtime devices - palmtops
and such - when discussing the new perl 6. See ww.perl.com.
To me the future aint there at all. I think that data and functionality
will be left to building-bound machines while mobile devices function as
terminals connecting to them through always-on wireless network.
Eric Smith
------------------------------
Date: Fri, 18 Aug 2000 10:21:27 -0400
From: Brian Horan <bhoran@gate.net>
To: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: problems with Tk and NT4
Message-Id: <Pine.A41.4.21.0008181020340.57386-100000@dakota.gate.net>
> i get perl of a NT4 box with sp6 .
is it ok ? poor thing perl must be sad!
~
'v' Brian Horan
// \\ Systems Analyst/Administrator/Programmer
/( )\ Miami Herald Publishing Company bhoran@herald.com
^`~'^
Linux: For when you're sick of CTRL-ALT-DEL
------------------------------
Date: 18 Aug 2000 09:48:08 -0500
From: tzz@iglou.com (Teodor Zlatanov)
Subject: Re: Regex Alternation Question
Message-Id: <399d3e98$1_1@news.iglou.com>
<399D2106.184AAF56@ppi.de>:Jonas Reinsch (Jonas.Reinsch@ppi.de):comp.lang.perl.misc:Fri, 18 Aug 2000 13:41:58 +0200:quote:
: In principle, the solution(s) suggest(s) to use separate
: matching instead of an alternation.
: This is faster (yes, even without precompilation), but
: it doesn't do the same. Consider the following:
:
: $string = "bla bli blub";
: $string =~ /(blub)|(bli)|(bla)/; # (bla) matches
: $string=~/(blub)/||$string=~/(bli)/||$string=~/(bla)/;#
: (blub) #
: matches
:
: That is, using seperate matching, the order of the
: patterns matters, while it doesn't when using an
: alternation (neglecting of course cases like
: $reg1="match";$reg2="matched").
: Of course problems exist where the two solutions are
: interchangable, but in other cases, they aren't.
Minor nitpick: the order in the alternation does matter. The regex engine
will try to match the alternatives in order at each position, so
/(Sam|Samwise)/ - to use the example from "Programming Perl" page 187, 3rd
ed. - will never match the second pattern as is, while /(Samwise|Sam)/ will
do the right thing.
The reason why (blub) matches in your example's third line is that you
short-circuit through (bla). Both of them match, so it's up to you to
decide what to do with that information. If you want the regex engine's
behavior, where you always start from the outside, then your way is
certainly better, but quite a bit slower.
--
Teodor Zlatanov <tzz@iglou.com>
"Brevis oratio penetrat colos, longa potatio evacuat ciphos." -Rabelais
------------------------------
Date: 18 Aug 2000 14:48:57 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Regex Alternation Question
Message-Id: <slrn8pqj5k.tj3.abigail@alexandra.foad.org>
Jonas Reinsch (Jonas.Reinsch@ppi.de) wrote on MMDXLIV September MCMXCIII
in <URL:news:399D2106.184AAF56@ppi.de>:
##
## So to reformulate my question:
## I'm thinking of a feature analogous to $+.
## While $+ gives the text that was matched
## by the last matching parenthesized pattern,
## the feature I think of would give the pattern of
## the last matching parenthesized pattern.
## Do you think that such a feature would be
## -useful (given it's fast); I mean useful to more people
## than just me
## -possible to implement (again, I didn't do something like
## this before)?
## Or, has anybody already started implementing anything
## similar?
Well, you can do this:
my $i = -1;
$string =~ /(blub(?{ $i = 0 }))|(bli(?{ $i = 1 }))|(blurp(?{ $i = 2 }))/;
if ($i == -1) {print "No match\n"}
else {my @sub_matches = qw /blub bli blurp/;
print "Matched: $sub_matches[$i]\n";
}
I tried to automate the the process:
#!/opt/perl/bin/perl -w
use strict;
use re 'eval';
my $string = "bla bli blurlp";
my @sub_matches = qw /blub bli blurp/;
my $i = -1;
my $re = join "|" =>
map {"($sub_matches[$_](?{ \$i = $_ }))"} 0 .. $#sub_matches;
# print $re, "\n";
$string =~ /$re/;
if ($i == -1) {
print "No match\n";
}
else {
print "Matched: $sub_matches[$i]\n";
}
__END__
But while $re contains exactly the same string as in the previous code
fragment, $i remains -1. I've no idea why this doesn't work.
Abigail
--
$_ = "\x3C\x3C\x45\x4F\x54"; s/<<EOT/<<EOT/e; print;
Just another Perl Hacker
EOT
------------------------------
Date: Fri, 18 Aug 2000 17:04:11 +0200
From: Jonas Reinsch <Jonas.Reinsch@ppi.de>
Subject: Re: Regex Alternation Question
Message-Id: <399D506B.4A55A566@ppi.de>
Teodor Zlatanov wrote:
> Minor nitpick: the order in the alternation does matter. The regex engine
> will try to match the alternatives in order at each position, so
> /(Sam|Samwise)/ - to use the example from "Programming Perl" page 187, 3rd
> ed. - will never match the second pattern as is, while /(Samwise|Sam)/ will
> do the right thing.
>
I think I was aware of this fact when writing:
>> That is, using seperate matching, the order of the
>> patterns matters, while it doesn't when using an
>> alternation (neglecting of course cases like
>> ^^^^^^^^^^^^^^^^^^^^
>> $reg1="match";$reg2="matched").
> The reason why (blub) matches in your example's third line is that you
> short-circuit through (bla). Both of them match, so it's up to you to
> decide what to do with that information.
Consider a problem like this: I have regexes matching
C-Comments, regexes matching quoted strings, regexes
matching certain kinds of keywords, regexes matching...
Now I want to split a string into pieces of comments,
quoted strings, etc.
Example:
$test_string = 'int foo;/*a variable*/char foo2[30]="tach";';
my $comment; # matches C-comment
my $type_keyword; # matches int *or* char
my $string # matches double-quoted string
Now with an alternation I would accomplish this like:
@splitted = split(($comment|$type_keyword|$string),$test_string);
@splitted now contains:
('', 'int', 'foo', '/*a variable*/', 'char', 'foo2[30]=', '"tach"', ';')
Yes, it's like you said: It's up to me how to use this information.
I don't see how this example could easily (and more efficient) be
accomplished with seperate matching (please regard the general
problem, not just this limited example).
If you want the regex engine's
> behavior, where you always start from the outside, then your way is
> certainly better, but quite a bit slower.
>
> --
> Teodor Zlatanov <tzz@iglou.com>
> "Brevis oratio penetrat colos, longa potatio evacuat ciphos." -Rabelais
Jonas.
------------------------------
Date: Fri, 18 Aug 2000 13:55:35 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Search and replace character sections
Message-Id: <39a23fe6.36819367@news.newsguy.com>
michaeljgardner@my-deja.com wrote:
>You want to replace the domain name with asterisks, I
>used x's to avoid any metacharacter confusion.
Metacharacters are not an issue here, except when the programmer
is confused. The last part of a substitution is not a regex, so
asterisks are not special and don't need to be backslashed.
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: Fri, 18 Aug 2000 09:50:57 -0500
From: GI812 <mail@mail.com>
Subject: try & catch
Message-Id: <399D4D51.97593664@mail.com>
Hello my brilliant friends! I've got a little bit of a c/java
background and have used tries and catches before. Just wondering if
there is something of the sort for perl. I've looked through my books,
but haven't found anything (so far). What I want to do is check to see
if a file is currently able to be written to or wait a period of time
and then try again. Kind of a multiuser problem. If anyone follows my
jibberish or has any insight I'd be happy to see what you have to say!
------------------------------
Date: Fri, 18 Aug 2000 15:04:09 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: try & catch
Message-Id: <slrn8pqkdt.pnk.rgarciasuarez@rafael.kazibao.net>
GI812 wrote in comp.lang.perl.misc:
>
>Hello my brilliant friends! I've got a little bit of a c/java
>background and have used tries and catches before. Just wondering if
>there is something of the sort for perl. I've looked through my books,
>but haven't found anything (so far). What I want to do is check to see
>if a file is currently able to be written to or wait a period of time
>and then try again.
Well, try/catch is usually for handling exceptional conditions, not for
this kind of job. Why not simply write :
-w $file or sleep($duration);
-w $file or die "I've waited too much, I give up\n";
or :
sleep($duration) while not -w $file;
--
Rafael Garcia-Suarez
------------------------------
Date: Fri, 18 Aug 2000 07:50:21 -0500
From: "Paul R. Andersen" <panderse@us.ibm.com>
Subject: Re: Two pipes and only one runs, why?
Message-Id: <399D310D.8C62A147@us.ibm.com>
I've spent more time looking at this and came up with something even
simpler that I think should work, but doesn't. Theories on why are
welcome.
I expect to see something like:
XXXLP did something.
XXXLP did something.
.
.
.
but I get:
LP did something.
XLP did something.
XLP did something.
.
.
.
Adjusting times and loop counts don't seem to matter. Why is it that
the repeat() only seems to run once for each message DummyProcess puts
out and why it that DummyProcess shows output first?
Am I missing something basic here about how pipes/threads/multitasking
etc. work? Is it that I need to have a semaphore to keep what I think
are two processes from using the writedata subroutine (or one of its
parts) at the same time?
#!/usr/contrib/bin/perl -w
use strict;
use Tk;
require Tk::ROText;
select (STDOUT); $| = 1;
my $main = new MainWindow;
$main->configure('-title' => "Demo of failure");
my $checkdata = $main->Scrolled("ROText")
->pack(-side => 'top', -fill => 'both');
$main->Button(-text => 'Runit',
-command => sub{RunTest(); }
) ->pack(-side => 'left');
MainLoop;
sub RunTest
{
my $udid = $checkdata->repeat(2000,sub{ writedata("X"); });
# ======================
my $cmd = "DummyProcess.pl";
open READPRIME, "$cmd |" or
die "Pipe for long running thing failed to open: $!\n";
select (READPRIME); $| = 1; select (STDOUT);
while (<READPRIME>)
{ writedata($_); }
close READPRIME;
print "Test ending\n";
$udid->cancel();
}
sub writedata
{
my ($Display) = @_;
$checkdata->insert('end',$Display);
$checkdata->see('end');
$checkdata->update();
}
This is the DummyProcess.pl file
#!/usr/contrib/bin/perl -w
use strict;
select (STDOUT); $| = 1;
for (my $i = 0; $i < 10; $i++)
{
for (my $j = 0; $j < 1000000; $j++)
{ my $k = 0; }
print "LP did something.\n";
}
--
Paul Andersen
+++++++++++++
The difference between theory and practice is that in theory there is no
difference between theory and practice; but in practice there is.
------------------------------
Date: Fri, 18 Aug 2000 14:19:00 GMT
From: The Milner Group, Inc. <milnergroup@usa.net>
Subject: Re: Upload file: Apache/perl - PLEASE HELP!!!
Message-Id: <8njgk0$sdf$1@nnrp1.deja.com>
Thank you for your feedback.
Once realized, the script was the cause (not the server), Everything
worked out.
- Anatoly.
In article <sO5n5.163$DT4.3995652@nnrp2.clara.net>,
newsgroups@ckeith.clara.net (Colin Keith) wrote:
> In article <8nhgqp$ljo$1@nnrp1.deja.com>, The Milner Group, Inc.
> <milnergroup@usa.net> wrote:
> >As a result I am getting the following error:
> >"Premature end of script headers".
>
> That's the result of your script not giving back proper headers to
your web
> server.
>
> >If I change to GET from POST, I can retrieve the file NAME, but the
> >actual body of the text file is not there.
> >1. Permissions are 777 on upload dir and cgi script.
>
> That is not a good habit to get into. Permissions should be 0755 at
best on
> your script. There is no need for your script to be writable by
anyone but
> yourself.
>
> >3. CGI is executing without error on command-line
>
> But they run in different environments, most notably of which is that
you
> have to return a valid HTTP header when returning data to the web
server.
>
> >#!/usr/local/bin/perl
> -w
> use strict;
>
> These should all by my() varaibles
>
> > $theext = ".gif";
> Extensions mean nothing about the file type or size, they're just
naming
> conventions.
>
> > my $req = new CGI;
> You should get into the habit of writing CGI->new();
>
> > $fileName =~ s!^.*(\\|\/)!!;
>
> If that's the only parsing you're going to do you might find you're
in
> trouble. It doesn't use the /g switch (!g in this case) so only the
first
> match will be replaced. You should certainly remove .. too and I
would
> suggest anything that isn't a character you can type on your
keyboard - and
> even some of those should go too. Create a file called '-rf' and see
how
> much fun you have removing it. Try the warez puppy naming conventions
and
> call the filename ". ".
>
> I would suggest you restrict file names with a couple of regexp's:
>
> # Very restrictive: Has to be at least 1 letter/number followed
by .gif
> if(!/^([A-Za-z0-9]+)\.gif$/)
>
> # Slightly less: The first character same as above,
> # but after that the name can _ - or .
> if(!/^([A-Za-z0-9][A-Za-z0-9_\.-]*)\.gif$/)
>
> You might want to go on to allow the filenaming conventions you get
on
> Win32, such as including (), &, [], spaces etc. But they have
problems. To
> be honest you might well be better off generating a filename yourself
and
> storing that in a table along with the 'real' filename, then
consulting the
> table:
>
> use Fcntl;
> use DB_File;
> my(%filename_to_real_name);
> tie(%filename_to_real_name, 'DB_File', $name_conv_db, O_CREAT|O_RDWR,
0666);
>
> ...
>
> $filename_to_real_name{generate_name} = $fileName;
>
> Then any time you want to access it, say another script you can just
use
> this code, except that you get the value rather than assign it ...
>
> >if ($allowall ne "yes") {
> >if (lc(substr($newmain,length($newmain) - 4,4)) ne $theext){
> >$filenotgood = "yes";
> >if ($filenotgood ne "yes") {
>
> Eww.
>
> if($allow_all && $newmain !~ /\.$theext$/i){
>
> >open (OUTFILE, ">$basedir/$fileName");
>
> No error handling. Try changing it to:
>
> if(!open( .. )){
> print header(),
> start_html('Error opening file'),
> p('An error occurred opening the file'),
> p("\"$!\""),
> end_html();
> exit(0);
> }
>
> >print "$basedir/$fileName<br>";
>
> That's probably generating your error, you have to print the headers -
at
> least the Content-Type, before you can print HTML.
>
> Col.
>
> ---
> Colin Keith
> Systems Administrator
> Network Operations Team
> ClaraNET (UK) Ltd. NOC
>
--
Anatoly Milner
The Milner Group, Inc.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 18 Aug 2000 16:11:22 +0300
From: Eyal Ben-David <eyalb@aks.com>
Subject: Re: version control win32
Message-Id: <m2em3mzpc5.fsf@eyalb_home.localdomain>
jponder9@my-deja.com writes:
> hi all,
> My colleague and I r experiencing problems when working on the
> same code modules with version control (e.g. how we incorporate each
> others updates!) Does anyone know of good version control software
> suitable for Perl on Win32? It will make us so much more productive!!
> :-)
>
> Thanx,
> Jimbo
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
CVS works fine on Win32 too.
You will have a nice GUI wrapper (WinCVS)
Check http://www.cvshome.org
Eyal.
------------------------------
Date: Fri, 18 Aug 2000 10:24:01 -0400
From: "Michael Weir" <mweir@jetform.com>
Subject: Win2K; Perl from command line
Message-Id: <spqhvanm87v139@corp.supernews.com>
Is there a way to invoke perl the way you do batch files? So instead of
typing 'perl myCmd.pl' I could just type 'myCmd' on the command line?
Thanks
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4057
**************************************