[8229] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1847 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 10 13:16:24 1998

Date: Tue, 10 Feb 98 10:01:34 -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, 10 Feb 1998     Volume: 8 Number: 1847

Today's topics:
    Re: Multithreaded servers and communicating object proc <tchrist@mox.perl.com>
    Re: New Perl book reviews (Andy Lester)
    Re: New Perl book reviews <tchrist@mox.perl.com>
    Re: Perl documentation (was re: Perl Year 2000 ...) lvirden@cas.org
    Re: Perl documentation (was re: Perl Year 2000 ...) <tchrist@mox.perl.com>
        perl form problem <charlesb@ccmail.orst.edu>
    Re: Perl HTML output in Win 95 (InterVisors)
        Perl problems with anonymous users <rgram@ingr.com>
    Re: Perl problems with anonymous users (John Klassa)
        perl5.003 and now CGI won't work <rbush@mail.dac.net>
    Re: Q: Using unpack or split to get fixed-length substr (RonaldWS)
    Re: regular expressions <tchrist@mox.perl.com>
    Re: returning the date <jdporter@min.net>
    Re: returning the date <tchrist@mox.perl.com>
    Re: returning the date <jhi@alpha.hut.fi>
    Re: Sharing variables between scripts <friedman@uci.edu>
    Re: Sharing variables between scripts (Jack Ostroff)
    Re: Sharing variables between scripts <tchrist@mox.perl.com>
    Re: Sharing variables between scripts <tchrist@mox.perl.com>
        strange split behaviour <ahartman@geolin5.geophys2.uni-bremen.de>
    Re: strange split behaviour <dboorstein@shopcfn.com>
    Re: substitution/expression <raconway@atos-group.com>
    Re: Syntax-coloring editor for NT (Andy Lester)
    Re: Syntax-coloring editor for NT <raconway@atos-group.com>
    Re: Using flock? <gedavis3@vt.edu>
    Re: Using flock? <tchrist@mox.perl.com>
    Re: Yet Another Sorting Question(TM) (Andrew M. Langmead)
    Re: Yet Another Sorting Question(TM) <jdporter@min.net>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 10 Feb 1998 16:43:40 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Multithreaded servers and communicating object processes (proper)
Message-Id: <6bq03s$lr4$1@csnews.cs.colorado.edu>

    [courtesy cc of this posting sent to cited author 
     and other potentially interested parties via email]

In comp.lang.perl.misc, darlenem@flash.net writes:
:I'm working on a medium-sized project that involves a multithreaded TCP server
:whose client processes need to be able to communicate with each other. I'm
:fairly new to UNIX and I know virtually nothing about IPC.

Here's another little example for you, currently called fwdport.
Is it a client?  Is it a server?  I don't know; it has both accepts
and connects in it; maybe it's a servoclient. :-)

What it is is a mulithreaded TCP forwarding proxy (linewise only,
not bytewise).  Why do you need this?  Let's say you have a firewall
machine that sits on two different networks.  Why would you do this?
Well, maybe you have a remote NNTP server that is only reachable from
the gateway machine, but you'd like people from your internal net to be
able to reach it.

For example:

    fwdport -s nntp -l int.biz.com -r hisname.org

will bind and listen on its internal interface (int.biz.com), and then
forward any connection on to hisname.org when one comes in.  In this case,
the port number for NNTP is used for both.

Another example, this one from reality:

    fwdport -l jhereg:9011 -r csnews:nntp

Here we bind our proxy server to port 9011 on our "jhereg" interface 
(that machine has four interfaces, believe it or not), and any 
connections get forwarded on the remote machine named "csnews"
on the port number corresponding to 

Will start a local proxy server bound to jhereg, port 9011, which when
connected to, will exchange data with the real remote server on csnews's
nntp port.

When a connection comes in from the internal network via accept, the
master proxy server forks off a clone copy of itself to handle the current
connection and returns to the accept state.  The clone connects up to
the designated remote server outside the firewall.  It twins itself via
yet another fork.  The first twin is the reader, the second the writer,
for the full duplex connection.

This is just a quick 30-minute hack I wrote last night, and isn't what I
would call production qualify.  It could use better code organization,
commenting, formatting, removal of redundant or dead code, etc.
But it has all the fundamental features of a reasonably sophisticated
application.

This is a fully multithreaded application, by which there are many threads
of control -- separate PCs -- all running within the same program.
Those who disparage fork can go read my posting of last week entitled
"Fork is cheap and powerful".  And furthermore, I challenge these people
to rewrite this server for Soloris/Linux/POSIX threads or in particular,
how you would do so under Windows.  Go ahead.  Make my day.  Show me.

