[6723] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 349 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 22 23:07:20 1997

Date: Tue, 22 Apr 97 20:01:34 -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, 22 Apr 1997     Volume: 8 Number: 349

Today's topics:
     Regular Expression Help Newbie <deepak@pcsltd.com>
     Re: Regular Expression Help Newbie (Clay Irving)
     Re: Regular expression with Hex code <rootbeer@teleport.com>
     sigaction drops signals? <mtw@eng.sun.com>
     Re: Stupid Question (Chipmunk)
     Re: They both suck! (was: Borland or Microsoft compiler <mcampbel@tvmaster.turner.com>
     Re: Variable interpolation (substitution) (Tad McClellan)
     Re: Warning: Michael Kagalenko post has imbedded JavaSc (Craig Berry)
     Re: Who will win?  Borland or Microsoft or Programmers? (John Zollinger)
     Re: Why is perl math so slow? <tchrist@mox.perl.com>
     Re: writing to text file from Perl ... <critter@quack.kfu.com>
     Re: XSUB: hash -> C struct ? <minaret@sprynet.com>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Tue, 22 Apr 1997 21:27:21 -0400
From: Deepak Thadani <deepak@pcsltd.com>
Subject: Regular Expression Help Newbie
Message-Id: <335D6579.7DDA@pcsltd.com>


Hello,
	I have a perl script in which
$_ = "881     /usr/spool/mmdf/lock/home"

What I want to do is get the number (in this case 881) into a variable
called $VALUE.  This is what I've got, which only seems to return
the 1.

$VALUE = /[0-9]*\S\//;

What I believe the above is doing is getting all the numbers until
I get to a white space or / right?  Apparently wrong since $VALUE
after running that line, is simply 1.

Please help...and explain how I can figure out reg exp's better if 
possible.  Thanks a lot.

Deepak	<deepak@pcsltd.com>


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

Date: 22 Apr 1997 22:31:19 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: Regular Expression Help Newbie
Message-Id: <5jjs9n$dsh@panix.com>

In <335D6579.7DDA@pcsltd.com> Deepak Thadani <deepak@pcsltd.com> writes:

>Hello,
>	I have a perl script in which
>$_ = "881     /usr/spool/mmdf/lock/home"

>What I want to do is get the number (in this case 881) into a variable
>called $VALUE.  This is what I've got, which only seems to return
>the 1.

>$VALUE = /[0-9]*\S\//;

>What I believe the above is doing is getting all the numbers until
>I get to a white space or / right?  Apparently wrong since $VALUE
>after running that line, is simply 1.

>Please help...and explain how I can figure out reg exp's better if 
>possible.  Thanks a lot.

You really want to *split* the fields:

$_ = "881     /usr/spool/mmdf/lock/home";
($value,$whatever) = split /\s+/;
print "$value\n";

-- 
Clay Irving                                        See the happy moron,
clay@panix.com                                     He doesn't give a damn,
http://www.panix.com/~clay                         I wish I were a moron,
                                                   My God! Perhaps I am!


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

Date: Tue, 22 Apr 1997 17:30:07 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Cheng Tyh Lin <a00lcj00@elc012.nchc.gov.tw>
Subject: Re: Regular expression with Hex code
Message-Id: <Pine.GSO.3.96.970422172559.14200F-100000@kelly.teleport.com>

On 22 Apr 1997, Cheng Tyh Lin wrote:

>   There are two strings as below. I am try to open a file, search for
> whether the file content the following $a string(in hex, E0 stands for \xE0).
> If it exists, substitute $a with $b.
> 
>     $a = "E0003D00E1002B00E7002A00E300";
>     $b = "a=b+c*d";
> 
> (1) Which is the most convenient way to implement this job?

I'd see about turning $a into a regular expression pattern, by putting in
\x before each hex pair. Then, it's pretty straightforward to do a
substitution, if the entire file will fit in memory at once. 

If it won't all fit in memory, read blocks of, say, 4096 characters at a
time. Save the last N-1 characters of each block to prepend to the next
block, so that you can match patterns which span blocks. N is the maximum
number of characters your pattern can match. 

If your substitution might make a block longer, you won't be able to edit
the file in place. But making a modified copy is probably better anyway.

> (2) Do I need to open this file in binmode?(This file is an executable
>     file produced by C++ language)

I'd have to say yes. Hope this helps!

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Tue, 22 Apr 1997 18:47:34 -0700
From: Mike Werner <mtw@eng.sun.com>
Subject: sigaction drops signals?
Message-Id: <335D6A36.2245@eng.sun.com>

I'm using sigaction to setup a handler for SIGCHLD.

It appears that when several children exit simultaneously, I do not
receive SIGCHLD signals from all of them.

The documentation seems to indicate that the signals should be reliably
delivered.

Has anyone observed this behavior?

Perl 5.003  Solaris 5.6 Beta_Update

mtw


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

Date: 23 Apr 1997 00:25:46 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: Stupid Question
Message-Id: <5jjkua$b99$1@dartvax.dartmouth.edu>

In article <3357C1FE.47B8258E@st.nepean.uws.edu.au>
Michael Slade <mslade@st.nepean.uws.edu.au> writes:

> How do I do something equivalent to /foo(.*)bar/si, in Perl *Version 4*?

--- According to Camel 1st Ed:
$*

Set to 1 to do multi-line matching within a string, 0 to tell Perl that
it can assume that strings contain a single line, for the purpose of
optimizing pattern matches.
---

Chipmunk


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

Date: 22 Apr 1997 18:01:59 -0400
From: Mike Campbell <mcampbel@tvmaster.turner.com>
Subject: Re: They both suck! (was: Borland or Microsoft compilers ?)
Message-Id: <r5afmqn2co.fsf@tvmaster.turner.com>


Jim Campbell <jec01@richmond.infi.net> writes:

> You Suck!

Very nice.  This from someone who cross-posts to 21 groups, quotes 33
lines of content for a 1 line reply of absolutely no merit whatsoever,
replying to someone who has been a stable, contributing member to the
programming community for at _least_ 7 years, and doubtlessly much
longer than that, and *HE* sucks?

Hahahah.... one can barely wonder what sort of inadequacy you are
attempting to make up for by such eloquent prose and amazing display
of net-iquette.

Go away, little boy.


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

Date: Tue, 22 Apr 1997 18:32:53 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Variable interpolation (substitution)
Message-Id: <5rhjj5.b54.ln@localhost>


SysAdmin (matrix@I_should_put_my_domain_in_etc_NNTP_INEWS_DOMAIN) wrote:


Why no email address anywhere? 

Not in the To:. 

Not in the Reply-To:.

Not in the signature...


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: 22 Apr 1997 23:55:40 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Warning: Michael Kagalenko post has imbedded JavaScript SPAM bomb!
Message-Id: <5jjj5s$q6n$3@marina.cinenet.net>

Michael D. Kersey (mdkersey@hal-pc.org) wrote:
: Michael Kagalenko wrote:
: > 
: Warning to Netscape users!!
: 
: The above poster, Michael Kagalenko, has inserted the following
: JavaScript code in his e-mail:
[script snipped]
: This will open windows in your browser until memory is exhausted and/or
: your system hangs.

This is annoying and rude behavior on MK's part -- but I must admit that 
I also see it as a loud "Get another newsreader!" wake-up call to 
Netscape users.  Any newsreader which allows *message content* to crash 
your machine is fundamentally and perhaps irreparably broken.  You should 
abandon it with all due speed -- the next fun little trick somebody finds 
may do far more than simply cost you a reboot.

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Tue, 22 Apr 1997 23:04:15 GMT
From: john_zollinger@arkona.com (John Zollinger)
Subject: Re: Who will win?  Borland or Microsoft or Programmers?
Message-Id: <335d426a.25874565@news.xmission.com>

M A <34110s96@student.csi.cuny.edu> wrote:

>Hi, 
>	My company is planning to start a project.  We have a big question
>about our investments.  We don't know if we should use Microsoft 
>compiler or Borland.  Some myth we heard over the net.

How about trying out a new concept:

1. Define the needs for your development environment, complier, etc.
2. Evaluate the available packages and buy the package that best
fulfills the needs you outlined in #1.

If it's borland, microsoft, joe's compiler emporium, etc. it doesn't
matter.  

Define what your needs are BEFORE you pick the solution, otherwise you
will never know if you found the right one for YOU.

It's the same for software development.  Define the problem before you
pick the tool to solve it.


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

Date: 23 Apr 1997 01:53:23 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Why is perl math so slow?
Message-Id: <5jjq2j$3na$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, Kevin Atkinson <kevina@clark.net> writes:
:Could some one explain to me why perl is so slow at arithmetic
:compared to C++.

Because Perl is optimized for strings not numbers, and normally it's
only compiled to byte code (or its moral equivalent), not to asm code
as C is.  Of course, you can compile Perl to C, and with a few hints to
the compiler get fine performance.

There.  Now that that's out of the way, could you please tell us why C++
is so stupid about automatic memory allocation, deallocation, general
garbage collection, and proper invocation of destructors? :-)

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com
There's some side effect based on the fact that SIGCHLD isn't sent by
anyone, but is fabricated by the kernel when a child dies.  It's a huge
kludge.  But then, it _is_ SysV. --Chip Salzenberg, aka <chs@nando.net>


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

