[10126] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3719 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 15 12:07:27 1998

Date: Tue, 15 Sep 98 09:00:22 -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, 15 Sep 1998     Volume: 8 Number: 3719

Today's topics:
    Re: ??? if ($fr "$test" $threshold) ??? (Andrew M. Langmead)
        assigning file contents to a string avern@hotmail.com
    Re: assigning file contents to a string <labrache@gaulois.cad.cea.fr>
    Re: assigning file contents to a string (Steve Linberg)
    Re: assigning file contents to a string (Matt Knecht)
        ch(mod/own) and links (Vladimir Gabrielescu)
    Re: ch(mod/own) and links <tchrist@mox.perl.com>
    Re: ch(mod/own) and links <webmaster@fccjmail.fccj.cc.fl.us>
        Communicating between server and client!! andy_williams@my-dejanews.com
    Re: difference between 'my' and 'local'? <ff@otis.arraycomm.com>
    Re: Edit in place problem with ActivePerl 5.005_002 benday@c-bridge.com
        File mod time in future? <tturton@cowboys.anet-dfw.com>
    Re: File mod time in future? <J.D.Gilbey@qmw.ac.uk>
    Re: finding out yesterdays date (Steve .)
    Re: Getting multiple scripts to read same configuration <tchrist@mox.perl.com>
    Re: help with perl reg. expr. andy_williams@my-dejanews.com
    Re: make DBD problem <eashton@bbnplanet.com>
    Re: milliseconds? <tchrist@mox.perl.com>
    Re: Perl & Java - differences and uses (Andrew M. Kuchling)
    Re: Perl & Java - differences and uses <zenin@bawdycaste.org>
    Re: PERL and Updating files <eashton@bbnplanet.com>
        reserving explicit memory for a hash reference... (Gerald Kropitz)
    Re: script: scriptMangle! (David A. Black)
    Re: script: scriptMangle! <tchrist@mox.perl.com>
    Re: selective split <oczoske@astro.obs-mip.fr>
    Re: STD I/O for WIN32 Perl <murrayb@vansel.alcatel.com>
        strict and Exporter <ff@otis.arraycomm.com>
    Re: strict and Exporter (David A. Black)
        Transposing an array perlperlperl@my-dejanews.com
    Re: Transposing an array <jeffp@crusoe.net>
    Re: Transposing an array (Greg Bacon)
    Re: Web Chat <jeff@vpservices.com>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Tue, 15 Sep 1998 14:31:09 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: ??? if ($fr "$test" $threshold) ???
Message-Id: <EzBxnx.GIv@world.std.com>

Rick Delaney <rick.delaney@shaw.wave.ca> writes:

>Or you could use a sub that conditionally determines the, er, condition:

>sub test_condition {
>    my($left, $op, $right) = @_;
>    for ($op) {
>        $_ eq '>' and return($left > $right);
>        $_ eq '<' and return($left < $right);
>	# etc.
>        return undef;
>    }
>}


One variation on this would be to create a hash of subroutines with
the various tests.

%test_condition = ( '>' => sub { return 1 if $_[0] > $_[1]; return 0 },
                    '<' => sub { return 1 if $_[0] < $_[1]; return 0 },
                    '=' => sub { return 1 if $_[0] == $_[1]; return 0 },
                   );

$test = '>';
$threshold = 500;
$fr = 1000;

die "Invalid test $test\n" unless $tests{$test};
$test_result = &{$test_condition{$test}}($fr,$threshold);
-- 
Andrew Langmead


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

Date: Tue, 15 Sep 1998 13:11:50 GMT
From: avern@hotmail.com
Subject: assigning file contents to a string
Message-Id: <6tlp2m$rn8$1@nnrp1.dejanews.com>

I know this is a very newbie-ish question, but I've already checked the FAQ. 
Does any know a very concise way (say, 1 line) to assign the contents of a
file to a string variable? I've seen instructions on processing a file
line-by-line or paragraph-by-paragraph, but I don't want to manipulate the
file contents in any way.  I just want to store the entire file in a
variable, so that I can later refer to the variable in a print statement. 
Can this be done without creating a sub-procedure?

Thanks in advance,
Avern

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Tue, 15 Sep 1998 16:13:10 +0100
From: Laurent LABRACHERIE <labrache@gaulois.cad.cea.fr>
Subject: Re: assigning file contents to a string
Message-Id: <35FE8406.8BA867B0@gaulois.cad.cea.fr>

avern@hotmail.com wrote:

> I know this is a very newbie-ish question, but I've already checked the FAQ.
> Does any know a very concise way (say, 1 line) to assign the contents of a
> file to a string variable? I've seen instructions on processing a file
> line-by-line or paragraph-by-paragraph, but I don't want to manipulate the
> file contents in any way.  I just want to store the entire file in a
> variable, so that I can later refer to the variable in a print statement.
> Can this be done without creating a sub-procedure?
>

try something like :$file = "file.dat";
open(FILE,"$file");
@line=<FILE>;

laurent




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

Date: Tue, 15 Sep 1998 11:36:41 -0500
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: assigning file contents to a string
Message-Id: <linberg-1509981136410001@ltl1.literacy.upenn.edu>

