[7874] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1499 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 18 13:17:24 1997

Date: Thu, 18 Dec 97 10:00:23 -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, 18 Dec 1997     Volume: 8 Number: 1499

Today's topics:
     Re: 6 elementary questions <dformosa@st.nepean.uws.edu.au>
     Re: Changing passwd <placej@ctcdist.com>
     Re: Compiling PERL for win95 (Paul Murray)
     Extensible File Handle Objects <gale@int-gw.livelink.com>
     find2perl and GNUish find (J.L.M.)
     How do I create NDBM file from a flat file? <chrislee@med.unc.edu>
     How do i process a variable length array lee.gammell@feedME
     Re: How do i process a variable length array (Honza Pazdziora)
     Re: JPL & PERL 5.004_04 under IRIX <bugaj@bell-labs.com>
     Re: last modification date on files <bugaj@bell-labs.com>
     Linux/Perl -> Oracle 7.3 on SCO Unix (or other) <broomberg@ccgroupnet.com>
     Looking for a nawk to perl converter (Jete Software Inc.)
     Re: NEED:  Fast, Fast string trim() <matkin@Owein.DoCS.UU.SE>
     Netscape & MIME On Newsgroups <bugaj@bell-labs.com>
     Re: Newbie can't add the -w flag to perl to get useful  <#@qz.to>
     Newbie NT Script question <Anonemouse@silk.win.tec.mn.us>
     Re: No Flock! -- Now What? <clark@s3i.com>
     Re: No Flock! -- Now What? (Christopher Masto)
     Re: Number of items in an array <reibert@mystech.com>
     one liners <kcm@tca1.dl.ac.uk>
     PERL & Puns (was Re: Perl Programmers Wanted!) <bugaj@bell-labs.com>
     Setting an Enviroment Variable in a Web Perl script (keefner)
     Sorting Hashes By Value <bugaj@bell-labs.com>
     Re: Timeout, fork and exec. <bugaj@bell-labs.com>
     Re: Which language pays most 17457 -- C++ vs. Java? <carla@ici.net>
     Re: Which language pays most 17457 -- C++ vs. Java? <carla@ici.net>
     Re: Which language pays most 17457 -- C++ vs. Java? (Kaz Kylheku)
     Why isn't this working? <guido@sportnet.nl>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 18 Dec 1997 15:40:52 GMT
From: ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au>
Subject: Re: 6 elementary questions
Message-Id: <882459648.549584@cabal>

In <678csr$75s$1@nntp1.ba.best.com> "Xah" <xah@best.com> writes:

>Some Perl beginner's questions I'v accumulated. I've not investigated them
>extensively, but those experienced should be able to help me out easily.
>Thanks.