Date: Tue, 22 Apr 1997 18:39:41 -0700
From: "Charles F. Ritter" <critter@quack.kfu.com>
Subject: Re: writing to text file from Perl ...
Message-Id: <335D685D.13C17845@quack.kfu.com>

Bob wrote:
> 
> Mark Smith <mark@backlash.net> wrote:
> >I am trying to write to a text file through my perl script, however, I
> >want to post to the top of the files rather than the bottom without
> >having to write the entire file in an array and re-writing it.  By

>         I'm a newbie to Perl, but you could do what I did.  Recently I
> wrote a perl script to create MOTDs, with a log, and I wanted the most
> recent at the top.  What I wound up doing is appending to the file.
> The files are then in reverse order.  I then read the entries in when
> it was time to view the MOTD and just did a reverse.  Adding an MOTD
> was therefore fast, and since I was reading the  whole file when
> viewing an MOTD, the only extra bit was a "reverse" of an array after
> the array was already in memory, which didn't seem to be bad at all.
> Not sure if this will apply to you, or if there is a better way (>+?).
> 

You might try tying the array to a database file. The 'tie' function
implements this and there is a good example of the technique in the
March 1997 edition of the Linux Journal.

-- 
Charles Ritter

Microsoft NT - when they are finally finished it will be the best
documented unix operating system on the market.


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

