[11768] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5368 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 13 04:07:33 1999

Date: Tue, 13 Apr 99 01:00:25 -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, 13 Apr 1999     Volume: 8 Number: 5368

Today's topics:
    Re: Can Perl implement a state machine? <uri@home.sysarch.com>
    Re: Can Perl implement a state machine? (Ronald J Kimball)
    Re: Count Linenumber <Philip.Newton@datenrevision.de>
    Re: Don't you have to work? (Ronald J Kimball)
    Re: Don't you have to work? (Ronald J Kimball)
    Re: Examples of slow regexes? (was: Re: Perl regexps co (Iain Chalmers)
        How to connect to WinNT Oracle database from Perl? agniora@usa.net
    Re: How to get yesterday date <Philip.Newton@datenrevision.de>
    Re: How to get yesterday date <Philip.Newton@datenrevision.de>
    Re: implement useradd in perl <uri@home.sysarch.com>
    Re: Newbie to programming; ajeet@my-dejanews.com
        Perl for Oracle 8? <sotoo@home.com>
    Re: Perl for Oracle 8? <eyounes@aol.com>
    Re: Perl regexps compared to Python regexps (Ilya Zakharevich)
    Re: pragma - relevant? <Philip.Newton@datenrevision.de>
    Re: Q:Bi-Directional Communication through sockets <hy3na@ispchannel.com>
        Refer to BBS installation pn Unix Server <H8905665@hanwha.co.kr>
        Seeking Exchange tools <tpg@cls.uob.com.sg>
        Stripping out all but the first word <rx@rxlist.com>
    Re: Stripping out all but the first word (Sam Holden)
    Re: Stripping out all but the first word <rx@rxlist.com>
    Re: Stripping out all but the first word <newman@dynamite.com.au>
    Re: Stripping out all but the first word (Sam Holden)
    Re: Stripping out all but the first word <rx@rxlist.com>
    Re: Stripping out all but the first word <rx@rxlist.com>
    Re: Stripping out all but the first word (Sam Holden)
    Re: Stripping out all but the first word <rx@rxlist.com>
    Re: stumped on regex - onto array (Ronald J Kimball)
    Re: The First Parameter in Bless??? (Ronald J Kimball)
        Trouble with exec() and system() in CGI ajeet@my-dejanews.com
        Weird behavior with connect() and IP numbers from @ARGV dfry@frymulti.com
        What is the end of file character for Mac <newman@dynamite.com.au>
        Where we can get perl code snippets? <okclub@communitech.net>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 13 Apr 1999 00:13:40 -0400
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: Can Perl implement a state machine?
Message-Id: <x7d819p37v.fsf@home.sysarch.com>

>>>>> "JD" == Jeffrey Davey <Jeffrey_Davey-P93404@email.mot.com> writes:

  JD> I was wondering if anyone knows how adept Perl is at implementing a
  JD> state machine.  The type we'd like to use is one that is table-driven,
  JD> in that functions called within a state are referenced from within an
  JD> array.  Haven't seen yet that Perl can do this.

perl is turing compatible. if you can describe it in computable terms it
can do it. big deal, all major languages can do that, so they all can
implement state machines.

HOW they support state machines or how you code them is the key. you can
use arrays and matrices with state values, giant case statements (which
of course perl does not have but who cares!), arrays of function refs,
massive if/then/else statements, arrays of labels which you goto thru
evals of strings stores in hashes, etc.

yes, perl can do state machines, but can you do them?

as someone else replied, arrays or hashes of sub refs is very easy to do
and very elegant in perl. if your state values are small integers,
arrays will be fine, or else use hashes which make for nice state
machines with any state value.

this will crash your perl when it runs out of stack.  store the state
code in a var and the main loop should do the dispatch if you want it to
work.

<bad pseudo perl code for a bistate machine>:

%states = (
		'state1' => \&state1,
		'state2' => \&state2,
) ;

sub state1 {

	print "hey, we are in state1!\n" ;

	&{$states{'state2'}} ;
}

sub state2 {

	print "hey, we are in state2!\n" ;

	&{$states{'state1'}} ;
}



uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Tue, 13 Apr 1999 00:24:33 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Can Perl implement a state machine?
Message-Id: <1dq64su.1ggb9dwi56524N@p116.tc2.state.ma.tiac.com>

Jeffrey Davey <Jeffrey_Davey-P93404@email.mot.com> wrote:

> I was wondering if anyone knows how adept Perl is at implementing a
> state machine.  The type we'd like to use is one that is table-driven,
> in that functions called within a state are referenced from within an
> array.  Haven't seen yet that Perl can do this.

i.e. an array of references to subroutines?  Sure, Perl can do that.

> Pointers to relevant information would be welcome.

Check out the perlreftut and perlref documentation.

-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Tue, 13 Apr 1999 09:22:28 +0200
From: Philip Newton <Philip.Newton@datenrevision.de>
Subject: Re: Count Linenumber
Message-Id: <3712F0B4.C3BF13E9@datenrevision.de>

Abigail wrote:
> 
> This is the shortest code I can think of:
> 
>        perl -wlpe '}{$_=$.' file

Clever. Took me a bit to figure out how it works.

Cheers,
Philip


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

Date: Tue, 13 Apr 1999 00:24:40 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Don't you have to work?
Message-Id: <1dq65jl.1kfofnttgvlbN@p116.tc2.state.ma.tiac.com>

Gabriel Richards <grichard@uci.edu> wrote:

> Some particularly helpful people in this newsgroup seem to get a word in on
> virtually every question posted. These people also presumably work and, I
> assume, are responding from work just as I am questioning from work. It must
> be incredibly time consuming, particularly when the gurus here actually take
> the time to test your code. I just want to know why? Is this part of your
> job specs? Are you just bored? Procrastinating? Altruistic? Or, like me, do
> you just find that at a computer job, especially among non-technical
> co-workers in "higher" education, it is easy to fart around doing what you
> want and appear to be busy and productive?

I only read the newsgroups from home.  I take an hour or so every
evening to read new posts in clpm, and generally reply to 10 or so.  I
listen to music, read email, and do other miscellaneous things at the
same time.

But if I could read them from work, I certainly would!

-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Tue, 13 Apr 1999 00:24:37 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Don't you have to work?
Message-Id: <1dq658z.vwbouq6agj5sN@p116.tc2.state.ma.tiac.com>

Larry Rosler <lr@hpl.hp.com> wrote:

> > Some particularly helpful people in this newsgroup seem to get a word in on
> > virtually every question posted.
> 
> As the most frequent poster in the most recent period (60 between 29 Mar
> and 05 Apr), perhaps I should respond.  DejaNews reports 58000 total 
> articles during that time, which seems way too high.  (Can anyone 
> explain that?  My guess is about 1000 messages on a weekday.)  But 
> whatever the real number is, 'virtually every question' seems like a 
> slight overstatement.

Actually, DejaNews _estimates_ 58000 articles during that time.
DejaNews only searches for as many articles as it is going to display;
it would be terribly inefficient if it had to find all 1600 messages
every time just to list 25 of them.  Unfortunately, this means its
estimates may be wildly inaccurate.

1000 is too high as well.  There are generally 200-250 messages posted
to this newsgroup each day.

-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Tue, 13 Apr 1999 14:48:01 +1000
From: bigiain@mightymedia.com.au (Iain Chalmers)
Subject: Re: Examples of slow regexes? (was: Re: Perl regexps compared to Python regexps)
Message-Id: <bigiain-1304991448010001@bigman.mighty.aust.com>

abigail wrote:


> ^^ I have, until now, never encountered a Perl regex that is "painfully
> ^^ slow", or not even "rather on the slow side". Can anybody please give an
> ^^ example of such a beast, point out the reason for it's slowness, and
> ^^ possibly even recipes on what to avoid?
> 
> 
> "aaaaaaaaaaaaaaaaaaaaaab"  =~  /a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a.c/;

*OUCH*! that hurts...

I'd read about this, but never really played around to see just how bad it
can get...

"aaaaaaaaaaaaaaaab"  =~  /a*a*a*a*a*a*a*a*a*a*a*a*a*a.c/;

took 115 seconds, up from 29 seconds with only 1 less a/a* in it

(I left the original one going for an hour before I gave up on it...)

Iain


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

Date: Tue, 13 Apr 1999 07:24:24 GMT
From: agniora@usa.net
Subject: How to connect to WinNT Oracle database from Perl?
Message-Id: <7eurf2$cbu$1@nnrp1.dejanews.com>

I looked at the DBD::Oracle module, but the documentation contains only the
how-to for Oracle on Linux, but with NT it would be different, and i dont know
much about Oracle DBA etc so i would need more specific details as to what
to look for, what file to change and what else to do to connect to Oracle.
could someone please help.
let me know also at the following email
smnayeem@agni.com

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


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

Date: Tue, 13 Apr 1999 09:27:17 +0200
From: Philip Newton <Philip.Newton@datenrevision.de>
Subject: Re: How to get yesterday date
Message-Id: <3712F1D5.44245121@datenrevision.de>

Philip Newton wrote:
> 
> Something = 60 * 60 * 24 = 86400, most likely.

Oops, I just saw Russ's post and realised I forgot to handle DST.
Ignoring DST may change the date as it makes some days 23 hours long and
some days 25 hours. So subtracting 86400 may, for some values of time(),
subtract either two days or no days instead of one.

Cheers,
Philip


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

Date: Tue, 13 Apr 1999 09:29:36 +0200
From: Philip Newton <Philip.Newton@datenrevision.de>
Subject: Re: How to get yesterday date
Message-Id: <3712F260.9DD29B3D@datenrevision.de>

Russ Allbery wrote:
> 
> # will subtract 0.  If $tdst is 1 and $ndst is 0, subtract an hour more
> # from yesterday's time since we gained an extra hour while going off
> # daylight savings time.  If $tdst is 0 and $ndst is 1, subtract a
> # negative hour (add an hour) to yesterday's time since we lost an hour.

Are there any weird places that add/subtract something other than one
hour in DST? Like 0.5 or 1.5 hours?

Cheers,
Philip


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

Date: 13 Apr 1999 00:02:00 -0400
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: implement useradd in perl
Message-Id: <x7g165p3rb.fsf@home.sysarch.com>

>>>>> "RD" == Rick Delaney <rick.delaney@home.com> writes:

  RD> You and Uri are obviously more experienced than I.  Don't all Unices
  RD> come with a useradd?

solaris does. sunos didn't (or still doesn't). i don't know about other
flavors. even if they do they wouldn't behave the same since they all
have little quirks regarding user info, e.g. yp or nis+, shadow, group
names, etc.