--tom

#!/usr/bin/perl -w
# fwdport - multithreaded linewise forwarding proxy servoclient
# tchrist@perl.com
# Mon, 09 Feb 1998 21:14:50 -0700
# version 0.1 (prototype/hack)

use strict;
use Getopt::Long;
use Net::hostent;
use IO::Socket;
use POSIX ":sys_wait_h";

my (
    %Children,
    $REMOTE,
    $LOCAL,
    $SERVICE, 
    $proxy_server,
    $ME, 
);

($ME = $0) =~ s,.*/,,;

check_args();
start_proxy();
service_clients();

sub service_clients { 
    my (
	$local_client,
	$lc_info,
	$remote_server,
	@rs_config,
	$rs_info,
	$kidpid,
    );

    $SIG{CHLD} = \&REAPER;

    accepting();
    while ($local_client = $proxy_server->accept()) {
	$lc_info = peerinfo($local_client);
	set_state("servicing local $lc_info");
	printf "[Connect from $lc_info]\n";

	@rs_config = (
	    Proto     => 'tcp',
	    PeerAddr  => $REMOTE,
	);
	push(@rs_config, PeerPort => $SERVICE) if $SERVICE;

	print "[Connecting to $REMOTE...";
	set_state("connecting to $REMOTE");
	$remote_server = IO::Socket::INET->new(@rs_config)
			    || die "remote server: $@";
	print "done]\n";

	$rs_info = peerinfo($remote_server);
	set_state("connected to $rs_info");

	$kidpid = fork();
	die "Cannot fork" unless defined $kidpid;
	if ($kidpid) {
	    $Children{$kidpid} = time();
	    close $remote_server;
	    close $local_client;
	    next;
	} 

	close $proxy_server;
	$kidpid = fork(); die "Cannot fork" unless defined $kidpid;

	if ($kidpid) {
	    set_state("$rs_info --> $lc_info");
	    select($local_client); $| = 1;
	    print while <$remote_server>;
	    kill('TERM', $kidpid);
	} else {
	    set_state("$rs_info <-- $lc_info");
	    select($remote_server); $| = 1;
	    print while <$local_client>;
	    kill('TERM', getppid());
	} 
	exit;
    } continue {
	accepting();
    } 
}

sub accepting {
    set_state("accepting proxy for " . ($REMOTE || $SERVICE));
}


sub check_args { 

    GetOptions(
	"remote=s"    => \$REMOTE,
	"local=s"     => \$LOCAL,
	"service=s"   => \$SERVICE,
    ) or die <<EOUSAGE;
    usage: $0 [ --remote host ] [ --local interface ] [ --service service ]   
EOUSAGE

    die "Need remote" unless $REMOTE;
    die "Need local or service" unless $LOCAL || $SERVICE;
}

sub start_proxy {
    my @proxy_server_config = (
      Proto 	=> 'tcp',
      Reuse     => 1,
      Listen    => SOMAXCONN,
    );
    push @proxy_server_config, LocalPort => $SERVICE if $SERVICE;
    push @proxy_server_config, LocalAddr => $LOCAL   if $LOCAL;
    $proxy_server = IO::Socket::INET->new(@proxy_server_config)
		    || die "can't create proxy server: $@";
    print "[Proxy server on ", ($LOCAL || $SERVICE), " initialized.]\n";
}

sub set_state { $0 = "$ME [@_]" } 

sub REAPER { 
    my $child;
    my $start;
    while (($child = waitpid(-1,WNOHANG)) > 0) {
	if ($start = $Children{$child}) {
	    my $runtime = time() - $start;
	    printf "Child $child ran %dm%ss\n", 
		$runtime / 60, $runtime % 60;
	    delete $Children{$child};
	} else {
	    print "Bizarre kid $child exited $?\n";
	} 
    }
    # If I had to choose between System V and 4.2, I'd resign. --Peter Honeyman
    $SIG{CHLD} = \&REAPER; 
};

sub peerinfo {
    my $sock = shift;
    my $hostinfo = gethostbyaddr($sock->peeraddr);
    return sprintf("%s:%s", 
		    $hostinfo->name || $sock->peerhost, 
		    $sock->peerport);
} 

-- 
	Tom Christiansen	tchrist@jhereg.perl.com
    "It's ironic that you would use a language as large as English to express
    so small a thought."
    	--Larry Wall


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

