[10784] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4385 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 8 23:07:21 1998

Date: Tue, 8 Dec 98 20:00:20 -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           Tue, 8 Dec 1998     Volume: 8 Number: 4385

Today's topics:
    Re: @INC newbie question (Tad McClellan)
    Re: Beginner Book? (Ronald J Kimball)
    Re: Better way to get values from a list? (Tad McClellan)
    Re: Better way to get values from a list? ptimmins@netserv.unmc.edu
    Re: Better way to get values from a list? (Ronald J Kimball)
    Re: Can someone tell me why .... <zenin@bawdycaste.org>
    Re: Can someone tell me why .... (Ronald J Kimball)
    Re: Errors with SETUID and Perl Script (Tad McClellan)
    Re: Errors with SETUID and Perl Script (Ronald J Kimball)
    Re: flock doesn't flock under perl/linux (Tad McClellan)
    Re: flock doesn't flock under perl/linux (Tad McClellan)
    Re: flock doesn't flock under perl/linux <dgris@moiraine.dimensional.com>
    Re: Hash slices - why are these equivalent?... (Ronald J Kimball)
    Re: Hash slices - why are these equivalent?... <rick.delaney@home.com>
    Re: Is there a 'predeclare subs' module ? (Mark-Jason Dominus)
    Re: Java in PERL <zenin@bawdycaste.org>
    Re: Not a subroutine reference (Ronald J Kimball)
    Re: please help.. <ng@usa.net>
        Regular Expressions <barcode@ice.net>
    Re: Regular Expressions <rick.delaney@home.com>
    Re: Regular Expressions (Larry Rosler)
    Re: Simple PERL on PC ? <zenin@bawdycaste.org>
        Still just a quickie <amcnulty@nortel.co.uk>
    Re: Storing In Memory <newsposter@cthulhu.demon.nl>
    Re: Why i can't "localize through a reference" in perl  (Ronald J Kimball)
    Re: Y2K potential problem in localtime() finsol@ts.co.nz
    Re: Y2K potential problem in localtime() (I R A Aggie)
    Re: Y2K potential problem in localtime() (Ronald J Kimball)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Tue, 8 Dec 1998 19:18:04 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: @INC newbie question
Message-Id: <c4jk47.841.ln@magna.metronet.com>

Cathy Huang (huang2@andrew.cmu.edu) wrote:

: I get this error message:
: Can't locate name_decoders.pl in @INC (@INC contains: c:\perl\lib\site
: c:\perl.....) at D:/listen/data/scripts\sessionify2.pl line 14.

: This is the code in sessionify2.pl, ending in line 14:
: -------------------
: use Cwd;
: $dir = cwd();
: print "sess2 dir = $dir\n";
: use lib $dir;
: #$dir2 = "d:\\listen\\data\\scripts\\";
: #use lib $dir2;

: require("name_decoders.pl");
: -------------------


   'use lib' is a *compile-time* thing, so it happens before the
   '$dir = cwd()' (a run-time thing).


use Cwd;

BEGIN { $dir = cwd() }  # use a BEGIN block

use lib $dir;



There are other alternatives as well.

The 'perldiag' man page describes all of the messages that perl
might issue.

See what it says about your message for the alternatives...



[ This has been asked and answered two other times in the last week.
  I am surprised that your Dejanews search didn't find it...
]


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


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

Date: Tue, 8 Dec 1998 22:31:42 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Beginner Book?
Message-Id: <1djqmae.6yniassy453wN@bay2-73.quincy.ziplink.net>

Jerome O'Neil <jeromeo@atrieva.com> wrote:

> Nnickee wrote:
> 
> > I answered the original post with what worked *for me*.
> 
> Ultimately, this is the only thing that matters.  If you like the book,
> and it helps you learn, then it's a good book.

With one significant caveat; someone who is using the book to learn Perl
probably will not recognize technical errors in the book.

What the book teaches is just as important as whether the book teaches.

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


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

Date: Tue, 8 Dec 1998 19:36:33 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Better way to get values from a list?
Message-Id: <17kk47.841.ln@magna.metronet.com>

Karl G. Jensen (karl_jensen@hp.com) wrote:

: I have an array with values in it of the form "a=b". The first entry in
: the array is a string with no "=" which I don't want to propagate.

: I want an array with values in it of the form "b".