and even the systems's useradd doesn't do all the things a new user
might need on a site like adding them to mail alias lists, sudo
permissions, home dir automounting, and other site specific stuff. i
don't do any large sysadmin now but i would always have a customized
useradd program (which might call the system one for the core features).

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Tue, 13 Apr 1999 07:00:45 GMT
From: ajeet@my-dejanews.com
Subject: Re: Newbie to programming;
Message-Id: <7euq2q$ac2$1@nnrp1.dejanews.com>

Well...If you are new to perl programming..I am only slightly older!!
But I would like to suggest a very good site for learning:

http://www.codebits.com/p5be/

As for the passwd protection, I guess once you learn perl basics, you'll
realise how easy it is! Basically, it's all up to you. You can create a
simple text file which stores usernames and passwds and checks everytime.
This is a very flimsy protection..but it'll do for a start!

If you are the admin of a webserver(NT or 95/98 or Unix), you can easily
protect ur site by simply changing the security permissions of ur folder!

-Ajeet

> hi people, =)
>
>     I am not a very well established programmer and i hope to be coming to
> this
> newsgroup more often to learn more about ways to program etc. could someone
> point me to some sites that give very clear instructions on specific
> learning oriented programming? - well that is not what this post is for!
>
> I really want to know how to do this :
> How to make a simple script that pass-protects a website...only thing is,  I
> want to learn how it is all done not just simply given a script it is too
> easy to get one off the
> WWW- i need to know how to make a HTML form for that script as well-  any
> help offered would be very much apreciated !
>
> ps remember to explain a lot I am new to this after all -
>
>

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


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