Date: 10 Feb 1998 14:52:53 GMT
From: petdance@maxx.mc.net (Andy Lester)
Subject: Re: New Perl book reviews
Message-Id: <6bppk5$lbt$1@usenet52.supernews.com>

hmmm, it seems like nobody's reading the paragraph parts of my page.
Maybe I need to rethink it.

: You should link to the other lists?
:     http://language.perl.com/critiques/index.html

I do, Tom.  In fact, I give you major props.

<BLOCKQUOTE>
The canonical reference point for Perl book reviews is Tom Christiansen's
Camel Critiques. Tom's reviews are fairly dry, but he's ruthless in his
assessment of the technical accuracy of the books discussed. It's good to
have someone with Tom's authority commenting on them.
</BLOCKQUOTE>

: Why don't you link to perl.com?
:     http://www.perl.com/
: Why don't you reference the standard port for Windows victims?
:     http://www.perl.com/ports/win32/Standard/

First, The latter URL is incorrect.  Second, there is a link to perl.com
on the main Perl page up a level (http://ChicagoMusic.com/perl/).  All I
was announcing was the book reviews.

I don't mean to make a set of pages that is the same as everyone else's.
I figure that by the time someone finds my pages, they'll know about
Perl.com, and that my mentioning it is a waste of space.

xoxo,
Andy

--
--
Andy Lester:        <andy@petdance.com>       http://tezcat.com/~andy/
Chicago Shows List: <shows@ChicagoMusic.com>  http://ChicagoMusic.com/



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

Date: 10 Feb 1998 17:12:00 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: New Perl book reviews
Message-Id: <6bq1p0$p1b$3@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, petdance@maxx.mc.net (Andy Lester) writes:
:hmmm, it seems like nobody's reading the paragraph parts of my page.

Yup, my bad.

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com
    Does the same as the system call of that name.
    If you don't know what it does, don't worry about it.
            --Larry Wall in the perl man page regarding chroot(2)


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

Date: 10 Feb 1998 14:48:21 GMT
From: lvirden@cas.org
Subject: Re: Perl documentation (was re: Perl Year 2000 ...)
Message-Id: <6bppbl$1s8$1@srv38s4u.cas.org>


According to Michael Wang <mwang@alhena.ibk.ml.com>:
:Craig Berry <cberry@cinenet.net> wrote:
:>That's one reason it's better to use the perldoc command (rather than 
:>man) to view perl documentation; you can get doc on a single function by 
:>doing e.g. 'perldoc -f length'.
:
:Thanks for the info. The problem with creating another documentation format
:is having to learn it. I have learned MANPATH, sending man page to Postscript

Another problem is finding consistency - not all documentation for perl
related items is distributed in the same manner.  A lot of doc (over 700
printed pages) comes with the core.  The install process creates man
pages and provides tools for creating HTML.  Other modules come with
separate pod files, or has the pod inside the code, or come with html.
Installation may or may not come with useful doc, may or may not create
equivalent man pages for the code, may or may not install said
doc, if the doc IS available and installed, may or may not install it
somewhere it can be found.

-- 
Larry W. Virden <URL:mailto:lvirden@cas.org> ICQ: 5744965
<URL:http://www.teraform.com/%7Elvirden/> <*> O- "We are all Kosh."
Unless explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.


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

Date: 10 Feb 1998 17:10:33 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Perl documentation (was re: Perl Year 2000 ...)
Message-Id: <6bq1m9$p1b$2@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, lvirden@cas.org writes:
:Installation may or may not come with useful doc, may or may not create
:equivalent man pages for the code, may or may not install said
:doc, if the doc IS available and installed, may or may not install it
:somewhere it can be found.

This situation is one I deem unacceptable.

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com

It's a damn poor mind that can only think of one way to spell a word.
                --Andrew Jackson


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

Date: Tue, 10 Feb 1998 10:02:23 -0800
From: Brian Charles <charlesb@ccmail.orst.edu>
Subject: perl form problem
Message-Id: <34E0962F.14B84B60@ccmail.orst.edu>

Hi,
    Can anyone look at the program below and tell me what's wrong. I'm a
newbie to PERL. I want this program to take input (name and email) from
a form and write it to a file which is then sorted and printed in html.
The first part of the program isn't working. Data isn't being appended
into the 'database' file from the form, but the data that is already in
'database' is being printed to html just fine.

Brian


#!/usr/bin/perl
require "cgi-lib.pl";
##########################################################################

# Get input and append data to database file
##########################################################################

print <<"html";
Content-type: text/html
<FORM METHOD=POST
ACTION="http://cmc-photo.cmc.orst.edu/cgi-bin/getemail1.pl">
<B>Last Name:</b><INPUT TYPE=TEXT NAME=lastname><br>
<B>First Name:</B><INPUT TYPE=TEXT NAME=firstname><br>
<B>E-mail:</B><INPUT TYPE=TEXT NAME=email><br>
<INPUT TYPE=SUBMIT VALUE="Submit">
<P>
html

&ReadParse;

#open the guestbook file and append data to the end of it
        open FILE,"database" or die "Cannot open database: $!";
          #print the information
          print FILE "$in{'lastname'}, $in{'firstname'}|$in{'email'}\n";

        close FILE;

#####################################################################
# Hash database file and print to html
#####################################################################
open DB, "database" or die "Cannot open myfile: $!";
        my %fields = map /^(.*?)\|(.*)/, <DB>;

        @lastname = keys(%fields);
        @sorted_names = sort(@lastname);

foreach $name (@sorted_names)
        {
        print  "<a href=\"mailto:$fields{$name}\">$name</a><br>\n";
        }
 close DB;





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

Date: Tue, 10 Feb 1998 15:33:51 GMT
From: intervisors@nospam.intervisors.nl (InterVisors)
Subject: Re: Perl HTML output in Win 95
Message-Id: <34e0730a.727289@194.109.6.91>

Hi,

Finally fixed the problem. I found a fix via a page that I found at
www.perl.com. Afyter entering a CGI mapper in the windows 95 registery
perl is used for all perl programs and the cause is closed.

Thanks Jack.

Luke



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

Date: Tue, 10 Feb 1998 09:22:57 -0600
From: Richard Graham <rgram@ingr.com>
Subject: Perl problems with anonymous users
Message-Id: <34E070D1.597E@ingr.com>

I currently am running a intranet with ISS 3.0 on a Windows NT 4.0
server.  Currently the server is configured in ISS to allow both BASIC
authentication and anonymous logins.  The web pages that use BASIC
authentication  have no trouble running perl correctly it is the
anonymous page I am having trouble with.  

Whenever a anonymous page calls to Perl I get the dreaded "save as"
dialog box in my browser.  I am assuming this was caused by a
permissions problem on my perl bin directory, so I went in and changed
the permissions on the perl directory and still had the problem.  I then
changed the permissions on the Windows NT system directory and still got
the save problem.  

The perl script is suppose to run from a form action: 
<form action="/cgi-bin/doit.pl"> 
I confirmed that the permissons are set for the cgi-bin directory as
well as the files located therein.  Can
someone please give me a clue as to what else I need to set?

Thanks!

Richard Graham
Please reply to: rgraham@ingr.com


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

Date: 10 Feb 1998 17:38:53 GMT
From: klassa@aursgh.aur.alcatel.com (John Klassa)
Subject: Re: Perl problems with anonymous users
Message-Id: <6bq3bd$fv4$1@aurwww.aur.alcatel.com>

On Tue, 10 Feb 1998 09:22:57 -0600, Richard Graham <rgram@ingr.com> wrote:

->I currently am running a intranet with ISS 3.0 on a Windows NT 4.0
->server.  Currently the server is configured in ISS to allow both BASIC
->authentication and anonymous logins.  The web pages that use BASIC
->authentication  have no trouble running perl correctly it is the
->anonymous page I am having trouble with.  
->
->Whenever a anonymous page calls to Perl I get the dreaded "save as"
->dialog box in my browser.  I am assuming this was caused by a
->permissions problem on my perl bin directory, so I went in and changed
->the permissions on the perl directory and still had the problem.  I then
->changed the permissions on the Windows NT system directory and still got
->the save problem.  
->
->The perl script is suppose to run from a form action: 
-><form action="/cgi-bin/doit.pl"> 
->I confirmed that the permissons are set for the cgi-bin directory as
->well as the files located therein.  Can
->someone please give me a clue as to what else I need to set?

As a first step, I'd take "comp.lang.perl.misc" out of the newsgroups
line, as your question has nothing to do with perl...

-- 
John Klassa / Alcatel Telecom / Raleigh, NC, USA <><


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

Date: Tue, 10 Feb 1998 17:17:33 GMT
From: Rod Bush <rbush@mail.dac.net>
Subject: perl5.003 and now CGI won't work
Message-Id: <34E08BAD.45BB@mail.dac.net>

I just installed the latest version of wwwstat on my Linux based Apache
web server. An upgrade to perl5.003 came with it. Now none of my cgi
scripts are working. Needless to say my customers are hot.
I was running perl5.001 and all was well. Can anybody help with
suggestions before I crawl back down in the pit?
Seems like going back to the perl5.001 would be the easiest solution but
I'm not sure how to uninstall the perl5.003.  Why? because I didn't
realise that I was installing perl5.003 till it was done. After
configuring wwwstat, I ran the makeall for it and it "upgraded" my
perl5.001 to 5.003. Hope somebody can help with advise.


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

Date: 10 Feb 1998 16:46:09 GMT
From: ronaldws@aol.com (RonaldWS)
Subject: Re: Q: Using unpack or split to get fixed-length substrings?
Message-Id: <19980210164601.LAA14753@ladder03.news.aol.com>

I took some time to look into this and it appears that the mundane substr may
work best.  You may wish to use the code below to check my suggestion against
others that come along ...

HTH

#!/usr/local/bin/perl

sub rndchar {
	return pack "c", ord('A') + int(26 * rand);
}

for ($i = 0; $i < (1 << 15); $i++) {
	$long_str .= rndchar;
}
$t = (times)[0];
print "user time generating string $t\n";

$split_len = 3;
$len = length($long_str);
$pieces = int($len / $split_len) + (($len % $split_len) ? 1 : 0);

for ($i = 0; $i < $len; $i += $split_len) {
	push @l, substr($long_str, $i, $split_len);
	
}
$t = (times)[0] - $t;
print "user time for substr no pre-alloc $t\n"; 
#keep the compiler honest - no optimizing away because we don't use @l
print "$l[0], $l[$pieces /2], $l[$#l], $#l\n";

#based on the suggestion by Tom Phoenix posted to the news group.
undef @l;
@l = ($long_str =~ /(.{1,3})/g); 
$t = (times)[0] - $t;
print "user time for global pattern match $t\n"; 
print "$l[0], $l[$pieces /2], $l[$#l], $#l\n";

undef @l;
@l = unpack "a3" x $pieces, $long_str;
$t = (times)[0] - $t;
print "user time for unpack match $t\n"; 
print "$l[0], $l[$pieces /2], $l[$#l], $#l\n";



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

Date: 10 Feb 1998 17:17:41 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: regular expressions
Message-Id: <6bq23l$p1b$5@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, ThomaJA@LFC.EDU (Mike Binkley) writes:
:for ($k = 0; $k < $#tokens; $k++){
:   if ($word =~ /@tokens[$k]/){
:      print "$word   @tokens[$k]\n";
:      };

That's very unperlian.  

1) You're using a for loop instead of the faster and easier foreach loop.
2) You are using an array slice when you should be using an array element.
3) You are interpolating patterns a zillion times for a super slow down.