># Question: How to explicitly force a conversion between number and string?
>(if there's way.)

You don't have to,  perl dose it for you automagicly.

># Question: in the following code, it seems that the second argument of
>foreach is automatically converted into an array. Is this behavior somewhere
>in man page?

>    while (<>) {
>        foreach $word (m/(\w+)/g) {
>            # do something with $word here
>        }
>    }

Matches return an array containing the matched string.  It documented in
the match man section of the man page.

># Question: explain the behavior of the following code. i.e. What is the
>context of @a in print and when is a separator added automatically?

>@a = (1 .. 10);
>print "@a\n";
>print @a;

In the first case @a is intropolated into the string,  this is when the
seperator is added.

In the second case @a is called in an array context and its treated like

print 1,2,3,4,5,6,7,8,9,10;

># Question: Why the following two versions of code differ? one prints just
>one line, the other prints the whole file.

>print <FILE>;

>$line = <FILE>;
>print $line;

The first one calls <FILE> in an array contenex and the whole of file is
slurped into memory.  In the second cause <FILE> is caled in a scaler
context and one line is called into memory.

># Question: Suppose I want to split a string, and get the second element,
>split it again and get the last element. What's the appropriate perl style
>code? For example, $str = 'GET /~xah/Curves_dir/Spc.html HTTP/1.0', and I
>want to split it by a space, then split the second element by a slash, then
>taking the last element 'Spc.html' as result.

>If I'm working with a functional language, then I can nest them something
>like

>(split(m@/@, (split(m@ @, $str))[2]))[-1]

It dosn't?  As far as I can tell it workes. However as perl counts from
zero it should be [1] rather then two.  Alos this will not work in a
print stament for some unfathanable reson.  If you whant it to work in a
print stamennt you will have to put a set of brackes around it.

--
Please excuse my spelling as I suffer from agraphia see the url in my header. 
Never trust a country with more peaple then sheep. I do not reply to mungged 
Support NoCeM http://www.cm.org/                   addresses.  
I'm sorry but I just don't consider 'because its yucky' a convincing argument


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

Date: Thu, 18 Dec 1997 08:53:44 -0500
From: "John C. Place" <placej@ctcdist.com>
Subject: Re: Changing passwd
Message-Id: <67ba8p$m5s$1@darla.visi.com>

Although opening a security hole you could write the script set the owner
(and I highly advise the group also) to root. Then do a set uid (chmod 4755)
on that file. That way you will only be root during the command. BUT I say
again this opens the door for potential unsavory persons.

Good Luck
John C. Place


Philip Ling wrote in message <67alh8$kr@hpg30a.csc.cuhk.edu.hk>...
>Hi,
>
>Is there a way for a non-root user to change other users' password ?
>If other users can pass the uid and existing password as parameters.
>Of course, the script is in perl.
>
>Thanks.




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

Date: 18 Dec 1997 16:01:48 GMT
From: murray-paul@usa.net (Paul Murray)
Subject: Re: Compiling PERL for win95
Message-Id: <slrn69ii7b.86s.murray-paul@unix2.netaxs.com>

On Mon, 15 Dec 1997, cdd2@gpu.srv.ualberta.ca <cdd2@gpu.srv.ualberta.ca>
>I am in the process of trying to compile a large script of mine into C
>source using M. Beattie's perl compiler.  My goal is to make a fully
>functional Win95 executable out of this script.
>
>My question is this...  When I do convert my PERL source into C
>source, will I be able to simply compile it using something like
>Microsoft Visual C++ or another Windows product?  My script only uses
>one module (Sockets).

You might want to use Perl2Exe from http://www.demobuilder.com/ which
is a little shareware utility which creates stand-alone executables
from perl scripts. It currently only works with the ActiveState port
of perl, not the standard port.

-Paul Murray


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

Date: Thu, 18 Dec 1997 17:42:52 +0200
From: RHS Linux User <gale@int-gw.livelink.com>
Subject: Extensible File Handle Objects
Message-Id: <Pine.LNX.3.96.971218171606.5581A-100000@int-gw.livelink.com>

It seems like the following would be an obvious improvement to Perl's
ability to deal with file handles in an OO environment, and to Perl OO in
general.

Why not let <$fh> call the getline or getlines method whenever $fh is
any kind of blessed reference?  There are many obvious benefits.  If
anyone else has tried to deal with IO handle base classes while at the
same time trying to standardize how object variables are stored, they
will know what I mean.  (I have some modules that are a good general
workaround for this problem, if anyone is interested.)

Is this hard to implement?  Is it / was it already done?

 .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .
Yitzchak Gale                   LiveLink Systems Ltd.
yitzchakg@LiveLink.com          World Leaders in Hyperlinking Technology
Tel.: +972-2-6528274 ext. 110   Fax: +972-2-6528365
            =>  http://www.livelink.com/  <=
 .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .




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

Date: 18 Dec 1997 09:57:46 -0600
From: fishbowl@fotd.netcomi.com (J.L.M.)
Subject: find2perl and GNUish find
Message-Id: <67bh5q$4kv$1@fotd.netcomi.com>

$ find2perl /home -name WhatIWant -maxdepth 4 -mindepth 4
Unrecognized switch: -maxdepth

 .... Why?  Can I rebuild find2perl so that it can use the GNU find syntax?
Can you suggest a perlism that will help?

--
g-r-a-t-e-f-u-l-l-y---[   email:<fishbowl@conservatory.com>   ]---l-i-v-i-n-g
d-e-a-d-i-c-a-t-e-d---[     http://www.conservatory.com/      ]-----l-i-g-h-t
Time goes, you say?  Ah no!  Time stays, *we* go.  -- Austin Dobson


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

Date: Thu, 18 Dec 1997 10:31:24 -0500
From: Chris Lee <chrislee@med.unc.edu>
Subject: How do I create NDBM file from a flat file?
Message-Id: <349941C7.E397C1C@med.unc.edu>

Howdy All,

I'm running into problems in creating a NDBM file from a flat file.  The flat
file is formatted as such:
	userid-=-TeacherName|Last Name, First Name-==-

Here's the script I developed:

open (FILE, "students98");
@foo = <FILE>;
close(FILE);
for (@foo) { $bar .= $_;}
@entries = split(/-==-/, $bar);

for (@entries) {
   local($key, $val) = split(/-=-/);
   $foo{$key} = $val;
}
$filename = "students99";
use Fcntl;
use AnyDBM_File;
tie (%db, "NDBM_File", $filename, O_RDWR|O_CREAT, 0664);
$db{$foo{'key'}} = $foo{'val'};
untie (%db);

the script generates a students99.pag and students99.dir file (which I need)
but does not contain any data.  Obviously, I've coded the script wrong but I
can't figure out where.  Perl -c says the syntax is ok but I've goofed up the
statements.  Any thoughts or suggestions kindly appreciated...

Happy Holidays,

chris


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

Date: 18 Dec 97 16:20:37 GMT
From: lee.gammell@feedME
Subject: How do i process a variable length array
Message-Id: <34994d55.0@lightning.ica.net>

Can you help an absolute beginner...?

I want to do some processing on the output of the unix command 'ps -ef', but each line has a variable length number of args.  How can i capture all of the users command line arguments into a single array or scalar ?

This is what i've got so far...

open(PS, '/bin/ps -ef|') || die "Can't open process table.\n";
$head=<PS>;
print $head;
while (<PS>) {
	chomp;
	$stime = (split(' ',$_))[4];
	# STIME could be either HH:MM:SS or MMM DD
	if ( $stime =~ /^\d\d:\d\d:\d\d$/) {
		($uid,$pid,$ppid,$c,$stime,$tty,$time,$cmd) = split(' ',$_);
	}
	else {
		($uid,$pid,$ppid,$c,$mon,$day,$tty,$time,$cmd) = split(' ',$_);
		$stime = join(' ',$mon,$day);
	}

	# process the data here....

}
close(PS);
--------
Many Thanks,
Lee Gammell


------------------------------------------------------------------
              Hungry for NEWSGROUPS??? USE feedME.ORG             
         Read and Post to 30,000 groups through feedME.ORG        
     FREE  FREE  FREE  http://www.feedME.ORG  FREE  FREE  FREE    
------------------------------------------------------------------



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

Date: Thu, 18 Dec 1997 16:59:56 GMT
From: adelton@fi.muni.cz (Honza Pazdziora)
Subject: Re: How do i process a variable length array
Message-Id: <adelton.882464396@aisa.fi.muni.cz>

lee.gammell@feedME writes:

> Can you help an absolute beginner...?
> 
> I want to do some processing on the output of the unix command 'ps -ef', but each line has a variable length number of args.  How can i capture all of the users command line arguments into a single array or scalar ?
> 
> This is what i've got so far...
> 
> open(PS, '/bin/ps -ef|') || die "Can't open process table.\n";
> $head=<PS>;
> print $head;
> while (<PS>) {
> 	chomp;
> 	$stime = (split(' ',$_))[4];

I am not sure I catch you well, but it seems to me that you are
looking for the third parameter to split, which is the number of
pieces you want to get (check perlfunc man page for split section). So
that the line will be split on spaces, but only on those delimiting
the first columns, not those delimiting arguments in command line
output.

Hope this helps,

--
------------------------------------------------------------------------
 Honza Pazdziora | adelton@fi.muni.cz | http://www.fi.muni.cz/~adelton/
                   I can take or leave it if I please
------------------------------------------------------------------------


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

Date: Thu, 18 Dec 1997 12:18:35 -0500
From: Stephan Vladimir Bugaj <bugaj@bell-labs.com>
Subject: Re: JPL & PERL 5.004_04 under IRIX
Message-Id: <34995AEB.3F54@bell-labs.com>

> Not sure your exact error, but I couldn't get it installed either.  I
> used the best method in the world, a new tardist for 5.004_04.  It can
> be found at http://reality.sgi.com/scotth/info/perl5.html and worked
> flawlessly.
> 
According to Scott, he used the PERL malloc() to build this... hence
it will not work with JPL.

If I don't get it working from the most recent suggestions I've been
given, I'll post the exact error.  If it works, I'll post how to do
it.

LL+P,
Stephan




-- 
  
                    "Do computers think?"
---------------------------------------------------------------
Stephan Vladimir Bugaj                      bugaj@bell-labs.com
Member of Technical Staff                        (908) 949-3875
Multimedia Communication Research Dept.     Rm. 4F-601, Holmdel
Bell Labs of Lucent Technologies   www.multimedia.bell-labs.com
PGPkey from http://www.pgp.net/wwwkeys.html or other keyservers
Non-Lucent website:     http://www.cthulhu-dynamics.com/stephan  
---------------------------------------------------------------
    STANDARD DISCLAIMER:My opinions are NOT those of LUCENT
---------------------------------------------------------------
           "Do submarines swim?" - E.W. Dijkstra


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

Date: Thu, 18 Dec 1997 10:54:14 -0500
From: Stephan Vladimir Bugaj <bugaj@bell-labs.com>
Subject: Re: last modification date on files
Message-Id: <34994726.167E@bell-labs.com>

> -M actually gives you the age of the file in days from the epoch, not the number
> of days since the last modification.
> 
> Anyway, instead of -M file, use (stat file)[9].  That will give you the age of
> the file in seconds from the epoch, which you can use as an argument to localtime().
> 
The "age of the file" is the last modified time.  When the file is
modified st_mtime is changed, and the "real" creation date is 
overwritten  by the new "modified" date.  As far as I know, aside
from saving this data yourself somewhere, once you modify a file
you lose the original creation date.

>From man stat:

 ...
st_mtim   Time when data was last modified.  Changed by the following
               system calls:  creat, mknod, pipe, utime, and write.  
	       The seconds portion of st_mtim is available as st_mtime.

That's what you're getting back from (stat file)[9].


LL+P,
Stephan



-- 
  
                    "Do computers think?"
---------------------------------------------------------------
Stephan Vladimir Bugaj                      bugaj@bell-labs.com
Member of Technical Staff                        (908) 949-3875
Multimedia Communication Research Dept.     Rm. 4F-601, Holmdel
Bell Labs of Lucent Technologies   www.multimedia.bell-labs.com
PGPkey from http://www.pgp.net/wwwkeys.html or other keyservers
Non-Lucent website:     http://www.cthulhu-dynamics.com/stephan  
---------------------------------------------------------------
    STANDARD DISCLAIMER:My opinions are NOT those of LUCENT
---------------------------------------------------------------
           "Do submarines swim?" - E.W. Dijkstra


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

Date: Thu, 18 Dec 1997 17:33:55 GMT
From: "Barry Roomberg" <broomberg@ccgroupnet.com>
Subject: Linux/Perl -> Oracle 7.3 on SCO Unix (or other)
Message-Id: <01bd0be3$4ccfa400$5e5667cf@red_dwarf_ii.ccgroupnet.com>


I'd like to be able to have a PERL program
on a Linux box access an Oracle instance across
the network.  I'm confused.  If I was connecting
2 SCO boxes, I'd setup a SQL/Net connection and
go from there.  No SQL/Net under Linux that
I'm aware of.  Am I wrong?  What are my
alternatives?  Can anyone point
me in a direction.  Thanks.



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

Date: 18 Dec 1997 11:30:58 -0500
From: jete@dgs.dgsys.com (Jete Software Inc.)
Subject: Looking for a nawk to perl converter
Message-Id: <67bj42$3kl@dgs.dgsys.com>

I have this large piece of code (which is a maintenance nightmare) written
in nawk. I attempted to use "a2p", which is the awk to perl converter, but
it trips on some of the nawk syntax.

So does anyone know of a nawk to perl converter??

-- Norman


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

Date: 18 Dec 1997 17:11:14 +0100
From: Matz Kindahl <matkin@Owein.DoCS.UU.SE>
Subject: Re: NEED:  Fast, Fast string trim()
Message-Id: <yf5yb1ivdgd.fsf@Owein.DoCS.UU.SE>

tony@crux.blackstar.co.uk (Tony Bowden) writes:

> Matz Kindahl (matkin@Owein.DoCS.UU.SE) wrote:
> : > Any advance?
>  
> : I tried the following version; seems to be ~25% faster than my
> : previous version.
> : 5) $_ = " $_ "; tr/ \n\r\t/ /s; $_ = substr($_,1,-1)
> 
> On short strings:
>   Benchmark: timing 50000 iterations of Exp1, Exp2...
>       Exp1:  2 secs ( 1.69 usr  0.00 sys =  1.69 cpu)
>       Exp2:  1 secs ( 1.21 usr  0.00 sys =  1.21 cpu)

Hmmm.... ~28% reduction. ;/

> On long strings:
>   Benchmark: timing 50000 iterations of Exp1, Exp2...
>       Exp1: 10 secs ( 9.44 usr  0.00 sys =  9.44 cpu)
>       Exp2: 10 secs ( 9.25 usr  0.00 sys =  9.25 cpu)

Hmmmm.... ~2% reduction. :(

> A nice advance, but unfortunately not that noticable on long strings.

Seems my test string wasn't long enough. :(

Well, at least I can comfort myself with that it certainly was more
readable. ;)

> Still the best to date though ;)
> 
> Thanks

You're welcome. :)

Regards,
-- 
Mats Kindahl                    ! matkin@docs.uu.se
Department of Computer Systems  ! 
Box 325                         ! Tel  +46 18 18 10 66
S-751 05 Uppsala                ! Fax  +46 18 55 02 25
SWEDEN                          ! URL  http://www.docs.uu.se/~matkin/

PGP Key fingerprint =  92 5C FC 39 32 A8 7F 91  01 56 A0 D3 9C A9 6C 81 
PGP key available under finger matkin@kay.docs.uu.se

"People do strange things when you give them money."
        -- Simple Minds


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

Date: Thu, 18 Dec 1997 11:40:46 -0500
From: Stephan Vladimir Bugaj <bugaj@bell-labs.com>
Subject: Netscape & MIME On Newsgroups
Message-Id: <3499520E.59E2@bell-labs.com>

I think this is Netscape's fault... because their Newsreader likes
MIME (it being part of a Web browser and all that) the default 
setting for Messenger messages is "send in Plain Text and HTML".

So, complain to them, not to us.

And those of you using Messenger: stop using the default.  Bad
USENETter, no biscuit.

Just to make this not TOTALLY off topic... does Messenger keep a
history of mails and posts and if so is anyone working on modules
Netscape::Messenger::History and Netscape::Messenger::History::
Newsgroup and Netscape::Messenger::History::Emailaddress (or 
whatever)?  (Heh, how about Net::NNTP::StripMIMECrap)


LL+P,
Stephan

-- 
  
                    "Do computers think?"
---------------------------------------------------------------
Stephan Vladimir Bugaj                      bugaj@bell-labs.com
Member of Technical Staff                        (908) 949-3875
Multimedia Communication Research Dept.     Rm. 4F-601, Holmdel
Bell Labs of Lucent Technologies   www.multimedia.bell-labs.com
PGPkey from http://www.pgp.net/wwwkeys.html or other keyservers
Non-Lucent website:     http://www.cthulhu-dynamics.com/stephan  
---------------------------------------------------------------
    STANDARD DISCLAIMER:My opinions are NOT those of LUCENT
---------------------------------------------------------------
           "Do submarines swim?" - E.W. Dijkstra


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

Date: 18 Dec 1997 17:33:20 GMT
From: Eli the Bearded <#@qz.to>
Subject: Re: Newbie can't add the -w flag to perl to get useful warnings
Message-Id: <eli$9712181222@qz.little-neck.ny.us>
Keywords: sponsored by the letter W

Dave Reed <daveSTOP*SPAMreed@webshowplace.com> wrote:

My address works. Does yours?

> I've been told to "add the -w flag to perl to get useful warnings."

Very good idea. I sometimes just use "$^W=1;" as the first non-comment
in the script myself. (The "^W" can be <ctrl-W> or a literal <^><W>.)

> How?  Type "perl -w" before the filename, like when using "perl -c"?

"perl -wc" or "perl -w -c" both work.

> Everyone seems to assume that Perl newbies are already programmers.

If you are new to programming that might be useful to mention in your
post, yes. It is hard to gugue the level to respond to people at often.

> Is there a useful place to start for those of us who never used Telnet before?

Telnet should not be needed for perl. :^)