In article <6tlp2m$rn8$1@nnrp1.dejanews.com>, avern@hotmail.com wrote:

> I know this is a very newbie-ish question, but I've already checked the FAQ. 
> Does any know a very concise way (say, 1 line) to assign the contents of a
> file to a string variable? I've seen instructions on processing a file
> line-by-line or paragraph-by-paragraph, but I don't want to manipulate the
> file contents in any way.  I just want to store the entire file in a
> variable, so that I can later refer to the variable in a print statement. 
> Can this be done without creating a sub-procedure?

$bigstring = join ('', <FILE>);
_____________________________________________________________________
Steve Linberg                       National Center on Adult Literacy
Systems Programmer &c.                     University of Pennsylvania
linberg@literacy.upenn.edu              http://www.literacyonline.org


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

Date: Tue, 15 Sep 1998 15:49:59 GMT
From: hex@voicenet.com (Matt Knecht)
Subject: Re: assigning file contents to a string
Message-Id: <H0wL1.27$XP2.491556@news3.voicenet.com>

avern@hotmail.com <avern@hotmail.com> wrote:
>Does any know a very concise way (say, 1 line) to assign the contents of a
>file to a string variable?

Well, It's s stretch to get it on one line, but this should be the
quickest way:

{ local $/; $file_contents = <FILE>; }

I'd probably write that as: 

{
    local $/;
    $file_contents = <FILE>;
}

But I'm a big fan of wasted key-strokes. :)

-- 
Matt Knecht - <hex@voicenet.com>


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

Date: 15 Sep 1998 09:50:34 -0400
From: vgabriel@lochaber.rutgers.edu (Vladimir Gabrielescu)
Subject: ch(mod/own) and links
Message-Id: <6tlrba$7qk$1@lochaber.rutgers.edu>

Hiya.

The perl chmod and chown functions seem to always operate on the real
file and not on a link pointing to it. For example if "foo" is a link to 
"bar" ( foo -> bar ) and I chown "foo", foo retains its ownership and bar
changes. Same stands true for chmod. 

This has the obvious question: huh? How in the world am it to change 
ownership and permissions on a link? I guess what I'm looking for is
the equivalent of the "chmod -h" which Solaris provides. 

Any help would be appreciated, mail prefered.

Vlad



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

Date: 15 Sep 1998 14:46:37 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: ch(mod/own) and links
Message-Id: <6tlukd$r9$4@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, vgabriel@lochaber.rutgers.edu (Vladimir Gabrielescu) writes:
:The perl chmod and chown functions seem to always operate on the real
:file and not on a link pointing to it. For example if "foo" is a link to 
:"bar" ( foo -> bar ) and I chown "foo", foo retains its ownership and bar
:changes. Same stands true for chmod. 

This has nothing to do with Perl.  This is a matter for your operating
system alone.  Perl gives access to your operating system's system calls.
What that system cares to do with these calls is beyond perl's control.

--tom
-- 
    It's there as a sop to former Ada programmers.  :-)
        --Larry Wall regarding 10_000_000 in <11556@jpl-devvax.JPL.NASA.GOV>


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

Date: Tue, 15 Sep 1998 10:59:35 -0400
From: "Bill Jones, FCCJ Webmaster" <webmaster@fccjmail.fccj.cc.fl.us>
Subject: Re: ch(mod/own) and links
Message-Id: <35FE80D7.B9946A60@fccjmail.fccj.cc.fl.us>

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

Vladimir Gabrielescu wrote:
> 
> Hiya.
> 
> The perl chmod and chown functions seem to always operate on the real
> file and not on a link pointing to it. For example if "foo" is a link to
> "bar" ( foo -> bar ) and I chown "foo", foo retains its ownership and bar
> changes. Same stands true for chmod.
> 
> This has the obvious question: huh? How in the world am it to change
> ownership and permissions on a link? I guess what I'm looking for is
> the equivalent of the "chmod -h" which Solaris provides.
> 
> Any help would be appreciated, mail prefered.
> 
> Vlad

You can't change the link itself, why whould you want to?

PS - My Solaris must be different than yours:
(See attached/below...)

__________________________________________________________________
Bill Jones FCCJ Webmaster | http://www.fccj.org/cgi/mail?webmaster
__________________________________________________________________
We are the CLPM... Lower your standards and surrender your code...
We will add your biological and technological distinctiveness to 
our own... Your thoughts will adapt to service us...
 ...Resistance is futile...
--------------FFE6E4C1B833049E1827F74D
Content-Type: text/plain; charset=us-ascii; name="attach"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="attach"

SunOS 5.5.1          Last change: 1 Feb 1995                    5

chmod(1)                  User Commands                  chmod(1)
$ chmod -h
usage:  chmod [-fR] <absolute-mode> file ...
        chmod [-fR] <symbolic-mode-list> file ...
where   <symbolic-mode-list> is a comma-separated list of
        [ugoa]{+|-|=}[rwxXlstugo]


--------------FFE6E4C1B833049E1827F74D--



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

Date: Tue, 15 Sep 1998 13:58:28 GMT
From: andy_williams@my-dejanews.com
Subject: Communicating between server and client!!
Message-Id: <6tlrq5$uvm$1@nnrp1.dejanews.com>

