[17087] in Perl-Users-Digest
Perl-Users Digest, Issue: 4499 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 2 21:10:38 2000
Date: Mon, 2 Oct 2000 18:10:19 -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: <970535419-v9-i4499@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 2 Oct 2000 Volume: 9 Number: 4499
Today's topics:
Re: multiple file scoping <ren.maddox@tivoli.com>
Re: multiple file scoping <brew@theMode.com>
Re: Newbie can't handle the "true"th... explanation de <ren.maddox@tivoli.com>
Please help me with this email parsing problem (Ranyart Olias)
Re: Proving the greatness of mod_perl <brew1@voicenet.com>
Re: Regex comparing street addresses <mauldin@netstorm.net>
Re: Result of functions in child processes (Martien Verbruggen)
Re: Result of functions in child processes (Garry Williams)
Re: Reverse by paragraphs - NOT! ollie_spencer@my-deja.com
Re: Reverse by paragraphs - NOT! ollie_spencer@my-deja.com
Re: Reverse by paragraphs - NOT! ollie_spencer@my-deja.com
Re: Reverse by paragraphs - NOT! ollie_spencer@my-deja.com
Re: Reverse by paragraphs - NOT! ollie_spencer@my-deja.com
scripts not working <pdmos23@geocities.com>
Re: scripts not working <jeff@vpservices.com>
Re: Search and Destroy <lr@hpl.hp.com>
Re: Sendmail/Perl question <aslay@ucsd.edu>
Re: Sendmail/Perl question <flavell@mail.cern.ch>
Re: sort files <anmcguire@ce.mediaone.net>
Re: sort files <lr@hpl.hp.com>
Re: sort files <lr@hpl.hp.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 02 Oct 2000 15:42:59 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: multiple file scoping
Message-Id: <m31yxzotyk.fsf@dhcp11-177.support.tivoli.com>
Bruce Schiller <brew1@voicenet.com> writes:
> Both files are currently in the same package (namely, main).
>
> I should have said what it is I'm trying to do, sorry! I have some
> subroutines that are common to more than one program, so I'm hoping to put
> them in a file and require them into each program. There are about 5
> variables (arrays of pointers to hashes) that I have made global (except
> that they are actually lexicals, declared at the opening of the program),
> since I use them extensively all through the different programs, otherwise
> I pass the vars in and/or define them lexically within the function.
>
> Hence my question asking if lexical variables can straddle multiple files
> (files that are in the same package). I don't think putting all my
> subroutines in a different package would help me, unless I'm missing
> something. Perlmod says separate packages are to help in making separate
> namespaces, not sharing variables.
This seems to do what you want:
--- blah.pl ----
our $GLOBAL;
sub blah {
print "\$GLOBAL is $GLOBAL\n";
}
1;
__END__
#!/usr/local/bin/perl -w
use strict;
our $GLOBAL;
require 'blah.pl';
$GLOBAL = "This is a test";
blah();
__END__
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Tue, 03 Oct 2000 00:19:56 GMT
From: Bruce Schiller <brew@theMode.com>
Subject: Re: multiple file scoping
Message-Id: <MC9C5.1220$bt.21752@news3.voicenet.com>
Brad Baxter <bmb@ginger.libs.uga.edu> wrote:
: Yes, I think you're missing the point. The point is that packages help
: you make separate namespaces so that you can *safely* share variables
: among packages. You can make modules that use Exporter, or you can make
: modules that implement object classes.
OK, that's what I was missing, the Exporter Module! With all my reading
for the past couple of days I missed the Exporter Module, designed for
just what I am trying to do, share just a couple of variables between
files (if I make them separate packages). Jeez......
Now I know what direction to go.
Thanks Brad and the other respondees for taking the time to point me in
the right direction.
brew (who can't see the forest for the trees occasionally)
--
==========================================================================
Strange Brew (brew@theMode.com)
Check out my Musician's Online Database Exchange (The MODE Pages)
http://www.TheMode.com
==========================================================================
------------------------------
Date: 02 Oct 2000 16:18:49 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Newbie can't handle the "true"th... explanation desired
Message-Id: <m3vgvbndqe.fsf@dhcp11-177.support.tivoli.com>
Larry Rosler <lr@hpl.hp.com> writes:
> In article <m34s2vout4.fsf@dhcp11-177.support.tivoli.com> on 02 Oct 2000
> 15:24:39 -0500, Ren Maddox <ren.maddox@tivoli.com> says...
> > Larry Rosler <lr@hpl.hp.com> writes:
> >
> > > $name = undef; # The value of $name is now undefined.
> > >
> > > undef $name; # The variable $name no longer exists.
>
> > What then, is the difference?
>
> For other than a lexical variable, whether or not the name actually
> exists in the symbol table. What the imnplications of this are (if any)
> I don't know, because I have never had to muck around at that level of
> coding.
Actually, it doesn't even seem to do that:
perl -e '$,=$\=$/;undef $x;print grep /^x$/, keys %::'
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 2 Oct 2000 17:43:05 -0500
From: ranyart@cyberspace.org (Ranyart Olias)
Subject: Please help me with this email parsing problem
Message-Id: <39da0ead.106943984@news-west.newscene.com>
I am trying to find a small snippet of code that can parse a text
file, (which happens to be a mail message body), and can extract the
plain text out (and discard any attachments, html, etc.).
For instance, I want to keep the section, below, beginning with
"Everything Andy posted" and ending with "Southeastern Cave
Conservancy", and discard all the rest.
Can anyone help?
------------------ message body ------------------------
This is a multi-part message in MIME format.
------=_NextPart_000_000B_01BFD2CC.4A4EC1E0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Everything Andy posted is true. I really wish he had not posted what
he = did about Byers. Any of you who are thinking about visiting the
cave, = please don't. Negotiations are very delicate. The owner of the
entrance = is obsessed about trespassers.
One incident right now could blow any chance of obtaining access to
the = natural entrance. Please stay away. Believe me, we are working
on access = right now.
Jim Wilbanks
Member, Board of Directors
Southeastern Cave Conservancy
------=_NextPart_000_000B_01BFD2CC.4A4EC1E0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2919.6307" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2><STRONG>Everything Andy posted is
true. = I really=20
wish he had not posted what he did about Byers. Any of you
who = are=20
thinking about visiting the cave, please don't. Negotiations are very
= delicate.=20
The owner of the entrance is obsessed about=20
trespassers.</STRONG></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><STRONG>One incident right now could
= blow any=20
chance of obtaining access to the natural entrance. Please stay away.
= Believe=20
me, we are working on access right now.</STRONG></FONT></DIV>
<DIV><STRONG><FONT face=3DArial size=3D2>Jim Wilbanks<BR>Member, Board
= of=20
Directors<BR>Southeastern Cave =
Conservancy</FONT></STRONG></DIV></BODY></HTML>
------=_NextPart_000_000B_01BFD2CC.4A4EC1E0--
------------------------------
Date: Tue, 03 Oct 2000 00:40:24 GMT
From: Bruce Schiller <brew1@voicenet.com>
Subject: Re: Proving the greatness of mod_perl
Message-Id: <YV9C5.1221$bt.21959@news3.voicenet.com>
cmalcolm@my-deja.com wrote:
: Is there a list of major web sites that are using mod_perl
: succesfully?
http://perl.apache.org/stories/
: The thing is, it seems to me that if you are trying to pursuade someone
: to invest in your idea, they will employ consultants to assess you, and
: these consultants only know about commercial, proprietry stuff, such as
: Java, Oracle, OAS, etc.
That's the purpose of Perl Mongers, I think, to market perl to the
populi.
: We firmly believe, in fact we KNOW, that mod_perl makes perl the best
: choice for our application. We know that these consultants are just
: plain ignorant.
: What can be done to persuade people that mod_perl is a viable
: solution?
Well, they are probably afraid they won't be able to find mod_perl
programmers if you and your people vanish, so part of your sales pitch
might be to find a source of good people that they could hire.
A rotary engine Wankel might be a good engine, but would you buy a car
with one under the hood? Luckily there are more perl programmers than
Wankel mechanics, I think!
brew
--
==========================================================================
Strange Brew (brew@theMode.com)
Check out my Musician's Online Database Exchange (The MODE Pages)
http://www.TheMode.com
==========================================================================
------------------------------
Date: Tue, 03 Oct 2000 00:40:47 GMT
From: Jim Mauldin <mauldin@netstorm.net>
Subject: Re: Regex comparing street addresses
Message-Id: <39D92AD1.77F7257F@netstorm.net>
Peter Sundstrom wrote:
>
[snip]
>
> Perhaps I didn't spell it out as precisely as I should have. The
> identifiers *must* have a space before and after them (therefore wouldn't
> match at the beginning or end of line).
Useless to belabor the point, I suppose, but if the above is true, then
Compare('4 123A SMITH ST','123A 4 SMITH ST');
would return DIFFERENT (no space before initial 4), whereas in your
original post you say it should return SAME.
Furthermore, in a subsequent post you say that
$add1 =~ s/([A-Z]*\d+[A-Z]*) ([A-Z]*\d+[A-Z]*)/$2 $1/;
is the solution (and it's a good one, given what you seem to want), but
this regex doesn't look for a space before the first identifier.
Just curious,
-- Jim
------------------------------
Date: Tue, 3 Oct 2000 09:12:54 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Result of functions in child processes
Message-Id: <slrn8ti236.jr6.mgjv@martien.heliotrope.home>
On Mon, 02 Oct 2000 20:19:42 +0200,
Torsten Schindler <Torsten.Schindler@ccc.uni-erlangen.de> wrote:
> Martien Verbruggen wrote:
>
> > >
> > > How can I get the result of my function afunc back from the child
> > > process?
> >
> > # perldoc perlipc
> >
>
> I have read it, but it wasn't very useful.
Not useful? In which sense? I must say I find it terribly useful every
time I need to remind myself on how to do certain things.
> Or can I pipe variables form a child to a parent process?
No, not directly. You will have to come up with some sort of
communication protocol. The simplest one being that the child pushes
that value into the pipe, and the parent reads it. If you need to
communicate more than one thing, you'll have to make it more 'complex'.
However, the parent doesn't have direct access to the 'variable'. All
you can communicate is values, just as if you were writing to a file,
and reading from it.
The same mroe or less goes for shared memory. You wouldn't be
communicating the value of a variable, but you'd just be storing some
data at a location where both processes get to it.
If you really want access to the same variable, you'l have to do
something with threads.
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | What's another word for Thesaurus?
NSW, Australia |
------------------------------
Date: Mon, 02 Oct 2000 22:34:04 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Result of functions in child processes
Message-Id: <w38C5.234$b7.16065@eagle.america.net>
On Mon, 02 Oct 2000 20:19:42 +0200, Torsten Schindler
<Torsten.Schindler@ccc.uni-erlangen.de> wrote:
>Martien Verbruggen wrote:
>
>> >
>> > How can I get the result of my function afunc back from the child
>> > process?
>>
>> # perldoc perlipc
>>
>
>I have read it, but it wasn't very useful.
>Or can I pipe variables form a child to a parent process?
I think you misunderstand what fork() does. The child process created
is a separate address space and *cannot* access the memory of the
parent. The parent *cannot* access the memory of the child. The only
direct information that the *parent* can obtain from the child is its
*exit* status. This is just a number. Any additional communication
between two processes *must* be done using some kind of interprocess
communication (IPC). The perlipc manual page discusses several
different forms of IPC. You need to choose one that will meet your
needs.
Another way to answer your question above is:
You can't.
You must design a method for the two processes to communicate with
each other. The most common techniques employed when the requirement
is for a parent and child of fork() to communicate with each other are
Unix domain sockets and pipes. Again, see perlipc.
--
Garry Williams
------------------------------
Date: Mon, 02 Oct 2000 22:36:38 GMT
From: ollie_spencer@my-deja.com
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <8rb2lm$enh$1@nnrp1.deja.com>
Hi and thanks for your reply.
I found it necessary to read-in the file line-by-line, rather than
"slurping" it into an array, so I could rid it of the header data.
However, in an experiment, I "slurp"ed it in (@Array=<INFILE>;) and
attempted to process it, with the same results as I posted. That of
course may simply mean I don't know yet how to do it...
ollie spencer
In article <8raga8$tl4$1@nnrp1.deja.com>,
amonotod <amonotod@netscape.net> wrote:
> In article <8rabr2$pa4$1@nnrp1.deja.com>,
> ollie_spencer@my-deja.com wrote:
> <snip>
> > in array @OF. For convenience, I would then like to reverse the file
> > so the initial paragraph is at the top, the most recent at the
bottom.
> > I seem unable to get the reversing procedure (from the Perl
Cookbook)
> > to work - the whole file is reversed line by line, not paragraph by
> > paragraph. I include the code below. Where am I going wrong?
> <snip>
> > #------------------------------------------------------------------
> > # Go through <INFILE> a line at a time...
> > #------------------------------------------------------------------
> > while(<INFILE>){
> <snip>
>
> I think that says it all....
>
> You might try something like:
> <PSUEDOCODE>
> $article = (<FILE>);
> @paras = split(/\n\n/, $article);
> foreach (@paras) {
> while($_) {
> </PSUEDOCODE>
>
> HTH,
> amonotod
>
> --
> `\|||/ amonotod@
> (@@) netscape.net
> ooO_(_)_Ooo________________________________
> _____|_____|_____|_____|_____|_____|_____|_____|
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 02 Oct 2000 22:47:16 GMT
From: ollie_spencer@my-deja.com
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <8rb39j$f7a$1@nnrp1.deja.com>
Hi and thanks for your reply-
I didn't mean to imply I don't have a way to reverse the file paragraph
by paragraph - I just reverse the whole dern thing, then read the
reversed file to the first blank line, storing as I go in @TMP(say) - on
reaching a blank line, I stop, reverse @TMP into my grand "reverse by
paragraph" array, and reinitialize @TMP. Seems to have less code than
yours(but I didn't count). I'd rather avoid anything other than vanilla
perl (not even a use ...).
I just wondered why documented functions don't do what I want. I
suspect it's me, but I'd like to know.
Also, with multiple blank lines, the {local $/ = '';...} procedure is
advertised to treat them as a single blank line, something that would
lead to complexities the way I'm doing it -
ollie spencer
In article <39D8C92D.B00B5F70@stomp.stomp.tokyo>,
"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
> ollie_spencer wrote:
>
> (snippage)
>
> > ...terminated by a blank line. It's complicated by the fact that the
file
> > is "upside-down", with the most recent paragraph at the top, the
first
> > paragraph at the bottom.
>
> > ... - the whole file is reversed line by line, not paragraph by
> > paragraph. I include the code below. Where am I going wrong?
>
> There are two undocumented functions in Perl
> which meet your needs quite well per your
> given parameters. Taking out the garbage
> is man's job, traditionally.
>
> use slurp (schizoid);
> use while (schizoid);
>
> Godzilla!
> --
> Androids And More
> http://la.znet.com/~callgirl/android.html
>
> TEST SCRIPT:
> ____________
>
> #!/usr/local/bin/perl
>
> print "Content-Type: text/plain\n\n";
>
> ## use slurp (schizoid);
>
> local ($/) = "©";
>
> open (TEST, "test.txt");
> $data = <TEST>;
> close (TEST);
>
> print "Boss, this is your input:\n\n$data\n\n";
>
> print "Boss, this is my output:\n\n";
>
> @Array = split (/\n\n/, $data);
> @Array = reverse (@Array);
>
> foreach $element (@Array)
> { print "$element\n\n"; }
>
> ## use while (schizoid);
>
> print "\n___\n\n\n\nBoss, this is your input:\n\n";
>
> open (TEST, "test.txt");
>
> local ($/) = "®";
>
> while (<TEST>)
> {
> print $_;
>
> $_ =~ s/\n\n/¦/g;
>
> $data = $_;
>
> close (TEST);
> }
>
> @Array = split (/¦/, $data);
> @Array = reverse (@Array);
>
> print "\n\nBoss, this is my output:\n\n";
>
> foreach $line (@Array)
> { print "$line\n\n"; }
>
> exit;
>
> PRINTED RESULTS:
> ________________
>
> Boss, this is your input:
>
> This is the first paragraph which is appear
> as the last paragraph after processing.
>
> This is the second paragraph which is to appear
> as the third paragraph after processing.
>
> This is the third paragraph which is to appear
> as the second paragraph after processing.
>
> This is the last paragraph which is to appear
> as the first paragraph after processing.
>
> Boss, this is my output:
>
> This is the last paragraph which is to appear
> as the first paragraph after processing.
>
> This is the third paragraph which is to appear
> as the second paragraph after processing.
>
> This is the second paragraph which is to appear
> as the third paragraph after processing.
>
> This is the first paragraph which is appear
> as the last paragraph after processing.
>
> ___
>
> Boss, this is your input:
>
> This is the first paragraph which is appear
> as the last paragraph after processing.
>
> This is the second paragraph which is to appear
> as the third paragraph after processing.
>
> This is the third paragraph which is to appear
> as the second paragraph after processing.
>
> This is the last paragraph which is to appear
> as the first paragraph after processing.
>
> Boss, this is my output:
>
> This is the last paragraph which is to appear
> as the first paragraph after processing.
>
> This is the third paragraph which is to appear
> as the second paragraph after processing.
>
> This is the second paragraph which is to appear
> as the third paragraph after processing.
>
> This is the first paragraph which is appear
> as the last paragraph after processing.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 02 Oct 2000 23:01:34 GMT
From: ollie_spencer@my-deja.com
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <8rb44b$g1q$1@nnrp1.deja.com>
Hi and thanks for posting.
I'm sorry, I thought the form of my data would be clear from my post.
Further data: The original file, as received from the *nix box, has a
header for each page(every 59 lines you get a new header). It
contributes nothing to the data, so I get rid of it by reading-in the
file line by line; since I know that the header ALWAYS begins begins
with a line containing the pattern (GTLT) and ALWAYS ends with a line
containing some number of dashes "-----" I use the range function to
squelch those lines - as shown in the code.
Since I filter the header from the input data, it doesn't figure in
subsequent coding( I thought I indicated that). It's just the reversing
of the "headerless" code using standard perl that is a problem.
In the "more than 1 way" tradition, I have written code that does what I
want, but is considerably less elegant than the way I thought it could
be done.
In article <t8uhtskf5on8r3vfr7ple6e5msf5q7qd8r@4ax.com>,
Bart Lateur <bart.lateur@skynet.be> wrote:
>
> >I am trying to process a file that has the following description:
> >It has a report header on each page. The data that follows the header
> >consists of paragraphs of data entered sequentially from a
> >manufacturing process(processing sector, when entered, data acquired,
> >etc.). There's no blank lines in a paragraph, but each paragraph is
> >terminated by a blank line. It's complicated by the fact that the
file
> >is "upside-down", with the most recent paragraph at the top, the
first
> >paragraph at the bottom.
> >
> >I successfully read-in the file, trash the header(after extracting
some
> >data), then discard certain irrelevant paragraphs, saving the keepers
> >in array @OF. For convenience, I would then like to reverse the file
so
> >the initial paragraph is at the top, the most recent at the bottom. I
> >seem unable to get the reversing procedure (from the Perl Cookbook)
to
> >work - the whole file is reversed line by line, not paragraph by
> >paragraph. I include the code below. Where am I going wrong?
>
> >{
> >local $/ = '';
> >@ROF=reverse @OF;
> >}
>
> It's a bit late for that, isn't it? You should have set paragraph mode
> ($/ = empty string) while reading in the file. Each array item should
> have been a paragraph, not a line.
>
> Now, whether or not your headers are paragrapsh too, isn't clear to
me.
> If not, you may have to switch between line mode an paragraph mode all
> the time.
>
> Since you don't provide sample data, I can't go into any more detail
> than this. Sorry.
>
> --
> Bart.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 02 Oct 2000 23:06:04 GMT
From: ollie_spencer@my-deja.com
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <8rb4co$g6t$1@nnrp1.deja.com>
Thanks for the reply.
I discovered "$\" *AFTER* I posted. I will experiment with that
tomorrow. I early recognized that "$/" dealt with file input, and tried
writing and re-reading a temp file to get the "reverse-by-paragraph"
working, but with no success(but I really didn't spend much time with it
after the first failure).
I'll post any results.
ollie spencer
In article
<Pine.A41.4.21.0010021720540.14510-100000@ginger.libs.uga.edu>,
Brad Baxter <bmb@ginger.libs.uga.edu> wrote:
> On Mon, 2 Oct 2000 ollie_spencer@my-deja.com wrote:
>
> > Hi- Another tale of woe.
> >
> > I am trying to process a file that has the following description:
> > It has a report header on each page. The data that follows the
header
> > consists of paragraphs of data entered sequentially from a
> > manufacturing process(processing sector, when entered, data
acquired,
> > etc.). There's no blank lines in a paragraph, but each paragraph is
> > terminated by a blank line. It's complicated by the fact that the
file
> > is "upside-down", with the most recent paragraph at the top, the
first
> > paragraph at the bottom.
> >
> > I successfully read-in the file, trash the header(after extracting
some
> > data), then discard certain irrelevant paragraphs, saving the
keepers
> > in array @OF. For convenience, I would then like to reverse the file
so
> > the initial paragraph is at the top, the most recent at the bottom.
I
> > seem unable to get the reversing procedure (from the Perl Cookbook)
to
> > work - the whole file is reversed line by line, not paragraph by
> > paragraph. I include the code below. Where am I going wrong?
>
> You say that the paragraphs are stored in @OF, but it looks to me like
> you're storing lines there. Take a look at the $/ variable (perldoc
> perlvar). Setting it to "" will let you read your file paragraph by
> paragraph.
>
> Brad
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 02 Oct 2000 23:23:48 GMT
From: ollie_spencer@my-deja.com
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <8rb5dt$h4g$1@nnrp1.deja.com>
Hi- I just looked at the way my original post was written - something
botched the code snippet I posted, so I repost it below in hopes it goes
out without change this time-
ollie spencer
====Beginning of code snippet
open INFILE or die "Couldn't open $INFILE... Exiting\n";
open OUTFILE or die "Couldn't open $OUTFILE... Exiting\n";
#------------------------------------------------------------------
#Set up $Technology and $Product so they are usable as flags
#------------------------------------------------------------------
undef $Technology;
undef $Product;
#------------------------------------------------------------------
# Go through <INFILE> a line at a time...
#------------------------------------------------------------------
while(<INFILE>){ # Rid file of header (extracting some info
# on the first pass)
# chomp();
if (/\(GTLT\)/ ... /-{40}/){
if (defined($Technology)){
next;
}else{
if (/^\s+PRODUCT\.\.(\S+)\s+\w(.{34}?)/){
($Product, $Technology)=($1, $2);
push @OF, "Product=$Product Technology=$Technology\n";
next;
}
}
}
#------------------------------------------------------------------
# This stuff gets saved to @OF
#------------------------------------------------------------------
if (/ MOVE OUT/ ... /^$/){
push @OF, "="x120 if / MOVE OUT/;
push @OF,$_;
}
if (/LOG AN EVENT/ ... /^$/){
{
push @OF, $_;
last if(/^$/);
}
}
}
#-------------------------------------------------------------------
# To this point the GTLT file has been read-in, headers removed.
# and the result saved in array @OF.
# Now try to reverse the file by paragraphs into array @ROF.
# per the Perl Cookbook------
#-------------------------------------------------------------------
{
local $/ = '';
@ROF=reverse @OF;
}
for $line( @ROF){print "$line\n";};
==== End of code snippet
In article <8rabr2$pa4$1@nnrp1.deja.com>,
ollie_spencer@my-deja.com wrote:
> Hi- Another tale of woe.
>
> I am trying to process a file that has the following description:
> It has a report header on each page. The data that follows the header
> consists of paragraphs of data entered sequentially from a
> manufacturing process(processing sector, when entered, data acquired,
> etc.). There's no blank lines in a paragraph, but each paragraph is
> terminated by a blank line. It's complicated by the fact that the file
> is "upside-down", with the most recent paragraph at the top, the first
> paragraph at the bottom.
>
> I successfully read-in the file, trash the header(after extracting
some
> data), then discard certain irrelevant paragraphs, saving the keepers
> in array @OF. For convenience, I would then like to reverse the file
so
> the initial paragraph is at the top, the most recent at the bottom. I
> seem unable to get the reversing procedure (from the Perl Cookbook) to
> work - the whole file is reversed line by line, not paragraph by
> paragraph. I include the code below. Where am I going wrong?
>
> ====Beginning of code snippet
>> Botched code was here---
> ==== End of code snippet
>
> The last line is the only print in the code.
>
> Thanks in advance!
>
> ollie spencer
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 03 Oct 2000 00:36:38 GMT
From: Pasquale <pdmos23@geocities.com>
Subject: scripts not working
Message-Id: <39D92AA7.DC6AE39C@geocities.com>
I have some perl scripts I was testing on Hypermart and they were
working perfectly fine. I tried them on Freedom 2 Surf & they are not
working(Internal Server Error).
I have checked the shebang line and all the other paths. I am using "-T"
& "-w" on the shebang line. I am also using "strict", "CGI" &
"CGI::Cookie." Any reasons why?
Thanks
Pasquale
------------------------------
Date: Mon, 02 Oct 2000 17:48:08 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: scripts not working
Message-Id: <39D92CC8.2B667F3@vpservices.com>
Pasquale wrote:
>
> I have some perl scripts I was testing on Hypermart and they were
> working perfectly fine. I tried them on Freedom 2 Surf & they are not
> working(Internal Server Error).
> I have checked the shebang line and all the other paths. I am using "-T"
> & "-w" on the shebang line. I am also using "strict", "CGI" &
> "CGI::Cookie." Any reasons why?
All excellent, but none relevant to this problem :-). The one you need
is
use CGI::Carp qw(fatalsToBrowser);
Because that is the only one that can tell you (maybe) what error you
are getting. Or even better, run it from the command line to make sure
it is working there first.
--
Jeff
------------------------------
Date: Mon, 2 Oct 2000 15:26:22 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Search and Destroy
Message-Id: <MPG.1442ab6de49af1ba98adf3@nntp.hpl.hp.com>
In article <8rauj6$auv$1@nnrp1.deja.com> on Mon, 02 Oct 2000 21:27:12
GMT, rathmore@tierceron.com <rathmore@tierceron.com> says...
>
> > my $numOrderFiles = my @sourceFile =
> > grep /\.txt\b/i => $ftp->ls('/some_directory/');
>
> Larry, that is beautiful. You can't see because this is a digital
> medium, but I'm grinning from ear to ear because I love this language,
> and you're the coolest!
Hardly. Using my favorite analogy of skier skill levels, functional
Perl -- good use of grep and map -- is intermediate.
BTW, I showed assignment of the size of the array to $numOrderFiles only
because it was in the original post. Ordinarily I would just use
@sourceFile in scalar context (implicit, or explicit where required).
No need for a separate variable, when Perl provides the needed
information trivially.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 02 Oct 2000 16:08:17 -0700
From: Rip Curl <aslay@ucsd.edu>
Subject: Re: Sendmail/Perl question
Message-Id: <39D91560.D35A1F14@ucsd.edu>
O DontBlameRipCurl=sorryfornotknowingaboutsecurityriskjusttryingtohelp!
Brad Baxter wrote:
> On Mon, 2 Oct 2000, Rip Curl wrote:
>
> > Why don't you just do it like this
> >
> > open(MAIL,"|sendmail -t $email_addrs");
> >
> > and forget about the "To:" line. This might solve your problem. You might
> > have to ditch the -t too.
> >
>
> Uh, no. -t tells sendmail to look for "To:"
> This is in general more secure.
>
> perldoc -q "how do i send mail"
>
> Please note, I'm not attempting to answer the OP, but it might help
> anyway.
>
> Brad
------------------------------
Date: Tue, 3 Oct 2000 01:23:46 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Sendmail/Perl question
Message-Id: <Pine.GHP.4.21.0010030122460.27436-100000@hpplus03.cern.ch>
On Mon, 2 Oct 2000, Rip Curl jeopardized:
> O DontBlameRipCurl=sorryfornotknowingaboutsecurityriskjusttryingtohelp!
Anyone who advises on security risks without understanding them is
by definition _NOT_ trying to help, but is making themselves part of
the problem.
------------------------------
Date: Mon, 2 Oct 2000 17:45:58 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: sort files
Message-Id: <Pine.LNX.4.21.0010021742380.2936-100000@hawk.ce.mediaone.net>
On Mon, 2 Oct 2000, Larry Rosler quoth:
LR> In article <slrn8tglg7.pbs.rgarciasuarez@rafael.kazibao.net> on Mon, 02
LR> Oct 2000 09:25:05 GMT, Rafael Garcia-Suarez <rgarciasuarez@free.fr>
LR> says...
LR> > Calvin wrote in comp.lang.perl.misc:
LR> > >I want to sort the files and directories by last modified. What should I
LR> > >add/change ? Thank you very much!
LR> >
LR> > Get the last modification time with:
LR> > my $mtime = (stat($filename))[9];
LR> > (make sure that $filename is not only the filename, but the full path
LR> > to it, i.e. with the directory name prepended.)
LR> > So you can get the sorted list by:
LR> > my @sorted = sort { (stat($a))[9] <=> (stat($b))[9] } @files;
LR>
LR> Note, though, that the above wastes a lot of cycles doing repeated
LR> stats, which matters if the directory has many files. See the
LR> documentation for more efficient ways of doing this. Here is one
LR> source:
LR>
LR> http://www.hpl.hp.com/personal/Larry_Rosler/sort/
Does anyone else think that this paper might make a good addition to the
standard Perl documentation. As in, 'perldoc perlsort'? Obviously D. E.
Knuth thought it was a pretty important subject, and it is a FAQ. But
perhaps the stardard distribution should come with a more comprehensive
explanation?
Just a thought...
anm
--
perl -wMstrict -MText::ParseWords -e "
system echo => grep defined() ? /./ : q++ => quotewords '\s+', 0, <<JAPH;
"""""""""""""""""""""""""""""""" Just """"""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""" another """"""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""" Perl """"""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""" Hacker """"""""""""""""""""""""""""""""
JAPH
"
------------------------------
Date: Mon, 2 Oct 2000 16:19:24 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: sort files
Message-Id: <MPG.1442b7d79d03946f98adf4@nntp.hpl.hp.com>
In article <Pine.LNX.4.21.0010021742380.2936-
100000@hawk.ce.mediaone.net> on Mon, 2 Oct 2000 17:45:58 -0500, Andrew
N. McGuire <anmcguire@ce.mediaone.net> says...
> On Mon, 2 Oct 2000, Larry Rosler quoth:
...
> LR> http://www.hpl.hp.com/personal/Larry_Rosler/sort/
>
> Does anyone else think that this paper might make a good addition to the
> standard Perl documentation. As in, 'perldoc perlsort'? Obviously D. E.
> Knuth thought it was a pretty important subject, and it is a FAQ. But
> perhaps the stardard distribution should come with a more comprehensive
> explanation?
I'm sure Uri would be happy to massage the text (currently available in
PDF, or in crummy HTML, or in the Micro$..t Word format from which the
HTML was generated) into POD.
The list of references includes Knuth and the relevant Perl
documentation (FMTYEWTK, FAQ, perldoc -f sort, et al), so it is an
adequate high-level starting point.
> Just a thought...
I like the thought...
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 2 Oct 2000 16:27:45 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: sort files
Message-Id: <MPG.1442b9d0277c3c8b98adf6@nntp.hpl.hp.com>
In article <MPG.1442b7d79d03946f98adf4@nntp.hpl.hp.com> on Mon, 2 Oct
2000 16:19:24 -0700, Larry Rosler <lr@hpl.hp.com> says...
...
> I'm sure Uri would be happy to massage the text (currently available in
> PDF, or in crummy HTML, or in the Micro$..t Word format from which the
> HTML was generated) into POD.
It would also give him a chance to remove the discussion of the still
not completed Sort::Records module that was promised in the paper
(<blush>).
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
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 4499
**************************************