[9886] in Perl-Users-Digest
Perl-Users Digest, Issue: 3479 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 19 00:07:18 1998
Date: Tue, 18 Aug 98 21:00:18 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 18 Aug 1998 Volume: 8 Number: 3479
Today's topics:
Re: Anyone ever successfully register some perl code as (Martien Verbruggen)
Re: comp.lang.perl.announce redux (Martien Verbruggen)
Re: comp.lang.perl.newbie (Ronald J Kimball)
Re: Converting to lowecase (Ronald J Kimball)
Re: Easy one for you. <dgris@rand.dimensional.com>
Greedy arrays in list assignments (Kevin Reid)
Re: Greedy arrays in list assignments (Jeremy D. Zawodny)
Re: Help! (with web database) (Patrick Timmins)
Re: Help! (with web database) (Randy Kobes)
Re: here's an implementation of diff in perl (Sam Holden)
Re: here's an implementation of diff in perl (Lloyd Zusman)
need a cgi programmer big time quick goodtimeweb@my-dejanews.com
Re: pattern matching with parenthesis <jdf@pobox.com>
Please help with HTTP::Response <jon@resonate.com>
Re: Please help with HTTP::Response (Maurice Aubrey)
Re: POSTing out (Martien Verbruggen)
Re: Problem with $^I in W95 (Ronald J Kimball)
Re: quotemeta (Ronald J Kimball)
Re: request for comments... (Ronald J Kimball)
revised implementation of diff in perl <ekoontz@lsi.sel.sony.com>
Trouble with perl invocation line (from Camel) [HPUX 10 <mgregory@asc.sps.mot.com>
wrapping text (Joy Mei Chen)
Re: wrapping text (Jeremy D. Zawodny)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 19 Aug 1998 02:40:13 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Anyone ever successfully register some perl code as an NT service?
Message-Id: <6rddud$m5q$2@nswpull.telstra.net>
In article <35D8FB53.42121F7B@erols.com>,
"Matthew O. Persico" <mpersico@erols.com> writes:
> Hmm. How do we add THIS to the FAQ?
We don't. It's about NT, not about perl.
> kingm1706@my-dejanews.com wrote:
>>
>> Use the instsrv.exe and srvany.exe that come with the Windows NT Resource kit
>> to install any program (including a PERL app) as a service.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: 19 Aug 1998 02:38:11 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: comp.lang.perl.announce redux
Message-Id: <6rddqj$m5q$1@nswpull.telstra.net>
In article <903485155.14302.0.nnrp-11.c2deb1c5@news.demon.co.uk>,
"Daniel Adams" <dan@fearsome.net> writes:
> To use an analogy, think of species development - if you accept evolution as
> at least premise if not proven (as anyone bar a neanderthal fundamentalist
> would do - but lets leave that for another ng shall we?) then all species
Why leave that to another newsgroup, and the discussion about English
not? I'd like to talk about growing cucumbers as well.
:)
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: Tue, 18 Aug 1998 23:21:26 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: comp.lang.perl.newbie
Message-Id: <1ddzb6p.gpz5h719qeg8wN@bay1-205.quincy.ziplink.net>
Andrew M. Langmead <aml@world.std.com> wrote:
> Especially with a language like Perl ... that gives you enough rope to bury
> yourself.
Okay, I have to ask... How much rope does it take to bury yourself?
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Tue, 18 Aug 1998 23:21:20 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Converting to lowecase
Message-Id: <1ddzatx.1gu44r7t5jmuN@bay1-205.quincy.ziplink.net>
Andrew M. Langmead <aml@world.std.com> wrote:
> C'mon Ronald. At the beach there is sun. You wouldn't want to lose
> that pale complexion that you've worked so hard to achieve. (After
> all, you were the one who shot down the idea of a Boston Perl Mongers
> cookout.)
No way... First, it wasn't a cookout, it was roller-blading. Second,
when someone suggested late night roller-blading, it wasn't me who
complained about losing their pale complexion from being outside.
Third, I pointed out that *late night* roller-blading wasn't really a
threat to pale complexions. :-)
Anyway, I think a cookout would be fun!
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Wed, 19 Aug 1998 03:01:18 GMT
From: Daniel Grisinger <dgris@rand.dimensional.com>
Subject: Re: Easy one for you.
Message-Id: <6rdea9$2qn$1@rand.dimensional.com>
[posted to comp.lang.perl.misc and mailed to the cited author]
In article <6rakie$prs@Xenon.Stanford.EDU>
hirano@Xenon.Stanford.EDU (Kelly Hirano) wrote:
<snip>
>my $line = qq!2|WARNINGS|WARNINGS|1600034|sunthu4|arbctprd!;
>my @array = split(/|/, $line);
^^^
That won't work. You are asking to match on the null pattern
or the null pattern. Try split(/\|/, $line).
dgris
--
Daniel Grisinger dgris@perrin.dimensional.com
"No kings, no presidents, just a rough consensus and
running code."
Dave Clark
------------------------------
Date: Tue, 18 Aug 1998 22:39:52 -0400
From: kpreid@ibm.net (Kevin Reid)
Subject: Greedy arrays in list assignments
Message-Id: <1ddrbcq.yp9jsj19h5mf4N@slip-32-100-246-136.ny.us.ibm.net>
Ken Pizzini <ken@halcyon.com> wrote:
> On Wed, 12 Aug 1998 15:51:59 GMT, Dave Lorand <davel@spc.uchicago.edu>
> wrote:
> >Or else:
> >
> > ($temp, @arr, $temp) = split //, 'abcde';
>
> That won't do what you meant it to: the @arr assignment is greedy...
Is there any reason why Perl (c|sh)ouldn't be changed so it isn't
greedy?
--
Kevin Reid. | Macintosh.
"I'm me." | Think different.
------------------------------
Date: 18 Aug 1998 23:31:40 -0400
From: jzawodn@wcnet.org (Jeremy D. Zawodny)
Subject: Re: Greedy arrays in list assignments
Message-Id: <m3vhnpabqb.fsf@peach.z.org>
kpreid@ibm.net (Kevin Reid) writes:
> Ken Pizzini <ken@halcyon.com> wrote:
>
> > On Wed, 12 Aug 1998 15:51:59 GMT, Dave Lorand <davel@spc.uchicago.edu>
> > wrote:
> > >Or else:
> > >
> > > ($temp, @arr, $temp) = split //, 'abcde';
> >
> > That won't do what you meant it to: the @arr assignment is greedy...
>
> Is there any reason why Perl (c|sh)ouldn't be changed so it isn't
> greedy?
Of course. :-)
Jeremy
--
Jeremy D. Zawodny Web Geek, Perl Hacker, etc.
http://www.wcnet.org/~jzawodn/ jzawodn@wcnet.org
LOAD "LINUX",8,1
------------------------------
Date: Wed, 19 Aug 1998 01:03:40 GMT
From: ptimmins@netserv.unmc.edu (Patrick Timmins)
Subject: Re: Help! (with web database)
Message-Id: <6rd89d$nib$1@nnrp1.dejanews.com>
In article <35D9D77B.3871@chebucto.ns.ca>,
Kevin <ap619@chebucto.ns.ca> wrote:
> Hi,
>
> I have a database(text file) of "goaltending tips".
[snip]
> **PLEASE RESOND BY EMAIL**
>
> Much appreciated!
> Sincerely,
> Kevin Howe
>
Can we some of your code?
Any relation to Gordie?
Patrick Timmins
U. Nebraska Medical Center
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: 19 Aug 1998 03:31:19 GMT
From: randy@theory.uwinnipeg.ca (Randy Kobes)
Subject: Re: Help! (with web database)
Message-Id: <slrn6tki78.mhf.randy@theory.uwinnipeg.ca>
On Tue, 18 Aug 1998 16:35:23 -0300, Kevin <ap619@chebucto.ns.ca> wrote:
>Hi,
>
>I have a database(text file) of "goaltending tips".
>I've created a TIPs webpage and want to have it so that the user can
>click a "VIEW NEXT TIP" button and the next record in the database will
>be displayed. So far I have only found scripts that allow for "random"
>displays, i.e. click the button and it randomly picks a tip from the
>database. This is a problem because they often choose the same tip(same
>record) several times in a row, even if teh database is large.
>Can anyone direct me to a script like the one I've described?
>I am on a unix server.
>
>**PLEASE RESOND BY EMAIL**
>
>Much appreciated!
>Sincerely,
>Kevin Howe
Hi,
If the script is choosing the same record several times in
succession, then this might indicate a problem with how the
rand() function is seeded. At least in perl 5.004_04 and higher
this is handled for you, but on earlier perls a call to srand()
should be made (once) in a program - see
perldoc -f rand
perldoc -f srand
Or, the client might be caching the result. In any case, the
following code should return a random record:
open (TIPS, "<tips.txt") or die "Can't open tips.txt: $!\n";
my @tips = <TIPS>;
close TIPS;
my $random_tip = $tips[ int rand @tips ];
with a suitable call to srand, if needed.
If instead of a random tip you wanted to cycle through the
tips in order, you could do it by creating a counter, placed
in a hidden field in the form, which would be increased by one
each time the form is submitted. This counter would then be used
to select the element of @tips. Using the CGI module, this would
look something like:
use CGI;
my $query = new CGI;
my $counter = $query->param('counter') || 0;
$counter++;
$query->param('-name' => 'counter', '-value' => $counter);
$query->print($query->start_html('Counter example'),
$query->start_form,
$query->hidden('-name'=>'counter', '-value'=>$counter),
"The counter is now $counter<BR>",
$query->submit,
$query->end_form,
$query->end_html,
);
Of course, when the counter reached the number of elements in
@tips, it should be reset to zero.
--
Best regards,
Randy Kobes
Physics Department Phone: (204) 786-9399
University of Winnipeg Fax: (204) 774-4134
Winnipeg, Manitoba R3B 2E9 e-mail: randy@theory.uwinnipeg.ca
Canada http://theory.uwinnipeg.ca/
------------------------------
Date: 19 Aug 1998 02:20:06 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: here's an implementation of diff in perl
Message-Id: <slrn6tkdim.l4m.sholden@pgrad.cs.usyd.edu.au>
On 18 Aug 1998 18:05:22 GMT, Greg Bacon <gbacon@cs.uah.edu> wrote:
>In article <6rcf1b$jug$1@pegasus.csx.cam.ac.uk>,
> mjtg@cus.cam.ac.uk (M.J.T. Guy) writes:
>: In article <6rcdf6$rfm$20@info.uah.edu>,
>: Greg Bacon <gbacon@cs.uah.edu> wrote:
>: >O(n + n lg n) is the same as O(n lg n).
>:
>: What's that got to do with Abigail's (correct) statement?
>
>It takes O(n) comparisons to check whether a set is already sorted.
>This is a simple approach, but most modern implementations of quicksort
>do something to avoid quicksort's O(n**2) worst case.
No matter what an algorithm does to detect a worse case for quicksort, there is
always a sequence which will take O(n**2), unless of course the checking
algorithm is taking O(n!) which would be kindof stupid...
The normal bad ones are sawtooth patterns of values...
Sam
------------------------------
Date: 19 Aug 1998 03:31:42 GMT
From: ljz@asfast.com (Lloyd Zusman)
Subject: Re: here's an implementation of diff in perl
Message-Id: <slrn6tkhqo.25o.ljz@sunspot.tiac.net>
On 17 Aug 1998 14:19:47 GMT, Greg Bacon <gbacon@cs.uah.edu> wrote:
> In article <slrn6tfct7.nka.ljz@sunspot.tiac.net>,
> ljz@asfast.com (Lloyd Zusman) writes:
> : There are lots of ways that two lines can differ, but only one way
> : that they can be identical. Given the possible set of characters that
> : could fill each of the N positions of the lines, there is a very high
> : probability that any two arbitrary lines will not match, and there is
> : also a very good chance that this non-matchingness will be detected
> : after a small number characters of the two lines have been compared.
>
> This is irrelevant. Saying that an algorithm's time complexity is
> O(N/2) is a fairly good indication that you don't understand the
> notation or the concept.
Very true.
But keep in mind the paragraph of mine you quoted above was written to
*contradict* my own, previously posted "O(N/2)" argument once I was
shown the fallacy of it by another poster.
> [ ... ] Here's the definition that Baase gives in
> the second edition of _Computer Algorithms: Introduction to Design
> and Analysis_:
>
> [ ... ]
Thank you.
In the case I mention in the paragraph you quoted, the probability is
high that the determination of matching/non-matching would occur after
the first character of the line is tested, irrespective of the
line-length value N. This is sublinear w/r/t N, so I suppose this
would be still be considered O(N) by the definition you supplied ...
right?
--
Lloyd Zusman 01234567 <-- The world famous Indent-o-Meter.
ljz@asfast.com ^ Indent or be indented.
------------------------------
Date: Wed, 19 Aug 1998 01:41:53 GMT
From: goodtimeweb@my-dejanews.com
Subject: need a cgi programmer big time quick
Message-Id: <6rdah2$qkr$1@nnrp1.dejanews.com>
Alright boys and girls, got a phat job offer for a CGI programmer, if living
in Sacramento California. We are a small web design company who is looking
for someone who can write and implement cgi programs on an NT Server. Need
immediately. The date of this message is 8/18/98. I need a person on
8/19/98. Job is pretty much set up already. The job if you wish to take it
calls for a search engine type program to be implemented on a client's web
site. We would like someone who has already created one or similar and is
able to show proof of it on a web site. But if you haven't done one, and
think you can slam this job, just tell me your qualifications and we'll go
from there. We are a small web design company. This job will lead to future
projects, so it's not just a one-time deal. Pay is negotiable. Email at
goodtime@goodtimeweb.com. Just send your qualifications, address, a way to
contact you, and any URLs showing examples of your work. Thank you and have
a nice day.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: 18 Aug 1998 21:01:18 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: pattern matching with parenthesis
Message-Id: <7m0591ch.fsf@mailhost.panix.com>
julzrulz@my-dejanews.com writes:
> unless (open (SAM, "$SAMFILE")){
^ ^
Those quotes aren't doing anything useful.
> next unless $_;
Do you mean to skip blank lines? What you have will also skip lines
consisting solely of zeros. Perhaps you want something like
next if /^\s*$/;
> foreach $pat (split(/\0/,$in{'class'})){
Unless $in{class} has binary 0s in it (not the character '0', but the
actual value 0), then that split will provide you with exactly one
pattern: the entire contents of $in{class}. Is that what you meant?
You'd better put some debugging print statements in there to make sure
that you're doing what you think you're doing. For example:
print qq(About to check "$field[4]" for pattern "$pat"...\n);
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf/
------------------------------
Date: 19 Aug 1998 01:08:53 GMT
From: "Jon C. Hodgson" <jon@resonate.com>
Subject: Please help with HTTP::Response
Message-Id: <35DA25AC.7291@resonate.com>
Help!
I've been programming PERL for a long time, but I a real newbie to OOP
stuff.
I need to substitute patterns in the $response->content() object before
I print it.
I can print:
$response=$ua->request($request);
print $response->content();
But I need to be able to subtitute globally one pattern for another:
s/pattern1/pattern2/g
before I print the content.
Is there a way to convert the $response->content() object to text that I
can step thru & process?
Thanks,
Jon
------------------------------
Date: Wed, 19 Aug 1998 03:55:05 GMT
From: maurice@hevanet.com (Maurice Aubrey)
Subject: Re: Please help with HTTP::Response
Message-Id: <slrn6tkj4q.2hc.maurice@localhost.localdomain>
On 19 Aug 1998 01:08:53 GMT, Jon C. Hodgson <jon@resonate.com> wrote:
>I've been programming PERL for a long time, but I a real newbie to OOP
>stuff.
>
>I need to substitute patterns in the $response->content() object before
>I print it.
>
>I can print:
> $response=$ua->request($request);
> print $response->content();
>
>
>But I need to be able to subtitute globally one pattern for another:
>
> s/pattern1/pattern2/g
>
>before I print the content.
>
>
>Is there a way to convert the $response->content() object to text that I
>can step thru & process?
Sure.
$_ = $response->content;
s/pattern1/pattern2/g;
--
Maurice Aubrey <maurice@hevanet.com>
The strongest reason for the people to retain the right to keep and
bear arms is, as a last resort, to protect themselves against tyranny
in government.
- Thomas Jefferson
------------------------------
Date: 19 Aug 1998 02:46:12 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: POSTing out
Message-Id: <6rde9k$m5q$3@nswpull.telstra.net>
In article <6r9j4r$msv$1@supernews.com>,
"Brian Andrus" <sysop@millenia.com> writes:
> How would I do a redirect and pass variables to another web page at the same
> time, using the POST method from PERL?
It's perl if you talk about the interpreter/program, and Perl if you
talk about the language. PERL doesn't exist in this group.
> I need to pass some variables that I use in a PERLSCRIPT off to another
> location to be processed further. BUT the other location expects the
> variables to be passed in POST mode.
Use LWP.
You can get it from CPAN, if it isn't already installed. Check to see
if it is, otherwise http://www.perl.com/CPAN/
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: Tue, 18 Aug 1998 23:21:28 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Problem with $^I in W95
Message-Id: <1ddzbng.s8gbbnh3dlyuN@bay1-205.quincy.ziplink.net>
Louie <louie@visca.com> wrote:
> However, when I try $^I = 'old/*.bak'; (the c:/texts/old/ directory
> exists), the original file is erased and no backup is made. In fact,
> this happens whenever a * is used. Finally, if I try $^I = 'bak'; the
> original file is erased and a 0 byte copy (numbers.txtbak) is created.
>
> Is this just MS-DOS weirdness? Thanks.
Mostly, it's a misunderstanding of $^I. The value of $^I is simply
appended to the name of the input file to create the backup. You can't
do anything cute with wild cards and prefixes, as you were trying to do.
When you say the original file is erased, do you mean the file is
deleted, or it exists but is empty? If the latter, make sure your file
is not empty before you execute the Perl script.
Other than that, I cannot say with certainty that $^I works properly
under DOS.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Tue, 18 Aug 1998 23:21:31 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: quotemeta
Message-Id: <1ddzbz5.1wjv21c14je4h1N@bay1-205.quincy.ziplink.net>
Patrick Clauberg <pat@uni.de> wrote:
> if ($file =~ /^(\w+\s+.*)+\s*#\s*(\w+\s*.*).mp3/) {
>
> unfortunately, some filenames contain (, {, ), } , which sometimes
> kills my regexp (something with "unmatched ( ...." )
Since you don't use $file within that regex, the contents of $file have
nothing to do with why you are getting that error. I would suggest
checking your regex to make sure all the paired characters are balanced.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Tue, 18 Aug 1998 23:21:34 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: request for comments...
Message-Id: <1ddzch4.ggo2o49jtwx2N@bay1-205.quincy.ziplink.net>
Bill Jones, FCCJ Webmaster <webmaster@fccjmail.fccj.cc.fl.us> wrote:
> next unless chr($first) =~ /^-?[a-zA-Z0-9]+$/;
> next unless chr($second) =~ /^-?[a-zA-Z0-9]+$/;
What's up with these regex matches? chr() always returns a single
character.
next unless chr($first) =~ /[a-zA-Z0-9]/;
next unless chr($first) =~ /[a-zA-Z0-9]/;
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Tue, 18 Aug 1998 18:40:17 -0700
From: Eugene Koontz <ekoontz@lsi.sel.sony.com>
Subject: revised implementation of diff in perl
Message-Id: <35DA2D01.EA3FBD54@lsi.sel.sony.com>
Thanks for your suggestions and advice regarding my earlier posting of
my diff implementation. I apologize for not noticing earlier messages
related to discussions of diff and its relation to perl. Our news server
seems to trash everything older than a week; thus at the time I
submitted,
I could not see the discussion. Next time I will check dejanews.
Corrections from John Porter and Mark-Jason Dominus are
gratefully
accepted and incorporated. (all remaining bugs and deficiencies are my
own, of course). I don't think there are any problems with infinite
loops; let me know if there are.
diff is certainly an interesting problem; more so than I realized
before
I posted. I would be interested in discussion of better algorithms, such
as
one that searches for large common sequences and that does so
efficiently.
This diff.pl supports no options and only outputs in
patch-readable
form. Also, the output of diff.pl is often not identical as that output
by GNU diff due to differences in the algorithm. Nevertheless, the
result of applying a diff.pl-generated patch and a GNU diff-generated
patch to the same file should be the same; at least it is in the file I
tested.
Complexity : I think that my algorithm is O(N^2 + M^2), where N
and M
are the length, in number of lines, of the two files, and disregarding
time
needed to compare two lines. (Not that it's not important, but it will
not
vary among different implementations of diff - as we know, it is
impossible to
compare two lines in better time than linear in the length of the line.)
Proof :
In the worst case, suppose the two files have NO lines in common, and
that file A has N lines and file B has M lines. The algorithm will do
the following :
begin
scan lines 1 to N of A
scan lines 1 to M of B
scan lines 2 to N of A
scan lines 2 to M of B
scan lines 3 to N of A
scan lines 3 to M of B
.
.
.
scan line N of A
scan line M of B
end
So in total,
N + (N-1) + (N-2) + ... 1 = N^2 lines scanned from A
M + (M-1) + (M-2) + ....1 = M^2 lines scanned from B
which is N^2 + M^2
Finally, about perl : when I use the -w switch I get these warnings :
Use of uninitialized value at /home/ekoontz/bin/diff.pl line 63.
Use of uninitialized value at /home/ekoontz/bin/diff.pl line 77.
Not sure why, can someone help? Here are lines 63 and 77
63: if ($filearray1[$advance1] eq $filearray2[$position2]) {
77: if ($filearray1[$position1] eq $filearray2[$advance2]) {
Here's the file :
#!/usr/local/bin/perl
# $Id: diff.pl,v 1.8 1998/08/19 00:19:32 ekoontz Exp $
# This is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# please send correspondence to the author : ekoontz@lsi.sel.sony.com
#
$state = 'start';
$filename1 = $ARGV[0];
$filename2 = $ARGV[1];
if ($#ARGV != 1) {
print "usage : diff.pl from-file to-file\n";
exit;
}
open FILE, "$filename1" || die "couldn't open $filename1!";
@filearray1 = (); # initialize it.
while (<FILE>) {
chomp;
push @filearray1, $_;
}
close FILE;
open FILE, "$filename2" || die "couldn't open $filename2!";
@filearray2 = (); # initialize it.
while (<FILE>) {
chomp;
push @filearray2, $_;
}
close FILE;
$position1 = 0;
$position2 = 0;
$advance1 = 0;
$advance2 = 0;
while ($state ne 'stop') {
SWITCH: {
if ($state eq 'start') {
if (($position1 > $#filearray1) || ($position2 > $#filearray2))
{
$state = 'stop';
last SWITCH;
}
else {
$advance1 = $position1;
$advance2 = $position2;
if ($filearray1[$position1] eq $filearray2[$position2]) {
$position1++;
$position2++;
}
else {
$state = 'advance_file_1';
}
last SWITCH;
}
}
if ($state eq 'advance_file_1') {
$advance1++;
if ($filearray1[$advance1] eq $filearray2[$position2]) {
$advance2 = $position2;
$state = 'advance_file_2';
}
elsif ($advance1 > $#filearray1) {
$state = 'advance_file_2';
}
else {
$state = 'advance_file_1';
}
last SWITCH;
}
if ($state eq 'advance_file_2') {
$advance2++;
if ($filearray1[$position1] eq $filearray2[$advance2]) {
$state = 'compare_and_report';
}
elsif ($advance2 > $#filearray2) {
$state = 'compare_and_report';
}
else {
$state = 'advance_file_2';
}
last SWITCH;
}
if ($state eq 'compare_and_report') {
if (($advance1 > $#filearray1) && ($advance2 > $#filearray2))
{
printf("%dc%d\n", $position1+1,$position2+1);
print "< $filearray1[$position1]\n";
print "---\n";
print "> $filearray2[$position2]\n";
$position1++;
$position2++;
}
elsif (((($advance1-$position1) > ($advance2-$position2)) &&
($#filearray2 > $advance2))
|| ($advance1 > $#filearray1)) {
if ($position2+1 < $advance2) {
printf("%da%d,%d\n", $position1,$position2+1,$advance2);
}
else {
printf("%da%d\n", $position1,$position2+1);
}
for ($i = $position2; $i < $advance2; $i++) {
print "> $filearray2[$i]\n";
}
$position2 = $advance2;
}
elsif (((($advance2-$position2) > ($advance1-$position1) &&
($#filearray1 > $advance1)))
|| ($advance2 > $#filearray2)) {
if ($position1+1 < $advance1) {
printf("%d,%dd%d\n", $position1+1,$advance1,$position2);
}
else {
printf("%dd%d\n", $position1+1,$position2);
}
for ($i = $position1; $i < $advance1; $i++) {
print "< $filearray1[$i]\n";
}
$position1 = $advance1;
}
$state = 'start';
last SWITCH;
}
}
}
# We're at the end of at least one of the files. print out anything left
over from the other.
if ($position1 <= $#filearray1) {
printf("%sd%s\n", $position1+1,$position2);
for ($i = $position1; $i < $#filearray1+1; $i++) {
print "< $filearray1[$i]\n";
}
}
elsif ($position2 <= $#filearray2) {
printf("%sa%s\n", $position1,$position2+1);
for ($i = $position2; $i < $#filearray2+1; $i++) {
print "> $filearray2[$i]\n";
}
}
------------------------------
Date: 18 Aug 1998 09:19:09 +0930
From: Martin Gregory <mgregory@asc.sps.mot.com>
Subject: Trouble with perl invocation line (from Camel) [HPUX 10.20]
Message-Id: <r8k947np8q.fsf@asc.sps.mot.com>
[Sorry if this is a repost. I didn't see this article make it last time.]
In the Blue Camel, under the -S option, it suggests an invocation
method in place of a #! that should survive most vagaries of operating
systems. It looks like this:
eval '(exit $?0)' && eval 'exec /usr/binperl -S $0 ${1+"$@"}'
& eval 'exec /usr/bin/perl -S $0 $argv:q'
if 0;
We have been using a modified version, like this:
eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}' # -*- Perl -*-
& eval 'exec perl -w -S $0 $argv:q'
if 0;
This has -w and also uses the perl on the person's path, which is what
we want (allows easy control of what perl is used, and saves
recipients of scripts having to edit the path to perl).
Unfortunately, this does not work under HPUX's "brilliant" new
Posix-compliant shell on HPUX 10.20.
Under this shell, when a script containing this invocation method is
invoked via perl's system() call with metacharacters in the command
line (hence via an exec, I guess), the resulting sh ends up executing
the second line and complaining about the & character.
I know that this is not exactly a Perl problem, but since the recipe
came from a Perl book, and Perl people use it, I'm hoping that a Perl
person might be able to tell me what is going on! (And all the code
quoted is valid perl :-) )
I guess I have two questions:
1) Is what HPUX sh is doing fair, or can I complain to HP?
2) Why was this shell-determining-tickery ever needed anyhow?
I can't see what is wrong with
eval 'exec perl -w -S $0 ${1+"$@"}' # -*- Perl -*-
if 0;
Isn't it the case that a script is always executed by sh, so all
that csh trickery was not needed?
Any illumination much appreciated!
Martin.
------------------------------
Date: 19 Aug 1998 02:26:32 GMT
From: joyness@leland.Stanford.EDU (Joy Mei Chen)
Subject: wrapping text
Message-Id: <6rdd4o$qpf$1@nntp.Stanford.EDU>
I have a program that stores text as one long string, but UNIX chokes up
with strings longer than 255 characters. how do i chop the string up and
store it in the most efficient manner?
thanx!
------------------------------
Date: 18 Aug 1998 22:43:26 -0400
From: jzawodn@wcnet.org (Jeremy D. Zawodny)
Subject: Re: wrapping text
Message-Id: <m37m05bsj5.fsf@peach.z.org>
joyness@leland.Stanford.EDU (Joy Mei Chen) writes:
> I have a program that stores text as one long string, but UNIX chokes up
> with strings longer than 255 characters. how do i chop the string up and
> store it in the most efficient manner?
Text::Wrap, I'd guess. Have you read the FAQ? Have you looked on CPAN?
Jeremy
--
Jeremy D. Zawodny Web Geek, Perl Hacker, etc.
http://www.wcnet.org/~jzawodn/ jzawodn@wcnet.org
LOAD "LINUX",8,1
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 3479
**************************************