Date: Tue, 13 Apr 1999 06:05:26 GMT
From: Omar Soto <sotoo@home.com>
Subject: Perl for Oracle 8?
Message-Id: <3712DE93.82EFD240@home.com>

This is a multi-part message in MIME format.
--------------F62848E7370F734FD58DAEBA
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hello all you Perl Hackers:

My hacking needs have led me to interface a Perl program to an oracle 8
Database.  What is the library that I need to use.  By the way, the
Oracle Database will be a Windows NT platform.

Thank You,

Omar Soto

--------------F62848E7370F734FD58DAEBA
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Omar Soto
Content-Disposition: attachment; filename="vcard.vcf"

begin:          vcard
fn:             Omar Soto
n:              Soto;Omar
org:            Home System
email;internet: sotoo@home.com
x-mozilla-cpt:  ;0
x-mozilla-html: FALSE
version:        2.1
end:            vcard


--------------F62848E7370F734FD58DAEBA--



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

Date: Tue, 13 Apr 1999 10:01:55 +0200
From: "Ysteric's" <eyounes@aol.com>
Subject: Re: Perl for Oracle 8?
Message-Id: <7eutas$lds@news.vtcom.fr>

hi,

I use perl & Oracle 8.
You need two modules :  DBI and DBD::Oracle