I have written a server to process requests from a client and then
return a "OK"/"NOT OK" message to the client
depending on success.

The client sends the request to the server ok, but I cant get the server
to return anything to the client.
Please help.

Andy

----------CODE--------

SERVER
=======
# Temporarily set default output to the handle NS
select(NS);


$| = 1;

select(STDOUT);

# Create socket

socket(S,AF_INET,SOCK_STREAM,$proto) || die "socket : $!";


$sockaddr = 'S n a4 x8';
$this = pack($sockaddr, AF_INET, $port, "\0\0\0\0");
bind(S, $this) || die "bind : $!";


listen(S,10) || die "listen: $!";

select(S);
$| = 1;
select(STDOUT);

#
# Create connections as clients "arrive".
#
for (;;) {

    $SIG{CHLD} = \&REAPER;
    ($addr = accept(NS,S)) || die $!;
    # The 'fork' creates a child process to handle this client.

    if (($child = fork()) == 0) {

         # We're the child...

         # unpack the information returned by 'accept' to get some
         # (readable) information about the client we're serving and
         # print it to standard output

         ($af,$port, $inetaddr) = unpack($sockaddr, $addr);
         @inetaddr = unpack('C4', $inetaddr);

         #  Convert internet address into something decent....

         $iaddr = "$inetaddr[0].$inetaddr[1].$inetaddr[2].$inetaddr[3]";

         # Compare IP address eventually.

         while (<NS>) {

             chomp;
             if (/^GET\s+(\S+)/) {
                 &processGet($1, $iaddr, NS);
             }

         }

         # Close the socket connection when the client goes away
         close(NS);
         # The forked server dies here
         exit;
   }


   close(NS);
}