: Here's how I did it:

:         foreach (@AB) {
:                 ($label, $field) = split('=');
:                 if ($field eq "") {
:                         next;   # Skip lines not of the form "a=b"

   But that skips *every* line without an equals sign.

   Above you said you wanted to skip the first entry.

   Which is it?

:                 }
:                 push @B, $field;
:         }


   You should be using the -w switch you know.

   Really.

   (and you should not ignore the messages it issues)

      #!/usr/bin/perl -w



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

@AB = qw/ one a=b c=d foo=bar nope perl=CGI(not!) /;

foreach (@AB) {
    push @B, $1 if /=(.*)/s;   # skip *all* lines that don't have an '='
}
foreach (@B) {print "$_\n"}


print "----------------------\n";


@B = @AB[1..$#AB];             # skip only the first array element
foreach (@B) {
   s/[^=]*=//;                 # delete up to the first '='
}
foreach (@B) {print "$_\n"}
------------------------------------------------


output:

b
d
bar
CGI(not!)
----------------------
b
d
bar
nope
CGI(not!)


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


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

Date: Wed, 09 Dec 1998 03:00:53 GMT
From: ptimmins@netserv.unmc.edu
Subject: Re: Better way to get values from a list?
Message-Id: <74kp55$2pd$1@nnrp1.dejanews.com>

In article <366DB24B.EE889DFA@hp.com>,
  karl_jensen@hp.com wrote:

> I'm looking for suggestions for a better way to code something.
>
> I have an array with values in it of the form "a=b". The first entry in
> the array is a string with no "=" which I don't want to propagate.

Don't have an array with values in the form of "a=b" ... have a hash
with a key of "a" and a value of "b" :) ... Seriously, if you have
a list of things in the form "a=b", there is usually a good reason
the two are linked together ... and a hash would be perfect for dealing
with this.

> I want an array with values in it of the form "b".
>
> Here's how I did it:
>
>         foreach (@AB) {
>                 ($label, $field) = split('=');
>                 if ($field eq "") {
>                         next;   # Skip lines not of the form "a=b"
>                 }
>                 push @B, $field;
>         }
>
> I expect that there is a way to do this in PERL with one line, without
> having to interate through the first array. Can someone kindly show me
> how?

Well, you'll still have to iterate through your array, but you could
eliminate checking for the first null field by shiftting it out:

        shift @AB;
        foreach (@AB) {
                ($label, $field) = split('=');
                push @B, $field;
        }

Notice in my example (and in yours), $label disappears in each iteration.
Are you sure you don't want to use a hash??? ... you might as well replace
$label above with 'undef'

Hope that helps

Patrick Timmins
$monger{Omaha}[0]

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


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

Date: Tue, 8 Dec 1998 22:31:46 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Better way to get values from a list?
Message-Id: <1djqmsi.crv4dgv03sowN@bay2-73.quincy.ziplink.net>

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

> #!/usr/local/bin/perl -w
> use Benchmark;
> 
> @a = qw(one two a=b c=d three e=f);
> 
> timethese ( (1 << (shift || 0) ), {
>     Join => sub { @result = join( "\n", @a ) =~ m/=(.+)$/mg },
>     Map  => sub { @result = map /=(.*)/, @a },
>     Push => sub { foreach (@a) { push @result, $1 if /=(.*)/ } },
> } );
> __END__
> 
> ActiveState 5.005_02 (mine, all mine)
> Benchmark: timing 65536 iterations of Join, Map, Push...
>       Join:  3 wallclock secs ( 4.52 usr +  0.00 sys =  4.52 CPU)
>        Map:  4 wallclock secs ( 5.03 usr +  0.00 sys =  5.03 CPU)
>       Push:  9 wallclock secs ( 8.55 usr +  0.09 sys =  8.64 CPU)

I don't think it will significantly change the Benchmark results, but
you should be aware that when the above Benchmark finished, the array
@result contained 199608 elements.

Push =>
   sub { @result = (); foreach (@a) { push @result, $1 if /=(.*)/ } },

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


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

Date: 09 Dec 1998 02:19:14 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Can someone tell me why ....
Message-Id: <913170020.427903@thrush.omix.com>

[posted & mailed]