> (I've been using a Mac almost daily since 1984 and doing HTML for years,
> but when it comes to Perl it seems like all the books on "How to Learn
> Greek" are written in Greek.)
> 
> Help?

There is a certain amount of lifting yourself by your bootstraps in
many books on learning languages.

Elijah
------
#!/usr/bin/perl -- -*- my ny.pm sig -*-
$_=$^ ;s;s;sss;;s^.^ju^&&s&P&.\n&&&(s(_..)(ers)||s|^|^^|)&&s(T)(q(st%eg))eg;
s<.(o).><$& new 1$$>i+s+\dst.+$a--||reverse(q(rep k))+ge;s*%.+u* so+*i;s=\++
="me"=mex&&s%ege%l$"hke%;$a||s/^\S+ /\/\//;s;\d+;yor;;s[KE]<ac$&>i;print $_;


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

Date: Thu, 18 Dec 1997 11:44:45 -0600
From: "Anon E. Mouse" <Anonemouse@silk.win.tec.mn.us>
Subject: Newbie NT Script question
Message-Id: <3499610D.2EB2494E@silk.win.tec.mn.us>

Hello,

I went through the FAQ and could not seem to find help on this.  Perhaps
I missed it.
I know this should be a really simple task...  I could not find a good
online tutor etc.. to help.
If anyone can help, I would appreciate it.  Thanks...

We have an NT Server 4.0, Perl 5.003_07, and want to use BLAT to mail a
form.
(unless someone knows of a sendmail thats 100% syntax compatible with
the unix one.
Im willing to change!)

The script was give to me as below.  The problem is that for me to use
BLAT (not the same syntax as sendmail) I need to arrange it so that I
end up doing BLAT mailform -t tome@ourplace.com -s "Info Request".

CURRENT SCRIPT
------------------
------------

$mailer = '/usr/lib/BLAT';

read(STDIN, $message, $ENV{'CONTENT_LENGTH'});

open(MAIL, "|$mailer -t") || die "Can't open $mailer!\n";
print MAIL "To: anonemouse\@rww.tec.mn.us\n";
print MAIL "From:WebForms-" . $ENV{'REMOTE_HOST'} . "\n";
print MAIL "Subject: Form posted: RWWTC Information Request form\n\n";
print MAIL "$message\n";
close (MAIL);
print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE></TITLE></HEAD>\n";
print "<BODY><H1></H1>\n";




--




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

Date: 18 Dec 1997 12:40:31 -0500
From: Clark Dorman <clark@s3i.com>
Subject: Re: No Flock! -- Now What?
Message-Id: <dwwh2tur4.fsf@s3i.com>


syarbrou@ais.net (Steve) writes:
> Only Linux with perl 5.004_04 seems to support in on the UNIX end.
> Other versions like Sun OS have man pages and everything, but they
> don't work with multiple writes.  You end up loosing your log or it's
> all screwed up.  I had to setup a Linux box to do this and it works
> flawlessly.  They say lockf() is the ultimate, most portable means to
> do this, but I have never tried it.
> 
> Steve

I've got access to SunOS, Solaris, and Irix 5.3 "on the UNIX end" and
have not experienced problems.  

Do you have some code that I can test my flock with?  The thing is
that flock in perlfunc doesn't really have a good example.  What I
would like is, for example, a program that forks itself a bunch of
times and each child repeatedly tries to read/write to the same file,
locking and unlocking as it goes.  I'll try to write something if
noone has something handy.
 
> On Wed, 17 Dec 1997 13:05:55 -0800, Vik Rubenfeld <VikR@aol.com>
> wrote:
> 
> >I'm finding that there are PERL installations that neither support nor emulate
> >FLOCK. What do you do on a system like that? Surely these systems have some
> >way of handling multiple simultaneous attempts to write to a single data file
> >-- don't they?
> >
> >Is it possible to develop something that is strictly PERL code, and can
> >provide flock or something like it under any setup? 
> >
> >Thanks very much in advance to all for any info.
> >
> >- Vik
> 

-- 
Clark


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

Date: 18 Dec 1997 17:47:37 GMT
From: chris@netmonger.net (Christopher Masto)
Subject: Re: No Flock! -- Now What?
Message-Id: <67bnjp$9gp$1@schenectady.netmonger.net>

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

In article <67bejl$b4s$1@csnews.cs.colorado.edu>,
Tom Christiansen  <tchrist@mox.perl.com> wrote:
>In comp.lang.perl.misc, syarbrou@ais.net (Steve) writes:
>:Only Linux with perl 5.004_04 seems to support in on the UNIX end.
>
>Please stop saying that, or file a specific bug report. 
>What you are saying here is catastrophic in the extreme,
>if it is true, which I am prepared to doubt.

Furthermore, I am not running Linux and I can confirm that the
following "test" of flock seems to indicate that it works just fine:

- - --8<-- - -

  #!/usr/local/bin/perl -w

  use Fcntl ':flock';
  use strict;

  $| = 1;

  open TEST, ">>/tmp/test.lck";
  while (1) {
    flock(TEST, LOCK_EX);
    print "$$ Locked.\n";
    sleep 1;
    print "$$ Unlocking.\n";
    flock(TEST, LOCK_UN);
  }

- - --8<-- - -

When several invocations of the above program are run simultaneously,
they behave exactly as one would expect:

4708 Locked.
4708 Unlocking.
4694 Locked.
4694 Unlocking.
4699 Locked.
4699 Unlocking.
4700 Locked.
4700 Unlocking.
4693 Locked.
4693 Unlocking.
4707 Locked.
4707 Unlocking.
4708 Locked.
4708 Unlocking.
4694 Locked.
4694 Unlocking.
-- 
= Christopher Masto        = chris@netmonger.net = http://www.netmonger.net/  =
= NetMonger Communications = finger for  PGP key = $19.95/mo unlimited access =
= Director of Operations   =   (516)  221-6664 	 = mailto:info@netmonger.net  =



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

Date: Thu, 18 Dec 1997 10:12:22 -0700
From: "Mark S. Reibert" <reibert@mystech.com>
Subject: Re: Number of items in an array
Message-Id: <34995976.300FB2E4@mystech.com>

brian d foy wrote:

>  * use @array in a scalar context (ick! i think this leads to lots
> of coding errors, so no example, although it works).

Uh Oh! I feel compelled to disagree! Using arrays in scalar context can lead to nicely succinct
and readable code, provided one knows the difference between scalar and list context. Lines like

if ( @thingsToDo ) { ... }

are wonderfully legible! :-)

