[17106] in Perl-Users-Digest
Perl-Users Digest, Issue: 4518 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 4 11:10:22 2000
Date: Wed, 4 Oct 2000 08:10:11 -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: <970672210-v9-i4518@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 4 Oct 2000 Volume: 9 Number: 4518
Today's topics:
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! (Michel Dalle)
Re: Reverse by paragraphs - NOT! <bmb@ginger.libs.uga.edu>
Re: Search an array <sariq@texas.net>
Re: SSL with HTTP::Request::Common qw(POST) ? (Wolfgang Schauer)
Re: Testing for numeric integer <ren.maddox@tivoli.com>
Re: The match operator & variables containing regexp-ch (Keith Calvert Ivey)
Re: what on is correct??? <jaap@stack.nl>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 04 Oct 2000 13:50:48 GMT
From: ollie_spencer@my-deja.com
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <8rfcjl$sj4$1@nnrp1.deja.com>
Hi and thanks for the reply.
Perhaps I wasn't clear. The file in question has a HEADER PARAGRAPH
every 60 lines - in other words, it is a file that was intended to be
printed, not processed by another program. By reading-in line-by-line,
I can elimnate all header data with the
while (/\(GTLT\)/ ... /"-"x45/) {next;} # OR SIMILAR
code line, thus removing any header data, since the header first line
always contains (GTLT) and the header last line always contains 45
adjacent "-" characters.
I wish I'd not mentioned the header, because it's NOT a my problem. I
successfully excise the header and place the headerless data into @OF,
even the blank lines.
NOW comes my problem.
I can write @OF to a file, then close and reopen it for reading.
(I know I can open a file for both writing and reading, but again,
that's NOT the problem)
I then do the {local $/=''; @ROF=reverse <INFILE>) bit and, after
closing the block to restore $/, get the result I desire: The file
reversed by paragraph.
That way WORKS. But it seems a bit clumsy!
I also have coded a paragraph by paragraph approach, about 10 lines, to
reverse the file by reading it in reverse, then reding paragraphs and
reversing them 1 by 1 to @ROF. Again successful
That way WORKS ALSO. But it also seems clumsy!
I thought I might temporarily change $/, $\, or $" so I could
reverse an *array* by paragraph, in the same manner as I reverse a
file, as I read it in, by paragraph.
Thus far, I am defeated. Nothing has worked for me in this vein.
That's why I posted. My posted code snippet seems to have been garbled
both times I posted it, but it should be readable if you realize the
original code actually ran - it just didn't reverse by paragraph. I
will repost anew, checking that the post is true to the original, if
anyone thinks they will benefit by it---
So I have a working program. But, I want (if possible) a more perl-ish
way to do the same thing, hopefully with an elegant solution. maybe it
doesn't exist - at least NO POSTER HAS SAID THAT YET!
ollie spencer
In article <m38zs68q8w.fsf@dhcp11-177.support.tivoli.com>,
Ren Maddox <ren.maddox@tivoli.com> wrote:
> ollie_spencer@my-deja.com writes:
>
> > 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.
>
> In case you didn't realize it, you can change $/ on-the-fly after
> reading part of the file. So, read the header data line-by-line,
>
> #LINES SNIPPED HERE
>
> Ren Maddox
> ren@tivoli.com
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 04 Oct 2000 13:53:15 GMT
From: ollie_spencer@my-deja.com
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <8rfco8$skj$1@nnrp1.deja.com>
I think I replied to this earlier. Please re-read my reply.
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: Wed, 04 Oct 2000 13:59:29 GMT
From: ollie_spencer@my-deja.com
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <8rfd3s$t22$1@nnrp1.deja.com>
Please! This is a work related problem. I have a real deadline, a real
task, and an impatient manager. I don't have time to post or read
inanities. You don't seem encumbranced by such concerns.
PLEASE DON'T BOTHER ME WITH NONSENSE. Re-READ my answer to your first
post. I'll not read any further posts by "Godzilla" to this string.
I may seem doltish. I am a physics PhD and 63 years old. If my
simplicity offends you, just ignore me, and I assure you I will
ignore you.
ollie spencer
In article <39DA0132.20572263@stomp.stomp.tokyo>,
"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
> Ben Kennedy wrote:
>
> > Godzilla! wrote:
>
> > > ollie_spencer@my-deja.com wrote:
>
> > > (snippage)
>
> > > > 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...
> > ..
> > > Having you here, constantly changing parameters,
> > > arguing with people, looking to get in a dig when
> > > you can, posting malice intent articles under myriad
> > > fake names, both male and female, is extremely rude,
> > > extremely thoughtless and your track history, clearly
> > > defines you as mentally unstable if not outright,
> > > psychotic.
>
> > The OP asked a simple question, thanked everyone for the
> > replies, posted ernest followups, thanked everyone again,
> > etc. There was nothing argumentative or malicious in his
> > posts. Now I do believe that you think he was harassing
> > the newsgroup in general, not you personally - this was not
> > clear from your post. My initial reaction was "Boy is she
> > paranoid" - but I do think you are wrong to think there is
> > one person out there faking requests for (and receiving)
> > help for various problems in this newsgroup.
>
> > --Ben Kennedy
>
> Well tarnation, Ollie. What type of yo-yo do you
> take me to be? A stringless yo-yo?
>
> * walks the dog with her yo-yo *
>
> What a dolt you are Ollie. Easy enough to see I am a
> talented yo-yo woman, often simply called "Yo Woman!"
>
> * rocks the cradle with her yo-yo *
>
> I have a string, Ollie, and wax it well with bee's wax.
>
> * goes around the world with her yo-yo *
>
> Look at this, Ollie. A Duncan yo-yo, the best made.
>
> * does a shooting star smacking Ollie on his forehead *
>
> Mine is an awesome and talented yo-yo perfect for stringing
> along a stringless yo-yo such as yourself, Frank.
>
> Godzilla!
> --
> Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
> UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
> BumScrew, South of Egypt ¦ HTML Programming Class
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 04 Oct 2000 14:59:42 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <8rfgmo$kl9$1@news.mch.sbs.de>
In article <8rfcjl$sj4$1@nnrp1.deja.com>, ollie_spencer@my-deja.com wrote:
[snip]
>I thought I might temporarily change $/, $\, or $" so I could
>reverse an *array* by paragraph, in the same manner as I reverse a
>file, as I read it in, by paragraph.
>
>Thus far, I am defeated. Nothing has worked for me in this vein.
>That's why I posted. My posted code snippet seems to have been garbled
>both times I posted it, but it should be readable if you realize the
>original code actually ran - it just didn't reverse by paragraph. I
>will repost anew, checking that the post is true to the original, if
>anyone thinks they will benefit by it---
>
>So I have a working program. But, I want (if possible) a more perl-ish
>way to do the same thing, hopefully with an elegant solution. maybe it
>doesn't exist - at least NO POSTER HAS SAID THAT YET!
I haven't followed this thread from the beginning, but it seems to me
that your problem description is a bit strange. You can't reverse an
array *by anything*. You simply reverse the order of its elements,
independently of what those elements contain (characters, lines,
paragraphs, numbers, hashes, ... whatever).
So if your original array contains paragraphs as elements and you
reverse the array, you will get the paragraphs in reverse.
But if your array contains lines, you will have lines in reverse order,
and if it contains individual characters, you will have the characters
in reverse.
Garbage in, garbage out :)
Michel.
------------------------------
Date: Wed, 4 Oct 2000 11:04:01 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Reverse by paragraphs - NOT!
Message-Id: <Pine.A41.4.21.0010041102300.12946-100000@ginger.libs.uga.edu>
On Wed, 4 Oct 2000 ollie_spencer@my-deja.com wrote:
> Please! This is a work related problem. I have a real deadline, a real
> task, and an impatient manager. I don't have time to post or read
> inanities. You don't seem encumbranced by such concerns.
>
> PLEASE DON'T BOTHER ME WITH NONSENSE. Re-READ my answer to your first
> post. I'll not read any further posts by "Godzilla" to this string.
Or any string. Godzilla is a troll whose sole object is exasperation.
Brad
------------------------------
Date: Wed, 04 Oct 2000 13:55:03 GMT
From: Tom Briles <sariq@texas.net>
Subject: Re: Search an array
Message-Id: <39DB36B7.FFD2DE53@texas.net>
"Andrew N. McGuire" wrote:
>
> On Tue, 3 Oct 2000, Arthur Dalessandro quoth:
>
> AD> I am making a script to search through FTP log files, pull the IP address
> AD> from each line, then add that IP address to an array if it isn't already
> AD> there. Then write the output to another log file. Problem is how to search
> AD> the entire array for a string, to see if it exists, without going through
> AD> all the
> AD> for i -> x
> AD> @test[i];
> AD> etc..
>
> Use grep.
>
> #!/usr/bin/perl -w
> use strict;
>
> my @array = qw/ foo bar baz /;
>
> if (grep /^foo$/ => @array) {
> print "we have foo!\n";
> }
> else {
> print "no foo here!\n";
> }
From the FAQ:
"Please do not use
$is_there = grep $_ eq $whatever, @array;
or worse yet
$is_there = grep /$whatever/, @array;
"These are slow (checks every element even if the first matches),
inefficient (same reason), and potentially buggy (what if there are
regexp characters in $whatever?)."
- Tom
------------------------------
Date: 4 Oct 2000 15:02:43 GMT
From: w-s@gmx.de (Wolfgang Schauer)
Subject: Re: SSL with HTTP::Request::Common qw(POST) ?
Message-Id: <8rfgqj$hhef2$1@fu-berlin.de>
[posted and mailed]
irf@netexecutive.com wrote in <8rdshe$o49$1@nnrp1.deja.com>:
> [ lwp and POST over https ]
have a look at
http://www.ics.uci.edu/pub/websoft/libwww-perl/archive/2000h2/0163.html
obviously there's a bug in lwp which might cause the problem you described.
Regards,
Wolfgang
------------------------------
Date: 03 Oct 2000 23:18:11 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Testing for numeric integer
Message-Id: <m3hf6tnssc.fsf@dhcp11-177.support.tivoli.com>
kcivey@cpcug.org (Keith Calvert Ivey) writes:
> Ren Maddox <ren.maddox@tivoli.com> wrote:
>
> >Which leads to the way I usually handle this, which is to have an
> >allowed range and check for that. Then the need to check for a valid
> >number is completely removed, as the numeric comparison will take care
> >of that for you (assuming you are excluding 0).
> >
> >if($number < 1 or $number > 99) {
> > # out of range
> >}
>
> But you'll need to do something before it like
>
> $number =~ tr/0-9//cd;
>
> or
>
> $number =~ s/.*?(\d*).*/$1/s;
>
> and then
>
> $number ||= 0;
>
> if you want to avoid warnings and deal with things like 1.5.
Or:
use warnings;
no warnings "numeric";
:)
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Wed, 04 Oct 2000 14:12:09 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: The match operator & variables containing regexp-characters
Message-Id: <39df3a01.41611959@news.newsguy.com>
Toralf Lund <toralf@kscanners.com> wrote:
>> if ($line =~ /\Q$variable/) {
>> ...
>> }
>
>This is exactly what I was looking for. I found a description right away in
>the manual pages now, of course, but I overlooked it earlier. I guess I could
>still get into trouble if the variable contains '\E', though, but it probably
>won't.
If the variable contains '\E', the '\Q' will change it to '\\E',
so everything's fine.
--
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
------------------------------
Date: Wed, 04 Oct 2000 14:54:55 GMT
From: "Jaap" <jaap@stack.nl>
Subject: Re: what on is correct???
Message-Id: <3xHC5.43455$Sb1.696063@nlnews00.chello.com>
Both are good, the first sais that in ALL other cases than $testver == 0 to
print test\n and the second sais that in other cases where $testver > 0 to
print that.
Teun
"Tigz" <tigz@ntlworld.com> schreef in bericht
news:j%DC5.12453$L12.251687@news2-win.server.ntlworld.com...
> Hi could someone tell me which is correct, both seem to work fine, but i
am
> not sure. I actually dont have a clue what i am doing... I am just trying
to
> lern....
>
> if ($testver eq 0) {
> print ("test 1"\n");
> } else {
> print ("test"\n");
> }
>
> or this:
>
> if ($testver eq 0) {
> print ("test 1"\n");
> }
> if ($tierlevel gt 0) {
> print ("test"\n");
> }
>
> thankx
> mick.
>
>
------------------------------
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 4518
**************************************