sub processGet {

    my $data = shift;
    my $iaddr = shift;
    my $fh = shift;

    my $dt = scalar localtime;

    #
    # There will be a whole list of directives
    # e.g. Hello etc
    #
    print "$data\n";
    my ($directive, $request) = split(/\:/, $data, 2);

    if ($directive eq "hello") {

        print $fh "OK\n"; # This should send OK back to the client
        #print NS "OK\n"; # Doesn't work either

}


CLIENT
======

    $iaddr = inet_aton($remote) or die "No host : $remote\n";
    $paddr = sockaddr_in($port, $iaddr);
    $proto = getprotobyname('tcp');
    socket(SOCK, PF_INET, SOCK_STREAM, $proto) or die "Socket : $!\n";
    connect(SOCK, $paddr);

    # Send message to Server
    print SOCK "GET hello:This+is+a+test";

    # Get message back from server... THIS HANGS UP THE CLIENT
    while ($_=<SOCK>)  {
        next unless $_;
        print;
    }
    close (SOCK);

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Tue, 15 Sep 1998 14:51:17 GMT
From: Farhad Farzaneh <ff@otis.arraycomm.com>
Subject: Re: difference between 'my' and 'local'?
Message-Id: <vuogshctui.fsf@otis.arraycomm.com>

jedihawk@mail.com (Kevin Hawkins) writes:

> 
> What's the difference between 'my' and 'local'?
> 
> I've been using 'my' for most of my subs, to keep the variables in
> their own, seperate stack, like this:
> 
>   sub test { my ($var1, $var2, $var3) = @_;
>     ...
>   }
> 
> Would it be a better idea to use 'local', like this:
> 
>   sub test { local ($var1, $var2, $var3) = @_;
>     ...
>   }
> 

My understanding is that the use of my is recommended over local.  Local
variables are put into the symbol table whereas my variables are not.  
Using my should be slightly more efficient.  Using local can be useful if
you want to override a predefined variable like $' or $, only for the
duration of a block.  You can define it using local (but not my), reassign
it to a new value, and when you exit the block the old value of the
variable is put back.

-- 
Farhad


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

Date: Tue, 15 Sep 1998 15:18:02 GMT
From: benday@c-bridge.com
Subject: Re: Edit in place problem with ActivePerl 5.005_002
Message-Id: <6tm0f9$4g1$1@nnrp1.dejanews.com>

You were right about the wild card not expanding.  I tried running it under NT
Korn Shell and it worked.

The reason I say that this is ActivePerl is that I've run this type of perl
program from the regular NT4 command line shell and it worked....but I was
using a different flavor of perl.

I've found a work around but I'd still like to run this using the regular NT
shell.

-Ben

In article <6tl7nq$9pv$1@nnrp1.dejanews.com>,
  dave@mag-sol.com wrote:
> In article <6tjvrv$p4o$1@nnrp1.dejanews.com>,
>   benday@c-bridge.com wrote:
> > I've used the following command a billion times but never with ActivePerl
> > for NT.
> >
> > perl -p -i.bak -e "s/foo/bar/g;" *.htm
> >
> > It says "Can't open *.htm: Invalid argument"
> >
> > I'm baffled.
> >
> > Does anyone what what I'm doing wrong?
>
> Ben,
>
> This isn't a Perl problem. You're using a shell that doesn't do automatic
> wildcard expansion before passing the command line to a program. This is a
> *bad* thing.
>
> Use Unix.
>
> hth,
>
> Dave...
>
> --
> dave@mag-sol.com
> London Perl M[ou]ngers: <http://www.mag-sol.com/London.pm/>
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum
>

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Tue, 15 Sep 1998 08:50:18 -0500
From: Tom Turton <tturton@cowboys.anet-dfw.com>
Subject: File mod time in future?
Message-Id: <35FE709A.C9D9BFCD@cowboys.anet-dfw.com>

In some simple scripts I've written, I've used (with no problems before)
a file modification test to see how long since a file has been modified:

     if (-M $filename >= $age_set) {}

Now one of my scripts is not executing the if-block code, and when I put
debug print statements I find that the modification time is NEGATIVE!?
About 5-7 minutes (-0.0037037 to -0.004976851851).

Additional info:  $filename is created during the running of the script
in which I am checking the file mod time, but I "assumed" that it would
have a very small POSITIVE number.

Program flow:
Main script "A" --> calls subroutine "B" --> subroutine runs a separate
perl script, "C", which creates the $filename file.  Upon return to main
body of script, if test performed on mod time.  $age_set is set equal to
0

Is there something keeping the file open upon return from the script
which created it?  I did not do an explicit close on the file, but
shouldn't this occur automatically on returning from "C" and "B"?

Thanks.

---Tom Turton



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

Date: Tue, 15 Sep 1998 15:27:47 +0100
From: Julian Gilbey <J.D.Gilbey@qmw.ac.uk>
Subject: Re: File mod time in future?
Message-Id: <35FE7963.5667D08D@qmw.ac.uk>

Tom Turton wrote:
> 
> In some simple scripts I've written, I've used (with no problems before)
> a file modification test to see how long since a file has been modified:
> 
>      if (-M $filename >= $age_set) {}
> 
> Now one of my scripts is not executing the if-block code, and when I put
> debug print statements I find that the modification time is NEGATIVE!?
> About 5-7 minutes (-0.0037037 to -0.004976851851).

Have you taken into account the fact that -M reports the modification
time in days FROM THE TIME THE SCRIPT STARTED EXECUTING?  If you don't
want this, then perhaps try something like:

#!/usr/bin/perl
$now=time;

[ rest of code ]

if ((-M $filename) + $now >= time) {...}

HTH,

   Julian


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

            Julian Gilbey             Email: J.D.Gilbey@qmw.ac.uk
       Dept of Mathematical Sciences, Queen Mary & Westfield College,
                  Mile End Road, London E1 4NS, ENGLAND
      -*- Finger jdg@goedel.maths.qmw.ac.uk for my PGP public key. -*-


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

Date: Tue, 15 Sep 1998 15:06:17 GMT
From: syarbrou@ais.net (Steve .)
Subject: Re: finding out yesterdays date
Message-Id: <35fe8242.934297@news.ais.net>

Wish I could but the stupid dos program that creates the original text
file is not y2k compliant and we do not have the source code to fix
it.

Steve

On 15 Sep 1998 04:09:00 GMT, neil@domingo.concordia.ca (Neil
Kandalgaonkar) wrote:

>In article <35fd5a3e.8691503@news.ais.net>, Steve . <syarbrou@ais.net> wrote:
>>I have a system that outputs a comma delimited file and then is passed
>>to my linux box.  The first field is the date like 09/14/98.  The date
>
>hm, I wonder what would happen in the year 2000? 
>
>come to think of it, there are a lot of programs out there like this...
>
>it's 1998 -- use four digit years.
>



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

Date: 15 Sep 1998 14:36:50 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Getting multiple scripts to read same configuration file
Message-Id: <6tlu22$r9$1@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, jauderho@transmeta.com writes:
:Secondly, formatting of the conf file, should I actually write something to
:extract the variables to be set or should I be lazy, do a bad thing and just
:using require have stuff like
:
:$ENV{PATH} =            "/bin:/usr/bin";
:$date =                 `/bin/date '+%m-%d-%y.%H:%M:%S'`;
:$etcdir =               "/etc";
:
:just pre defined and ready to go? 

Certainly you should just require the config file, which is in perl as you
have it there.  No good reason to writing parsing code, and many not to.
Perl parses already, and allows infinite flexibility.

--tom
-- 
    Actually, you'll know we're nearing the end when I make |$foo| mean
    "absolute value"...  :-) Larry Wall in <1994Feb25.192042.17196@netlabs.com>


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

Date: Tue, 15 Sep 1998 14:07:43 GMT
From: andy_williams@my-dejanews.com
Subject: Re: help with perl reg. expr.
Message-Id: <6tlsbe$vma$1@nnrp1.dejanews.com>

In article <6tkb2b$8on$1@nnrp1.dejanews.com>,
  david@ceres.ca.gov wrote:
> Hello
> 	I was hoping someone out there has a perl script which can do the
> following with each entry in a flatfile database. Change each pipe
> delimited entry from:
>
> http://html-resources.com| HTML Resources |10-Sep-1998|cgi/misc|Great place
> for html resources |
>
> to:
> 1|HTML Resources|http://html-resources.com|10-Sep-1998|cgi/misc|Great place
> for html resources |
>
> The number at the beginning of the entry needs to increment by one for each
> entry
>
> Thanks in advance
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum
>

Not really a question for here. Doesn't look like you've tried to do it
yourself.

However try this...