-----------------------------
   Mark S. Reibert, Ph.D.

  Mystech Associates, Inc.
  3233 East Brookwood Court
   Phoenix, Arizona 85044

    Tel: (602) 732-3752
    Fax: (602) 706-5120
 E-mail: reibert@mystech.com
-----------------------------




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

Date: 18 Dec 1997 16:43:16 GMT
From: Kevin Maguire <kcm@tca1.dl.ac.uk>
Subject: one liners
Message-Id: <67bjr4$op4@newton.cc.rl.ac.uk>

How to this in a perl one-liner

replace record 3 of line 10 in file nozz10 with hello:
head -9 nozz10; head -10 nozz10 | tail -1 | awk '{$3="hello"; print $0}' ; tail +11 nozz10

Must be pretty easy ?!  And faster than the above?  What about for all
files (*10) in a one-liner?  

Kev 
--


                    \\\|///
                  \\  - -  //
                   (  @ @  )
+-----------------oOOo-(_)-oOOo---------------------+
| Kevin Maguire                Daresbury Laboratory |
| K.Maguire@dl.ac.uk                     Warrington |
| Tel: (01925) 603221                      Cheshire |
| Fax: (01925) 603634                United Kingdom |
+-------------------------Oooo----------------------+
                   oooO   (   )
                  (   )    ) /
                   \ (    (_/
                    \_)


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

Date: Thu, 18 Dec 1997 11:28:59 -0500
From: Stephan Vladimir Bugaj <bugaj@bell-labs.com>
Subject: PERL & Puns (was Re: Perl Programmers Wanted!)
Message-Id: <34994F4B.794B@bell-labs.com>

 ...
> So,
> 
> perl is used to refer to the compiler/interpreter
> 
> Perl is used to refer to the language itself
> 
> PERL is not used  ;-)
> 
 ...