Eric from Paris (FRANCE)

Omar Soto a icrit dans le message <3712DE93.82EFD240@home.com>...
>Hello all you Perl Hackers:
>
>My hacking needs have led me to interface a Perl program to an oracle 8
>Database.  What is the library that I need to use.  By the way, the
>Oracle Database will be a Windows NT platform.
>
>Thank You,
>
>Omar Soto
>




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

Date: 13 Apr 1999 05:26:14 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Perl regexps compared to Python regexps
Message-Id: <7eukhm$j1q$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Lindsey
<ldubb@u.washington.edu>],
who wrote in article <ldubb-1204991839080001@c36852-a.sttln1.wa.home.com>:
> In article <slrn7h54l4.5k0.sholden@pgrad.cs.usyd.edu.au>,
> sholden@cs.usyd.edu.au wrote:
> 
> > I believe python regular expression are as powerful as older perl 
> > regular expressions. I think python uses perl style regular expressions now,
> > but not the cutting edge version. This means python misses out on the
> > newer features that no one knows about anyway? Look-behind is an example
> > I believe (I could be wrong on this).
> 
> Python's "re" is based on Philip Hazel's PCRE, and is extremely similar
> to Perl 5.005's regular expressions.  It's got lookbehind, once-only
> subpatterns, and conditional subpatterns, as well as the earlier stuff.
> I don't know how they compare in terms of performance, though I'd be
> interested in hearing anyone's experience.

Note that Python does not allow executable code in RExen, but Perl has
no named subpatterns.  And 5.005_5* has infinitely more powerful (but
not completely ironed out yet) 'embedded' patterns.

Moreover, Perl REx-repetitors are stack-based (at least the
"complicated" ones), which may lead to problems with a short stack.
Do not know about Python's ones.

Ilya


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

Date: Tue, 13 Apr 1999 09:16:30 +0200
From: Philip Newton <Philip.Newton@datenrevision.de>
Subject: Re: pragma - relevant?
Message-Id: <3712EF4E.C2DC2074@datenrevision.de>

Philip Newton wrote:
> 
> How about this, then? Is it relevant to clpm?

I found another nice on IRC EFnet channel #perl:

"So ... i program all my perl while sitting in a chair.  so obviously i
should ask all my perl questions on #furniture, right...."

Cheers,
Philip


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

Date: Tue, 13 Apr 1999 00:24:14 -0400
From: "Scott Stolpmann" <hy3na@ispchannel.com>
Subject: Re: Q:Bi-Directional Communication through sockets
Message-Id: <923977153.090.9@news.remarQ.com>

Hi Bret,

After the socket(SOCK,MSG,FLAG, TO)  statement  use  this:

while ( $line =<SOCK>) {
print  "$line";
}

that will display whatever the server script is outputing on your browser.

I hope that's what you want.



Scott



Bret wrote in message <7e1n73$8p5$1@mochi.lava.net>...
>Hi, I'm still learning perl, so any help is appreciated.
>Thanks in advance
>
>Q:  How can I get a client and server script to communicate bi-directionaly
>through sockets
>using
>    use Socket;?
>I can get the server to send to the client, but can't get the client to
send
>back to the server.
>
>Thanks for any help
>
>
>




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