The standard documentation set (including the FAQ) covers these issues.

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com
In general, if you think something isn't in Perl, try it out, because it
usually is.  :-)
        --Larry Wall in <1991Jul31.174523.9447@netlabs.com>


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

Date: Tue, 10 Feb 1998 11:49:29 -0500
From: John Porter <jdporter@min.net>
Subject: Re: returning the date
Message-Id: <34E08519.B98@min.net>

Clay Irving wrote:
> 
>   A Summary of the International Standard Date and Time Notation
>   by Markus Kuhn
>   http://www.ft.uni-erlangen.de/~mskuhn/iso-time.html

Hokay. Please disregard my earlier post in this thread.
ISO has done The Right Thing.  Except ! I am amazed that they
are allowing 2-digit year representations.  When we gonna learn?

John Porter


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

Date: 10 Feb 1998 17:07:54 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: returning the date
Message-Id: <6bq1ha$p1b$1@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, jdporter@min.net writes:
:Then there's the U.S. military's Date Time Group (DTG) format:
:	YYYYMMDDHHMMSS.HH
:all parts optional, from the outside in (to seconds) (as I recall).

What's the trailing HH after the dot?

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com
"I'll put an end to the idea that a woman's body belongs to her . . . the
 practice of abortion shall be exterminated with a strong hand."
    --Adolf Hitler, _Mein Kampf_


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