$count = 1;
while (<>) {
    @f = split(/\|/);
    print "$count\|$f[1]\|$f[0]\|$f[2]\|$f[3]\|$f[4]\n";
    $count++;
}

Andy Williams

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Tue, 15 Sep 1998 15:38:53 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: make DBD problem
Message-Id: <35FE87AB.7E1D3C1@bbnplanet.com>

Koos Schut wrote:

> make: Warning: Can't find `make.rules': No such file or directory
> LD_RUN_PATH="/local/bin/oracle/lib:/lib" 

This is just a guess, but you might want to loose the LD_RUN_PATH and 
try again. 

-- 
e.

"All of us, all of us, all of us trying to save our immortal souls, some
ways seemingly more round-about and mysterious than others. We're having
a good time here. But hope all will be revealed soon."  R. Carver


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

Date: 15 Sep 1998 14:40:00 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: milliseconds?
Message-Id: <6tlu80$r9$3@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, miho21@yahoo.com writes:
:Huh? can anyone explain that please? what does qw has to do with anything???
:qw is a built in function? how come i never heard of it?

Because you haven't checked the manpages or read much Perl code?

--tom
-- 
Pointers are sharp tools, and like any such tool, used well they can
be delightfully productive, but used badly they can do great damage
(I sunk a wood chisel into my thumb a few days before writing this).
    --Rob Pike


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

Date: 15 Sep 1998 10:08:17 -0400
From: akuchlin@cnri.reston.va.us (Andrew M. Kuchling)
Subject: Re: Perl & Java - differences and uses
Message-Id: <3dbtohcvu6.fsf@amarok.cnri.reston.va.us>

Zenin <zenin@bawdycaste.org> writes:
>         Just a personal commentary.  I've been playing with the features
>         of the newest Perl through the beta and for many of the systems I
>         build I don't think I could live without them anymore.  I primarily

	That's interesting; what 5.005 regex features do you use, and
for what purpose?  From the list of:

	1) Lookbehinds
	2) (?> )
	3) The conditional notation (?(cond)true|false)
	4) Calling Perl code from inside a regex.

	None of these except feature 4 seems a vast advance over
5.004's notation.  My intuition is that they're all aimed at highly
sophisticated users, and most uses of regular expressions are simple.
In particular, 2 and 4 require that you have a very good idea of how
the regular expression engine operates.  Relatively few users seem to
have this understanding; consider all the people who seem startled to
find that <.*> matches "<title>A Season in Hell</title>" and not
"<title>").

	Philip Hazel seems to be working on 1 and 3 for PCRE as used
in exim; 2 is already there, but not available from Python for
historical reasons.  That leaves feature 4, which is irrelevant for
exim, so PH won't be implementing it, and I'm willing to wait and see
if and how embedded code gets used over 5.005's life-cycle.  


-- 
A.M. Kuchling			http://starship.skyport.net/crew/amk/
The spreadsheet matrix is a creative prison bound by A1 and Z1000. Walls. A
psychological prison. Unlike the Black Death, nobody sees this malady. There
will be no cure. Soon it will be too late.
    -- John C. Dvorak


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

Date: 15 Sep 98 14:08:00 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Perl & Java - differences and uses
Message-Id: <905868425.452048@thrush.omix.com>

Abigail <abigail@fnx.com> wrote:
: Zenin (zenin@bawdycaste.org) wrote on MDCCCXLI September MCMXCIII in
: <URL: news:905830672.564598@thrush.omix.com>:
        >snip<
: Please show me an easy to use data encapsulation method to use with
: Perl-OO. (Beyond the simple "Don't touch that!") I've been looking for years.

        Are you looking for a real electric fence, or just something that
        looks like one?  I was working on a real one with the electricity
        turned off, until the betas of 5.005 got fields.pm, which did
        a bulk of what I was trying to do in a much better way.

        The electricity is still turned off though.  The only way I've found
        to turn it up is to tie your object's thingy, which forces two
        method lookups for every access. :-(  Fields.pm helps, but only
        for compile time.  Run time lookups are wide open.

        You can get by this a bit better in some ways by tieing each field's
        thingy as needed to a scalar class.  I like this method with
        field.pm, because it gives the best of all worlds IMHO.  It removes the
        silly set/get method calls for everything, but if you need to have
        some you can simply tie those fields so the access is magical.  The
        field.pm pragma takes care of typos, mostly.  In this design:

                $obj->{foo} = "bar";

        May, or may not call a setFoo() method.  The user need not know or
        care, but the power of encapsulation is maintained along side the
        ease of use and efficiency of public fields.  This feels the
        most Perlish to me, as well as being an interesting way of extending
        the semantics of how encapsulation normally looks and works.

        All that said, you're right.  There is no way to fully keep someone
        out of your sand box if they really want in.  And there is no
        simple way to put up a big fence.

-- 
-Zenin (zenin@archive.rhps.org)           From The Blue Camel we learn:
BSD:  A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts.  Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.)  The full chemical name is "Berkeley Standard Distribution".


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

Date: Tue, 15 Sep 1998 14:45:45 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: PERL and Updating files
Message-Id: <35FE7B36.AAC7B953@bbnplanet.com>

Mark-Jason Dominus wrote:

> Yes, it will.  It'll do anything you ask it to.  You let `find' do the
> directopry recursing part, and it calls the subroutine which you
> procivde, which can open each file and do the substitutions.

I was, perhaps, being a bit too literal. My point was merely that find
alone will not do the job the original question was seeking to do. 

-- 
e.

"All of us, all of us, all of us trying to save our immortal souls, some
ways seemingly more round-about and mysterious than others. We're having
a good time here. But hope all will be revealed soon."  R. Carver


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

Date: 15 Sep 1998 14:07:04 GMT
From: gkropitz@ghome.intern.Austria.EU.net (Gerald Kropitz)
Subject: reserving explicit memory for a hash reference...
Message-Id: <slrn6vsth1.6r1.gkropitz@ghome.intern.Austria.EU.net>

while (%ccc = $qh->fetchhash) {
	push @{$zzz[0]}, \%ccc;
}

after finishing the loop i can pop from zzz but the hash
reference seems to be dysfunctional... i suspect that i'm
overwriting the same memory area every loop...

my temporary solution is:

while (%ccc = $qh->fetchhash) {
	$ggg = &ugly(%ccc);
	push @{$zzz[0]}, $ggg;
}

sub ugly {
	my %hash = @_;
	return \%hash;
}

is there a more intelligent solution out there?

TIA

-gerald


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

Date: Tue, 15 Sep 1998 09:21:58 EDT
From: dblack@saturn.superlink.net (David A. Black)
Subject: Re: script: scriptMangle!
Message-Id: <6tlplm$j7e$1@earth.superlink.net>

Hello -

jauderho@transmeta.com (Jauder Ho) writes:


>something I wrote a long time ago. it almost works, the last I remmeber is
>that it didn't handle print statements all that well. Hopefully someone will
>take this and fix it up. Just a little exmaple of what too much time on your
>hands can do to you...


For those of us who like to stay one step ahead of this kind of thing
(and/or disapprove of it on various grounds), here's a quick antidote.
Like the original, it almost works.  Actually, since its real purpose 
is to suggest that code mangling can be substantially countered by an 
intermediate Perl programmer over his morning coffee, perhaps it
completely works.


David Black
dblack@saturn.superlink.net


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

# Usage:  perl unmangle filename
#
# where filename is a ".mangle" file from the mangle script.
#
# The result is ugly but much more readable.
#
# This is pretty scrappy code.  It's just a quick demo of the
# pointlessness of making code unreadable.  (Or maybe I've
# proven the opposite point :-)


use strict;

my $all = do {local $/=undef; <>};
$all =~ s/\n/ /g;
my @lines = $all =~ /(.*?;)/g;

my $suname  = "sub01";
my $scname  = "sca01";
my $arname  = "arr01";
my $haname  = "has01";

my (%subs, %scas, %arrs, %hass) = ();

for my $l (@lines) {
    for ($l=~/sub\s+(\w{13})/g)      { if (!$subs{$1}) {$subs{$1}=$suname++} }
    for ($l=~/\$([^\W_]{13})/g)      { if (!$scas{$1}) {$scas{$1}=$scname++} }
    for ($l=~/\@(\w{13})/g)          { if (!$arrs{$1}) {$arrs{$1}=$arname++} }
    for ($l=~/\$(\w{13})\[[^\]]\]/g) { if (!$arrs{$1}) {$arrs{$1}=$arname++} }
    for ($l=~/\%(\w{13})/g)          { if (!$hass{$1}) {$hass{$1}=$haname++} }
    for ($l=~/\$(\w{13})\{[^}]\}/g)  { if (!$hass{$1}) {$hass{$1}=$haname++} }
} 

my $prog = join "", @lines;

# Null keys are showing up - esp. when unmangling the mangled mangle script
# itself.  There's interference somewhere between its regexes and mine.
# I haven't unmangled this... but the 'next's are a workaround.  (The keys
# are all $1's from pattern matches.  Whence the nulls?)

for my $ar (keys %arrs) {
    next unless $ar;
    $prog =~ s/$ar/$arrs{$ar}/g
}

for my $ha (keys %hass) {
    next unless $ha;
    $prog =~ s/$ha/$hass{$ha}/g
}

for my $sc (keys %scas) {
    next unless $sc;
    $prog =~ s/$sc/$scas{$sc}/g;
}

for my $su (keys %subs) {
    next unless $su;
    $prog =~ s/$su/$subs{$su}/g
}