Date: 22 Apr 1997 23:56:21 GMT
From: "Geoff Mottram" <minaret@sprynet.com>
Subject: Re: XSUB: hash -> C struct ?
Message-Id: <01bc4f78$7bc66280$c56eafce@cactus>


> Is there a commonly accepted "best" way to map a perl5.004 hash to a C
> struct when doing XSUB programming?  Up to now, i've simply been doing
> a lot of hv_fetch()es to get hash values into the proper spots of the
> struct.  This strikes me as a little cumbersome.

I generally use arrays to pass C structure data back and forth.  You can
pass all of the elements in a single call and a single return.  If you add
elements to the structure later, just add them to the end of the array. 
This way, old scripts won't break when you add a new element to the
structure.  Arrays seem to be a very efficient method of exchanging this
data.  Returning an array is as simple as using XPUSH calls for each
element of your structure.  The perl script to fetch your structure would
look like this:

	my @data = your_get_function();

Then use $data[0], $data[1], etc. to fetch the data.

The perl script to pass elements to your C routine would look like this:

	your_set_function($element1, $element2, $element3...);

I personally wouldn't use pack to create structures for the very reason you
suggested -- alignment problems.  It's much better to perform the
assignments to each element in C and let the compiler deal with the
alignment issues.  It will also make your code much more portable.

-- 
Geoff Mottram
minaret@sprynet.com


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

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

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