Date: 10 Feb 1998 19:48:56 +0200
From: Jarkko Hietaniemi <jhi@alpha.hut.fi>
Subject: Re: returning the date
Message-Id: <oeek9b34agn.fsf@alpha.hut.fi>


Tom Christiansen <tchrist@mox.perl.com> writes:
> :Then there's the U.S. military's Date Time Group (DTG) format:
> :	YYYYMMDDHHMMSS.HH
> :all parts optional, from the outside in (to seconds) (as I recall).
> 
> What's the trailing HH after the dot?

Hundreths-Hundreths?

-- 
$jhi++; # http://www.iki.fi/~jhi/
        # There is this special biologist word we use for 'stable'.
        # It is 'dead'. -- Jack Cohen


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

Date: 10 Feb 1998 15:10:53 GMT
From: "Eric D. Friedman" <friedman@uci.edu>
Subject: Re: Sharing variables between scripts
Message-Id: <6bpqlt$ki8@news.service.uci.edu>

[mailed, posted]

In article <6bpoo0$s40@newsops.execpc.com>,
Brian M. Beaulieu <banman@execpc.com> wrote:

<contents of 'variables.pl'
<--
<#!/usr/bin/perl
<$var1 = 'value1';
<$var2 = 'value2';
<etc..
<--
<
<and i have script1.pl, script2.pl etc ..
<and I want to use variables.pl in script#.pl .. sharing the variables..
<sort of like sharing a sub{}; in between scripts.. 
<Sounds like it can't be done.. but thanks for your help.