Well, perhaps, but if you like all caps for language names like
I do (who knows why?)... and if you like acronyms... then PERL
as the Pathologically Ecclectic Rubbish Lister (which would be
perl4) seems to work.  Perhaps, though, perl5 needs to be PERL
as Practically Emulates a Real Language (well, of course Perl
IS a real language - but since it gets called a "scripting" language 
and we all know (sic) that those are worse than "real" languages
like C or Assembler or Fortran, I suppose Perl has been successful
because it can Emulate a "real" language better than other "scripting"
languages like LISP ;-> ).

Not having gotten much sleep lately, I also came up with a bad
pun for spending late nights with Perl.  It came out of me when
a friend asked why I was so tired lately and I told her:

"I've been burning the Camel at both ends."

LL+P,
Stephan


  
                    "Do computers think?"
---------------------------------------------------------------
Stephan Vladimir Bugaj                      bugaj@bell-labs.com
Member of Technical Staff                        (908) 949-3875
Multimedia Communication Research Dept.     Rm. 4F-601, Holmdel
Bell Labs of Lucent Technologies   www.multimedia.bell-labs.com
PGPkey from http://www.pgp.net/wwwkeys.html or other keyservers
Non-Lucent website:     http://www.cthulhu-dynamics.com/stephan  
---------------------------------------------------------------
    STANDARD DISCLAIMER:My opinions are NOT those of LUCENT