$prog =~ s/(for.*?{)/$1\n\t/g;
$prog =~ s/(while.*?{)/$1\n\t/g;
$prog =~ s/(}\s+)([^=])/$1\n$2/g;
$prog =~ s/(sub.*?{)/$1\n\t/g;
$prog =~ s/;/;\n/g;

print $prog;


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

Date: 15 Sep 1998 14:39:05 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: script: scriptMangle!
Message-Id: <6tlu69$r9$2@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, jauderho@transmeta.com writes:
:# This will hopefully render a perl script mostly unreadable so
:# that others can't easily steal your code.

Why in God's name would you do such an evil thing, and then show it to
others as well?

And I don't see any write-only mode on the filesystem here, so I don't
think that this prevents a cp.

There are only two solutions to preventing "theft": either give the
thing away right from the get-go, or else slap a killer licence on it.

--tom
-- 
A factor of 3000 is actually significant --Andrew Hume


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

Date: Tue, 15 Sep 1998 16:50:30 +0200
From: Oliver Czoske <oczoske@astro.obs-mip.fr>
Subject: Re: selective split
Message-Id: <35FE7EB6.6CEF@astro.obs-mip.fr>

Brock Sides wrote:
> 
> In article <35FD2E00.5F5E@astro.obs-mip.fr>, Oliver Czoske
> <oczoske@astro.obs-mip.fr> wrote:
> 
> > Hi,
> > this should be a very common problem, but as I'm not used to regexps I
> > haven't yet found a solution. What I want to do is to split a database
> > entry where the fields are separated by ':'. Now, the fields themselves
> > may contain colons which are then masked by a backslash. How do I get
> > split to split at colons unless they are preceded by a backslash?
> >
> > Thanks for any help.
> 
> Well, since I'm sure you've upgraded to 5.005 (you have upgraded to 5.005,
> right?), you can use the wonderful addition of "lookbehind assertions":
> 
> my @fields = split /(?<!\\):/, $record;

No, I haven't yet upgraded. MAybe I will... Anyway, I solved my problem
using a very dirty hack: I first replaced the combination \: by a very
uncommon character (v, luckily my data are all numbers or English),
split, and then rereplaced the v by \:. Not nice, but it did the job. 

-- 


--------------------------------------------------------------------
Oliver Czoske			e-mail: oczoske@ast.obs-mip.fr
Observatoire Midi-Pyrenees	Tel.:   +33 5 61 33 28 29
14, av. Edouard Belin           Fax:    +33 5 61 33 28 40
31400 Toulouse         
--------------------------------------------------------------------

http://www.obs-mip.fr/omp/umr5572/people/oczoske/index.html


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

Date: 15 Sep 1998 07:42:48 -0700
From: Brad Murray <murrayb@vansel.alcatel.com>
Subject: Re: STD I/O for WIN32 Perl
Message-Id: <u67epo2s7.fsf@vansel.alcatel.com>

Terry Gliedt <tpg@cls.uob.com.sg> writes:

> I've seen this fail too. Seems that on NT the file association code
> behaves a little surprisingly. I think you'll find that this will work.

But it shouldn't behave randomly.  I use the following association and
I get quite satisfactory results.  It is not the way NT sets up the
association for you (bad NT): 

  perl->Shell->Open->Command (Default) = "c:/perl/bin/perl.exe %0 %*"

> 
>     perl myperl.pl < foo-in.txt > foo-out.txt
> 
> This is the case with perl, version 5.004_02 in my world at least

This circumvents the problem entirely and has the added benefit of not
requiring special client configuration in order to work properly.  It's
my preference for delivered tools.


-- 
Brad Murray       "The fall of modern man will be preceded by the
Software Analyst   de-evolution of communications to the days of
Alcatel Canada     oral tradition."  --Tom Christiansen paraphrased


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

Date: Tue, 15 Sep 1998 14:35:01 GMT
From: Farhad Farzaneh <ff@otis.arraycomm.com>
Subject: strict and Exporter
Message-Id: <vur9xdculm.fsf@otis.arraycomm.com>


Hello,

I'm trying to get all my scripts to 'use strict' but have run into trouble
with some that export variables that I use as constants in other scripts.
My understanding and experience is that you can't export lexical variables
because they're not in the namespace.  However if I define some variables
for export using local, I can't use strict without further specifications.
Is this understanding correct and is there a clean workaround?

file a.pm:
---- -----
#!/bin/perl

package a;

use Exporter;
@ISA = ('Exporter');
@EXPORT_OK = qw($x);

use strict;

$x = 10;

1;

file b:
---- -:

#!/bin/perl

use a('$x');

print "x = $x\n";

----------

Without the 'use strict' line, I get 

   x = 10

With the use strict line, I get

   Global symbol "x" requires explicit package name at a.pm line 11.
   Compilation failed in require at b line 3.
   BEGIN failed--compilation aborted at b line 3.

Changing 
   $x = 10;
to
   my $x = 10;

gives 
  x=

-- 
Farhad


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

Date: Tue, 15 Sep 1998 11:36:18 EDT
From: dblack@saturn.superlink.net (David A. Black)
Subject: Re: strict and Exporter
Message-Id: <6tm1hi$6s3$1@earth.superlink.net>

Hello -

Farhad Farzaneh <ff@otis.arraycomm.com> writes:


>file a.pm:
>---- -----
>#!/bin/perl

>package a;

>use Exporter;
>@ISA = ('Exporter');
>@EXPORT_OK = qw($x);

>use strict;

>$x = 10;

>1;

>file b:
>---- -:

>#!/bin/perl

>use a('$x');

>print "x = $x\n";

>----------

>Without the 'use strict' line, I get 

>   x = 10

>With the use strict line, I get

>   Global symbol "x" requires explicit package name at a.pm line 11.
>   Compilation failed in require at b line 3.
>   BEGIN failed--compilation aborted at b line 3.

>Changing 
>   $x = 10;
>to
>   my $x = 10;

>gives 
>  x=

Add this line after use strict in a.pm:

use vars qw($x);

What that means is: "Even though I've said use strict, compiler, please
let me just say '$x' without saying '$package::x'."

The other choice would be to qualify $x fully:

$a::x = 10;

David Black
dblack@saturn.superlink.net


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

Date: Tue, 15 Sep 1998 13:34:46 GMT
From: perlperlperl@my-dejanews.com
Subject: Transposing an array
Message-Id: <6tlqdm$t1t$1@nnrp1.dejanews.com>

Disclaimer: I have Programming Perl (first edition), Learning Perl (first
edition), Programming Perl (second edition), Effective Perl Programming
(1998), Perl The Programmer's Companion (1997), Perl Resource Kit, and the
Perl Cookbook. I read these books and the FAQ and searched DejaNews and found
nothing.

APL provides a generalized transpose function for interchanging the
coordinates of an array. Is there a corresponding function in perl, or an
easy way to get from @a to @b, where:

   @a = ([1, 2, 3],
         [4, 5, 6]);

and:

   @b = ([1, 4],
         [2, 5],
         [3, 6]);

?

The next step of this question is how to convert the above to a hash.
Suppose you have a multidimensional array of names and IQ scores:

   @c = (['Larry Wall', 200],
         ['Tom Christiansen', 180],
         ['Gary Burnore', 0]);

How can this be transformed into the following:

   %d = (names => ['Larry Wall', 'Tom Christiansen', 'Gary Burnore'],
         iqs   => [200, 180, 0]);

?

Thanks for any pointers and suggestions.

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Tue, 15 Sep 1998 10:11:36 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Transposing an array
Message-Id: <Pine.GSO.3.96.980915100832.14186A-100000@crusoe.crusoe.net>

> The next step of this question is how to convert the above to a hash.
> Suppose you have a multidimensional array of names and IQ scores:
> 
>    @c = (['Larry Wall', 200],
>          ['Tom Christiansen', 180],
>          ['Gary Burnore', 0]);
> 
> How can this be transformed into the following:
> 
>    %d = (names => ['Larry Wall', 'Tom Christiansen', 'Gary Burnore'],
>          iqs   => [200, 180, 0]);

Like so: (this can be compacted, but I want to show the mechanism well)

@names = map { $_->[0] } @c;
@iqs = map { $_->[1] } @c;

%d = ( names => [@names], iqs => [@iqs] );


--
Jeff Pinyan (jeffp@crusoe.net)
www.crusoe.net/~jeffp

Crusoe Communications, Inc.
973-882-1022
www.crusoe.net



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

Date: 15 Sep 1998 14:18:56 GMT
From: gbacon@itsc.uah.edu (Greg Bacon)
Subject: Re: Transposing an array
Message-Id: <6tlt0g$78e$1@info.uah.edu>

In article <6tlqdm$t1t$1@nnrp1.dejanews.com>,
	perlperlperl@my-dejanews.com writes:
: APL provides a generalized transpose function for interchanging the
: coordinates of an array. Is there a corresponding function in perl, or an
: easy way to get from @a to @b, where:
: 
:    @a = ([1, 2, 3],
:          [4, 5, 6]);
: 
: and:
: 
:    @b = ([1, 4],
:          [2, 5],
:          [3, 6]);

If you're looking for a builtin, you won't find it.  I suspect PDL
(Perl Data Language--find it on the CPAN) probably can do something
like this.  You could always roll your own:

    sub transpose {
        my @old = @_;
        my @new;

        for (my $i = 0; $i < @old; $i++) {
            for (my $j = 0; $j < @{ $old[$i] }; $j++) {
                $new[$j][$i] = $old[$i][$j];
            }
        }

        @new;
    }

Perhaps a little more Perlishly:

    sub transpose {
        my @old = @_;
        my @new;

        foreach my $row (@old) {
            my $i = 0;
            foreach my $elt (@$row) {
                push @{ $new[$i++] }, $elt;
            }
        }

        @new;
    }

: The next step of this question is how to convert the above to a hash.
: Suppose you have a multidimensional array of names and IQ scores:
: 
:    @c = (['Larry Wall', 200],
:          ['Tom Christiansen', 180],
:          ['Gary Burnore', 0]);
: 
: How can this be transformed into the following:
: 
:    %d = (names => ['Larry Wall', 'Tom Christiansen', 'Gary Burnore'],
:          iqs   => [200, 180, 0]);

I would be amazed to find a builtin that intuits key names correctly. :-)

    for (@c) {
        push @{ $d{names} }, $_->[0];
        push @{ $d{iqs}   }, $_->[1];
    }

but it would probably be better to do

    for (@c) {
        my($name,$iq) = @$_;

        $iq{$name} = $iq;
    }

Hope this helps,
Greg
-- 
I used to be sad because I had no woman.  Then I met a man who had no hands. 
    -- Rick Riebs


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

Date: 15 Sep 1998 15:03:26 GMT
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Web Chat
Message-Id: <35FE8129.329908DD@vpservices.com>

A webcrawler search for "web chat" returns 6 pages of results.  Some of
these are spurious, but a number refer to perl/web chat software.

- Jeff

Marc Lopez wrote:
> Where I can find a Web-based chat in perl that it allows 30 people
> to talk and the rest only can read the conversation?


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

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


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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