Wow, you really know how to make a simple question confusing.  Here's
how I would have phrased your question (answer follows):

I've got several scripts that use the same constant variables.  Rather
than maintain them separately in each script, I'd like to put those
constants into a file from which my scripts can import the needed
values.  How do I do it?

The answer is:

read the Exporter man page, and once you've understood it, put your
constants into a separate package that exports them to namespace of
scripts that "use" your package.  One nice way to set up the
constants is to use the "constant" pragma.

package shared;

use vars qw(@ISA @EXPORT @EXPORT_OK);

@ISA = qw ( Exporter );

@EXPORT_OK = ( FOO );

use constant 'FOO' => 15;

Then, in your scripts:

use shared qw ( FOO );

print FOO, "\n";
-- 
Eric D. Friedman
friedman@uci.edu


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

Date: 10 Feb 1998 15:35:21 GMT
From: jack_h_ostroff@groton.pfizer.com (Jack Ostroff)
To: "Brian M. Beaulieu" <banman@execpc.com>
Subject: Re: Sharing variables between scripts
Message-Id: <6bps3p$8uu2@mascagni.pfizer.com>

[mailed and posted]

Eric Friedman's suggestion of using Exporter is probably a more correct approach,
but would "require" do what you want?

Jack
jack_h_ostroff@groton.pfizer.com


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

Date: 10 Feb 1998 17:23:06 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Sharing variables between scripts
Message-Id: <6bq2dq$p1b$6@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, "Brian M. Beaulieu" <banman@execpc.com> writes:
:contents of 'variables.pl'

Perfect name for a perl library.

:#!/usr/bin/perl

Remove that line.

:$var1 = 'value1';
:$var2 = 'value2';
:etc..
:and i have script1.pl, script2.pl etc ..
:and I want to use variables.pl in script#.pl .. sharing the variables..
:sort of like sharing a sub{}; in between scripts.. 

I really don't understand your confusion between scripts and
libraries.  But what you really need to learn how to do
is namespace control and import/export mechanisms from 
modules.

:Sounds like it can't be done.. but thanks for your help.

It's trivial -- once you know how.  

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com

    One difference between a man and a machine is that a machine 
    is quiet when well oiled.


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

Date: 10 Feb 1998 17:25:58 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Sharing variables between scripts
Message-Id: <6bq2j6$p1b$7@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, jack_h_ostroff@groton.pfizer.com (Jack Ostroff) writes:
:Eric Friedman's suggestion of using Exporter is probably a more correct approach,
:but would "require" do what you want?

require doesn't import.   

And before you go trying to write a function, find at least three bugs
in the following, and fully explain them.

    getmod("Foo::Bar");
    sub getmod {
	require $_[0];
	import  $_[0];
    } 
    func 3;  # really Foo::Bar::func()

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com


Sometimes when you fill a vacuum, it still sucks.   --Rob Pike


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

Date: 10 Feb 1998 16:21:48 +0100
From: Andreas Hartmann <ahartman@geolin5.geophys2.uni-bremen.de>
Subject: strange split behaviour
Message-Id: <opafbz1o4y.fsf@geolin5.geophys2.uni-bremen.de>

I just built perl 5.004_04 on Sun-OS 4. Everything was going okay, but
if I try to split a line of input with leading whitespace like

   12312   12312   1212

with 