---------------------------------------------------------------
           "Do submarines swim?" - E.W. Dijkstra


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

Date: Thu, 18 Dec 1997 13:54:03 GMT
From: keefner@visi.com (keefner)
Subject: Setting an Enviroment Variable in a Web Perl script
Message-Id: <349929a5.1170718424@news.visi.com>

I want to run a certain program during the exceution of a
cgi/perl script but it fails. The program runs fine from
the command line as the same user as the WebServer
is running as so I think its one of the required enviroment
vairables.

I've tried adding the env vairable to the server startup
but that doesn't work.

setenv XXXX_HOME_DIR /xxxx/cgi-bin  
is all that is required from a command line in order for the
program to work. How do I embed that into the perl script?

Or is there a way to initialize a Netscape server with that
value at startup that I have overlooked.

Craig


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

Date: Thu, 18 Dec 1997 11:12:29 -0500
From: Stephan Vladimir Bugaj <bugaj@bell-labs.com>
Subject: Sorting Hashes By Value
Message-Id: <34994B6D.2781@bell-labs.com>

Other than using a less moronic sorting routine than selection
sort (like quicksort or insertion sort, which I'm writing right 
now) is there a better way to sort hashes on values than this:

(a better way would be something that took advantage of PERL 
structures to avoid all the function call setups and variable 
foo.)

(Which very obviously looks like the C code I derived it from,
my perl often looks like C, sorry)

$r_hash = %foo;
$r_keys = keys(%foo);
$r_sortedkeys = &selectionSortHashKeysOnValues($r_hash,$r_keys);

foreach (@{$r_sortedkeys}) { do_something($foo{$_}); }

#takes a reference to a hash and to an array of hash keys,
#returns a reference to the keys sorted by descending 
#(numeric) order
sub selectionSortHashKeysOnValues($$)
  {
    my ($r_hash,$r_keys) = @_;
    my @keys = @{$r_keys};

    my $len = @keys;
    my $i,$j;
    for($i=$len-1;$i>0;$i--)
      {
	$j = &MaxKey(0,$i,$r_keys, $r_hash);
	$r_keys = &Swap($j,$i,$r_keys);
      }
    return $r_keys;
  }

sub MaxKey($$$$)
  {
    my ($low,$high,$r_keys,$r_hash) = @_;
    my %hash = %{$r_hash};
    my @keys = @{$r_keys};
    my $max = $low;
    my $i;
    for($i=$low+1;$i<=$high;$i++)
      {
	if($hash{"$keys[$max]"} > $hash{"$keys[$i]"})
	  { $max = $i; }
      }
    return $max;
  }

sub Swap
  {
    my($i,$j,$r_keys) = @_;
    @keys = @{$r_keys};
    $temp = $keys[$i];
    $keys[$i] = $keys[$j];
    $keys[$j] = $temp;
    return \@keys;
  }


LL+P,
Stephan

-- 
  
                    "Do computers think?"
---------------------------------------------------------------
Stephan Vladimir Bugaj                      bugaj@bell-labs.com
Member of Technical Staff                        (908) 949-3875
Multimedia Communication Research Dept.     Rm. 4F-601, Holmdel
Bell Labs of Lucent Technologies   www.multimedia.bell-labs.com
PGPkey from http://www.pgp.net/wwwkeys.html or other keyservers
Non-Lucent website:     http://www.cthulhu-dynamics.com/stephan  
---------------------------------------------------------------
    STANDARD DISCLAIMER:My opinions are NOT those of LUCENT