Owen <info@kn1.com> wrote:
: this script for a chat programm does not delete the message database when
: the limit is reached. It does reset the counter to 0 but does not delete the
: database
: --------------------------------------
: #!/usr/local/bin/perl

	no -w?  For shame...
	No use strict either.... :-/

: # Perl version 5.004 usage (See documentation.)
: ################################################
: use 5.004;

	I still prefer BEGIN { require 5.004 } as older perls don't
	understand use VERSION.

: ###########################################################################
: # Simple Chat version 1.000 beta release 1
: #
: ###########################################################################
	>snip<

	This really should be in perldoc, no?

	=head NAME

	Simple Chat version 1.000 beta release 1
	
	=head DESCRIPTION

	Simple Chat is just that...a simplt program intended to serve as a
	chat room on your website.  To run Simple Char v1.0 you must have
	Perl installed on your server.
	
	...etc...

	=head1 AUTHOR
	
	Wesley M. Craft   wcraft@bellatlantic.net
	
	http://wmcdirectmg.hypermart.net
	
	=head1 HISTORY
	
	May 7, 1998 - Initial building of version 1 beta 1 begins.
	
	=cut
	
	See `perldoc perldoc' for details.

	>snip<
: # Read the fields NAME and MESSAGE from the form submission
: ###########################################################################
	>snip<

	Any reason you're not using the CGI module for this?

: # Dynamically display a new form.  If the user has spcified a name, it will
: # be used, otherwise the value in $defaultname will be used.
: ###########################################################################
: if ($cgilocation eq "")
: {

	Perl knows what is generally true and what is false.  This is more
	Perlishly writen as:

	if ($cgilocation) {
	    $cgilocation = $cgipath . "/" . $cginame;
	}
	else {
	    $cgilocation = $cginame;
	}

	Or even:

	$cgilocation = $cgilocation
	    ? $cgilocation = $cgipath . "/" . $cginame;
	    : $cgilocation = $cginame;

	And opening brackets should not be lined up with the closing, but
	maybe that's just me. :-)

	>snip<
: # Check the counter file to determine if we have reached the limit. If so,
: # we will delete the message database and start a fresh one.
: ###########################################################################
: open(cnter, "$cntrname");
: flock(cnter, LOCK_EX);
: read(cnter, $current, 2);

	Ack.... Always, but always test the return values of your system
	calls.  Strings inside of scalars need not be quoted.  Also, pretty
	much universal Perl coding convention has filehandles in all upper
	case:

	open CNTER, $cntrname
	    or die "Can not open '$cntrname': $!, stopped";

	flock CNTER, LOCK_EX
	    or die "Error locking on '$cntrname': $!, stopped";

	my $bytesRead = read CNTER, $current, 2;
	defined $bytesRead
	    or die "Error reading data from '$cntrname': $!, stopped";
	$bytesRead == 2
	    or die "$bytesRead returned from read '$cntrname', expected 2, stopped";

: if ($current == $limit)
: {
:         unlink ("$filename");

	unlink $filename
	    or die "Error deleting '$filename': $!, stopped";

: close(cnter);

	close CNTER
	    or die "Error closing data file '$cntrname': $!, stopped";

: open(MF, ">>$filename");
: flock(MF, LOCK_EX);

	...or die "blagh, blagh, blagh: $!, stopped";

	>snip<
:         print OUT "<!-- JavaScript to force auto-reload every x
: seconds -->\n";
:         print OUT "<SCRIPT LANGUAGE=JavaScript>\n";
:         print OUT "function TR\(\)\n";
:         print OUT "{\n";
:         # print OUT "window.scroll\(0, $scrolly\)\n";
:         print OUT "setTimeout\('location.reload\(\)', $delay\);\n";
:         print OUT "}\n";
:         print OUT "</SCRIPT>\n";
:         print OUT "</HEAD>\n\n";
:         print OUT "<BODY BGCOLOR=\"$bgc\" onLoad=\"TR\(\)\">\n";

	You showed earlier in your code you know how to use here-docs, so
	why do you use this style here?

:         open (INF, $filename);
:         @indata = <INF>;
:         close (INF);

	...or die $!....
	
	Until you start testing your system call return values you'll never
	figure this problem out and quite likely have many others.  Get used
	to coding under -w and use strict, it will save you tons of
	debugging time in the long run.  See the CGI::Carp man page for
	details about sending fatal data to the browser to make debugging
	easier (eg, use CGI::Carp qw(fatalsToBrowser);).
	
-- 
-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, 8 Dec 1998 22:31:51 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Can someone tell me why ....
Message-Id: <1djqn2b.509p03sr5kxbN@bay2-73.quincy.ziplink.net>

Owen <info@kn1.com> wrote:

> this script for a chat programm does not delete the message database when
> the limit is reached. It does reset the counter to 0 but does not delete the
> database

> if ($current == $limit)
> {
>         unlink ("$filename");
>         $current = 0;
> }

Yes, Perl can tell you why, if you ask it to.

unlink($filename) or die "Could not delete message database: $!\n";


(Do something similar for all your open() calls.  If you don't check for
errors, you won't know when they occur.)

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


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

Date: Tue, 8 Dec 1998 18:57:34 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Errors with SETUID and Perl Script
Message-Id: <uthk47.841.ln@magna.metronet.com>

Erik (eln@cyberhighway.net) wrote:
: In article <74k85g$k4t$1@nnrp1.dejanews.com>,
: 	mike_orourke@em.fcnbd.com writes:
: > Here is a better copy of the code :

[ snip code with whitespaces squished to a single space]

: You have a weird definition of "better".


   I think he has a weird definition of "newsreader"  ;-)


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


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

Date: Tue, 8 Dec 1998 22:31:53 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Errors with SETUID and Perl Script
Message-Id: <1djqnb5.rlpidp5m0ou0N@bay2-73.quincy.ziplink.net>

[posted and mailed]

<mike_orourke@em.fcnbd.com> wrote:

> Let me try again.....
> 
> [third time posting code all run together with no formatting]

I would guess that this is your problem...

> -----------== Posted via Deja News, The Discussion Network ==----------
                ^^^^^^^^^^^^^^^^^^^^

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


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

Date: Tue, 8 Dec 1998 18:45:01 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: flock doesn't flock under perl/linux
Message-Id: <d6hk47.841.ln@magna.metronet.com>

Daniel Grisinger (dgris@moiraine.dimensional.com) wrote:

: From perlfunc (in this case TRUE is defined as 1 and FALSE is
                                   ^^^^^^^^^^
: 0, not undef):


   I cannot find the definition that you are referring to.

   Where, exactly, does it say that?


[
   I ask because I cannot believe that it is defined so.

   It may return 1 for TRUE today, but I don't believe that
   can be relied on.

   I think you _can_ rely on it not being '0', or '', or 
   something that ends up being one of those two after
   being converted to a string (the standard description
   of Perl's idea of truth).
]


   I did find this in perlfunc, which seems to be saying 
   something different from the quote above:

----------------
In general, functions in Perl that serve as wrappers for system calls
of the same name (like chown(2), fork(2), closedir(2), etc.) all return
true when they succeed and C<undef> otherwise,
----------------



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


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

Date: Tue, 8 Dec 1998 18:50:21 -0600
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: flock doesn't flock under perl/linux
Message-Id: <dghk47.841.ln@magna.metronet.com>

Daniel Grisinger (dgris@moiraine.dimensional.com) wrote:

: I can't think of anything off the top
: of my head that returns -1 for failure.


   Me either.

   But after searching for '<-1>' in perlfunc, I can name a few  :-)

      index() if you haven't mucked with $[

      syscall()

      wait()

      waitpid()
   

   but that's it.


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


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

Date: 08 Dec 1998 19:53:07 -0700
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: flock doesn't flock under perl/linux
Message-Id: <m3iufmuiuk.fsf@moiraine.dimensional.com>

tadmc@metronet.com (Tad McClellan) writes:

> Daniel Grisinger (dgris@moiraine.dimensional.com) wrote:
> 
> : From perlfunc (in this case TRUE is defined as 1 and FALSE is
>                                    ^^^^^^^^^^
> : 0, not undef):
> 
>    I cannot find the definition that you are referring to.
> 
>    Where, exactly, does it say that?

It doesn't, at least not in the documentation.  I arrived at the
values (and thus at what the definitions of TRUE and FALSE must
be) using Devel::Peek and the debugger.  I'll send you details
if you'd like.

dgris
-- 
Daniel Grisinger          dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print 
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'


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

Date: Tue, 8 Dec 1998 22:31:56 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Hash slices - why are these equivalent?...
Message-Id: <1djqnhm.2xlner8ojvn1N@bay2-73.quincy.ziplink.net>

Simon Parsons <simonp@ftel.co.uk> wrote:

> # (2)
> @{%h}{@a} = ();
> 
> I understand (1) and amperfectly happy with it, but why does case (2) work?

  DB<1> @a = (1, 3, 5, 7);

  DB<2> @{%h}{@a} = ();
Bizarre copy of HASH in leave at (eval 5) line 2, <IN> chunk 2.

  DB<3> x %h
  empty array


It doesn't work.

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


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

Date: Wed, 09 Dec 1998 03:44:38 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Hash slices - why are these equivalent?...
Message-Id: <366DF3DA.D733946A@home.com>

[posted & mailed]

Ronald J Kimball wrote:
> 
> Simon Parsons <simonp@ftel.co.uk> wrote:
> 
> > # (2)
> > @{%h}{@a} = ();
> >
> >  why does case (2) work?
> 
>   DB<1> @a = (1, 3, 5, 7);
> 
>   DB<2> @{%h}{@a} = ();
> Bizarre copy of HASH in leave at (eval 5) line 2, <IN> chunk 2.
> 
>   DB<3> x %h
>   empty array
> 
> It doesn't work.
> 

Maybe not in the debugger.  But this code prints 'cz'.

#!/usr/bin/perl -w

%h = ();
@a = (1..4);

@{%h}{@a} = qw/a b c d/;
print "$h{3}\n";

${%h}{2} = 'z';
print $h{2};


-- 
Rick Delaney
rick.delaney@shaw.wave.ca


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

Date: 8 Dec 1998 22:28:16 -0500
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Is there a 'predeclare subs' module ?
Message-Id: <74kqog$aqe$1@monet.op.net>
Keywords: grantor Seagram such sweater

In article <366D7DD8.47681C0F@tiuk.ti.com>,
Alex Davies  <Alex.Davies@tiuk.ti.com> wrote:
>
>Is there a way of automatically predeclaring _all_  your
>subroutines, kinda like:

I tried to get it to work with __DATA__, to eleminate the dependency
on $0, but that didn't work, because __DATA__ isn't opened until it's
too late.

>(but with the necesary bells and whistles...) ?

I think you're going to have a hard time getting it exactly right.
For example:


	sub
	fred
	{ $_[0]{F} = qq{
	sub actually_this_is_really_a_string { "that looks like a sub" }
	}


I tried

while (<D>) {
  next unless /^\s*sub\s*(([_A-Za-z]\w*)\s*[^\{]*)/;
  eval "sub $1;";
  if ($@) {
    require Carp;
    Carp::carp("Couldn't predeclare subroutine `$2': $@.\n");
  }
}