while (<>) {
	$n=split;
}

$n is 4. The manual page states that any leading spaces are removed, and
an older version (5.003) on a linux platform behaves like that. 

Is this a bug or did I miss something? I got no serious errors
when I compiled the source.

Thanks,
  Andy.


-- 
***********************************************************************
Andreas Hartmann                mailto:ahartman@geophys2.uni-bremen.de 
Department of Geoscience        http://gphsrv1.geophys2.uni-bremen.de/
University of Bremen
***********************************************************************


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

Date: Tue, 10 Feb 1998 12:36:24 -0500
From: Dan Boorstein <dboorstein@shopcfn.com>
Subject: Re: strange split behaviour
Message-Id: <34E09018.5E7839E@shopcfn.com>

Andreas Hartmann wrote:
> 
> I just built perl 5.004_04 on Sun-OS 4. Everything was going okay, but
> if I try to split a line of input with leading whitespace like
> 
>    12312   12312   1212
> 
> with
> 
> while (<>) {
>         $n=split;
> }
> 
> $n is 4. The manual page states that any leading spaces are removed, and
> an older version (5.003) on a linux platform behaves like that.

also from the man page:

 If not in a list context, returns the number of fields found and splits
 into the @_ array. 

try putting parens around $n.

--
dan boorstein <dboorstein@shopcfn.com>


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

Date: Tue, 10 Feb 1998 18:06:14 +0100
From: "R. Allen Conway" <raconway@atos-group.com>
Subject: Re: substitution/expression
Message-Id: <14953E9BAF17D111926800805FA66B71019AF794@hermes.atos-group.com>

One way of doing it is ...

