[8404] in Perl-Users-Digest
Perl-Users Digest, Issue: 2021 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 4 14:16:33 1998
Date: Wed, 4 Mar 98 11:00:29 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 4 Mar 1998 Volume: 8 Number: 2021
Today's topics:
Re: bizzare split problem danboo@negia.net
Re: Context Sensitive RexExp (Tom Grydeland)
Re: contexts: is there such a thing as array? <jdporter@min.net>
Re: contexts: is there such a thing as array? <cmargoli@world.northgrum.com>
Re: contexts: is there such a thing as array? <cmargoli@world.northgrum.com>
Re: Debugging Perl and extensions (Perl gurus please he <pcunnell+usenet@csfp.co.uk>
Directory Processing and File output <webmaster@jersey.net>
Re: Easy Unix Problem (4 U Guys) (Hunter Johnson)
Re: Example for use Win32::NetResource::AddConnection (David Risner)
Re: Example for use Win32::NetResource::AddConnection (Nick Tonkin)
external libraries <scott.ranzal@mci.com>
Re: external libraries (Nathan V. Patwardhan)
Re: Learn Perl on the WEB? - YES!!... well, sorta... <merlyn@stonehenge.com>
Re: Learn Perl on the WEB? - YES!!... well, sorta... <jdporter@min.net>
Re: line number indication in Perl (I R A Aggie)
Re: ORAPERL: How can I get an output paramater from an twod@not.valid
Re: QUIZ: answer and hash slice tutorial <cmargoli@world.northgrum.com>
quoted scalar surprises [Was: Anybody want a small puzz (Ken Fox)
redirecting from a directory to a script (J. S.)
Re: redirecting from a directory to a script <hsommer@micro.ti.com>
Searching in Perl <Jeremy.Ellman@mari.co.uk>
Re: Searching in Perl <jdporter@min.net>
Re: Searching in Perl <ajohnson@gpu.srv.ualberta.ca>
testing <cs2rb@scms.rgu.ac.uk>
Re: tr question (Joe McMahon)
Re: Using stdout of a script started by perl within per <jdporter@min.net>
Re: What am I doing wrong? <jdporter@min.net>
Re: What is PERL? Learn JAVA instead? <jdporter@min.net>
Re: What is PERL? Learn JAVA instead? (Nathan V. Patwardhan)
Re: What is PERL? Learn JAVA instead? <merlyn@stonehenge.com>
Re: What is PERL? Learn JAVA instead? <jdporter@min.net>
Re: What is PERL? Learn JAVA instead? (Abigail)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 04 Mar 1998 11:55:29 -0600
From: danboo@negia.net
To: Matthew.Wickline@usa.net
Subject: Re: bizzare split problem
Message-Id: <6dk4hf$htt$1@nnrp1.dejanews.com>
In article <6djokm$54n$1@nnrp1.dejanews.com>,
wickline@essrl.wustl.edu wrote:
>
[snip]
> $textarea_string =~ s/^\s+//sm;
> $textarea_string =~ s/\s+$//sm;
here is where your problems lie. i assume you are trying to remove any
space bound to the beginning and end of the *string*. you have put your
regexes in what jeffrey friedl terms "clean multi-line mode" (p.232). this
means that ^ and $ can also bind to logical lines, that is after and
before \n.
think of $textstring as "a\n\nb\n\nc\n\nd\n\ne\n\nf\n\n".
^^ ^^
1 2
so regex 1 says, pull out one or more \s immediately after the beginning of
the string or after a \n. since you have no leading \s option two is used.
regex two says, pull out one or more \s immediately before a \n or the end
of the string. in this case, that is the \n just after 'b'.
the cure is quite simple. just remove the 'sm' modifiers. then ^ and $ will
only bind to the beginning and end of the string.
and i think you can skip the part where you check for non empty sections.
i believe your 'split(/\n(?:\s*\n)+/, $textarea_string)' will take care of
this on its own; leaving you with a much more concise script. :)
cheers,
dan boorstein
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: 4 Mar 1998 17:55:06 GMT
From: Tom.Grydeland@phys.uit.no (Tom Grydeland)
Subject: Re: Context Sensitive RexExp
Message-Id: <slrn6fr5bq.479.Tom.Grydeland@mitra.phys.uit.no>
On Wed, 04 Mar 1998 12:37:11 +0000,
Alex Whittaker <Alex_Whittaker-1@sbphrd.com> wrote:
> I appreciate that we can write a very complex regexp which includes all
> of the possiblilities, which looks something like:
>
> /^(?:ABC.{8,16}|.{1}ABC.{7,15}|.{2}ABC.{6,14}|..etc..)ABC/
>
> But I really would like a general solution.
> Thoughts?
Interesting problem. You had two .* in the original post, right?
Did you try matching the same string with four different regexes:
/ .* .* /
/ .*? .* /
/ .* .*? /
/ .*? .*? /
and then checking each (if any) match for appropriate lenght?
If that doesn't help, perhaps you need to make your own state machine.
> -- Alex Whittaker --
--
//Tom Grydeland <Tom.Grydeland@phys.uit.no>
------------------------------
Date: Wed, 04 Mar 1998 12:28:17 -0500
From: John Porter <jdporter@min.net>
Subject: Re: contexts: is there such a thing as array?
Message-Id: <34FD8F31.7E11@min.net>
Uri Guttman wrote:
>
> $stuff = ( @stuff ) ;
>
> $stuff is 'three' not 3. the context is a list and not scalar and so the
> scalar gets the last element of the list.
As I said before, you are wrong. The context is scalar.
$stuff gets the count of @stuff.
> > "...assignment to a scalar variable evaluates the right-hand side in a
> > scalar context, while assignemtn to an array or a hash... evaluates
> > the right-hand side in a list context." (45)
>
> this is slightly unclear. they mean an array or hash VARIABLE. you can
> have an array or hash on the left hand side in a scalar context by
> indexing into it. the RHS or LHS is irrelevant. it is the context which
> can be created in many ways on either side of =.
It is not unclear at all. At least, not if you already understand it
:-)
The context of the rhs of an assignment is determined by the lhs,
plain and simple. The lhs might be a scalar expression:
$foo =
$bar[0] =
$baz{V} =
Or the lhs might be a list expression:
@bar =
@baz{qw(V W)} =
( $x, $y, $z ) =
%toot =
Another thing to keep in mind is that even assignments are evaluated
in context, and can be lvalues.
> ($one, $two) = ( /(\w+) (\w+)/g )[ 1, 2 ] ;
> @array = ( /(\w+) (\w+)/g )[ 1, 2 ] ;
> @array[1, 2] = /(\w+) (\w+)/g ;
>
> these all only assign 'It', 'is'
Yeah, if you set $[ = 1.
------------------------------
Date: Wed, 4 Mar 1998 17:01:47 GMT
From: Charles Margolin <cmargoli@world.northgrum.com>
Subject: Re: contexts: is there such a thing as array?
Message-Id: <34FD88FB.35AB@world.northgrum.com>
Uri Guttman wrote:
> $stuff = ( @stuff ) ;
>
> $stuff is 'three' not 3. the context is a list and not scalar and so the
> scalar gets the last element of the list.
Not quite.
my @stuff = qw(one two three);
my $stuff = ( @stuff );
print "$stuff"\n";
prints 3 (using perl 5.004_03 Maybe it's time to upgrade.).
Perl seems to be optimizing this case. I'm not sure whether that's a
bug or a feature.
--
Charles G. Margolin DSSD Internal Information Services
cmargoli@world.northgrum.com Northrop Grumman Corp. 0624/23
margolin@acm.org Hawthorne, California 90250-3277
------------------------------
Date: Wed, 4 Mar 1998 18:31:11 GMT
From: Charles Margolin <cmargoli@world.northgrum.com>
Subject: Re: contexts: is there such a thing as array?
Message-Id: <34FD9DEF.94F@world.northgrum.com>
Charles Margolin wrote:
>
> Uri Guttman wrote:
>
> > $stuff = ( @stuff ) ;
> >
> > $stuff is 'three' not 3. the context is a list and not scalar and so the
> > scalar gets the last element of the list.
>
> Not quite.
>
> my @stuff = qw(one two three);
> my $stuff = ( @stuff );
> print "$stuff"\n";
>
> prints 3 (using perl 5.004_03 Maybe it's time to upgrade.).
>
> Perl seems to be optimizing this case. I'm not sure whether that's a
> bug or a feature.
>
Oops. It's a feature, according to perltrap. I wish, though, that
this could be made clear in perldata with some more complex examples.
--
Charles G. Margolin DSSD Internal Information Services
cmargoli@world.northgrum.com Northrop Grumman Corp. 0624/23
margolin@acm.org Hawthorne, California 90250-3277
------------------------------
Date: Wed, 04 Mar 1998 17:55:07 +0000
From: Paul Cunnell <pcunnell+usenet@csfp.co.uk>
To: Ilya Zakharevich <ilya@math.ohio-state.edu>
Subject: Re: Debugging Perl and extensions (Perl gurus please help)
Message-Id: <34FD957B.3697@csfp.co.uk>
Ilya Zakharevich wrote:
>
> [A complimentary Cc of this posting was sent to Paul Cunnell
> <pcunnell+usenet@csfp.co.uk>],
> who wrote in article <34FD1D3A.6F34@csfp.co.uk>:
>
> > Probably. It's hard to say without actually seeing some code. I
> > do know that you have to be very careful about what you make
> > mortal when constructing complex return structures.
>
> Stop spreading the FUD! There is nothing simpler: just use _noinc()
> variant of newRV_*, and make mortal whatever comes to stack - which
> means toplevel thing(s).
>
> Ilya
That may be so, but it sure puzzled the hell out of me. As far as I
could determine, I needed to mortalise the 'containers' in the
structure ( newHV() and newAV ), but not the items contained
within them.
And yes, I _did_ read perlxs.pod, perlxstut.pod, perlguts.pod
et. al.
Paul.
(Oh and sorry about the crappy linewrap on the last post.)
FYI, The structure I was creating looks something like this:
0 HASH(0x3239a0)
'calculators' => HASH(0x13ca78)
'Curve' => HASH(0x2bc480)
'R_Type' => 'DbSZeroCurve'
'bumped_spread' => 0
'currency' => 'DEM'
'mktlag' => 2
'npoints' => 43
'points' => ARRAY(0x316774)
0 HASH(0x316e78)
'P_Type' => 'MMCurvePoint'
'curve_name' => 'DEM_MM'
'df' => 0.999906258788239
'dt' => 884649600
'id' => 'DEM_LIBTN'
'manual_flag' => 1
'manual_rate' => 0.03375
'ratefield' => 'ASK'
'rt' => 0.03375
'stub' => 0
'zrt' => 0.034217146096346
1 HASH(0x2dc850)
'P_Type' => 'MMCurvePoint'
'curve_name' => 'DEM_MM'
'df' => 0.999329616382343
'dt' => 885168000
'id' => 'DEM_LIBSW'
'manual_flag' => 1
'manual_rate' => 0.0345
'ratefield' => 'ASK'
'rt' => 0.0345
'stub' => 0
'zrt' => 0.0349674393156247
...
--
Paul Cunnell CSFB RDG (pcunnell+usenet@csfp.co.uk) +44 171 888 2946
------------------------------
Date: Wed, 04 Mar 1998 13:03:05 -0500
From: Josh Cook <webmaster@jersey.net>
Subject: Directory Processing and File output
Message-Id: <34FD9759.7B01@jersey.net>
Hopefully someone can help me with this! I'm _very_ new to programming
with perl and have just developed a need for this script:
I need to parse through a directory and 'grab' only the .htm files.
With these files, I would like to make a webpage has hyperlinks to the
htm files from the directory, i.e.: If there is a file called me.htm, I
would like the script to produce a page that has a something like this:
<a href="me.htm">me</a>
Can someone please help me with this???
Thanks and if possible, please respond via email
Josh
------------------------------
Date: 4 Mar 1998 18:34:48 GMT
From: jhunterj@lexis-nexis.com (Hunter Johnson)
Subject: Re: Easy Unix Problem (4 U Guys)
Message-Id: <6dk6s8$ble@mailgate.lexis-nexis.com>
In article <6dhrvp$aab$1@brokaw.wa.com>, Elf Sternberg <elf@halcyon.com> wrote:
> To those reading this on comp.lang.perl, is there an easier way to
> split a line 'every nth character' without the cockamamie
> while/for/substr construction I've got [in the previous post]? I
> actually have wracked my brains on this before without coming up
> with a satisfactory answer.
perl -p -e 's/(.{8})/$1\n/g'
will do it for n=8. Change the 8 for other ns.
Hunter
--
J. Hunter Johnson | "A little consistent wholesome modeling and
jhunterj@lexis-nexis.com | costly servanthood are worth millions of
(937) 865-6800 x5385 | true words harshly spoken."
Lexis-Nexis, Dayton, OH | -- Ron Sider
------------------------------
Date: Wed, 04 Mar 1998 16:55:30 GMT
From: drisner@geocities.com (David Risner)
Subject: Re: Example for use Win32::NetResource::AddConnection
Message-Id: <34fe872d.6009796@wingate>
On Wed, 4 Mar 1998 16:49:30 +0100, "Burkhard Kiesel"
<burkhard.kiesel@med.siemens.de> wrote:
>is there anyone who has experience with the Win32::NetResource module.
>May be it is possible that I can get some examples how to use this.
>I just want to connect to a shared drive on a other host.
I have always found it easiest just to do the following type of
command:
system("net use j: \\\\server\\sharename");
Unless you are doing a bunch of connections and are so speed critical
that you can't afford to spawn a separate process, this should work
just fine.
--
David Risner -- Programmer (Java, CGI, NeXT)
Electronic Desktop Project, California State University, Los Angeles
Main E-Mail: drisner@geocities.com Backup E-Mail: drisner@yahoo.com
http://www.geocities.com/~drisner/ Voice Mail/Fax (714)242-1315
------------------------------
Date: Wed, 04 Mar 1998 18:27:13 GMT
From: nick@NOSPAMTHANKSciof.sbcc.net (Nick Tonkin)
Subject: Re: Example for use Win32::NetResource::AddConnection
Message-Id: <34fd9cc3.348947299@news.silcom.com>
Not to mention that no one I have ever talked to has been able to get
NetResource::AddConnection to work . . . If you do, let me know! I
hate using the system call for that.
Nick
On Wed, 04 Mar 1998 16:55:30 GMT, drisner@geocities.com (David Risner)
wrote:
>On Wed, 4 Mar 1998 16:49:30 +0100, "Burkhard Kiesel"
><burkhard.kiesel@med.siemens.de> wrote:
>
>>is there anyone who has experience with the Win32::NetResource module.
>>May be it is possible that I can get some examples how to use this.
>>I just want to connect to a shared drive on a other host.
>
>I have always found it easiest just to do the following type of
>command:
>
>system("net use j: \\\\server\\sharename");
>
>Unless you are doing a bunch of connections and are so speed critical
>that you can't afford to spawn a separate process, this should work
>just fine.
>
>--
>David Risner -- Programmer (Java, CGI, NeXT)
>Electronic Desktop Project, California State University, Los Angeles
>Main E-Mail: drisner@geocities.com Backup E-Mail: drisner@yahoo.com
>http://www.geocities.com/~drisner/ Voice Mail/Fax (714)242-1315
------------------------------
Date: Wed, 04 Mar 1998 16:57:52 GMT
From: scott ranzal <scott.ranzal@mci.com>
Subject: external libraries
Message-Id: <34FD874D.4487@mci.com>
i am trying to get information about using external libraries with perl.
in particular i have a CISAM file library that i would like to use. i
have looked at the manpages and am still confused
thanks
------------------------------
Date: 4 Mar 1998 17:28:20 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: external libraries
Message-Id: <6dk2vk$5g1@fridge.shore.net>
scott ranzal (scott.ranzal@mci.com) wrote:
: i am trying to get information about using external libraries with perl.
You mean libraries written in C/C++ ?
: in particular i have a CISAM file library that i would like to use. i
: have looked at the manpages and am still confused
What manpages did you peruse? I believe that perlxstut and perlxs
will be helpful.
--
Nathan V. Patwardhan
------------------------------
Date: 04 Mar 1998 10:26:01 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: dwaring@nwsr.com (David Waring)
Subject: Re: Learn Perl on the WEB? - YES!!... well, sorta...
Message-Id: <8czpj65pw6.fsf@gadget.cscaper.com>
>>>>> "David" == David Waring <dwaring@nwsr.com> writes:
David> I wish I could find a collection of Perl 5 scripts that were so
David> well documented that I could use them as learning tools.
And you're ruling out http://www.stonehenge.com/merlyn/WebTechniques/,
because ... ?
David> Not to say that they are not out there but I have not found
David> them. In general the web does not provide much Perl learning
David> support.
Ahh. This is the problem. You just haven't found the useful stuff
yet. :) Sorry, the secret meeting where we handed out the URLs was
last friday. :)
Hint: "www.yahoo.com" and friends. "www.infoseek.com" and friends.
"www.dejanews.com" and friends.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 180 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Wed, 04 Mar 1998 12:35:14 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Learn Perl on the WEB? - YES!!... well, sorta...
Message-Id: <34FD90D2.5081@min.net>
Randal Schwartz wrote:
>
> Hint: "www.yahoo.com" and friends. "www.infoseek.com" and friends.
> "www.dejanews.com" and friends.
You're implying that yahoo, infoseek, and dejanews are not friends;
they each have their own clique.
John Porter
------------------------------
Date: Wed, 04 Mar 1998 13:36:12 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: line number indication in Perl
Message-Id: <fl_aggie-0403981336120001@aggie.coaps.fsu.edu>
In article <6djpdv$83n@news-central.tiac.net>, mike@stok.co.uk (Mike Stok)
wrote:
+ You can use literate programming to produce a script with embedded pod
+ documentation, they aren't mutually exclusive. For some pointers to the
+ differences between literate programming, verbose commenting and man pages
+ you can look at http://shelob.ce.ttu.edu/daves/faq.html
Looks interesting. Sorry, I'm just an old fortran programmer...documentation?
what's that?? :\
James
--
Consulting Minister for Consultants, DNRC
The Bill of Rights is paid in Responsibilities - Jean McGuire
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/CPAN-local/doc/FAQs/cgi/idiots-guide.html>
------------------------------
Date: 4 Mar 1998 17:20:42 GMT
From: twod@not.valid
Subject: Re: ORAPERL: How can I get an output paramater from an Oracle Stored Procedure
Message-Id: <6dk2ha$6mr$4@vnetnews.value.net>
Master Disk (pax@adv.magwien.gv.at) wrote:
: It's no problem to call Stored Procedures and to put an IN parameter.
: But how can i get an OUT parameter ?
If you ain't using the DBI and DBD modules, you should be IMHO. Which leads
us nicely into : RTFM as this is question 5.4 in the DBI FAQ - http://www.
hermetica.com/ technologia/perl/DBI/index.html will get you the FAQ plus other
documents.
IAP
--
I am using anti-spam measures, please replace 'not.valid' with 'value.net'
------------------------------
Date: Wed, 4 Mar 1998 17:31:44 GMT
From: Charles Margolin <cmargoli@world.northgrum.com>
Subject: Re: QUIZ: answer and hash slice tutorial
Message-Id: <34FD9000.734@world.northgrum.com>
Uri Guttman wrote:
> @array{ @array } = ( [ @array ] ) x @array ;
Is there a reason to copy the original array into an anonymous array?
Why not use a reference to @array?
@array{ @array } = ( \@array ) x @array ;
--
Charles G. Margolin DSSD Internal Information Services
cmargoli@world.northgrum.com Northrop Grumman Corp. 0624/23
margolin@acm.org Hawthorne, California 90250-3277
------------------------------
Date: 4 Mar 1998 18:15:50 GMT
From: kfox@pt0204.pto.ford.com (Ken Fox)
Subject: quoted scalar surprises [Was: Anybody want a small puzzle?]
Message-Id: <6dk5om$bvr5@eccws1.dearborn.ford.com>
Uri Guttman <uri@sysarch.com> writes:
> SPC@popstar.com writes:
> > if ($deleted != "$file"){
>
> is $file numeric or text? if text, the comparison should be 'ne'
> also you don't need to quote standalone scalars
Whenever I see code like this I suspect that the programmer learned
shell scripting first. ;) You're right the vast majority of the time.
However, an unquoted scalar is not equivalent to a quoted scalar. The
difference is usually not important, but I've recently run into a common
situation where it bites the unsuspecting. Don't start quoting all your
scalars just because you read this though!
I had a bit of code in a CGI script (using CGI.pm) like this:
foreach my $p ($cgi->param) {
my $v = $cgi->param($p);
if ($v ne "") { # BUGGY
...
}
}
The line marked with the comment is buggy because $v can be a file handle
object representing a file upload field. If it is, then Perl dies with
the error:
Operation `ne': no method found,
left argument in overloaded package Fh,
right argument has no overloaded magic at ...
Changing from $v to "$v" eliminates the bug. There are other (better)
fixes of course, but this demonstrates the difference.
- Ken
P.S. Perl is starting to get pretty complicated. I think I'll have
to go back to using C++. ;)
--
Ken Fox (kfox@ford.com) | My opinions or statements do
| not represent those of, nor are
Ford Motor Company, Powertrain | endorsed by, Ford Motor Company.
Analytical Powertrain Methods Department |
Software Development Section | "Is this some sort of trick
| question or what?" -- Calvin
------------------------------
Date: Wed, 04 Mar 1998 17:22:34 GMT
From: jsaya@iname.com (J. S.)
Subject: redirecting from a directory to a script
Message-Id: <6dk2u5$a0u@bgtnsc02.worldnet.att.net>
I would like to have a script in my cgi-bin directory that will
forward people to another web site, but I want them to be able enter
one of several URL's to be forwarded.
An example would be:
http://www.server.com/forward/theirname
But, I only want to create the 'forward' directory and have the
theirname portion read by a script to forward to another web site.
I could use:
http://www.server.com/forward?theirname
but I'd rather use the first one.
Is this possible?
Please email jsaya@iname.com
Thank you
------------------------------
Date: Wed, 04 Mar 1998 12:05:25 -0600
From: Holly Sommer <hsommer@micro.ti.com>
Subject: Re: redirecting from a directory to a script
Message-Id: <34FD97E5.79C74E8E@micro.ti.com>
J. S. wrote:
: I would like to have a script in my cgi-bin directory that will
: forward people to another web site, but I want them to be able enter
: one of several URL's to be forwarded.
...
: Is this possible?
Yes. Do it with server preferences and 403 (or 402?) response headers.
Need further clarification? Ask at a CGI or web-based newsgroup, not
one about perl programming.
Followups set.
-Holly
------------------------------
Date: Wed, 04 Mar 1998 17:12:50 +0000
From: "Jeremy.Ellman" <Jeremy.Ellman@mari.co.uk>
Subject: Searching in Perl
Message-Id: <34FD8B90.D697B9E7@mari.co.uk>
Hi,
I 'm re-implementing some data searching code that I've been using a
binary search to solve in C. I did consider just re-writing this as is,
but I wondered if there is some trick that I'm missing. Speed is
important.
The data is made up of numbers 1-1000. These are partitioned into
ordered variable sized sub sets. The problem is to decide if two numbers
are in the same group.
e.g
{{ 0, 1}, { 2, 3, 4, 5, 6}{7, 8, 9} etc
Thanks for any suggestions,
Jeremy
------------------------------
Date: Wed, 04 Mar 1998 12:37:40 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Searching in Perl
Message-Id: <34FD9164.4EC0@min.net>
Jeremy.Ellman wrote:
>
> Hi,
>
> I 'm re-implementing some data searching code that I've been using a
> binary search to solve in C. I did consider just re-writing this as is,
> but I wondered if there is some trick that I'm missing. Speed is
> important.
>
> The data is made up of numbers 1-1000. These are partitioned into
> ordered variable sized sub sets. The problem is to decide if two numbers
> are in the same group.
>
> e.g
> {{ 0, 1}, { 2, 3, 4, 5, 6}{7, 8, 9} etc
>
> Thanks for any suggestions,
>
> Jeremy
No, actually, that technique you're using now is the best one.
Honestly, how can we make an assessment of code you don't show?
John Porter
------------------------------
Date: Wed, 04 Mar 1998 11:56:48 -0600
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: Searching in Perl
Message-Id: <34FD95E0.4E53ECE@gpu.srv.ualberta.ca>
Jeremy.Ellman wrote:
!
! Hi,
!
! I 'm re-implementing some data searching code that I've been
! using a binary search to solve in C. I did consider just
! re-writing this as is, but I wondered if there is some trick that
! I'm missing. Speed is important.
!
! The data is made up of numbers 1-1000. These are partitioned into
! ordered variable sized sub sets. The problem is to decide if two
! numbers are in the same group.
!
! e.g
! {{ 0, 1}, { 2, 3, 4, 5, 6}{7, 8, 9} etc
one way would be to create a hash with the numbers as keys
and their set membership as values...then just test if two
keys have the same value in the hash:
#!/usr/bin/perl -w
$i=1;
while(<DATA>) {
foreach (split) { #populate our hash
$hash{$_}=$i;
}
$i++;
}
# now lets test some random number pairs
@some_nums=(0..16);
for (1..10) { #try it a few times
# get a couple random elements of @some_nums
$num_1=$some_nums[rand @some_nums];
$num_2=$some_nums[rand @some_nums];
# simple test
if ($hash{$num_1} == $hash{$num_2}) {
print "$num_1 and $num_2 both in set $hash{$num_1}\n";
} else {
print "$num_1 and $num_2 in different sets\n";
}
}
__DATA__
0 1
2 3 4 5 6
7 8 9
10 11
12 13 14 15 16
------------------------------
Date: Tue, 03 Mar 1998 21:14:38 +0000
From: Bremner R <cs2rb@scms.rgu.ac.uk>
Subject: testing
Message-Id: <34FC72BE.3486CB69@scms.rgu.ac.uk>
I'm testing. Sorry.
------------------------------
Date: Wed, 04 Mar 1998 13:38:04 -0500
From: joe.mcmahon@gsfc.nasa.gov (Joe McMahon)
Subject: Re: tr question
Message-Id: <joe.mcmahon-0403981338040001@prtims.stx.com>
In article <34FC6D94.630B@wmccmsvr.ssr.hp.com>, Wayne Patton
<wbpatto@wmccmsvr.ssr.hp.com> wrote:
>#!/usr/local/bin/perl
>#
>$_="0000301";
>print "before -> $_\n";
>tr/^0//d;
>print "after -> $_\n";
>
>
>This should strip the leading zeros right?
>
And any carets you happen to have as well. Remember that the left-hand
side is a set of characters, not a pattern in tr///.
You could also just add zero to it.
--- Joe M.
------------------------------
Date: Wed, 04 Mar 1998 12:32:46 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Using stdout of a script started by perl within perl ...
Message-Id: <34FD903E.19C0@min.net>
Jirtme Gonze wrote:
>
> I'm starting with perl and I would like to retrieve within perl,
> the stdout of another script started with the system command.
Read the documentation on the system function:
perldoc -f system
Or did your sysadmin heinously delete the doc files
from your perl installation?
hth,
John Porter
P.S.
You really ought to trim down that excessive signature file.
------------------------------
Date: Wed, 04 Mar 1998 12:06:04 -0500
From: John Porter <jdporter@min.net>
Subject: Re: What am I doing wrong?
Message-Id: <34FD89FC.6F3F@min.net>
Geert Roovers wrote:
>
> Hi... in my opinion, the next script should fetch a number form a file,
> increase it, and overwrite the file with this new number. Perl does not
> agrre with me though...
>
> open(LOGFILE, "+>count.log") || die "Horribly";
> $a = <LOGFILE>;
> print(++$a);
> print LOGFILE ($a);
> close(LOGFILE)
>
> (I also tried open(LOGFILE, "+<count.log"); and open(LOGFILE,
> "+>>count.log);)
>
> ~Geert
Man, you're taking your chances, asking a FAQ in this newsgroup!
perlfaq5: I just want to increment the number in the
file. How can I do this?
hth,
John Porter
------------------------------
Date: Wed, 04 Mar 1998 12:09:57 -0500
From: John Porter <jdporter@min.net>
Subject: Re: What is PERL? Learn JAVA instead?
Message-Id: <34FD8AE5.11DD@min.net>
Frank wrote:
>
> There's stuff you can do in PERL that would be difficult, or
> impossible, to do with JAVA. And vice versa.
(I bet you knew this was coming:)
Name two things that you can do in Java, which would be
impossible, or even difficult (by general agreement), to
do in Perl.
These languages are not really distinguished by what they
are capable of doing.
John Porter
------------------------------
Date: 4 Mar 1998 17:05:43 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: What is PERL? Learn JAVA instead?
Message-Id: <6dk1l7$5g1@fridge.shore.net>
John Porter (jdporter@min.net) wrote:
: Perl and Java are essentially the same language. When you've learned
: one, you know them both.
No way. This presumes that Perl relies only on OOP and a million
other things that I'm sure other folks will disagree with you about
like string processing, regexps, etc. It's hardly the case that
knowing one dictates knowing both. With an affection for C and
knowledge of shell programming, sed, and awk I was able to delve into
Perl fairly smoothly. I can't say the same for Java.
How many times have you seen Perl programmers try to do the same
things they would've done with arrays in Perl in Java and failed? Or
vice versa.
: As I say, they are basically the same; but Pure Java has as slight
: advantage in most areas (compilation speed, executable size, ease
: of use, platform-independence, etc.)
You're kidding, right? Java is really slow, or at least slower than I
would've hoped. Executable size isn't an issue, imho. What
executable(s) where you talking about? Platform-independence isn't
really an issue, either. Java isn't platform-independent as soon as
someone proves a situation where Java doesn't work everywhere ... and
I know that these cases exist.
: Both of these languages are really only suitable for web site
: development. If you need to do heavy duty data processing,
: you should probably look at C++ or SQL.
You're full of crap. Perl *only* suitable for web development?
Holy tchrist! I bet that I could find hundreds of system
administrators, hackers and others who would disagree with you.
Are you sure that you're really John Porter who generally makes
sensible postings?
--
Nathan V. Patwardhan
------------------------------
Date: 04 Mar 1998 10:19:18 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: brieweb@aol.com (Brieweb)
Subject: Re: What is PERL? Learn JAVA instead?
Message-Id: <8c7m6a74rt.fsf@gadget.cscaper.com>
>>>>> "Brieweb" == Brieweb <brieweb@aol.com> writes:
Brieweb> I heard Randal Schwartz say he could write an entire httpd server in 90 lines
Brieweb> of PERL.
No, that's an http *proxy* server. A simple web server is much shorter.
>From "perldoc HTTP::Daemon"...
use HTTP::Daemon;
use HTTP::Status;
$d = new HTTP::Daemon;
print "Please contact me at: <URL:", $d->url, ">\n";
while ($c = $d->accept) {
$r = $c->get_request;
if ($r) {
if ($r->method eq 'GET' and $r->url->path eq "/xyzzy") {
# this is *not* recommened practice
$c->send_file_response("/etc/passwd");
} else {
$c->send_error(RC_FORBIDDEN)
}
}
$c = undef; # close connection
}
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 180 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Wed, 04 Mar 1998 12:41:04 -0500
From: John Porter <jdporter@min.net>
Subject: Re: What is PERL? Learn JAVA instead?
Message-Id: <34FD9230.6CAD@min.net>
Nathan V. Patwardhan wrote:
>
> You're kidding, right?
Right.
> Are you sure that you're really John Porter who generally makes
> sensible postings?
Man, I thought it would be a little more obvious.
Didn't you see my facial expressions as I was typing it?
Sorry. I just we should have some fun with that FAQ,
"How are Perl and Java different?"
[deep obeisance]
John Porter
------------------------------
Date: 4 Mar 1998 18:16:11 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: What is PERL? Learn JAVA instead?
Message-Id: <6dk5pb$6m5$1@client3.news.psi.net>
scott@softbase.com (scott@softbase.com) wrote on 1646 September 1993 in
<URL: news:6djnif$rno$6@scully.new-era.net>:
++ Abigail (abigail@fnx.com) wrote:
++
++ > Perl and Python are probably more suitable for cross platform programs
++ > than Java.
++
++ The biggest plus Perl has going for it is the *source* is transportable
++ across platforms. Therefore, if a program doesn't run, you have the
++ source and can make it run. Java is the opposite: you have bytecodes
++ and are basically SOL unless you have the source too and can recompile
++ it. Perl's strength is the just-in-time compile.
++
++ (I guess that's why I have always wondered what the point behind the
++ Perl -> Java-runtime compiler is. It seems to give up the best features
++ of Perl.)
I can see one advantage, the same advantage as I see for the "compiler",
it allows you to deliver a program written in Perl to someone who
doesn't have Perl installed, but does have a Java VM.
It's not something everyone needs, but I wouldn't be surprised if that
would be beneficial for a large group of people.
Abigail
--
perl -wleprint -eqq-@{[ -eqw\\- -eJust -eanother -ePerl -eHacker -e\\-]}-
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.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 2021
**************************************