---------------------------------------------------------------
           "Do submarines swim?" - E.W. Dijkstra


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

Date: Thu, 18 Dec 1997 11:20:27 -0500
From: Stephan Vladimir Bugaj <bugaj@bell-labs.com>
Subject: Re: Timeout, fork and exec.
Message-Id: <34994D4B.446B@bell-labs.com>

Randal's WebTechniques Column #20 talks about this timeout problem
and sending web browsers a "please wait" type message to keep the
client from timing out and the user from not knowing what's up:

http://www.stonehenge.com/merlyn/WebTechniques/col20.html

Even though the code example is available on the web I don't want to
post it here without his permission, but if you don't have web access
I'll email it to you (if he doesn't post it here first ;-> ).  

LL+P,
Stephan



> 
> I have a Perl script that takes a long time to finish (it imports an 8meg
> file into a mySQL database) and it always produces a "Request Timeout" HTTP
> error. Is there a way to bypass the HTTP timeout error?
> 
> I tried doing a fork and then an exec to spawn a backround process that I
> was hoping would not be subject to the timeout limitation.  Unfortunately,
> it didn't work.
> 
> Would anyone know of another way?  I am on Apache and using Perl 5.003.
> 
> Thanx,
> Chris Lambrou
> <chris@cglis.com>

-- 
  
                    "Do computers think?"
---------------------------------------------------------------
Stephan Vladimir Bugaj                      bugaj@bell-labs.com
Member of Technical Staff                        (908) 949-3875
Multimedia Communication Research Dept.     Rm. 4F-601, Holmdel
Bell Labs of Lucent Technologies   www.multimedia.bell-labs.com
PGPkey from http://www.pgp.net/wwwkeys.html or other keyservers
Non-Lucent website:     http://www.cthulhu-dynamics.com/stephan  
---------------------------------------------------------------
    STANDARD DISCLAIMER:My opinions are NOT those of LUCENT
---------------------------------------------------------------
           "Do submarines swim?" - E.W. Dijkstra


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

Date: Thu, 18 Dec 1997 10:52:17 -0500
From: Alicia Carla Longstreet <carla@ici.net>
To: Osvaldo Pinali Doederlein <osvaldo@visionnaire.com.br>
Subject: Re: Which language pays most 17457 -- C++ vs. Java?
Message-Id: <349946B1.72E3@ici.net>

Osvaldo Pinali Doederlein wrote:
 
> Hi Alicia,
 
> Alicia Carla Longstreet wrote in message <3494B7DA.5463@ici.net>...

Take care on attributes, I did *not* write this list of 'commandments'.

> >> >1. Actual programs must be written in it.
> >> >2. Lots of libraries must be written for it.
> >> >3. Most computer architectures must have a compatible version of it.
> >> >4. Source code must be easily understable (by good coders).
> >> >5. Lots of programmers must know the language in deep.
> >> >6. The syntax must be simple. The semantics must be well defined.
> 
> Wow, another ten-commandments list.
 
> > Number 5, there are a lot of programmers who know C inside and out,
> > probabaly more than any other language (possibly excepting COBOL and
> > FORTRAN).  I can name a dozen or more on this forum alone.
> > C is quite understandable to anyone who knows it.
 
> If you read twenty lines of any C code, you will understand it, no matter
> how badly/well written.  Now, try to figure out some complex algorithm, or
> an entire application. When you look at some piece of C code, you read
> something like "*ptr++ = foo()" then you literarily interpret it as "call
> funcion f, store some scalar result in the address pointed by ptr and let
> ptr point to the next position of whatever the buffer". I don't call this
> "understantding" anything at all. You need to read lots of context and
> rebuild your mental interpretation of the code (just like a several-pass
> compiler) in order to finally obtain a high-level, "real" idea of the code.
 
