[10977] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4577 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 7 21:07:14 1999

Date: Thu, 7 Jan 99 18:00:18 -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           Thu, 7 Jan 1999     Volume: 8 Number: 4577

Today's topics:
    Re: "internal server error" (Clay Irving)
        ANNOUNCE: DbFramework-1.05 <paul@miraclefish.com>
        C's sizeof(long) != Perl's length pack "l"; khlim@altavista.net
    Re: Case Modification (Clay Irving)
    Re: Does anyone know how to add blind carbon copies (Bc (Stephen Clouse)
    Re: Help with hashes. (Martien Verbruggen)
    Re: line continuation; the switch statement <andrew@geac.co.nz>
    Re: Need to replace <DEL>'s in data file (Martien Verbruggen)
    Re: Not Quite FAQ: perl for Win32 w/out console (Jeffrey Drumm)
    Re: Perl Criticism <jeromeo@atrieva.com>
    Re: Perl Criticism <mds-resource@mediaone.net>
    Re: Perl Criticism <metcher@spider.herston.uq.edu.au>
    Re: Perl Criticism <mds-resource@mediaone.net>
    Re: Perl Criticism <mds-resource@mediaone.net>
        Perl uses in NT <mctaylor@primenet.com>
    Re: ping script in perl ....where can I get one? <support@hotpost.dk>
    Re: Q on search & replace in larger strings (Tad McClellan)
    Re: socket programming: picking a port automatically <estabroo@ispn.com>
    Re: Sorting question (Tad McClellan)
    Re: Why _cannot_ dmake libwin32 ??? <mds-resource@mediaone.net>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 7 Jan 1999 20:31:49 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: "internal server error"
Message-Id: <773n65$smi@panix.com>

In <36950532.AF3E1068@email.com> Eirik Johansen <webpages@email.com> writes:

>I've just started learning Perl and I recently modified a CGI-skripy,
>but now it won't work and I don't know why. Would someone be as kind as
>to rund it un their Unix shell (I don't have Unix) and tell me which
>line makes the error.

Uh, why can't you run it on your machine?

Double uh, if I run it in a UNIX shell where am I going to get
$ENV{'CONTENT_LENGTH'} from?


>Eirik Johansen

>#!/usr/bin/perl

># This script will take information from a form
># and place it in a mail to the desired recipent

>print "Content-type:text/html\n\n";

Hmm. This doesn't look right. 

-- 
Clay Irving
clay@panix.com


------------------------------

Date: Fri, 08 Jan 1999 01:00:22 +0000
From: Paul Sharpe <paul@miraclefish.com>
Subject: ANNOUNCE: DbFramework-1.05
Message-Id: <369558A6.CB871FE4@miraclefish.com>

Recently submitted to PAUSE

  file: $CPAN/authors/id/P/PS/PSHARPE/DbFramework-1.05.tar.gz
  size: 24518 bytes
   md5: 8565a4b40fe51d3084382248b87e9590

DbFramework is a collection of classes for manipulating Mysql
databases.  The classes are loosely based on the CDIF Data Model
Subject Area.  There are methods for representing data model objects
as HTML and a class which can be subclassed to add persistency to Perl
objects.  See the POD for further details.

The module includes a CGI application which provides an HTML forms
interface for manipulating Mysql databases.

Prerequisites
=============

  Alias
  CGI
  DBI
  Msql-Mysql-modules
  ePerl (for dbforms.cgi)

6-1-1999                    Paul Sharpe          <paul@miraclefish.com>
-----------------------------------------------------------------------
RELEASE 1.05

= INTERFACE
  Table
    - New method dbh($dbh) (added pod for AUTOLOAD() method)
    = Improved form and template support
      - new() now takes list of form rather than template definitions 
        and evals configuration from config.pl files.
      - New method read_form()
      - More pod  
  - Default output templates now handle foreign keys by replacing them
    with columns from the related table.
  - <DbValue> template tag can now contain a list of attributes to be
    substituted for values.
  dbforms.cgi
    - fills values from related table for foreign keys in default
      output template.
    - Now handles user-defined forms.


------------------------------

Date: Fri, 08 Jan 1999 01:00:54 GMT
From: khlim@altavista.net
Subject: C's sizeof(long) != Perl's length pack "l";
Message-Id: <773lc5$ro8$1@nnrp1.dejanews.com>

Hello guru,

How to use Perl to correctly read/interpret a binary file that written by a C
program  ( on the same machine ) if  Perl  print length pack "l";  # result
in 4 but C  printf("%d", sizeof(long));  # result in 6


Thanks!!

regards,
KH Lim

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


------------------------------

Date: 7 Jan 1999 20:27:03 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: Case Modification
Message-Id: <773mt7$se3@panix.com>

In <3694FD5F.8A789676@xsite.net> Andy Biegel <andy@xsite.net> writes:

>Pardon me if this is too obvious...

Its in the standard documentation that comes with Perl. Its too obvious...

>How can I go about taking a string (for example):

>"THIS IS A TEST"

>and modifying it so that only the first letter of each word is
>capitalized? Any help would be appreciated.

perldoc perlfunc

     ucfirst EXPR

     ucfirst Returns the value of EXPR with the first character
             uppercased.  This is the internal function
             implementing the \u escape in double-quoted strings.
             Respects current LC_CTYPE locale if use locale in
             force.  See the perllocale manpage.

             If EXPR is omitted, uses $_.

-- 
Clay Irving
clay@panix.com


------------------------------

Date: Fri, 08 Jan 1999 01:09:43 GMT
From: see.sig@for.address (Stephen Clouse)
Subject: Re: Does anyone know how to add blind carbon copies (Bcc's) to Sendmail?
Message-Id: <36965a7c.26007821@news.kc.net>

On Thu, 7 Jan 1999 19:24:44 -0500 in message
<<773iv0$llt$1@camel29.mindspring.com> comp.lang.perl.misc>, "John"
<news@coupon1.com> wrote:

>For some reason, our Sendmail ignores the "Bcc:account@domain" line.

This is not a Perl question.

Try comp.mail.sendmail.

-- 
Stephen Clouse -- steve at acme-labs dot com (Anti-Spam enabled)
Acme Labs -- Resident Megalomaniac (http://www.acme-labs.com)


------------------------------

Date: Fri, 08 Jan 1999 01:36:24 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Help with hashes.
Message-Id: <sidl2.121$FY1.4966@nsw.nnrp.telstra.net>

In article <773gnl$1h1$1@news1.bu.edu>,
	lcoates@bu.edu (Laran Coates) writes:

> In other words, if $key{$val} = 2, how can I increment the value of $key{$val}
> to 3.

$key{$val}++;	# or as a prefix op
$key{$val} += 1;
$key{$val} = $key{$val} + 1;

And others.

BTW. Your choices of names are a bit unfortunate. What you call %key,
is in fact a hash table. What you call $val is in fact the key into
this hash table. 2 (or 3 after the increment) is the value of that
element.

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | 
Commercial Dynamics Pty. Ltd.       | What's another word for Thesaurus?
NSW, Australia                      | 


------------------------------

Date: Fri, 8 Jan 1999 13:51:36 +1300
From: "Andrew Mayo" <andrew@geac.co.nz>
Subject: Re: line continuation; the switch statement
Message-Id: <773lb8$nrs$1@news.akl.netlink.net.nz>


Tom Christiansen wrote in message <772gq0$u1$1@csnews.cs.colorado.edu>...
> [courtesy cc of this posting sent to cited author via email]
>
>In comp.lang.perl.misc,
>    "Andrew Mayo" <andrew@geac.co.nz> writes:
>:BUT.... if there were more than one of these in my program, the second one
>:would have to have a different label at the top, not SWITCH. (AFAIK).
>
>This is false.  You can reuse labels.
>

[set gently ironic mode = on]


Oh, can you - interesting... well, I was also told you can omit them, which
is even better. The thing is, page 104 of Programming Perl presents some
switch statements and being a newbie I took the line of reasoning that went
"gee, these guys are, like, experts; they wouldn't use a label if it wasn't
necessary, would they?". (after all, the authors are Larry Wall, Tom
Christiansen and Randal L Schwartz and who am I to argue with *them*)?
bashful <g>

so, wouldn't *this* be better as a canonical case?

    {
    if (conditional expression1)
            {
            ....do case 1 stuff;
            next;
            }

    if (cond expr 2)
            {
            .....do case 2 stuff;
            next;
            }

    }

which does seem to work Ok, and allows me to do C-ish things like drop into
the next case if I want. Or is there some subtle Perl-ish trap I'm going to
fall into here? (its just that I am rather fond of switch statements, coming
from other programming languages)

As for label scope, I submit that Programming Perl is not terribly
forthcoming on this topic - at least, checking the page numbers in the index
for 'Label'.

I've been using this as my bible on the basis that the back cover modestly
states 'If you buy only one book about Perl, no one .... will question your
judgement'.

Since I did buy only one book, would it be fair to say that it *plus* the
man pages constitute the definitive programmer's reference, clarifying all
issues of semantics and syntax in the same way that reading the ANSI C
standard from cover to cover does?. Or is there some other information I
should have access to?. I say this, bearing in mind that I don't expect
either of those sources to teach me good Perl style, or contain all the Perl
source ever written, or show me all the silly traps I can fall into. But,
for example, when I come across this...

$var = {  };

as I did in a piece of sample Perl code I just lifted off this group,right
now I'm not exactly sure what that assignment is doing. This is where formal
BNF grammars etc do tend to help... is there such a thing for Perl?





------------------------------

Date: Fri, 08 Jan 1999 01:44:54 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Need to replace <DEL>'s in data file
Message-Id: <qqdl2.122$FY1.4966@nsw.nnrp.telstra.net>

In article <36954919.D1A605@lanl.gov>,
	Jeannie Sandoval <jisand@lanl.gov> writes:
> I need to replace <DEL> with spaces  in a text file.

Do you need to replace the literal string <DEL>, or do you mean that
you have character sequences which correspond to whatever comes out
when you press your delete key?

The former:

# perl -le '$_ = "Some string with <DEL> in it"; s/<DEL>/ /g; print'
Some string with   in it

This works fine.

If youre looking to replace whatever the del key outputs (sometime
^H, sometime ^?, sometime something else), you'll have to find out
from your environment what that is (On unices, stty may be helpful, or
the POSIX module).

When you have found out, you can just use a regexp like:

s/^?/ /g;

(Where ^? is the literal character), or you can use the escaped hex
value of it, which you can probably find in some ascii table.

For speed, if it's a single character, tr/^?/ / will probably be
better.

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | The gene pool could use a little
Commercial Dynamics Pty. Ltd.       | chlorine.
NSW, Australia                      | 


------------------------------

Date: Fri, 08 Jan 1999 01:41:38 GMT
From: drummj@mail.mmc.org (Jeffrey Drumm)
Subject: Re: Not Quite FAQ: perl for Win32 w/out console
Message-Id: <36955930.256003447@news.mmc.org>

[posted and mailed]

On Thu, 07 Jan 1999 13:15:16 -0500, Tripp Lilley <tripp.lilley@perspex.com>
wrote:

>I realize that the "how do I get the console to go away when I'm running
>a Perl/Tk script?" is a FAQ. And I realize that the answer is in the
>Cookbook. No problem.
>
>The Not Quite FAQ is this: has anyone built a /non/ console-mode perl
>for Win32? I realize it's probably a nasty undertaking. Nevertheless,
>anyone undertaken it? I tried dejanews on what I considered relevant
>keywords.

(snip)

If you're talking about NT, have you looked at the parameters for the START
command? I'm not at my NT system at the moment, but I believe you can run a
console app in a hidden window. At the very least you can run it minimized
with the /MIN flag:

START /path/to/script /MIN

If you're talking about 95/98, /M (minimized) is pretty much it.

-- 
                           Jeffrey R. Drumm, Systems Integration Specialist
                                  Maine Medical Center Information Services
                                     420 Cumberland Ave, Portland, ME 04101
                                                        drummj@mail.mmc.org
"Broken? Hell no! Uniquely implemented." -me


------------------------------

Date: Thu, 07 Jan 1999 16:34:47 -0800
From: Jerome O'Neil <jeromeo@atrieva.com>
To: topmind@technologist.com
Subject: Re: Perl Criticism
Message-Id: <369552A7.F369A70@atrieva.com>

topmind@technologist.com wrote:
> 
> Reply to Jerome O'Neil's 1/6 message:
> 
> >> I have four different shells open on my desktop right now, along with
> several X-processes and other GUI like things.  Which one represents the
> "one" command line?  <<
> 
> I did NOT say Unix has *only* command lines. 

You didn't?  What is this all about then:

===QUOTE===
Much of Perl, for example, resembles UNIX scripting languages because
that is what the author was familiar with. UNIX systems have utilities
that allow extensive commands to be issued on the command line. Since
there is only one command line, UNIX programmers 
                               
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
have a tradition of trying to fit as much on one line as possible. 
===UNQUOTE===

So, *again*, which one of my four separate shells running right now is
the "one command line?"  The fact that you don't even understand the
relationship between the "command line" and the kernel speaks volumes
about your qualifications on this topic.

> You just defeated your self-built straw man. What motivaed you to turn light-
> grey and dark-grey into black-and-white? Common != Only

1. The fact that you said "...there is only one command line"

2. On a world accessible web page.

3. And then tried to deny it.  

If there is any straw man here, it is your whole argument.
 
> >> Your attempts at differentiating "scripting" languages, as opposed to "real"
> languages is false.  There is no such dichotomy. <<
> 
> See my reply to Heath Halcomb's similar false statement.

I read it.  Expounding your error over and over does not change the fact
that you are still wrong.  Example #2, for instance.  I have written
mission critical military applications in sh.

> >> I consider any language that does not return a value from an assignment
> broken.  If it's the rvalue, that's a Good Thing. <<
> 
> What is your criteria for stating that? Because you are just plain used to it?
> Nicotine? I worded the pros and cons if it. Where's your's?

Pro: They are convenient and easily understood.  That's a Good Thing.
Con:  They are misunderstood by people with an obvious axe to grind and
a penchant for ignoring the documentation.

Lets go back to your "pro's and con's"

===QUOTE===
A summary of Perl's bigger problem areas are:

- Unnecessary deviations from the "function rule".

- Parameter and variable scope handling

- "Leaky" assignment statements

- Inter- and intra- statement communication problems (including
excessive use
of "command piping")

===UNQUOTE===

Quite clearly, you declare them "problems" (*BIGGER* problems, no less),
and that's it.  So you declare them a con, and expound them as so in
your web page.  You even offer a "prewhile()" construct as an
alternative.  No pro's, though.  Quite clearly, you don't even read your
own material, which lends even more credence to my wager.

> I'll bet another beer that your biggest misunderstanding stems from having not
> RTFM enough.
> 
> I think you have had too many beers and too much Perl. Go to AA and get a Perl
> Arm Patch. You are too used to bad language constructs that you think they are
> good. Addiction city!

If a predilection for well documented, clearly understood and readable
constructs makes me an addict, I'll just stay an addict.  Of course, I
sure wish I could clutter up my code with things like "option selectors"
and other nonsense.  What you propose is a cute version of VisualBasic. 
Been there, done that, it sucks.

-- 
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947 
The Atrieva Service: Safe and Easy Online Backup  http://www.atrieva.com


------------------------------

Date: Thu, 07 Jan 1999 19:12:23 -0600
From: "Michael D. Schleif" <mds-resource@mediaone.net>
Subject: Re: Perl Criticism
Message-Id: <36955B77.9BB564FF@mediaone.net>

Isn't set theory fun?

C is a subset of programming languages.
C++ is a subset of programming languages.
Pascal is a subset of programming languages.
Java is a subset of programming languages.
Perl is a subset of programming languages.

OK, I may not be the brightest linguist, but, what's your point?

topmind@technologist.com wrote:
> 
> Scripting languages are a subset of programming languages. C, C++,
> Pascal, and Java are NOT scripting languages, for example.

-- 

Best Regards,

mds
mds resource
888.250.3987

"Dare to fix things before they break . . . "

"Our capacity for understanding is inversely proportional to how much we
think we know.  The more I know, the more I know I don't know . . . "


------------------------------

Date: Fri, 08 Jan 1999 11:33:00 +1000
From: Jaime Metcher <metcher@spider.herston.uq.edu.au>
Subject: Re: Perl Criticism
Message-Id: <3695604C.A8B87F01@spider.herston.uq.edu.au>

topmind@technologist.com wrote:
> 
> Reply to Heath Holcomb's 1/7 message:
> 
> >> [Unnecessary deviations from the "function rule".]
> This seems like an effort to codify something that is more a matter of taste
> than anything else. <<
> 
> I gave 3 criteria why the function rule is important. (Simpler language,
> easier to document, easier to learn). If you disagree, I challenge you to
> give higher- ranking criteria or reasons. Criticism is easy, supplying
> alternatives is the hard part.
> 

Perl has as a basic philosophy the notion that consistency is
over-rated.  Larry Wall (quoted from memory) - "Perl almost always does
what you want, unless what you want is consistency".  This has often
been discussed, as has the way in which perl has been inspired by
natural language.

The way you talk about the function rule is a perfect example of
somebody rating consistency over intuitiveness.  There are languages
designed this way, and people who like them.  There are, however, other
kinds of people and, fortunately, other kinds of programming languages.

Consider:

spoken: "A equals B plus C"
perl: $a = $b + $c;
function rule: assign (a, add(b, c));

I understand you don't advocate the application of the function rule to
this level.  This is where you agree with Larry - only apply the
function rule where it makes sense (I think making sense qualifies as
"necessary", don't you?).  However, what makes sense to you doesn't
necessarily make sense to anyone else.  Perl makes sense to me - the guy
at the next desk thinks it's gibberish.  C'est la vie.

Another case:

spoken: "A is the square root of B"
perl: $a = sqrt $b;
alt perl: $a = sqrt ($b);
function rule: assign (a, sqrt(b))
less fanatic version: a = sqrt(b)

You get to choose what you want to be consistent with.  A
self-consistent programming language is no doubt a beautiful thing, but
it's the semantic equivalent of an infinite loop or a self-reflexive
argument.  Perl tends to be consistent with the way some (many)
programmers think.  Scary as that might be, it's much more useful.

-- 
Jaime Metcher


------------------------------

Date: Thu, 07 Jan 1999 19:31:18 -0600
From: "Michael D. Schleif" <mds-resource@mediaone.net>
Subject: Re: Perl Criticism
Message-Id: <36955FE6.13D7C20A@mediaone.net>

OK, but, what alternatives has the Enterprise?  BSOD?  Isn't it amazing,
with *so many* stupid, pointy-haired people running loose, that stock
markets continue to set new records?  Clearly, among the stupidest
people are those amassing fortunes in capital gains from companies
doomed to fail }:-^

Actually, if you ever have to eke out a living by providing your
employer with JIT code to solve Production IT challenges in a remarkably
platform-heterogeneous Enterprise, I bet that you will, sooner or later,
look for a language that promotes quick development, quick testing and
solid metrics -- in other words, some language that will optimize your
time-to-Production cycle.  In my case, I have found nothing better than
Perl.  My handlers consider me to be a magician and pay me handsomely to
perform.

Actually, when you stop, for a moment, to consider languages that most
need rethinking, English, and this from a 4th generation American, most
remarkably stands as a testament to how-to _and_ how-not-to build a
language.  Seriously, my challenge to you, as eloquent as you have been,
friend, if you were building a new language from the ground up, would
you duplicate English?

Truly, truly, truly, irony is the philosopher's last vestige of sanity .
 . .

topmind@technologist.com wrote:
> 
> What if it turns out that the ratio of stupidity to cleverness is 2:1? If that
> is the case, then Unix will drag down a company. (It may not be 2, but IMO
> stupidy gt cleverness.)
> 
< snip > 
>
> My observation is that there are too many stupid programmers that use certain
> features out pure BOREDOM and technical CHALLANGE, not to make programs more
> maintanable or elegant. Some language constructs are more likely to be abused
> than used to make better software IMO.
> 
> What is an example of something you consider powerful in Perl that cannot be
> done in a "safer" way without significant power loss?  (That is a direct
> challenge, by the way. Any takers?)

-- 

Best Regards,

mds
mds resource
888.250.3987

"Dare to fix things before they break . . . "

"Our capacity for understanding is inversely proportional to how much we
think we know.  The more I know, the more I know I don't know . . . "


------------------------------

Date: Thu, 07 Jan 1999 19:51:05 -0600
From: "Michael D. Schleif" <mds-resource@mediaone.net>
Subject: Re: Perl Criticism
Message-Id: <36956489.5AEEC32F@mediaone.net>

Is it interesting to note that, simply because you ``can still make a
dichotomy'' *does not* testify to its existence?  Does a tree falling in
the forest make noise without somebody to hear it?

topmind@technologist.com wrote:
> 
> Perhaps there is no sharp dividing line, but one can still make a dichotomy.
> Your statement is like saying, "There are no such thing as short people
> because there is no clear dividing line."

Hammers *are not* optimized for chopping down trees.
Submarines *are not* optimized for interstellar transportation.
Homo sapiens *is not* optimized for immortality.

I give up -- what's your point?

> Scripting languages are not *optimized* for:
> 
> 1. Fast applications like 3D graphics.
> 
> 2. Critical military and medical applications.
> 
> 3. Building a big commercial OS and/or interpreter.
> 
> 4. Building mass-distribution applications like wordprocessing.

This is my absolute favorite unreasonable assertion }:-^

The blind cannot see, therefore seeing is not possible.
My neighbor's newborn infant cannot drive my car, therefore my car
cannot be driven.
I do not know how to fly, therefore it is not possible for anybody to
travel to the stars.

> 1. Very tough to mix arrays and scalars unless you have only one array at the
> end of the list.
> 
> 2. "Getting used to" means it is tougher to learn, with little benefits in
> return.
> 
> 3. There is no simple mechanism for passing by-value.

Cool.  Please, *do not* use them.

> It's all a matter of taste, but at least I am attempting to evaluate different
> "tastes". Leaky assignments create several rough spots in a language. Their
> risks outweigh the benefits IMO.

And, the difference between programming, in this context, and, let's
say:
  Governmental deficit budgeting;
  Nazi insurrection of European Jews; or
  Global warming :)

> Optional = stupid programmers will overuse it and stick SOMEBODY ELSE with the
> mess! Hit and run programming.

Again, I'm enjoying this thread -- at least until I grow bored.  Ho-hum
 . . .

-- 

Best Regards,

mds
mds resource
888.250.3987

"Dare to fix things before they break . . . "

"Our capacity for understanding is inversely proportional to how much we
think we know.  The more I know, the more I know I don't know . . . "


------------------------------

Date: Thu, 7 Jan 1999 17:13:24 -0800
From: "Mike" <mctaylor@primenet.com>
Subject: Perl uses in NT
Message-Id: <773m45$dt0$1@nnrp03.primenet.com>

Hi, I'm new to the Perl world. My boss, a unix administrator, suggested I
learn some Perl and apply it to my NT administration. Could anyone show me
where I could find some good examples or situations where I could use Perl
in NT?

Please email miket@bcbg.com or mctaylor@primenet.com

Thank you,

Mike Taylor





------------------------------

Date: Fri, 8 Jan 1999 01:55:47 +0100
From: "Hotpost support - Mads Sxgaard" <support@hotpost.dk>
Subject: Re: ping script in perl ....where can I get one?
Message-Id: <773l25$3qee$1@news-inn.inet.tele.dk>


Thanks for your help - I found one now.




------------------------------

Date: Thu, 7 Jan 1999 18:42:30 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Q on search & replace in larger strings
Message-Id: <m9k377.jki.ln@magna.metronet.com>

walter (tavi367@ibm.net) wrote:
: Say I have a scalar '$fileContents', in which I slurped an entire text file
: into.

: Say I have a Hash '%spec_Chars', of 100 keys and mated values.

: Now, I need to run through this scalar to see if any of these keys are in
: this scalar and if so replace it with the value of that key.

: Do I do this?

:    foreach (keys %spec_Chars)
:    {
:       $fileContents =~ s/$spec_Chars{$_}/$_/i;
:    }

: Or am I missing something Perl-esque that would make this better?


   In addition to Uri's suggestions, you might also look at
   the Perl FAQ, part 6:

      "How do I efficiently match many regular expressions at once?"



   I sometimes just take the easy road (runs slow, codes up fast) and:

      $re = join '|', reverse sort keys %spec_Chars;

      $fileContents =~ s/($re)/$spec_Chars{$1}/go;


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: Thu, 07 Jan 1999 19:12:56 -0600
From: Eric Estabrooks <estabroo@ispn.com>
To: Daniel Reeves <dreeves@flip.eecs.umich.edu>
Subject: Re: socket programming: picking a port automatically
Message-Id: <36955B97.B3D1E633@ispn.com>

Daniel Reeves wrote:

> Is there a way for a server program written in perl to automatically pick
> a free port and print it?  (ie, "this server is listening on port x...")
>
> Thanks,
> Daniel


$sock = IO::Socket::INET->new(Listen => 1,
                                LocalAddr => 'localhost',
                                Reuse => 1,
                                Proto => 'tcp');

$port = $sock->sockport();

print "this server is listening on port $port\n";


Hope this helps,


Eric
 estabroo@ispn.com




------------------------------

Date: Thu, 7 Jan 1999 19:02:34 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Sorting question
Message-Id: <afl377.n7j.ln@magna.metronet.com>

Ilya (no_spam_ilya@napavlly.rose.hp.com) wrote:


: If I have an array that I want to sort by 2 fields, I do:

:   @new_lines=sort by_components @new_lines;

:   sub by_components
:     {


      local $^W = 0;  # disable warnings, documented in perlvar.pod


:        (split(/\s+/,$a))[$key1] cmp (split(/\s+/,$b))[$key1]
:                             ||
:        (split(/\s+/,$a))[$key2] cmp (split(/\s+/,$b))[$key2];
:     }


: This will sort the array first by  $key1 field and then by $key2 field.  My
: problem is that  sometimes not all lines have $key2  field, i.e. lines that
: are not  long enough. Everything  sorts fine even  in that case, but  I get
: annoying messages of the type:

: Use of uninitialized value at ./convert_all.pl line 200.

: I need to put an if statement in the by_components sub, but nothing I tried
: worked. Any ideas?


#UNTESTED!

sub by_components
  {
     my ($a1, $a2) = (split(/\s+/,$a))[$key1, $key2];
     my ($b1, $b2) = (split(/\s+/,$b))[$key1, $key2];

     return $a1 cmp $b1 unless $a1 eq $b1;
     
     return 0 unless defined($a2) and defined($b2);

     return $a2 cmp $b2;
  }



--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: Thu, 07 Jan 1999 19:04:02 -0600
From: "Michael D. Schleif" <mds-resource@mediaone.net>
Subject: Re: Why _cannot_ dmake libwin32 ???
Message-Id: <36955982.5D5C6F09@mediaone.net>

Jaime, et al. ==>

Thank you, for this hint.  I will be trying it later tonight.

I am seriously puzzled by the *total lack* of response to this post, as
well as, mine about CPAN failing!

Some have responded via Email only, only to recommend that I use
ActiveState and PPM, rather than compiling my own Perl.

This, however, is unattractive to me.  I am in the position of building
`cross-platform' tools for several flavors of winDoze and several
flavors of *NIX in a Fortune 100 Enterprise.  I have gravitated to Perl
*because* of its platform-independence -- one (1) script, crafted
properly, can be run on *any* of my supported systems.  I am concerned
that, if I *do not* control Perl compilation, I may *lose* some
platform-independence.  Am I wrong???

Also, obviously, I am _not_ an accomplished C programmer, especially
from the perspective of compiling and debugging the act of compiling. 
The design intent behind such mechanisms as `Makefile.PL' (at least,
under *NIX) renders my inexperience trivial -- usually }:-^