Date: Tue, 13 Apr 1999 07:33:41 GMT
From: "Brian Dooly" <H8905665@hanwha.co.kr>
Subject: Refer to BBS installation pn Unix Server
Message-Id: <prCQ2.1514$UC6.2467@news.bora.net>

Hi All,

I'm managing the Unix Server for Homepage.
Now I want to construct BBS on this server.
I've a problem. I don't know the methode.

Please teach me the way or recommend the referenced site.

Thank you.
-----------^^)





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

Date: Tue, 13 Apr 1999 14:03:11 +0800
From: Terry Gliedt <tpg@cls.uob.com.sg>
Subject: Seeking Exchange tools
Message-Id: <3712DE1E.BD643B6@cls.uob.com.sg>

I'm trying to write some tools to allow me to send Email to an Exchange
server (SMTP protocol has been artifically blocked in this case) and I
hope someone has used Perl to solve this. Specifically I'm looking for:

 (1) Perl (or other) code to submit Email to an Exchange user. It cannot
use the SMTP protocol as Internet addresses (e.g. terry@mycompany.com)
are not allowed. It must use the Exchange address format.

(2) Perl (or other) code to allow one to programmatically get the
address of an Exchange user from the Exchange global address list.

Any leads would be greatly appreciated  TIA!

--
================================================================
Terry Gliedt     tpg@cls.uob.com.sg    http://www.hps.com/~tpg/
United Overseas Bank               Personal Email:  tpg@hps.com




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

Date: Mon, 12 Apr 1999 22:11:36 -0700
From: Neil Sandow <rx@rxlist.com>
Subject: Stripping out all but the first word
Message-Id: <3712D208.467E@rxlist.com>

I have a variable in a perl script, $xbrand, that can be one or more
words.  When there are more than one word I would like it to
be just the first word  (i.e. Penicillin VK  would become simply
Penicillin)

My last try was something like this:
$xbrand =~ /^(\w*?)(.*)$/;

I found this suggestion in an archive of this newsgroup but it
leads to the following error: 
/^(\w*?)(.*)$/: nested *?+ in regexp 

Can somebody help me with this?    Thanks!  -Neil


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

Date: 13 Apr 1999 05:16:34 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Stripping out all but the first word
Message-Id: <slrn7h5kpi.no9.sholden@pgrad.cs.usyd.edu.au>

On Mon, 12 Apr 1999 22:11:36 -0700, Neil Sandow <rx@rxlist.com> wrote:
>I have a variable in a perl script, $xbrand, that can be one or more
>words.  When there are more than one word I would like it to
>be just the first word  (i.e. Penicillin VK  would become simply
>Penicillin)
>
>My last try was something like this:
>$xbrand =~ /^(\w*?)(.*)$/;
>
>I found this suggestion in an archive of this newsgroup but it
>leads to the following error: 
>/^(\w*?)(.*)$/: nested *?+ in regexp 
>
>Can somebody help me with this?    Thanks!  -Neil

Sounds like you have a very old version of perl...

What about /(\w+)/ ?

-- 
Sam

Can you sum up plan 9 in layman's terms? It does everything Unix does
only less reliably.
	--Ken Thompson


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

Date: Mon, 12 Apr 1999 22:29:44 -0700
From: Neil Sandow <rx@rxlist.com>
To: sholden@cs.usyd.edu.au
Subject: Re: Stripping out all but the first word
Message-Id: <3712D648.C5F@rxlist.com>

Sam Holden wrote:
> 
> On Mon, 12 Apr 1999 22:11:36 -0700, Neil Sandow <rx@rxlist.com> wrote:
> >I have a variable in a perl script, $xbrand, that can be one or more
> >words.  When there are more than one word I would like it to
> >be just the first word  (i.e. Penicillin VK  would become simply
> >Penicillin)
> >
> >My last try was something like this:
> >$xbrand =~ /^(\w*?)(.*)$/;
> >
> >I found this suggestion in an archive of this newsgroup but it
> >leads to the following error:
> >/^(\w*?)(.*)$/: nested *?+ in regexp
> >
> >Can somebody help me with this?    Thanks!  -Neil
> 
> Sounds like you have a very old version of perl...
> 
> What about /(\w+)/ ?
> 
> --
> Sam
> 
> Can you sum up plan 9 in layman's terms? It does everything Unix does
> only less reliably.
>         --Ken Thompson