$field =~ s/([ \/])([a-z]/$1.uc($2)/eg;

>  I am attempting to capitalize any character in a field that follows a " "
or
>a "/". Forget doubling them up, right now I'd settle for getting *either*
to
>work. According to the manuals (camel 2nd ed p73) I should be able to put
an
>expression as the 2nd part of a substitution. But when I try:
>
>$field = "Tom jerry";
>$field =~ s/ [a-z]/(uc $&)/e;
>print $field;
>




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

Date: 10 Feb 1998 16:36:43 GMT
From: petdance@maxx.mc.net (Andy Lester)
Subject: Re: Syntax-coloring editor for NT
Message-Id: <6bpvmr$od$1@usenet40.supernews.com>

: Buying proprietary software is almost understandable when a free 
: equivalent is not available, but paying $100 for a text editor is
: ridiculous.  As long as people like you keep buying their crap,
: people like Microsoft will continue to screw the rest of us.

Oh, well, why didn't you just SAY you were one of those "all software must
be free"/"God, I wish it was still the 70s" doofs? 

Paying $100 for a text editor that I like and that I want and is worth
$100 to me is not ridiculous.

So, in your opinion, which software is valid to spend money on?  Or can I
never spend money on software without being tarred as "people like you"?

And how is Microsoft screwing you?  You're happy with your free software,
so how does Microsoft  have anything to do with you?  

I'll repeat it: Find someone who cares.  I'm sorry that you have to clutch
at things to take offense from.

xoxo,
Andy


--
--
Andy Lester:        <andy@petdance.com>       http://tezcat.com/~andy/
Chicago Shows List: <shows@ChicagoMusic.com>  http://ChicagoMusic.com/



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

Date: Tue, 10 Feb 1998 18:12:33 +0100
From: "R. Allen Conway" <raconway@atos-group.com>
Subject: Re: Syntax-coloring editor for NT
Message-Id: <14953E9BAF17D111926800805FA66B71019B0424@hermes.atos-group.com>

The problem is not so much the $100 and Micro$oft, it's how can you possibly
NOT want to use EMACS? There is no better editor - it's worth every Mbyte it
occupies and no Mickey Mouse PC editor coming from Micro$oft, or Borland or
whoever, comes anywhere close. Of course you could always write an editor in
PERL or PERL/tk if you want to be a little fancy.

Andy Lester a icrit dans le message <6bpvmr$od$1@usenet40.supernews.com>...

>Paying $100 for a text editor that I like and that I want and is worth
>$100 to me is not ridiculous.
>
>So, in your opinion, which software is valid to spend money on?  Or can I
>never spend money on software without being tarred as "people like you"?
>
>And how is Microsoft screwing you?  You're happy with your free software,
>so how does Microsoft  have anything to do with you?
>
>I'll repeat it: Find someone who cares.  I'm sorry that you have to clutch
>at things to take offense from.




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

Date: Tue, 10 Feb 1998 11:25:08 -0500
From: "Jerry Davis" <gedavis3@vt.edu>
Subject: Re: Using flock?
Message-Id: <6bpv4l$mgn$1@solaris.cc.vt.edu>

Well most OS will prevent two operations from writing at the same time but
they wont prevent this

simple counter example
START with a counter file with the value 100 stored in it.
script 1 opens counter file and reads in the 100
script 1 increments 100 =>101
script 2 opens counter file and reads in the 100 (no changes have been made
to the file yet)
script 2 increments 100 => 101
script 1 writes 101 to file
script 2 writes 101 to file
END counter file contains value 101

The counter was accessed twice yet it only shows one more "visit".


Thanks everyone for the help with flock, sadly Microsuck has been unable to
put together a working os yet.

Somehow I flocked a file, the script crashed, and the file got garbaged.
When I tried to delete the file, I couldn't, nor could I re-name it, or
upload a modified version.
I built a script that showed me that the file was still flocked exculsive,
yet when I unflocked it I got a 1 (good) return value, but running the
script again showed the exclusive flock still on!

I eventualy emailed my sysadmin and was told that they could only delete the
file after shutting the server down.  Sunday (5 days after the incident)
they shutdown for scheduled mantinance and I got rid of the offending file.
Luckily it was just in a test directory,  could you imagine if I made a
script to modify my index.html file!

I think I will stay away from flock at least till I move to a real OS

Jerry





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

Date: 10 Feb 1998 17:14:27 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Using flock?
Message-Id: <6bq1tj$p1b$4@csnews.cs.colorado.edu>

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

In comp.lang.perl.misc, "Jerry Davis" <gedavis3@vt.edu> writes:
:Well most OS will prevent two operations from writing at the same time 

That's patently untrue.

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com

    #define SIGILL 6         /* blech */
        --Larry Wall in perl.c from the 4.0 perl source code


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

Date: Tue, 10 Feb 1998 17:07:08 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Yet Another Sorting Question(TM)
Message-Id: <Eo6A7w.Gqv@world.std.com>

David Fetter <dfetter@shell4.ba.best.com> writes:

>field1:field2:field3:field4
>a:foo:JAPH1:
>b:bar::St. Paul
>c::JAPH3:Ba'al-Zevuv
>:baz:JAPH4:Larry Wall

>The thing I'd like to do is:

>select field1,field2,field3,field4
>from table
>order by field1, field2

>Right now, I have a crude, inextensible hack that doesn't quite work
>right--bombs when it runs across blanks in the key fields.

Where do you want the blank fields to sort? How does it "bomb"? Where
should you look? Probably the FAQ at <URL:http://www.perl.com/CPAN/doc
/manual/html/pod/perlfaq4/How_do_I_sort_an_aray_by_anyth.html>

As the FAQ suggests, probably the best thing to do is split the input
up into fields first, then sort on those fields. Again, as the FAQ
suggests, if you want to sort on multiple fields, compare the primary
field, and if equal sort on the secondary field. (Use of "cmp" and
"<=>" combined with the "or" operator is really great for this since
the comparison operator will return false if its operands are equal
and the logical or operator will evaluate its right operand if its
left operand is false.)

[David: Just to check, is there anything in the FAQ entry you did not
understand? Or did you just miss it.]

while(<>) {
  $input{$_} = [ split /:/ ];
}

print sort { $input{$a}[0] cmp $input{$b}[0] or 
             $input{$a}[1] cmp $input{$b}[1]    } keys %input;
-- 
Andrew Langmead


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

Date: Tue, 10 Feb 1998 12:08:56 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Yet Another Sorting Question(TM)
Message-Id: <34E089A8.7F29@min.net>

David Fetter wrote:
> 
> What I want to do a SQL-some maneuver like, given a 2-D rectangular
> array (in general with empty spaces), sort by several fields, and
> don't barf on emptiness.
> 
> field1:field2:field3:field4
> a:foo:JAPH1:
> b:bar::St. Paul
> c::JAPH3:Ba'al-Zevuv
> :baz:JAPH4:Larry Wall
> 
> The thing I'd like to do is:
> 
> select field1,field2,field3,field4
> from table
> order by field1, field2

I think what you want is the Sprite module from CPAN.
You did scan the CPAN, didn't you?


> Right now, I have a crude, inextensible hack that doesn't quite work
> right--bombs when it runs across blanks in the key fields.

Show Us The Code!

hth,
John Porter


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

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

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