[16636] in Perl-Users-Digest
Perl-Users Digest, Issue: 4048 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 17 18:06:00 2000
Date: Thu, 17 Aug 2000 15:05:30 -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: <966549929-v9-i4048@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 17 Aug 2000 Volume: 9 Number: 4048
Today's topics:
Re: archive of perl scripts- first language (Malcolm Dew-Jones)
Re: Attatching files in an email using perl <care227@attglobal.net>
Best way to perform multiple s//'s on a file (Colin Keith)
Re: Calling C code from perl script (Malcolm Dew-Jones)
Re: cross platform newline processing (Malcolm Dew-Jones)
Re: Extracting values from a variable / using split or <abe@ztreet.demon.nl>
Re: Extracting values from a variable / using split or <care227@attglobal.net>
Finding a duplicate character vanis@my-deja.com
Re: Finding a duplicate character <kjetilskotheim@iname.com>
Re: Finding a duplicate character <godzilla@stomp.stomp.tokyo>
Re: Formatting Integer/String (Greg Bacon)
Re: Formatting Integer/String <kjetilskotheim@iname.com>
FTP client ls? <campbell@coaps.fsu.edu>
Re: FTP client ls? (Greg Bacon)
Re: FTP client ls? (Teodor Zlatanov)
Re: glob failed (child exited with status -1, core dump (Anno Siegel)
grepping for multiple fields <russ_jones@rac.ray.com>
Re: grepping for multiple fields <russ_jones@rac.ray.com>
Re: grepping for multiple fields <care227@attglobal.net>
Re: grepping for multiple fields (Greg Bacon)
Re: grepping for multiple fields <russ_jones@rac.ray.com>
Re: help i'm stuck!!! <kjetilskotheim@iname.com>
Re: help i'm stuck!!! <lr@hpl.hp.com>
Help please! <cvinfo@mail.com>
Help with pattern matching please!!! mattsacks@yahoo.com
Re: Help with pattern matching please!!! <care227@attglobal.net>
Re: Help with pattern matching please!!! msacks@my-deja.com
how to ignore ampersand in post operation narasim@usc.edu
Re: how to ignore ampersand in post operation (Greg Bacon)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 17 Aug 2000 13:22:02 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: archive of perl scripts- first language
Message-Id: <399c496a@news.victoria.tc.ca>
jm (sales@uniconart.com) wrote:
: Good to hear from you jack and yes we must stay in touch......if only as
: moral support when things get heavy.
: I'm not using Perl in my work at the moment as I don't know enough, but
: hope to use it as a step to a new career.
If you use a computer then I think you could find ways to use it as
your own personal tool to gain experience.
For example, on Windows, write a short script to make your application
windows all return to a predefined position. Several such scripts, run as
batch files, would give you your own "desk top manager".
Or e.g. if you write SQL then write a simple tool to convert a
DESC TABLE_NAME output (which you copy using windows clipboard) into a
select statement that is easy to edit to select just the columns you need.
------------------------------
Date: Thu, 17 Aug 2000 14:45:36 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Attatching files in an email using perl
Message-Id: <399C32D0.EAF4C72E@attglobal.net>
M Nair wrote:
>
> Hi.
>
> I am trying to send emails with attatchments from within perl running on
> Solaris. I have done this before using mail and setting the
> Content-Type and Mime formats etc..but I dont recollect it now...
> Can anyone help me?
Read the documentation for MIME::Lite. It includes a MIME primer,
and is also a perfect module for what you want to do.
HTH
------------------------------
Date: Thu, 17 Aug 2000 21:31:46 GMT
From: newsgroups@ckeith.clara.net (Colin Keith)
Subject: Best way to perform multiple s//'s on a file
Message-Id: <6RYm5.161$DT4.3959527@nnrp2.clara.net>
Hey folks,
I'm after some opinions on the 'best way' to implement rewriting of files
on the fly. The idea is to take a file with HTML text from disk and send it
out (back to a browser but that's irrelevant) and replace certain parts with
data from my program. I know that it would be easier to implement it using
CGI.pm or similar so that it can slot in the variables. But, this should be
usable by people who need to muck about with the HTML template moving logos
and fiddling with wording and stuff, but who have no clue about Perl.
Thats an icky description, but what I'd like to be able to do is feed a sub
the name of a file, and a list of what to search for and the replacement for
each match. The problem is that I see this getting stupidly slow. If I
replace 'NAME="bob"' with 'NAME="tom"' that's not a problem I just compare
every line against the search pattern and replace it .. (s///), but if I add
a second search-and-replace pair to the list, then I have to perform 2 sar's
for each line, and so on .. I can see that with a couple this is going to
slow to a crawl.
Now I thought about it a little but I can't see an obvious way to beat this
growth. I wondered if I would help if I generated a big regexp of all of the
matches, joined them together with |'s before reading and for each line of
the file matched that. If it didn't match then to go on, if it did to
apply each sar-pair to the line.
Unfortunately I do'nt think that will help too much, although it would cause
each match to be tried only once, rather than /g'd which is better
because the majority of lines wouldn't match any regexp. The composite
regexp pattern could use /o because it isn't changing. But it still appears
to be more work. I've played a little bit, but it seems very clunky, so
Guru's .... Suggestions on 'the best way'.
This is particularly odd since the search patterns aren't known in advance.
As in:
%replacements = ( '%LOGIN'=>$user,
'NAME="name" VALUE="' => "NAME=\"name\" VALUE=\"$user",
'CLASS="fred"' => 'CLASS="red5');
replace_on_fly($filename, %replacements);
"You are stupid don't do it that way" is a valid response, but mostly if
qualified with a "I would suggest you try ..... instead" :)
Oh and I did try looking on CPAN, but er.. it's broke at the moment :(
"Illegal division by zero at
/app/unido-i06/sun4_56/lang/perl/5.005_54/lib/site-perl/WAIT/InvertedIndex.
pm line 310, chunk 5. "
*sniffs sadly*
I'm sorry Mr Guru, I didn't mean to break your luvely script :'( :-)
Cheers for any help:)
Col.
---
Colin Keith
Systems Administrator
Network Operations Team
ClaraNET (UK) Ltd. NOC
------------------------------
Date: 17 Aug 2000 13:14:20 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Calling C code from perl script
Message-Id: <399c479c@news.victoria.tc.ca>
regina mcguigan (ramcguig@us.ibm.com) wrote:
: does anyone have any experience interfacing C code with perl scripts?
A new module called(?) Inline was just announced. I would check that out,
it looks easy to use.
------------------------------
Date: 17 Aug 2000 13:12:07 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: cross platform newline processing
Message-Id: <399c4717@news.victoria.tc.ca>
: Mark Johnson wrote:
: >
: > Hi,
: > I need to read text files line by line. Problem is these text files
: > may have been created on Mac, PC or unix. As a consequence I don't know
: > whether the newline code is CR or LF or CR LF.
: > I have searched FAQs on CPAN and at www.perl.com, but I can't find
: > anything that deals with this situation. Can anybody point me in the
: > direction of a solution?
: ...
: > Mark
: >
: > p.s. The program will be running on a unix box if that matters.
You will need to examine enough of the file to determine what type of text
it contains (or remember what system sent the file).
Open and then close the file, reading something not too big but longer
than any line you expect, look for \r\n or \n or \r to decide the file
type (assuming the file won't have these characters except as new lines).
Then set $/ as appropriate to read each line. There are various ways to
convert to the local new line convention on output. The easiest may be to
chomp all the input, and then add \n on output. chomp cuts off the end of
the string based on $/, so once $/ is set then chomp works correctly no
matter what type of file you're reading.
$/ = $calculated_seperater;
# reopen FILE
while (<FILE>)
{ chomp;
# do something, e.g. $line=$_;
print OUT $line,"\n";
}
------------------------------
Date: Thu, 17 Aug 2000 22:29:23 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Extracting values from a variable / using split or regexp... /complex q.
Message-Id: <4jgopsguo49fqvjb6grk5rqj7c62c0f3i3@4ax.com>
On Wed, 16 Aug 2000 17:05:14 +0200, Jimmy Lantz
<jimmy.lantz@ostas.lu.se> wrote:
> Hi,
> I have the following problem (Pseudocode mixed with snippets of perl):
>
> I have an variable $targeted which I need to match with the following regexp
> (the \D last in the reg exp needs to be lower-case)
> /(\D{3}?)(\d{3}?$|\d{3}?\D)/
There is a difference between 'non-digit' (\D) and 'letter' ([A-Za-z]).
> I need to push every occurence of a match in an array @targets .
> (Examples of correct/incorrect values below)
> if there's an incorrect occurence I need to push that into @missedtargets
> the variable $ targeted sometimes containes spaces between the hits and
> sometimes it doesn't.
>
> CCCNNNc , CCCNNN /C = uppercase letter / N =num / c = lower-case letter
local $_ = $targeted;
if ( /^ #match from start
(?: #group
[A-Z]{3} #three upcase chars
\d{3} #three digit chars
[a-z]? #an optional lowcase char
\ * #optional spaces
)+ #one or more of these groups
$ #match up to the end
/x) {
push @targets, /([A-Z]{3}\d{3}[a-z]?) */g;
} else {
push @missed, $_;
}
See the perlre manpage for more information.
--
Good luck,
Abe
------------------------------
Date: Thu, 17 Aug 2000 15:04:24 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Extracting values from a variable / using split or regexp... /complex q.
Message-Id: <399C3738.71CB73D6@attglobal.net>
Jimmy Lantz wrote:
>
> Hi,
> I have the following problem (Pseudocode mixed with snippets of perl):
Please don't do that.
> I have an variable $targeted which I need to match with the following regexp
> (the \D last in the reg exp needs to be lower-case)
If it needs to be lower case, why isn't it lower case?
> /(\D{3}?)(\d{3}?$|\d{3}?\D)/
^ ^ ^
These question marks do nothing. I know the docs mention them, but
I have no idea why. {3} will match 3 times without the ?.
> I need to push every occurence of a match in an array @targets .
> if there's an incorrect occurence I need to push that into @missedtargets
> the variable $ targeted sometimes containes spaces between the hits and
> sometimes it doesn't.
Where are you getting the data that is in $targeted from? You could
easily do something like:
if ($targeted =~ /regex/){
push @targets, $targeted;
}else{
push @missedtargets, $targeted;
}
but i assume your problem is crafting a regex that will match? or??
>
> CCCNNNc , CCCNNN /C = uppercase letter / N =num / c = lower-case letter
>
> Example of correct values:
> AAA123
> BBB321HHH765d JIT763 #NB! this is 3 correct hits: BBB321, HHH765d and
> JIT763.
Would you want these 3 correct matches divided in the array or
not? I am not sure from reading this.
> I would very much appreciate pointers or helpfull links on how to do this.
> BTW. I have RTFM.
more information would help alot. Can you be more specific?
------------------------------
Date: Thu, 17 Aug 2000 19:28:47 GMT
From: vanis@my-deja.com
Subject: Finding a duplicate character
Message-Id: <8nheck$ii4$1@nnrp1.deja.com>
Hi,
Let's say
$sentence = "Thee easyy questionss cann bee foundd inn thee faqq";
I'd like to search for every occurrence of a sequentially-duplicate
character, and potentially replace that character with something else
(i.e. parentheses.. The(e) easy(y)..etc)
Tia,
V
P.s. A link to the faqs please...
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 17 Aug 2000 20:50:01 +0200
From: Kjetil Skotheim <kjetilskotheim@iname.com>
To: vanis@my-deja.com
Subject: Re: Finding a duplicate character
Message-Id: <399C41E9.DC0D6337@iname.com>
vanis@my-deja.com wrote:
>
> Hi,
>
> Let's say
>
> $sentence = "Thee easyy questionss cann bee foundd inn thee faqq";
>
> I'd like to search for every occurrence of a sequentially-duplicate
> character, and potentially replace that character with something else
> (i.e. parentheses.. The(e) easy(y)..etc)
$sentence = "Thee easyy questionss cann bee foundd inn thee faqq";
$sentence =~ s/(\w)(\1)/$1($2)/g;
print "$sentence\n"
The(e) easy(y) questions(s) can(n) be(e) found(d) in(n) the(e) faq(q)
--
Kjetil Skotheim
kjetilskotheim@iname.com
------------------------------
Date: Thu, 17 Aug 2000 14:50:04 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Finding a duplicate character
Message-Id: <399C5E0C.D16A27E8@stomp.stomp.tokyo>
vanis@my-deja.com wrote:
> Let's say
My, my, another new cliché. I've noticed dozens of different
people use "Let's say" as a preample. Seems to be replacing
this other popular cliché, "Let's suppose...."
> $sentence = "Thee easyy questionss cann bee foundd inn thee faqq";
> I'd like to search for every occurrence of a sequentially-duplicate
> character, and potentially replace that character with something else
> (i.e. parentheses.. The(e) easy(y)..etc)
"I am from penn state. Last night, I slept at a bed and breakfast inn.
Upon awakening, I discovered an aardwolf ate my car tires and, more
frustrating, an aardvark sprayed graffito on my windshield. Aargh!
What confuses me though, is finding a zebrass in bed with me."
How will you handle this simple set of sentences?
Godzilla!
------------------------------
Date: Thu, 17 Aug 2000 18:11:28 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Formatting Integer/String
Message-Id: <spoamg2er5j134@corp.supernews.com>
In article <Pine.GSO.4.10.10008171058470.1476-100000@sparc.nic.bc.ca>,
John <johnt@sparc.nic.bc.ca> wrote:
: Is there a simple way to format an integer (turning it into a string) to
: have a consistant number of digits irregardless of number?
You want to use the sprintf operator. Find its documentation in the
perlfunc manpage.
Greg
--
The power of accurate observation is commonly called cynicism by those who
have not got it.
-- George Bernard Shaw
------------------------------
Date: Thu, 17 Aug 2000 20:56:05 +0200
From: Kjetil Skotheim <kjetilskotheim@iname.com>
To: John <johnt@sparc.nic.bc.ca>
Subject: Re: Formatting Integer/String
Message-Id: <399C4355.52DF95AA@iname.com>
John wrote:
>
> Is there a simple way to format an integer (turning it into a string) to
> have a consistant number of digits irregardless of number?
>
> ex All numbers would have 7 digits:
> 1000 = 0001000
> 45678 = 0045678
> 998765 = 0998765
> 1235678 = 1235678
>
$numer=1007;
printf("%07d",$number); #will print 0001007
printf("%7d",$number); #will print 1007 (yes, with three spaces in
front)
$number=sprintf("%05d",$number);
print $number; #will print 01007
Try command:
perldoc -f sprintf
--
Kjetil Skotheim
kjetilskotheim@iname.com
------------------------------
Date: Thu, 17 Aug 2000 16:14:16 -0400
From: Stacey Campbell <campbell@coaps.fsu.edu>
Subject: FTP client ls?
Message-Id: <399C4797.821951A6@coaps.fsu.edu>
I am writing an FTP client given this information:
The files are named like this:
"NPR.QWND.QS.Dyyddd.Shhmm.Ehhmm.Bnnnnnnn
Where yyddd is the year and julian date, hhmm is hours and minutes for
data
start (S) and end (E), and nnnnnnn is the orbit number. You can do a ftp
ls
command to see what is available.
example;
ls 'NPR.QWND.QS.*' (be sure to use single quotes on the file
name.)"
The information above is helpful during a hands-on FTP session, but I'm
trying to write a perl program to get the files automatically, so I need
to do get an array of the files to download, by doing an $ftp->ls( ).
How do I execute the ls command above, in an FTP client?
-Stacey Campbell
------------------------------
Date: Thu, 17 Aug 2000 20:31:45 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: FTP client ls?
Message-Id: <spoithjr5j19@corp.supernews.com>
In article <399C4797.821951A6@coaps.fsu.edu>,
Stacey Campbell <campbell@coaps.fsu.edu> wrote:
: The information above is helpful during a hands-on FTP session, but I'm
: trying to write a perl program to get the files automatically, so I need
: to do get an array of the files to download, by doing an $ftp->ls( ).
: How do I execute the ls command above, in an FTP client?
grep() it:
my @files = grep /^NPR\.QWND\.QS\./s, $ftp->ls;
Greg
--
Bigamy is having one wife too many. Monogamy is the same.
-- Oscar Wilde
------------------------------
Date: 17 Aug 2000 16:59:10 -0500
From: tzz@iglou.com (Teodor Zlatanov)
Subject: Re: FTP client ls?
Message-Id: <399c521e$1_1@news.iglou.com>
<399C4797.821951A6@coaps.fsu.edu>:Stacey Campbell (campbell@coaps.fsu.edu):comp.lang.perl.misc:Thu, 17 Aug 2000 16:14:16 -0400:quote:
: The information above is helpful during a hands-on FTP session, but I'm
: trying to write a perl program to get the files automatically, so I need
: to do get an array of the files to download, by doing an $ftp->ls( ).
: How do I execute the ls command above, in an FTP client?
Look at the Net::FTP module on cpan (www.cpan.org)
http://theoryx5.uwinnipeg.ca/CPAN/data/libnet/Net/FTP.html
it's a part of the libnet distribution. Do a dir() and then grep the output
for whatever data you need to extract, then get() the files you need. It's
pretty easy, really.
--
Teodor Zlatanov <tzz@iglou.com>
"Brevis oratio penetrat colos, longa potatio evacuat ciphos." -Rabelais
------------------------------
Date: 17 Aug 2000 18:57:45 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: glob failed (child exited with status -1, core dumped)
Message-Id: <8nhcj9$m4m$1@lublin.zrz.tu-berlin.de>
<mrfloppy@sanitize.net> wrote in comp.lang.perl.misc:
>Hi,
>
>I'm getting these after upgrading perl (to perl-5.00503-11) on one of
>our machines (RedHat Linux 6.0). They don't occur if I run the same
>utility from the shell, only from crond and atd. /bin/csh is runnable
>from atd and crond's enviroments, I've confirmed.
>
>I can't strace because perl or the specific combination of things
>involved when globbing in Perl doesn't seem to like that.
>
>The script is still working - it looks like the glob returns what it
>should and the script works with it, the error messages seems to be an
>artifact but I don't know of what. I haven't even found the core that
>it
>claims is being dumped, but this line hasn't been properly exhausted
>yet.
>
>Any ideas?
You may want to get rid of the glob. If you use readdir and regex
selection instead, you will have at least much more control over
what is happening when something goes wrong. If the problem is
related to the forked glob process, it will go away.
Anno
------------------------------
Date: Thu, 17 Aug 2000 13:53:39 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: grepping for multiple fields
Message-Id: <399C34B3.68F50A9D@rac.ray.com>
This problem came up in a quick and dirty script that I was writing
today, and I know that there has to be some better way than the one I
used, which was ugly brute force. I just didn't have time to do it
right.
I have a file that contains lines like this:
text text text blah blah (12345/54321) rejected blah blah etc.
Some lines have one number in the parens, some have two, separated by
a slash. Not all lines have rejected in them, but if they do, I want
them. I also want any other lines that have one or more of the same
numbers that were in the rejected lines. So, given these lines:
line 1 stuff here more stuff etc (12345) etc etc....
line 2 some other text here (12345/44332) rejected
line 3 yadda yadda yadda (67890) more text here
line 4 t'was brillig (44332) outgrabe
I'd want line 2 because it says "rejected" somewhere in it
I'd want lines 1 and 4 because their numbers show up in line two
I wouldn't want line 3 because the number doesn't match a "rejected"
line
The file is small enough to just slurp into an array, so I did that
(@lines) and then I used
foreach(@lines)
{
if (/rejected/)
{
if ( /\((\d+)\)/ ) # if one number in parens
{
push (@numbers,$1);
}
elsif ( /\((\d+)\/(\d+)\)/ ) # if two numbers, separated by a
slash
{
push (@numbers,$1,$2);
}
}
}
next I cleaned the duplicates out of @numbers
then I did this:
foreach $line (@lines)
{
foreach $number (@numbers)
{
if ( $line =~ /\($number[\/\)]/ )
{
push (@finally,$line);
last;
}
}
}
The original input file was under a thousand lines, the number of
numbers was only about fifteen, so it wasn't too bad a pig,
considering I only had to run it once. (not counting testing)
But it seems like there should be some cleaner way of doing it. I
couldn't figure any way around the first run through @lines to capture
the numbers from the "rejected" lines, since a line we want might come
up before the "rejected" line that refers to it.
I fooled around with
grep { who knows } @lines;
and
grep { or here either } @numbers;
but couldn't think of anything off hand.
If anyone has time to fire off a suggestion, I'd sure count it as a
learning experience.
Thanks for reading this far,
Russ
--
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: Thu, 17 Aug 2000 14:34:14 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: grepping for multiple fields
Message-Id: <399C3E36.EB85897B@rac.ray.com>
Russ Jones wrote:
>
> This problem came up in a quick and dirty script that I was writing
> today, and I know that there has to be some better way than the one I
> used, which was ugly brute force. I just didn't have time to do it
> right.
>
I'm trying to head Drew off: I don't WANT to write it in COBOL.
--
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: Thu, 17 Aug 2000 15:47:49 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: grepping for multiple fields
Message-Id: <399C4165.8149661E@attglobal.net>
Russ Jones wrote:
>
> Russ Jones wrote:
> >
> > This problem came up in a quick and dirty script that I was writing
> > today, and I know that there has to be some better way than the one I
> > used, which was ugly brute force. I just didn't have time to do it
> > right.
> >
>
> I'm trying to head Drew off: I don't WANT to write it in COBOL.
Rexx?
------------------------------
Date: Thu, 17 Aug 2000 20:20:22 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: grepping for multiple fields
Message-Id: <spoi86ijr5j94@corp.supernews.com>
In article <399C34B3.68F50A9D@rac.ray.com>,
Russ Jones <russ_jones@rac.ray.com> wrote:
: I have a file that contains lines like this:
:
: text text text blah blah (12345/54321) rejected blah blah etc.
:
: Some lines have one number in the parens, some have two, separated by
: a slash. Not all lines have rejected in them, but if they do, I want
: them. I also want any other lines that have one or more of the same
: numbers that were in the rejected lines. So, given these lines:
:
: line 1 stuff here more stuff etc (12345) etc etc....
: line 2 some other text here (12345/44332) rejected
: line 3 yadda yadda yadda (67890) more text here
: line 4 t'was brillig (44332) outgrabe
:
: I'd want line 2 because it says "rejected" somewhere in it
: I'd want lines 1 and 4 because their numbers show up in line two
: I wouldn't want line 3 because the number doesn't match a "rejected"
: line
You have to make two passes:
#! /usr/bin/perl -w
use strict;
my %rejected;
my @caught;
my @lines = split /\n/, <<EOLines;
stuff here more stuff etc (12345) etc etc....
some other text here (12345/44332) rejected
yadda yadda yadda (67890) more text here
t'was brillig (44332) outgrabe
EOLines
for (@lines) {
if (/rejected/) {
for (m< \( (\d+) (?:/(\d+))? \) >x) {
next unless defined $_;
++$rejected{$_};
}
push @caught, $_;
}
}
for (@lines) {
next if /rejected/;
foreach my $num (m< \( (\d+) (?:/(\d+))? \) >x) {
next unless defined $num;
push @caught, $_ if $rejected{$num};
}
}
print $_, "\n" for @caught;
Greg
--
In Christianity neither morality nor religion come into contact with reality
at any point.
-- Nietzsche
------------------------------
Date: Thu, 17 Aug 2000 16:13:32 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: grepping for multiple fields
Message-Id: <399C557C.F20414D3@rac.ray.com>
Greg Bacon wrote:
>
> You have to make two passes:
>
(good code snipped because my news
server makes me post more reply than quoted)
>
That's some really good-looking code. Thanks, I've already learned a
bunch. I always forget about the :? in regexp's. I forget about using
foreach against a regexp, too.
I really appreciate the time you put into this.
Russ
> In Christianity neither morality nor religion come into contact with reality
> at any point.
> -- Nietzsche
That Nietzsche, what a card!
--
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: Thu, 17 Aug 2000 21:05:30 +0200
From: Kjetil Skotheim <kjetilskotheim@iname.com>
To: pape_98@my-deja.com
Subject: Re: help i'm stuck!!!
Message-Id: <399C458A.F83D1E8D@iname.com>
@sorted = sort @data; #will sort "alphabethically"
1,10,15,2,20...
@sorted = sort {$a cmp $b} @data; #same as above, {$a cmp $b} is the
default
@sorted = sort {$a <=> $b} @data; #will sort by number: 1,2,10,15,20...
easy peacy
pape_98@my-deja.com wrote:
>
> i'm trying to sort numbers and i'm using this approach:
> @sorted = map { $_->[0] }
> sort { $a->[1] cmp $b->[1] }
> map { [ $_, uc( (/\d+\s*(\S+)/)[0]) ] } @data;
>
> but it sorts the numbers by the first digit (1,10,15,2,25,3,5, etc..)
> how do i get it to sort the numbers by order of greatness(1,2,3,4,5,..)
> ????
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
--
Kjetil Skotheim
kjetilskotheim@iname.com
------------------------------
Date: Thu, 17 Aug 2000 14:41:16 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: help i'm stuck!!!
Message-Id: <MPG.1405fbd3b0850e6a98ac8a@nntp.hpl.hp.com>
In article <8nh5on$7qr$1@nnrp1.deja.com> on Thu, 17 Aug 2000 17:01:25
GMT, pape_98@my-deja.com <pape_98@my-deja.com> says...
> i'm trying to sort numbers and i'm using this approach:
^^^^^^^
> @sorted = map { $_->[0] }
> sort { $a->[1] cmp $b->[1] }
<=>
> map { [ $_, uc( (/\d+\s*(\S+)/)[0]) ] } @data;
I don't understand the key extraction. If it is to be a number, why
upper-case it? And why use \S instead of \d? And as it is list
context, why the subscripting?
map { [ $_, /\d+\D+(\d+)/ ] } @data;
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 17 Aug 2000 22:33:48 +0100
From: "Miriam" <cvinfo@mail.com>
Subject: Help please!
Message-Id: <399c5a97@212.18.160.197>
Hi group,
I've created a small perl script that I whould like to share with others but
I don't want them to change it.
Since my perl cgi is text code, is there a way to encrypt or compile my
script into .exe ou some other way to avoid them to read and change my code?
I've tried perl2exe, seems ok but the final file size is huge. Is there some
other program around there that let me do the same but makes smaller files?
Any help apreciated
Thank you
Miriam
------------------------------
Date: Thu, 17 Aug 2000 21:19:26 GMT
From: mattsacks@yahoo.com
Subject: Help with pattern matching please!!!
Message-Id: <8nhks7$qm4$1@nnrp1.deja.com>
Hi.
I have scoured this board and have not found anything close enough to
my problem to help me.
I am trying to hide the domain of an email address. To do this I want
to replace the section in between the '@' and '.com/.edu/.net/.org' of
an email address with '*' to protect the identity of the email sender.
I have only been using perl for a short while, and this is the search
and replace test string that I am trying: s/\b\@*com/\*/g;
Just to be sure I'm clear, the intent of the string is to
convert "jack1test@hotmail.com" to "jack1test@*******.com"
Thanks in advance.
-Matt
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 17 Aug 2000 17:29:35 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Help with pattern matching please!!!
Message-Id: <399C593F.DF668719@attglobal.net>
mattsacks@yahoo.com wrote:
>
> Hi.
> I have scoured this board and have not found anything close enough to
> my problem to help me.
>
How many times are you going to post this? This makes 3. Both
of the earlier posts got correct answers. Why post a 3rd time?
------------------------------
Date: Thu, 17 Aug 2000 21:49:33 GMT
From: msacks@my-deja.com
Subject: Re: Help with pattern matching please!!!
Message-Id: <8nhml6$sor$1@nnrp1.deja.com>
Please disregard this post. Thanks.
In article <8nhks7$qm4$1@nnrp1.deja.com>,
mattsacks@yahoo.com wrote:
> Hi.
> I have scoured this board and have not found anything close enough to
> my problem to help me.
>
> I am trying to hide the domain of an email address. To do this I want
> to replace the section in between the '@' and '.com/.edu/.net/.org' of
> an email address with '*' to protect the identity of the email sender.
>
> I have only been using perl for a short while, and this is the search
> and replace test string that I am trying: s/\b\@*com/\*/g;
>
> Just to be sure I'm clear, the intent of the string is to
> convert "jack1test@hotmail.com" to "jack1test@*******.com"
>
> Thanks in advance.
>
> -Matt
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 17 Aug 2000 18:14:36 GMT
From: narasim@usc.edu
Subject: how to ignore ampersand in post operation
Message-Id: <8nha1n$d42$1@nnrp1.deja.com>
Hi, I am using the LWP module to fetch a web page using the POST
operation. Now, I have a line of code as follows:
$req->content("field_1=$name&field_2=$loc");
where field_1 and field_2 are specified in the original html code of
the webpage, and the variables $name and $loc are what i pass.
there are no problems with the line above, except when $name (say),
contains an '&' itself, e.g., AT&T. at this point, it takes the name as
AT and ignores the &T.
I have tried using single quotes around the whole expression, but that
causes problems with the variables $name and $loc.
is there an easy fix?
thanks a lot.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 17 Aug 2000 18:42:40 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: how to ignore ampersand in post operation
Message-Id: <spoch0hgr5j125@corp.supernews.com>
In article <8nha1n$d42$1@nnrp1.deja.com>,
<narasim@usc.edu> wrote:
: Hi, I am using the LWP module to fetch a web page using the POST
: operation. Now, I have a line of code as follows:
:
: $req->content("field_1=$name&field_2=$loc");
:
: where field_1 and field_2 are specified in the original html code of
: the webpage, and the variables $name and $loc are what i pass.
:
: there are no problems with the line above, except when $name (say),
: contains an '&' itself, e.g., AT&T. at this point, it takes the name as
: AT and ignores the &T.
Take a look at the URI::Escape module that comes with the LWP. Be
careful that you escape the appropriate characters.
Greg
--
A priest advised Voltaire on his death bed to renounce the devil.
Replied Voltaire, "This is no time to make new enemies."
------------------------------
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 4048
**************************************