in an attept to get it to handle prototypes correctly.

>Or is this a bad idea ... ;)

I think it's an awful idea.  

Not that that stoped me from working on it.  

Here's my new, improved version.  It caches the function declarations
in a separate file; next time you run it, it tries to read this file
back in at compile time instead of grovelling over the source code.
If the file is out-of-date, it rebuilds it.  The declarations for the
file `foo.pl' are stored in (where else?) `foo.h'.  

If you're sure that .h file is good, and should never be rebuilt, add
the line

	$H_FROZEN = 1;

to it somewhere.  If it has that, it won't be rebuilt even if it's out
of date.

It should be safe to use in modules (with `Module.pm' getting its own
`Module.h' file) but I haven't tested that.

If you want me to take your name off of it, I'll understand.
Otherwise it's going up on my web site and you'll get full credit.

################################################################
# allsubs.pm
# Usage:
#   use allsubs;
# Locate and pre-declare all the subroutines in your file.
# (With caching.  I love caching.  Everything should be cached.)
#
# Retarded concept by Alex Davies (Alex.Davies@tiuk.ti.com)
# Idiotic module copyright 1998 M-J. Dominus (mjd-perl-allsubs@plover.com)
# Who is the greater pinhead?  You decide.
#

my $mainfile = (caller)[1];
my $H = $mainfile;
print "H: $H\n";
$H =~ s/\.[^.]*$//;    # foo.xy.pl => foo.xy.h.  
$H .= '.h';            # Would     => foo.h  have been better?
eval { require $H };
my $err = $@;
my $ood = 0;

return if $H_FROZEN;

if (!$err) {
  my $hfile = $INC{$H};
  my $main_mtime = (stat $mainfile)[9];
  my $h_mtime = (stat $H)[9]; 
  $ood = ($h_mtime < $main_mtime);
  if ($ood && !rename $H, "$H.bak") {
    require Carp;
    Carp::croak("Could not remove out-of-date prototype file `$H': $!;
aborting");
  }
}

if ($@ || $ood) {
  local *D;
  local *H;  # Greetings, miserable Earth vermin.
  open D, $0 or die "$0: $!";
  unless (open H, "> $H") {
    require Carp;
    Carp::carp("Warning: couldn't write file $H: $!.\n");
    undef $H;
  }

  while (<D>) {
    next unless /^\s*(sub\s*([_A-Za-z]([\w]|::)*)\s*[^\{]*)/;
    print H $1, ";\n" if defined $H;
    eval "$1;";
    if ($@) {
      require Carp;
      Carp::carp("Couldn't predeclare subroutine `$2': $@.\n");
    }
  }
  print H "1;\n" if defined H;
} 


"Cogito, ergo sum.";         # A required file must return a true value.


#
#
################################################################


Hope this helps.  Have an obfuscated day.



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

Date: 09 Dec 1998 02:22:58 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Java in PERL
Message-Id: <913170243.982558@thrush.omix.com>

Alex Shaykevich <shaykevi@ptolemy.arc.nasa.gov> wrote:
: The original release of JPL seemed only to support Perl calls from
: within Java, and not the other way around.  I'd like to call Java
: methods from within my Perl code.  I've seen several articles hinting
: that this can be done, including one at www.perl.com.
:
: Anyone have any experience doing this?   Any advice would be much
: appreciated.

	Last I heard it was to be part of JPL's functionality, but at the
	time embedding a JVM inside perl was still on the to-do list...

-- 
-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, 8 Dec 1998 22:31:57 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Not a subroutine reference
Message-Id: <1djqo40.ywlrba21m3pdN@bay2-73.quincy.ziplink.net>

Aaron Young <ayoung@sigg.com> wrote:

>   #$SIG{CHLD} = \TAO::Queue::_REAPER();

> Now all I have to do is go back and try and figure out why I thought the above
> code snippet was a good idea

You probably assumed that this would assign to $SIG{CHLD} a reference to
the subroutine TAO::Queue::_REAPER().  As you must have discovered, this
code will actually call the subroutine TAO::Queue::_REAPER(), and assign
to $SIG{CHLD} a reference to the result.

The correct way to take a reference to a subroutine is like so:

\&subroutine

Note the ampersand, and the absence of parentheses.  Any other way and
you get a reference to the result of calling the subroutine.

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


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

Date: Tue, 8 Dec 1998 20:36:51 -0600
From: "Enrico Ng" <ng@usa.net>
Subject: Re: please help..
Message-Id: <74knqa$r8o$1@info3.fnal.gov>

I cant get to that either.
I have tried http://www.vejrum.dk/WWW-Mail/, but I cant get it to work.
also, I have tried emumail, but it does not work, way ... too slow.
I tried http://www.canvasis.com/scripts/pop/, but its just a web form,  I
cant get to the perl code.
does any one have a perl code that can do it, I dont know too much about
perl so I would know how to use a pop3client.pm module either.
--
--
Enrico Ng <ng@usa.net>
WVHS Internet
http://www.ipsd.org/wvhs

j <mocat@best.com> wrote in message 366fd691.146798870@nntp.best.com...
>On Tue, 8 Dec 1998 19:19:17 -0600, "Enrico Ng" <ng@usa.net> wrote:
>
>>2. I want to browse the web through my web server.
>>many common sites (such as email services) are blocked out at work, so I
was
>>wondering if there was a way i could make a perl form so I could type an
>>address in and go to a certain site.
>
>try using a public proxy.  www.anonymizer.com is a decent one.




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

Date: Tue, 8 Dec 1998 21:05:08 -0600
From: "Troy D. Olson" <barcode@ice.net>
Subject: Regular Expressions
Message-Id: <74kp28$ses$1@remarQ.com>

I have users input variable length alpha-numeric data with symbols and white
space via barcode reader.  My problem is AIAG standards have placed an alpha
character at the beginning of the string (i.e. P, Q, R).  How can I check
the string for the existence of P or Q add-ons and wack them.

Example:
    P123456-ab Ready_Rod
    Q12345-ab Tank

Ultimate Solution:
    123456-ab Ready_Rod
    12345-ab Tank

Remember some of the numbers have no alpha to start the string.
I have been able to remove selected alpha characters but it wacks all
occurrences in the string and not only the first. (probably misuse of the ^)

Thanks for your support.

Troy




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

Date: Wed, 09 Dec 1998 03:18:31 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Regular Expressions
Message-Id: <366DEDC4.81B17555@home.com>

[posted & mailed]

Troy D. Olson wrote:
> 
> How can I check the string for the existence of P or Q add-ons 
> and wack them.

    $string = 'P123456-ab Ready_Rod';
    $string =~ s/^[A-Z]//;

This assumes only one leading uppercase letter.  I leave the general
case to you.

perldoc perlre

> I have been able to remove selected alpha characters but it wacks all
> occurrences in the string and not only the first. (probably misuse of 
> the ^)

Probably misuse of /g, but we will never know since you forgot to post
what you tried.

-- 
Rick Delaney
rick.delaney@shaw.wave.ca


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

Date: Tue, 8 Dec 1998 19:26:34 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Regular Expressions
Message-Id: <MPG.10d78dc28e4b7dda989948@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <74kp28$ses$1@remarQ.com> on Tue, 8 Dec 1998 21:05:08 -0600, 
Troy D. Olson <barcode@ice.net> says...
 ...
> Example:
>     P123456-ab Ready_Rod
>     Q12345-ab Tank
> 
> Ultimate Solution:
>     123456-ab Ready_Rod
>     12345-ab Tank

  $string =~ s/^[PQ]//;

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 09 Dec 1998 02:25:38 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Simple PERL on PC ?
Message-Id: <913170403.498901@thrush.omix.com>

[posted & mailed]

Brian D. Schieber <schieb@seabass.gsfc.nasa.gov> wrote:
: Hi,
:  I checked the FAQ but the link to Win32 PC PERL is dead...
: I have some PERL scripts (on UNIX) that I'd like to give to Windows95
: users.  What PERL for PC is simple to use and install that I can tell
: my users about?

	$CPAN/ports/win32/Standard/x86/perl5.00402-bindist04-bc.zip

-- 
-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: Wed, 9 Dec 1998 01:57:44 -0000
From: "Antony" <amcnulty@nortel.co.uk>
Subject: Still just a quickie
Message-Id: <74kldi$9k4@bmdhh222.europe.nortel.com>

Hey Expert-Type People,

I want to finish a small program that I am working on, but have one little
problem.

My script needs to be run a subroutine every time the timestamp of a certain
file is altered.

I tried a couple of ideas but most seem to impractical and too memory
consuming.


Also, anyone ever come up with many problems in porting UNIX perl scripts
over to WinNT ?
Got any hints for doing it quicker?
Because I'm here all weekend doing just that and it's really starting to get
on my nerves.


Awaiting all helpful comments,

Antony






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

Date: Tue, 08 Dec 1998 21:13:29 -0500
From: Erik van Roode <newsposter@cthulhu.demon.nl>
Subject: Re: Storing In Memory
Message-Id: <366DDCC9.76B64869@cthulhu.demon.nl>

Chris Haines wrote:
> 
> I am trying to figure out how I can store a variable or array in my
> system memory.  I know this can be done but my book doesn't address
> that.  Please help.

What do you mean ? You currently store variables on stick-it notes
on your screen and now you want to use the actual computer for storing
data?

You seem to think your variables are currently _not_ stored in system
memory. What makes you think that? You seem to be confused about
something, answering that question may shed some light on what your
question actually is ...

Erik




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

Date: Tue, 8 Dec 1998 22:31:59 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Why i can't "localize through a reference" in perl version 5.005_02
Message-Id: <1djqom5.9dwsuu1lffdw5N@bay2-73.quincy.ziplink.net>

FENG XIAN, ALEX <feng_xian@mitel.com> wrote:

> thanks for your suggestions anyway. maybe sometime it's easier to ask a
> question to somebody than to read documents. 

For the person asking the question, maybe, but not for the person who is
expected to answer.  :-P

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


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

Date: Wed, 09 Dec 1998 01:54:27 GMT
From: finsol@ts.co.nz
Subject: Re: Y2K potential problem in localtime()
Message-Id: <74kl8i$vci$1@nnrp1.dejanews.com>

In article <01be22f2$9aab4c20$a4c448c2@is>,
  "Simmo" <simsi@hotmail.com.nospam> wrote:
> Hi,
>
> Apologies if this has been posted or if i'm doing something silly but i've
> noticed in my localtime() calls that when the year gets to 2000, the year
> gets returned as 100.

Warning, Simmo, Perl programmers can get very tetchy when this subject is
discussed. According to the experts out there is no problem with
localtime()usage - despite continued evidence to the contrary such as yours.
Their opinion is that anyone who does misuse it should not be programming. 
Many Perl programmers are certainly not amenable to having other programmers
alerted to the issue via this forum.

If you would like to learn more about the 'booby trap code' problem and the
associated programmer denial, you can access my articles published in
Computerworld at URL:
http://www.ts.co.nz/~finsol/y2k_articles.htm

You are not alone in misunderstanding the localtime() year value.

Jocelyn Amon
Financial Solutions Limited
http://www.ts.co.nz/~finsol/

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


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

Date: Tue, 08 Dec 1998 21:17:03 -0500
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Y2K potential problem in localtime()
Message-Id: <fl_aggie-0812982117030001@aggie.coaps.fsu.edu>

In article <74kl8i$vci$1@nnrp1.dejanews.com>, finsol@ts.co.nz wrote:

+ In article <01be22f2$9aab4c20$a4c448c2@is>,
+   "Simmo" <simsi@hotmail.com.nospam> wrote:
+ > Hi,
+ >
+ > Apologies if this has been posted or if i'm doing something silly but i've
+ > noticed in my localtime() calls that when the year gets to 2000, the year
+ > gets returned as 100.
+ 
+ Warning, Simmo, Perl programmers can get very tetchy when this subject is
+ discussed. According to the experts out there is no problem with
+ localtime()usage - despite continued evidence to the contrary such as yours.
+ Their opinion is that anyone who does misuse it should not be programming. 

No. Wrong. What it means is that people should consult the documentation 
when confronted with seemingly strange results.

Had Simmo consulted the documentation (perldoc -f localtime) he would have
seen:

    All array elements are numeric, and come straight out of a
    struct tm. In particular this means that $mon has the range
    0..11 and $wday has the range 0..6 with sunday as day 0. Also,
    $year is the number of years since 1900, that is, $year is 123
    in year 2023.

Had Simmo consulted DejaNews on "Y2K" in this newsgroup, he would have
seen it hashed out a thousand times before.

+ If you would like to learn more about the 'booby trap code' problem and the
+ associated programmer denial

The only "denial" is your seeming inability to understand a simple concept:
it is a documented feature, and if you understand the documentation, you
will be able to extract an unambiguous, non-contexted dependent answer.
Those who do not read the documentation are doomed to fail.

A more elegant way to get a context-dependent 2 digit year is:
$year=(localtime)[5] % 100;

James - time for a Larry Wall-ism:

Many computer scientists have fallen into the trap of trying to define
languages like George Orwell's Newspeak, in which it is impossible to
think bad thoughts. What they end up doing is killing the creativity
of programming.
 -- Larry Wall


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

Date: Tue, 8 Dec 1998 22:32:06 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Y2K potential problem in localtime()
Message-Id: <1djqoss.1qnfwy7teiltzN@bay2-73.quincy.ziplink.net>

[posted and mailed]

Simmo <simsi@hotmail.com> wrote:

> Apologies if this has been posted or if i'm doing something silly but i've
> noticed in my localtime() calls that when the year gets to 2000, the year
> gets returned as 100. I have supplied a really really simple fix below -

Your fix is not silly at all.  Numerous newbies have assumed that
localtime has a bug and will return 0 in 2000.  In contrast, you were
able to figure out that localtime() will actually return 100, and that
adding 1900 is the correct way to handle this.  Well done!

Here's the silly part...  This behavior, and the really really simple
fix, are clearly documented in perlfunc.  Please read the documentation!

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


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

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

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