[19231] in Perl-Users-Digest
Perl-Users Digest, Issue: 1426 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 2 06:06:16 2001
Date: Thu, 2 Aug 2001 03:05:09 -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: <996746709-v10-i1426@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 2 Aug 2001 Volume: 10 Number: 1426
Today's topics:
Re: active state and CGI? <ron@savage.net.au>
Re: Anonymous Subroutines and shared vars? <bkennedy99@Home.com>
Re: calling a perl script from perl <zachmay@hotmail.com>
Re: challenging question <ilya@martynov.org>
Re: challenging question (Damian James)
Re: challenging question <wyzelli@yahoo.com>
Re: Converting in Image::Magick <ron@savage.net.au>
Re: csh together with perl <bkennedy99@Home.com>
FAQ: How do I find the first array element for which a <faq@denver.pm.org>
global variables <manuel.koerner@rexroth.de>
Re: global variables (Anno Siegel)
Re: how to find free disk space (Win32) <acid-spam@acid06.cjb.net>
Re: how to validate a regular expression.. (Anno Siegel)
Howto run traceroute-parse IP's-store in array? (Adam)
Re: Howto run traceroute-parse IP's-store in array? (Anno Siegel)
Is regex in grep() automatically precompiled? <Tassilo.Parseval@post.rwth-aachen.de>
Re: Is regex in grep() automatically precompiled? (Anno Siegel)
Re: join lines ? (Yves Orton)
Re: Matching Strings in an array <ahamm@sanderson.net.au>
Re: Matching Strings in an array <kistler@gmx.net>
Re: newbie question about file concatenation <if.xoboi@jks.invalid>
Re: OT: spelling (was Re: chess in perl) <if.xoboi@jks.invalid>
Re: password protact a file (Martien Verbruggen)
Re: password protact a file (Damian James)
Re: perl regular expression grammar (Mark Jason Dominus)
Re: read files into arrays... <if.xoboi@jks.invalid>
SOAP/WSDL Web services search <bill.leigh@leighly.fsnet.co.uk>
Re: What should happen with this perl code? <kistler@gmx.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 2 Aug 2001 15:35:02 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: active state and CGI?
Message-Id: <hH5a7.3036$257.125547@ozemail.com.au>
zawy
Instructions for downloading and installing a pre-compiled version of Apache for Windows are here:
http://savage.net.au/Perl.html#Configuring-Apache
--
Cheers
Ron Savage
ron@savage.net.au
http://savage.net.au/index.html
------------------------------
Date: Thu, 02 Aug 2001 04:37:13 GMT
From: "Ben Kennedy" <bkennedy99@Home.com>
Subject: Re: Anonymous Subroutines and shared vars?
Message-Id: <ZN4a7.59200$EP6.14218372@news1.rdc2.pa.home.com>
"BCC" <a@b.c> wrote in message news:3B68417F.8043898F@b.c...
> So that when I call mySub1, I get the warning. So it would seem I have
> a choice, I can either rewrite these as anonymous subroutines, or
> explicitly pass in my cgi params everytime I call the sub. The latter
> sounds cleaner to me, and I can do this, but it seems rather painful as
> there are a lot of params. Would a hash be best to pass all the cgi
> params in to my sub? Or an array...?
>
> Which method is prefered in this situation, and would it be possible to
> see an example?
It is of course up to you, but I would fetch the parameters as a hash ref
and pass it to the subs:
my $q = new CGI;
...
my $params = $q->Vars;
mysub($params,"A1", "B2");
sub mysub {
my($param_ref, $arg1, $arg2 ) = @_;
print "Param a is $parm_ref->{a} etc etc \n";
...
}
Hope this helps--
--Ben Kennedy
------------------------------
Date: Wed, 1 Aug 2001 23:53:04 -0700
From: "Zach May" <zachmay@hotmail.com>
Subject: Re: calling a perl script from perl
Message-Id: <9kaipg$hi8$1@nd.eastky.net>
"M" <lithotroph@hotmail.com> wrote in message
news:90EE8B796pr5j8k@24.132.65.8...
>
> Hello,
>
> A probably stupid question: Can someone inform me on how to call a
> perl script from a current perl script while terminating the later
> (removing it from the stack) at the same time?
try:
exec 'foo.pl';
- Zach May.
------------------------------
Date: 02 Aug 2001 09:04:27 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: challenging question
Message-Id: <878zh3kq78.fsf@abra.ru>
W> Nice Algorithm.
W> Rewritten more compactly and using some Perl defaults (just as an example to
W> OP and for fun)
Relying on Perl defaults often causes a lot of warnings under perl
-w. And IMHO -w should be always turned on since it helps to find many
errors which can't be catched with just 'use strict'. This is why I
prefer to initialize variables always.
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: 2 Aug 2001 06:18:23 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: challenging question
Message-Id: <slrn9mhs4g.9fl.damian@puma.qimr.edu.au>
Ilya Martynov chose 02 Aug 2001 09:04:27 +0400 to say this:
>...
>Relying on Perl defaults often causes a lot of warnings under perl
>-w.
I'm nitpicking, but actually this is not correct. Perl builtins tend to be
exempt from warnings and from strict. Indeed, I have used this factum to avoid
initialising vars in the JAPH below, which is -w and strict clean, at least
under 5.6.x :-).
>And IMHO -w should be always turned on since it helps to find many
>errors which can't be catched with just 'use strict'...
I couldn't agree more, but it's not a reason to avoid the builtins. You
might want to avoid the builtins to increase legibility, however :-).
Cheers,
Damian
--
@:=grep!($;+=m!$/|#!),split//,<DATA>;@;=0..$#:;while(@;){for($;=@;;--$;;)
{@;[$;,$:]=@;[$:,$;]if($:=rand$;+$|)!=$;}push@|,shift@;if$;[0]==@|;select
$,,$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker # rev 3.1 -- a JAPH in progress, I guess...
------------------------------
Date: Thu, 2 Aug 2001 15:54:15 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: challenging question
Message-Id: <vf6a7.43$fw.2137@vic.nntp.telstra.net>
"Ilya Martynov" <ilya@martynov.org> wrote in message
news:878zh3kq78.fsf@abra.ru...
>
> W> Nice Algorithm.
>
> W> Rewritten more compactly and using some Perl defaults (just as an
example to
> W> OP and for fun)
>
> Relying on Perl defaults often causes a lot of warnings under perl
> -w. And IMHO -w should be always turned on since it helps to find many
> errors which can't be catched with just 'use strict'. This is why I
> prefer to initialize variables always.
Can you give an example of where using a default would cause a warning
under -w?
BTW I also always work under -w and 'use strict'.
Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass it
around');
$d='$_$a$s$b$w';$e='$_$a$s$b';sub d{$h=shift;$h=~s/\$(\w+)/${$1}/g;return$h}
sub
e{return(shift!=1)?'s':''}for(reverse(1..100)){$s=e($_);$f=d($d);$g=d($e);
$c.="$f\n$g\n$t\n";$_--;$s=e($_);$e=d($d);$c.="$e\n\n";}print"$c*hic*";
------------------------------
Date: Thu, 2 Aug 2001 15:50:27 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: Converting in Image::Magick
Message-Id: <MV5a7.3046$257.125768@ozemail.com.au>
Kolorove
See below.
--
Cheers
Ron Savage
ron@savage.net.au
http://savage.net.au/index.html
Kolorove Nebo <sky@mail.lviv.ua> wrote in message news:3B67B8D5.D9D1E169@mail.lviv.ua...
> I'm using Image::Magick on Win32 platform.
> Can anybody point me an exaple of using "convert" command
> in PERL scripts in Win32 distribution.
> In my case i got message: could not find convert.al in @INC (there is no
> file
> with such name at my computer at all, i've cecked it), is it possible
> that i have
> to load any additional libriaries or programms to use CONVERT.
ImageMagick's convert program is a stand-alone program. Hence it is not in Image::Magick. Hence the error message.
Of course, you could use Perl to run convert like you would run any other command-line program, eg using system() or `` (backticks).
You will need to explain what you are trying to do before we can work out how to help.
------------------------------
Date: Thu, 02 Aug 2001 04:44:34 GMT
From: "Ben Kennedy" <bkennedy99@Home.com>
Subject: Re: csh together with perl
Message-Id: <SU4a7.59214$EP6.14225020@news1.rdc2.pa.home.com>
"Rainer Theuer" <Rainer.Theuer@sci-worx.com> wrote in message
news:3B67E68F.33004255@sci-worx.com...
> Hi all,
> i try to write a script which should replace a string in a given file .
> The perl call has a problem with ENV variables , because the perl
> call don't know the content.
> Does anyone know whats wrong or how to solve my problem ?
> Thanks
You can access arguments to a perl script in @ARGV, you might have better
luch passing your parameters in this way rather than messing with the
environment
--Ben Kennedy
------------------------------
Date: Thu, 02 Aug 2001 06:20:19 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How do I find the first array element for which a condition is true?
Message-Id: <Di6a7.66$l_m.177781760@news.frii.net>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.
+
How do I find the first array element for which a condition is true?
You can use this if you care about the index:
for ($i= 0; $i < @array; $i++) {
if ($array[$i] eq "Waldo") {
$found_index = $i;
last;
}
}
Now "$found_index" has what you want.
-
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to
news:news.answers
or to the many thousands of other useful Usenet news groups.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-1999 Tom Christiansen and Nathan
Torkington. All rights reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
04.43
--
This space intentionally left blank
------------------------------
Date: Thu, 2 Aug 2001 09:31:09 +0200
From: "Manuel Körner" <manuel.koerner@rexroth.de>
Subject: global variables
Message-Id: <9kavje$1711@sunny.mannesmann.de>
hi to all,
if i include perl source with the require command and
define some global variables in this source for example
our $TRUE = 1 and i try to access the variable in the
main module this would cause an error and i don't know
why.
Thanks for help
Manuel Körner
------------------------------
Date: 2 Aug 2001 09:30:05 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: global variables
Message-Id: <9kb6it$o31$1@mamenchi.zrz.TU-Berlin.DE>
According to Manuel Körner <manuel.koerner@rexroth.de>:
> hi to all,
>
> if i include perl source with the require command and
> define some global variables in this source for example
> our $TRUE = 1 and i try to access the variable in the
> main module this would cause an error and i don't know
> why.
*sigh*
How do you "define" the variable in the external source? Is it
in its own package, or package main? How do you "try to access"
the variable in the main program? Under a fully qualified name, or
in the default package? Are you running under "strict"? Finally,
what error does it cause?
Even in a seemingly simple situation you must give us *something*
to go on.[1]
BTW, it is not a good idea to introduce a particular value for boolean
true in Perl. Since almost every scalar value is true, a comparison
to your $TRUE will turn out wrong in most cases.
Anno
[1] If I sound like Kira here, that's because she's right in some
things, just like stopped clock is right twice a day. Be glad
I didn't ask him to "define his parameters".
------------------------------
Date: Thu, 2 Aug 2001 05:35:38 -0000
From: "Acid" <acid-spam@acid06.cjb.net>
Subject: Re: how to find free disk space (Win32)
Message-Id: <tmi3vjrc8t0j95@corp.supernews.com>
Win32::DriveInfo should do it.
-Acid
"John Stumbles" <jstumbles@bluearc.com> escreveu na mensagem
news:b65eb2a6.0108010241.119537fd@posting.google.com...
> Is there a module? Or some fairly portable way to do this? On windoze
> even grepping `dir` for 'bytes free' fails if the disk is empty :-(
>
> My hack (below) is to create an empty file, repeat the `dir` then
> delete the file - oh dear!
>
> sub touch($);
> sub drive_free_space($)
> {
> my $drive = shift ;
> my $dir = `dir $drive`;
> unless ($dir =~ /([\,\d]+) bytes free/m) # empty dir
> {
> touch ("$drive\\_T_E_M_P.123") ;
> $dir = `dir $drive`;
> DEBUG $dir;
> unlink "$drive\\_T_E_M_P.123" ;
> }
> $dir =~ /([\,\d]+) bytes free/m or die "unable to get bytes free
> from DIR $drive";
> my $bytes = $1 ;
> $bytes =~ s/\,//g ;
> return $bytes
> }
> sub touch ($)
> {
> my $filename = shift or return ;
> open (OUT, ">$filename") or die "Could not create file $filename -
> $!\n";
> close OUT ;
> }
>
> And what about unices?
>
> In general this seems to be a rather glaring omission from perl's
> generally overflowing toolkit of system admin resources :-( Any ideas?
>
> --
> John Stumbles
> http://www.stumbles.org/John
>
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
------------------------------
Date: 2 Aug 2001 10:03:19 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how to validate a regular expression..
Message-Id: <9kb8h7$o31$2@mamenchi.zrz.TU-Berlin.DE>
According to Bob Walton <bwalton@rochester.rr.com>:
> Sarah Lin wrote:
> >
> > Hi there. how do i validate a regular expression that entered by the user?
> > perl will die if "(q1" is entered, and that's the thing i try to avoid..
> > any PM for this? any help?
> ...
> > -sarah
> You could use eval to evaluate it and test for any errors that
> resulted. perldoc -f eval.
More specifically, you could
my $regex = eval { qr/$string/};
die $@ if $@;
...and use the (precompiled) $regex later.
Accepting a regex from a user is tricky business. Take a look at the
quotemeta function and the "use re" pragma and see if they apply.
Anno
------------------------------
Date: 1 Aug 2001 23:48:54 -0700
From: xenite9@my-dejanews.com (Adam)
Subject: Howto run traceroute-parse IP's-store in array?
Message-Id: <b67a511f.0108012248.887dc06@posting.google.com>
Hello,
I am trying to write a Perl script that will run traceroute (or maybe
mtr) and parse out the IP addresses and store them in an array.
Anyone know how to do this? Below is my ATTEMPT to do half of the
job, and I can't make it work properly. Just to point out the
obvious, I am not a Perl programmer, so be gentle. Please help.
-----------
#!/usr/bin/perl -w
use strict;
system("/usr/sbin/traceroute www.google.com > tr.txt");
my @array = ("tr.txt");
for my $i(@array) {
open(FH, "$i");
while(<FH>) {
$_ =~ s/ /\n/g;
#THE ABOVE LINE DOES HALF OF THE WORK, BUT I CAN'T GET IT TO ONLY
#PARSE LINES BEGINNING WITH "(" AND ENDING IN ")" WHERE THE IP
#ADDRESSES ARE LOCATED.
print $_;
}
}
------------
MY PROJECT OUTLINE:
After they are in the array I want to run ping, nmap, mtr or whatever
on those IP's. My end goal is to be able to graphically display IP's
and their routes, run port scans/OS detection (or any other
applicaton) like Cheops-ng does, but in a web browser via Perl CGI
scripts. It would be nice to eventually completely get all the
system() commands out and have it be pure Perl for
performance/portability reasons. Anyways, now I can't do something
simple like parsing text and putting it into an array, so I hope that
someone can post some answers.
Thanks,
Adam.
------------------------------
Date: 2 Aug 2001 07:33:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Howto run traceroute-parse IP's-store in array?
Message-Id: <9kavou$il4$1@mamenchi.zrz.TU-Berlin.DE>
According to Adam <xenite9@my-dejanews.com>:
> Hello,
>
> I am trying to write a Perl script that will run traceroute (or maybe
> mtr) and parse out the IP addresses and store them in an array.
> Anyone know how to do this? Below is my ATTEMPT to do half of the
> job, and I can't make it work properly. Just to point out the
> obvious, I am not a Perl programmer, so be gentle. Please help.
>
> -----------
> #!/usr/bin/perl -w
>
> use strict;
>
> system("/usr/sbin/traceroute www.google.com > tr.txt");
There is no need to save the output in a file. Perl can catch
command output immediately.
> my @array = ("tr.txt");
>
> for my $i(@array) {
> open(FH, "$i");
>
> while(<FH>) {
> $_ =~ s/ /\n/g;
> #THE ABOVE LINE DOES HALF OF THE WORK, BUT I CAN'T GET IT TO ONLY
> #PARSE LINES BEGINNING WITH "(" AND ENDING IN ")" WHERE THE IP
> #ADDRESSES ARE LOCATED.
I don't see how this does much of the job. It breaks one line into
multiple lines, but that doesn't help you identify the ip address.
> print $_;
> }
> }
[snippage]
I'd use qx (perldoc -f qx) to execute the traceroute command and
a regex (in list context) to extract the parenthesized parts:
my @ip_addrs = map /\(([^)]*)\)/, qx( traceroute www.google.com);
Anno
------------------------------
Date: Thu, 02 Aug 2001 10:16:32 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Is regex in grep() automatically precompiled?
Message-Id: <3B690C60.2080106@post.rwth-aachen.de>
Hi!
Lately I had been frequently grep()ping through @arrays, like in
@result = grep(/$pat/, @array);
$pat now could either be a string: $pat = '^ha|lo$';
or rather a precompiled pattern: $pat = qr(^ha|lo$);
Now I wonder whether Perl internally precompiles the grep-pattern for
the sake of performance or whether this should still be done by hand.
The description of grep() in the perldocs doesn't throw any light on
that so I hoped somehere in this group might now.
Thanks in advance,
Tassilo
--
Calm down, it's only ones and zeroes,
Calm down, it's only bits and bytes,
Calm down, and speak to me in English,
Please realize that I'm not one of your computerites.
------------------------------
Date: 2 Aug 2001 08:56:06 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Is regex in grep() automatically precompiled?
Message-Id: <9kb4j6$mfd$1@mamenchi.zrz.TU-Berlin.DE>
According to Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>:
> Hi!
>
> Lately I had been frequently grep()ping through @arrays, like in
> @result = grep(/$pat/, @array);
>
> $pat now could either be a string: $pat = '^ha|lo$';
> or rather a precompiled pattern: $pat = qr(^ha|lo$);
>
> Now I wonder whether Perl internally precompiles the grep-pattern for
> the sake of performance or whether this should still be done by hand.
> The description of grep() in the perldocs doesn't throw any light on
> that so I hoped somehere in this group might now.
The regex in grep isn't treated differently from any other regex:
grep's first argument is just an expression that is evaluated for
its boolean value. If it contains (or just is) a regex, so what?
So the answer is the same as for any regex: If it contains a string
it will be recompiled each time, unless the /o modifier prohibits that
for good. If you want finer control, use qr//.
Anno
------------------------------
Date: 2 Aug 2001 00:50:46 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: join lines ?
Message-Id: <74f348f7.0108012350.75faea60@posting.google.com>
"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message news:<3B68A9C1.1E5DE7D1@stomp.stomp.tokyo>...
> Yves Orton ignorantly and hatefully trolled:
>
> > Godzilla! wrote:
> > > Tim wrote:
> > > > Godzilla! wrote:
> > > > > Tim wrote:
>
> > #!perl
>
>
> Your code produces incorrect results.
Prove it Lizard. I dont think you can.
Quite frankly, either you didnt read my mail, (small surprise as you
seem to think that anyone who criticizes you is a troll), but my code
works according to the critera in my mail, where I specifically point
out that I am not going to filter his data for him. (He wasn't clear
on the issue anyway.)
As far as I could tell his problem in principle was how to
A) Rejoin slash terminated indented split lines
B) Parse said rejoined line into a number of vars and an array
My code does the above.
So if you want to sling out such statements please at least have the
courage to post what you consider to be the problem. (And most other
posters would probably also include a fix, but my guess is that you
would prefer to lecture.)
Yves
------------------------------
Date: Thu, 2 Aug 2001 15:07:48 +1000
From: "Andrew Hamm" <ahamm@sanderson.net.au>
Subject: Re: Matching Strings in an array
Message-Id: <3b68e089@news.iprimus.com.au>
Ryan Gralinski wrote in message ...
>
>foreach $cname (@covers)
>{
> if($cname =~ @words){do this..}
>}
>
>i need to match if every element of @words is in $cname
>
Do you mean, you need to match if ANY of @words is in $cname? If so:
$pattern = join '|', @words;
foreach $cname (@covers)
{
if($cname =~ /$pattern/o) { do this }
}
If you REALLY mean you want every member of @words to be found in $cname,
then try:
foreach $cname (@covers)
{
$dang_nabbit = 0;
grep { $cname =~ /$_/ or $dang_nabbit = 1 } @words;
if(not $dang_nabbit) { do this }
}
--
Lamarr: My mind is a raging torrent, flooded with rivulets of thought
cascading into a waterfall of creative alternatives.
Taggart: Gol-darn it, Mr. Lamarr, you use your tongue purdier than a
twenty dollar who.re.
Lamarr: Sh!t - kicker...
-- Blazing Saddles
------------------------------
Date: Thu, 02 Aug 2001 08:03:55 +0200
From: Per Kistler <kistler@gmx.net>
To: Ryan Gralinski <ryan@bong.net>
Subject: Re: Matching Strings in an array
Message-Id: <3B68ED4B.987E4C9F@gmx.net>
Ryan Gralinski wrote:
> foreach $cname (@covers)
> {
> if($cname =~ @words){do this..}
> }
> i need to match if every element of @words is in $cname
Hi Ryan
Whether it makes sense or not, technically it would work
like that:
#!/usr/bin/perl
use strict;
my @covers = ('John York', 'Fred Miller', 'Bill Nealy');
my @words = qw(John York);
for my $cname ( @covers ){
if( @words == grep { $cname =~ /$_/ } @words ){
print "cname '$cname' matched by all of '@words'\n";
}
}
-Per.
--
Per Kistler, kistler@gmx.net
------------------------------------------------------------------
------------------------------
Date: Thu, 2 Aug 2001 12:29:34 +0300
From: Sami Jarvinen <if.xoboi@jks.invalid>
Subject: Re: newbie question about file concatenation
Message-Id: <MPG.15d2d05fbb08f4b598969a@news.yhteys.mtv3.fi>
Tassilo von Parseval wrote:
> Tassilo von Parseval wrote:
> Sorry, little mistake:
> > Well:
> > open FILE1, "file1";
> > open FILE2, "file2";
> > open FILE3, "file3";
> > open CONC, "concatenated_files";
> should be:
> open CONC, ">concatenated_files"; # for writing, not reading
Checking for the return value of 'open' would also be a good idea:
open FILE, "file" or die "Unable to open 'file': $!";
And remember to 'use strict' and 'use warnings'.
And don't forget to brush your teeth before going to sleep.
*grin* Sorry.
--
To demunge e-mail address, remove ".invalid" and reverse the rest.
See <URL:http://www.faqs.org/faqs/net-abuse-faq/munging-address/>
for details on "spam-blocking".
------------------------------
Date: Thu, 2 Aug 2001 12:30:04 +0300
From: Sami Jarvinen <if.xoboi@jks.invalid>
Subject: Re: OT: spelling (was Re: chess in perl)
Message-Id: <MPG.15d349191596f56098969e@news.yhteys.mtv3.fi>
Steve Holland wrote:
> Sami Jarvinen <if.xoboi@jks.invalid> writes:
> > Speaking of spelling, why do some people sometimes say 'optomize'
> > instead of 'optimize'?
> There are two reasons. First, "optimise" is often pronounced
> "optomise" and people whose native language is not English tend to
> write words the way they are pronounced. The second reason is that
> "o" is right next to "i" on most English keyboards (and many
> non-English ones) so it is easy for a finger to slip.
I did consider these possibilities and they both seemed unlikely, so
I became curious...
Ah well, perhaps the usenauts did just happen to type the same typo
multiple times in the same article.
Btw, English isn't my native language, so if any of you notice severe
grammatical/spelling errors in my postings, feel free to correct me,
I'll appreciate it :-)
--
To demunge e-mail address, remove ".invalid" and reverse the rest.
See <URL:http://www.faqs.org/faqs/net-abuse-faq/munging-address/>
for details on "spam-blocking".
------------------------------
Date: Thu, 02 Aug 2001 06:13:00 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: password protact a file
Message-Id: <slrn9mhrrc.1rf.mgjv@verbruggen.comdyn.com.au>
On 2 Aug 2001 04:03:29 GMT,
Damian James <damian@qimr.edu.au> wrote:
> Jag Man chose Thu, 02 Aug 2001 00:16:19 GMT to say this:
>>How can it be done from perl, any built in function? similar to "vi -x".
>>
>
> The direct equivalent to `vi -x` would be crypt(). See `perldoc -f crypt`.
Not really.
The -x option to vi tells it to decrypt and encrypt a file on load and
save. The crypt() Perl builtin function is a one way hashing function
generally used for passwords on Unixes. They are unrelated. As perldoc
-f crypt would have told you:
crypt PLAINTEXT,SALT
Encrypts a string exactly like the crypt(3)
function in the C library
[snip]
Note that `crypt' is intended to be a one-way
function, much like breaking eggs to make an
omelette. There is no (known) corresponding
decrypt function. As a result, this function
isn't all that useful for cryptography. (For
that, see your nearby CPAN mirror.)
The vi -x encryption corresponds more to crypt(1) on unices, not to
crypt(3), although there is no guarantee that they will do the same
thing (vi -x and crypt(1), I mean).
Martien
--
Martien Verbruggen |
Interactive Media Division | I took an IQ test and the results
Commercial Dynamics Pty. Ltd. | were negative.
NSW, Australia |
------------------------------
Date: 2 Aug 2001 06:36:08 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: password protact a file
Message-Id: <slrn9mht5q.9fl.damian@puma.qimr.edu.au>
Martien Verbruggen chose Thu, 02 Aug 2001 06:13:00 GMT to say this:
>On 2 Aug 2001 04:03:29 GMT,
> Damian James <damian@qimr.edu.au> wrote:
>> ...
>> The direct equivalent to `vi -x` would be crypt(). See `perldoc -f crypt`.
>
>Not really.
>
>The -x option to vi tells it to decrypt and encrypt a file on load and
>save. The crypt() Perl builtin function is a one way hashing function
>generally used for passwords on Unixes. They are unrelated. As perldoc
>-f crypt would have told you...
Bleh, of course <hangs head in shame>. Guess I just wasn't thinking.
To the OP: try searching for encryption and decryption oriented packages on
CPAN :-).
Cheers,
Damian
------------------------------
Date: 2 Aug 2001 02:31:18 -0400
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: perl regular expression grammar
Message-Id: <01-08-007@comp.compilers>
Keywords: parse
Ilmari Karonen <usenet11522@itz.pp.sci.fi> wrote:
>I may be remembering the exact dirty details wrong. I suggest you see
>the code in toke.c
I think you will find it in regcomp.c, not toke.c.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Thu, 2 Aug 2001 12:29:44 +0300
From: Sami Jarvinen <if.xoboi@jks.invalid>
Subject: Re: read files into arrays...
Message-Id: <MPG.15d2d0fd6eb2892598969c@news.yhteys.mtv3.fi>
Tassilo von Parseval wrote:
> Nathan Randle wrote:
> >is there a way of reading specific lines from a text file into an array
> >Eg. read lines 10 - 30 of data.dat
>
> Use an array-slice for that:
>
> open FILE, "data.dat" or die "Error: $!";
> my @array = (<FILE>)[9 .. 29];
In case the OP doesn't know, what actually happens here is that the
whole file is read into memory (an action commonly referred to as
'slurping the file'). It's fine for relatively small files but usually
frowned upon as there's rarely any reason to do so.
# read the file line by line, print lines $first thru $last
my ( $first, $last ) = ( 9, 29 );
open FILE, "data.dat" or die "Unable to open 'data.dat': $!";
while ( <FILE> ) {
print if ( $. == $first ) .. ( $. == $last ); # flip-flop
last if $. > $last;
}
I'm sure someone can think of a more Perlish way though.
--
To demunge e-mail address, remove ".invalid" and reverse the rest.
See <URL:http://www.faqs.org/faqs/net-abuse-faq/munging-address/>
for details on "spam-blocking".
------------------------------
Date: Thu, 2 Aug 2001 08:32:05 +0100
From: "Bill Leigh" <bill.leigh@leighly.fsnet.co.uk>
Subject: SOAP/WSDL Web services search
Message-Id: <9kavv5$ld4$1@newsg4.svr.pol.co.uk>
If your interested in the emerging technology
for SOAP web services, try the following
web site.
SOAP and WSDL Web Services searching
http://www.salcentral.com
Bill
------------------------------
Date: Thu, 02 Aug 2001 08:09:58 +0200
From: Per Kistler <kistler@gmx.net>
To: yin_12180@yahoo.com
Subject: Re: What should happen with this perl code?
Message-Id: <3B68EEB6.884ABE3F@gmx.net>
yin_12180@yahoo.com wrote:
> Is it possible to load two conditionals in a for loop?
> For example, what should happen if I do the following?
> for ($i = 0;($i < 4, $i < 6); $i++) {
> print "$i\n";
> }
Hi Yin
To meet both conditions (although useless in this case) you could do:
for( my $i = 0; ( $i < 4 and $i < 6 ); $i++ ){ }
In your case it's a list of statements. The result of the
last one is visible for for(){}, therefore it prints the
numbers up to 5.
-Per.
--
Per Kistler, kistler@gmx.net
------------------------------------------------------------------
------------------------------
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 1426
***************************************