/(\w+)/  At least doesn't error out but it isn't stripping any words
beyong the first space either (Penicillin VK is still Penicillin VK)


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

Date: Tue, 13 Apr 1999 15:31:17 +1000
From: Chris Newman <newman@dynamite.com.au>
Subject: Re: Stripping out all but the first word
Message-Id: <3712D6A4.24C5B9B@dynamite.com.au>

Try $xbrand=~s/ \W.*/ /;



Neil Sandow wrote:

> I have a variable in a perl script, $xbrand, that can be one or more
> words.  When there are more than one word I would like it to
> be just the first word  (i.e. Penicillin VK  would become simply
> Penicillin)
>
> My last try was something like this:
> $xbrand =~ /^(\w*?)(.*)$/;
>
> I found this suggestion in an archive of this newsgroup but it
> leads to the following error:
> /^(\w*?)(.*)$/: nested *?+ in regexp
>
> Can somebody help me with this?    Thanks!  -Neil



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

Date: 13 Apr 1999 05:33:47 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Stripping out all but the first word
Message-Id: <slrn7h5lpr.onj.sholden@pgrad.cs.usyd.edu.au>

On Mon, 12 Apr 1999 22:29:44 -0700, Neil Sandow <rx@rxlist.com> wrote:
>Sam Holden wrote:
>> 
>> What about /(\w+)/ ?
>
>/(\w+)/  At least doesn't error out but it isn't stripping any words
>beyong the first space either (Penicillin VK is still Penicillin VK)

But $1 contains 'Penicillin'...


-- 
Sam

compiling kernels is what I do most, so they do tend to stick to the
cache ;)	--Linus Torvalds


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

Date: Mon, 12 Apr 1999 22:42:14 -0700
From: Neil Sandow <rx@rxlist.com>
Subject: Re: Stripping out all but the first word
Message-Id: <3712D935.78C0@rxlist.com>

Sam Holden wrote:
> 
> On Mon, 12 Apr 1999 22:29:44 -0700, Neil Sandow <rx@rxlist.com> wrote:
> >Sam Holden wrote:
> >>
> >> What about /(\w+)/ ?
> >
> >/(\w+)/  At least doesn't error out but it isn't stripping any words
> >beyong the first space either (Penicillin VK is still Penicillin VK)
> 
> But $1 contains 'Penicillin'...
> 
> --
> Sam
> 
> compiling kernels is what I do most, so they do tend to stick to the
> cache ;)        --Linus Torvalds

Ohhhh  I needed to add a 2nd line, $xbrand=$1
that seems to do the trick!  Thanks, Sam!


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

Date: Mon, 12 Apr 1999 22:47:56 -0700
From: Neil Sandow <rx@rxlist.com>
Subject: Re: Stripping out all but the first word
Message-Id: <3712DA8C.6A3F@rxlist.com>

Chris Newman wrote:
> 
> Try $xbrand=~s/ \W.*/ /;

Thanks, Chris.  That didn't work by itself either but Sam's 
previous one does when I add the 2nd line of $xbrand=$1

xbrand= $brand;
$xbrand =~ s/<[^>]*>//g ;    #strips html tags               
$xbrand =~ /(\w+)/;          #separates first word
$xbrand=$1;                  #variable = first word

Finally ready for prime time at www.rxlist.com/cgi/rxlist.cgi!

Thanks, again.


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

Date: 13 Apr 1999 06:16:59 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Stripping out all but the first word
Message-Id: <slrn7h5oar.q70.sholden@pgrad.cs.usyd.edu.au>

On Mon, 12 Apr 1999 22:47:56 -0700, Neil Sandow <rx@rxlist.com> wrote:
>Chris Newman wrote:
>> 
>> Try $xbrand=~s/ \W.*/ /;
>
>Thanks, Chris.  That didn't work by itself either but Sam's 
>previous one does when I add the 2nd line of $xbrand=$1
>
>xbrand= $brand;
>$xbrand =~ s/<[^>]*>//g ;    #strips html tags               
>$xbrand =~ /(\w+)/;          #separates first word
>$xbrand=$1;                  #variable = first word
>
>Finally ready for prime time at www.rxlist.com/cgi/rxlist.cgi!