Please, somebody comment . . .

Jaime Metcher wrote:
> 
> Here's an excerpt from a post of mine to the dbi-users mailing list:
> 
> 3. I had to add
>   $opts{DEFINE}  = "-DWin32_Winsock";
>    to the Win32 section of Makefile.PL.  The SOCKET typedef is needed in
> socket.h, which is included from
> U:\perl5\lib\MSWin32-x86\CORE/win32.h:290,
>                  from U:\perl5\lib\MSWin32-x86\CORE/config.h:2100,
>                  from U:\perl5\lib\MSWin32-x86\CORE/perl.h:137,
>                  from u:\perl5\site\lib\MSWin32-x86/auto/DBI/DBIXS.h:13,
>                  from ODBC.h:13,
>                  from ODBC.xs:1:
> It's defined in the Mingw32 include/Win32/Sockets.h (which is included
> from
> mysql.h,windows.h) only if Win32_Winsock is defined.  It actually is
> defined again (and too late) by perl5\lib\MSWin32-x86\CORE/win32.h:26.

-- 

Best Regards,

mds
mds resource
888.250.3987

"Dare to fix things before they break . . . "

"Our capacity for understanding is inversely proportional to how much we
think we know.  The more I know, the more I know I don't know . . . "


------------------------------

Date: 12 Dec 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 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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 4577
**************************************

home help back first fref pref prev next nref lref last post