> The problem with C is not its brackets or terseness or even absence of OO;
> the problem is expressiveness.  of course you can write ling-long,
> descriptive variable names (complete with hungarian garbage so you can fake
> types in a language which requires types but doesn't really implement them)
> and LOTS of comments; but then the reader will interpret your documentation,
> not your code.

Comments are part of the source code IMO.  Code is not only written for
the computer but for the human reader as well.  Insisting that the
compilable part of the source code always be self-documenting is a
unrealistic goal.  Most languages that try to be this tend to collapse
from the 'weight' of the source code.  People like C, partly because its
terseness makes it easy to type.  When properly done, short one page
functions with adaquete comments to explain the purpose of the function
and periodic comments to indicate what the next logical block of code is
supposed to do (commenting loops and conditionals for examples), C code
can be most readable and easily maintained.

I would *much* rather maintain C code than Clipper code!  Imagine a
'private' variable that was 'in scope' for *every* function called even
callbacks to higher level functions  ARRRRRGGGGGGGG!!!!!  I *love* C's
lexical scoping rules.

-- 
****************************************************************
What is the speed of dark?
When you're sending someone Styrofoam, what do you pack it in?
Why are there Braille signs on drive-up ATM's?
How come you never hear about gruntled employees?
I have an answering machine in my car.
    It says "I'm home now.
    But leave a message and I'll call when I'm out."
=========================================
Alicia Carla Longstreet     carla@ici.net
=========================================
READ THE FAQ for more information:
   C-FAQ ftp sites: ftp://ftp.eskimo.com or ftp://rtfm.mit.edu
   Hypertext C-FAQ: http://www.eskimo.com/~scs/C-faq/top.html


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

Date: Thu, 18 Dec 1997 11:06:04 -0500
From: Alicia Carla Longstreet <carla@ici.net>
Subject: Re: Which language pays most 17457 -- C++ vs. Java?
Message-Id: <349949EC.77B5@ici.net>

Mark Framness wrote:
 
> Shmuel (Seymour J.) Metz" writes:

> #>> C provides the needed primitives to do anything you need.

> #> You got this wrong; C does not have the needed primitives to handle
> #> sets, do string matching, do record-oriented I/O, etc., except in the
> #> trivial sense that anything can be simultated on anything else.

What you are describing are *not* primitives.  
Sets are a high-level construct, in C you define an array and write the
code to manipulate it, in C++ you create a class (which is a feature
filled container for what you do in C).

Strings are also a high level construct.  C and C++ do not have string
data types, instead they use Zero terminated character arrays.  *That*
is the primitive.

The same goes for Record-oriented I/O, this is a high level construct
*not* a primitive.

There are high level langauges that have these high-level constructs,
but they are built from the same primitives that the C porogrammer
*must* use.  In other words, C programmers (and C++ programmers) write
those neat high-level constructs from the low-level primitives
available.

BTW, I recently upgraded to CodeBase 6.3 from Sequiter Software.  This
library provides all those nice neat high level constructs for database
programming that you have confused with primitives.
 
> What do you mean sets?  As in the mathematical sense?  String matching?  Huh?
> what do strcmp, strstr etc do?

Yes strcmp(), strstr(), etc are the high-level constructs built on the
primitives available to manage strings.  String handling is the only
real 'high-level' construct that is available in Standard C.  For linked
lists, matrices, record I/O, etc. you need to either write your own set
of functions or buy some prewritten functions.
 
> It seems to me that the first statement is accurate.  You just have to do more
> work in C & C++ to do the same things in other languages.

P.S. To those of you in nyc.foods - Sorry but you *won't* see this!
-- 
****************************************************************
What is the speed of dark?
When you're sending someone Styrofoam, what do you pack it in?
Why are there Braille signs on drive-up ATM's?
How come you never hear about gruntled employees?
I have an answering machine in my car.
    It says "I'm home now.
    But leave a message and I'll call when I'm out."
=========================================
Alicia Carla Longstreet     carla@ici.net
=========================================
READ THE FAQ for more information:
   C-FAQ ftp sites: ftp://ftp.eskimo.com or ftp://rtfm.mit.edu
   Hypertext C-FAQ: http://www.eskimo.com/~scs/C-faq/top.html


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

Date: 18 Dec 1997 16:41:35 GMT
From: bill@cafe.net (Kaz Kylheku)
Subject: Re: Which language pays most 17457 -- C++ vs. Java?
Message-Id: <67bjnv$j35$1@brie.direct.ca>

In article <e9k976.8h3.ln@localhost>, Tad McClellan <tadmc@metronet.com> wrote:
>: what do strcmp, strstr etc do?
>          ^^^^^^  ^^^^^^
>
>Those are not *primitives* (ie. built-in to the language).
>
>Those are library calls (ie. add-ons to the language).

Nonsense. They are standard parts of the C language required by the ISO
standard. You could also say that the word ``water'' isn't really part of the
English language either, just an add-on noun that is part of the standard
vocabulary. You would, however, get funny looks from people.

>
>You won't find 'strcmp' in a C compiler's grammar.

I use a compiler which will inline functions like strcpy() and abs().
This isn't done through any fancy inline code or preprocessing in any
header files either. The compiler recognizes these internally as though
they were operators, or primitives if you will. 

It's true that the library names are not part of the grammar of the language.
But they are part of the basic lexicon of the language and can be recognized
as such by a compiler.

C is just clever enough to define its primitives in such a way that they
behave like functions; they have conventional function prototypes, their
address can be taken, and so forth.


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

Date: Thu, 18 Dec 1997 17:42:02 +0100
From: "Guido Smit" <guido@sportnet.nl>
Subject: Why isn't this working?
Message-Id: <67bjta$91n$1@news2.xs4all.nl>

Can anyone tell me why the following script is not working with the
webserver IIS 4.0?
I tried it with addusers and usrtogrp from the resource kit, and that
worked.
The advantage from the win32 module is that you can create users more easily
and uncheck the box : user must change password at next logon. Only the perl
script is not doing what is should do..

#!c:/perl

push(@INC,"/scripts/");      # The path of the local cgi-bin dir
#push(@INC,"d:");              # The path of the local cgi-bin dir
require("cgi-lib.pl");             # Include a cgi-library
use Win32::NetAdmin;        # use the admin module
&ReadParse;                      # read and parse

$passwordAge = 31;
$privilege = USER_PRIV_USER;
$homeDir = 'c:\\';
$comment = ($in{'name'});
$flags = UF_SCRIPT+UF_DONT_EXPIRE_PASSWD+UF_PASSWD_CANT_CHANGE;
$scriptpath = 'C:\\';

Win32::NetAdmin::UserCreate('',

$in{'login'},$in{'passwd'},$passwordAge,$privilege,$homeDir,$comment,$flags,
$scriptpath) ||

print "not created\n";
Win32::NetAdmin::GroupAddUsers('','members', $in{'login'}) || print "not
grouped\n";

print "<HTML>\n";
      print "<HEAD><TITLE>Succesfull registration</TITLE></HEAD>\n";
      print "<BODY BGCOLOR=#FFFFFF TEXT=#000000>\n";
      print "<CENTER><FONT FACE=Arial SIZE=5>Registration
Succesfull</FONT></CENTER><P>\n";
      print "\n<P><a href='/user/members/index.html'>Enter the members
area</A><BR>\n";
      print "</BODY>\n";
      print "</HTML>";
      exit;




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

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

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