Until you get something like : <img alt="-->" src="arrow.gif">.

If you are parsing HTML you should be using HTML::Parser.

But now I've been playing around and trying different ways of doing what
you originally asked :

Making the assumption that the first word starts at the start of the string,
ie. /^\w/ matches.

And if you really don't wantto keep a copy of the original string and just 
assign $1 straight back to it a substitution is probably better...
s/\W*(\w*).*/$1/

However, as I gave an example for trying to parse HTML like that just
doesn't work...

-- 
Sam

PC's are backwards ... throw them out! Linux is ok though.
	--Rob Pike (on the subject of CR/LF etc)


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

Date: Mon, 12 Apr 1999 23:40:49 -0700
From: Neil Sandow <rx@rxlist.com>
Subject: Re: Stripping out all but the first word
Message-Id: <3712E6F1.5FCB@rxlist.com>

Sam Holden wrote:
> 
> On Mon, 12 Apr 1999 22:47:56 -0700, Neil Sandow <rx@rxlist.com> wrote:
> >Chris Newman wrote:
> >>
> >> Try $xbrand=~s/ \W.*/ /;
> >
> >Thanks, Chris.  That didn't work by itself either but Sam's
> >previous one does when I add the 2nd line of $xbrand=$1
> >
> >xbrand= $brand;
> >$xbrand =~ s/<[^>]*>//g ;    #strips html tags
> >$xbrand =~ /(\w+)/;          #separates first word
> >$xbrand=$1;                  #variable = first word
> >
> >Finally ready for prime time at www.rxlist.com/cgi/rxlist.cgi!
> 
> Until you get something like : <img alt="-->" src="arrow.gif">.
> 
> If you are parsing HTML you should be using HTML::Parser.
> 
> But now I've been playing around and trying different ways of doing what
> you originally asked :
> 
> Making the assumption that the first word starts at the start of the string,
> ie. /^\w/ matches.
> 
> And if you really don't wantto keep a copy of the original string and just
> assign $1 straight back to it a substitution is probably better...
> s/\W*(\w*).*/$1/
> 
> However, as I gave an example for trying to parse HTML like that just
> doesn't work...
> 
> --
> Sam
> 
> PC's are backwards ... throw them out! Linux is ok though.
>         --Rob Pike (on the subject of CR/LF etc)

Thanks, I guess it's always better to do something with one command 
than with two.  As far as the html parsing, I'm sure you're right
but in the case of my application, there are no -->'s to worry about
so s/<[^>]*>//g works perfectly for me.  -Neil


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

Date: Tue, 13 Apr 1999 00:24:41 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: stumped on regex - onto array
Message-Id: <1dq68km.1bqwbq1tuf0jlN@p116.tc2.state.ma.tiac.com>

Eric Smythe <ericsm@iafrica.com> wrote:

> I need to parse the input into arrays - so 
> 
>  @array=($stringA, $priceA, $stringB, $priceB, \
> $stringC, $prineB ...$priceN)
> .. where $stringX is the stuff inbetween the two prices.
> 
> How would I set a routine to incorporate the regex above and do that?

You could do it with split().

Normally split() splits up the target string and tosses out the
delimiters matched by the regex.  However, if there are capturing
parentheses in the regex, the captured text will be included in the list
returned by split ().

@array = split( m[
                  (                     # main grab
                    \d{0,2}             # 0-2 digits
                    \.                  # required .
                    \d\d                # required 2 digits
                    (?:                 # group the second part
                      -                 # required - separator
                      \d{0,2}           # 0-2 digits
                      \.                # required .
                      \d\d              # required 2 digits
                    )?                  # optional second price
                  )                     # main grab
                  \b                    # boundary (not really needed)
                ]x,                     # extended            
               $text);

Observe that the regex has a single pair of capturing parentheses,
capturing everything matched by the regex (the \b is a zero-length
assertion, so capturing it is unnecessary).

HTH!

-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Tue, 13 Apr 1999 00:24:42 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: The First Parameter in Bless???
Message-Id: <1dq69ne.3x5w5ylpdbp1N@p116.tc2.state.ma.tiac.com>

Sys Adm 89806 Manager of programing development and Intranet Resources
<ruben@llinderman.dental.nyu.edu> wrote:

>  With static class methods, it seems that he's changing his mind on this
>  and is adding a scalar $pkg to the parameter list.  Why would it be needed
>  for a static Method and not an instance?

The syntax $object->method(), when executed, magically includes $object
as a parameter to method().  Although $object doesn't appear within the
parentheses of the method call, it nonetheless becomes the first element
of @_.

Hence code like:

sub method {
  my $self = shift;
  # ...
}

HTH!

-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Tue, 13 Apr 1999 07:25:23 GMT
From: ajeet@my-dejanews.com
Subject: Trouble with exec() and system() in CGI
Message-Id: <7eurgu$ce6$1@nnrp1.dejanews.com>

Hi all!

I have a CGI script where, I need to delete a temp file created by another
script. But, whenever I run the script file on the server using:
exec("del $filename"); or system("del $filename"); or unlink(<$filename>);
It doesnt work as long as it is inside the "Content type" header of CGI

But, when I run it from the command line, it performs the system function.
Why is that so??? Any idea anybody?

Thanx
-Ajeet

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


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

Date: Tue, 13 Apr 1999 07:06:24 GMT
From: dfry@frymulti.com
Subject: Weird behavior with connect() and IP numbers from @ARGV
Message-Id: <7euqdd$anc$1@nnrp1.dejanews.com>



I have a script (call it "getdata") that is called called via back-ticks from
another script:

	$data = `/usr/local/bin/getdata $ip`;

where $ip is an IP number.

getdata does this:

-------------------
use Socket;

$site = shift;
$port = 23;
$iaddr = inet_aton($site);
$paddr = sockaddr_in($port,$iaddr);
$proto = getprotobyname('tcp');
$res = socket(SOCK,PF_INET,SOCK_STREAM,$proto);
connect(SOCK,$paddr) ;
-------------------

Okay, here's the problem: the connect() call fails each time. If I hard code
the given IP address in the script it works, though. That is, replace	  
$site = shift; with	$site = "198.11.57.5"; and we're okay.

But I can't find any way in which the IP address coming in via @ARGV is
different than a hard coded string. For instance, if I do this:

	$site = shift;
	$site2 = "198.11.57.5";

	if ( $site eq $site2 ) { print "Yep, they're the same!\n"; }

I find that the two strings -- the one from the command line and the hard
coded one -- are identical but connect() still fails.

If I print out all the intermediate values ( e.g. $iaddr, $paddr, $proto,
$res), I find they're all identical regardless of whether $site comes in via
the command line or is hard coded. The only distinguishing behavior is the
failure of connect().

I've changed the name of my variable $site and I've declared it in a various
ways. I've tried hacks like

	$site = "$site";
	$site = join(".",split(/\./,$site));
	$site = sprintf("%s",$site);

and none of them make any difference. As a practical matter, my relevant IP
numbers are drawn from a small set so I hard coded the IPs in the script to
make it actually work for me for now:

	$site = shift;
	if ( $site =~ /23/ ) { $site = "10.1.23.10"; }
	elsif ( $site =~ /24/ ) { $site = "10.1.24.10"; }
	elsif ( $site =~ /25/ ) { $site = "10.1.25.10"; }

and that works. But it's obviously a horrible hack and doesn't solve the core
problem.

Any suggestions would be much appreciated.

David Fry
dfry@frymulti.com





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


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

Date: Tue, 13 Apr 1999 15:05:47 +1000
From: Chris Newman <newman@dynamite.com.au>
Subject: What is the end of file character for Mac
Message-Id: <3712D0AA.621802BF@dynamite.com.au>

I am progressing through the 'Learning Perl' book on my Apple. For the
shorter exercises it is quickest to type data via the screen. I am now
looking for a end of file character(s) to active the Perl script to
accept the input. I understand that for Unix this is Ctrl D and often
Ctrl Z elsewhere except Macintosh. Can someone please help



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

Date: Tue, 13 Apr 1999 16:17:53 +0900
From: =?euc-kr?B?udrBvrq5IChQYXJrLCBKb25nLVBvcmsp?= <okclub@communitech.net>
Subject: Where we can get perl code snippets?
Message-Id: <7eur74$ijo$1@news2.kornet.net>

Where is perl code snippets??

Do you 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 5368
**************************************

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