[22125] in Perl-Users-Digest
Perl-Users Digest, Issue: 4347 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jan 6 00:05:49 2003
Date: Sun, 5 Jan 2003 21:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 5 Jan 2003 Volume: 10 Number: 4347
Today's topics:
Re: How can split ignore quoted characters? <ahamm@mail.com>
OO primer, please! <bik.mido@tiscalinet.it>
Re: OO primer, please! <mgarrish@rogers.com>
Re: OO primer, please! <reggie@_reggieband.com>
Re: OO primer, please! <penny1482@attbi.com>
Re: OO primer, please! <chris@cmb-enterprises.com>
Perl City <rdsteph@earthlink.net>
Re: Perl City <mgarrish@rogers.com>
Re: regex code evaluation (??{code}) <pinyaj@rpi.edu>
RSA <des64NOSPAM@gmx.de>
Re: RSA <goldbb2@earthlink.net>
Re: Should I worry about the optimizer. (Mark Jason Dominus)
Re: Should I worry about the optimizer. (Mark Jason Dominus)
Re: Should I worry about the optimizer. <goldbb2@earthlink.net>
Solaris 5.8 Perl compilation problem (Michael)
Re: Threads, dynamic loading programs, and using global <goldbb2@earthlink.net>
Re: Trying to capture blocks of data (Tad McClellan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 6 Jan 2003 11:40:01 +1100
From: "Andrew Hamm" <ahamm@mail.com>
Subject: Re: How can split ignore quoted characters?
Message-Id: <avajdl$dlmrs$1@ID-79573.news.dfncis.de>
Robert Nicholson wrote:
> How do you specific the pattern for split to ignore the quoted
> characters of the character you want to split on?
>
> ie. you want to split on ',' but you want to ignore \, in the text
>
> if I use
>
> split (/[^\\],/);
>
> that will chop of the last character of any matching field
>
> how can I match without chopping off that last character?
You sound suspiciously like you are trying to handle CSV (Comma Separated
Values) which allows quotes around fields, and escaping quotes etc. If so,
the Text::CSV module wins hands-down.
--
There's nowt wrong wi' owt what mitherin' clutterbucks don't barly grummit!
-
Replies directly to this message will go to an account that may not be
checked for a week or two. For more timely e-mail response, use (only
in an emergency) ahamm sanderson net au with all the usual punctuation.
------------------------------
Date: Mon, 06 Jan 2003 00:16:50 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: OO primer, please!
Message-Id: <a2dh1v0gfful83m25opm6ahrumrpu4dntm@4ax.com>
<premise>
I have no experience in OO programming (in general and) in Perl. I
know that there are both good reference manpages and tutorials,
however I'd like to see practically how to work on a task I'm taking
into account right now.
</premise>
So, the problem is this: I'd like to implement an interface to store
tables (please don't point me to suitable modules: it's just for
experimenting/learning) and eventually to print them out.
The interface should work like this:
my $table1=table->new;
for my $x (1..5) {
for my $y (1..3) {
$table1->entry($x,$y)->put(fun($x,$y));
}
}
Obviously there should be a corresponding method 'get' and a method
'$table1->printt()' to print the table once it's filled[*], and
possibly others to follow (but I'd like to keep it as simple as
possibe initially).
As an aside, I seem to recall that there's a way to make a custom
defined function return an l-value: I think it would be great to be
able to store entries with a command like
$table1->entry($x,$y)=fun($x,$y);
and to get them just by referring to them. I doubt that this conflicts
with the OO approach in general, but it doesn't seem to bad in cases
like this.
I know that it would be more fair to read the relevant docs and
possibly ask here if I have any difficulty (I'll do so indeed in case
I don't receive any answer); nevertheless I'd be very grateful if
somebody could be so kind and provide a *skeleton* of code...
[*] To be definite, at this stage a portion of code like this should
suffice:
{
local ($,,$\)=("\t","\n");
print @{$_} for @table;
}
(this implies that $x and $y are swapped as indexes of 2-dim array
@table used here - it should be the array used practically to store
the values)
Michele
--
>It's because the universe was programmed in C++.
No, no, it was programmed in Forth. See Genesis 1:12:
"And the earth brought Forth ..."
- Robert Israel on sci.math, thread "Why numbers?"
------------------------------
Date: Mon, 06 Jan 2003 00:02:10 GMT
From: "mgarrish" <mgarrish@rogers.com>
Subject: Re: OO primer, please!
Message-Id: <6I3S9.175301$yW.65269@news04.bloor.is.net.cable.rogers.com>
"Michele Dondi" <bik.mido@tiscalinet.it> wrote in message
news:a2dh1v0gfful83m25opm6ahrumrpu4dntm@4ax.com...
> <premise>
> I have no experience in OO programming (in general and) in Perl. I
> know that there are both good reference manpages and tutorials,
> however I'd like to see practically how to work on a task I'm taking
> into account right now.
> </premise>
>
Object Oriented Perl by Damian Conway (Manning Publications)
Good luck getting someone to write the code for you...
Matt
------------------------------
Date: Mon, 06 Jan 2003 00:49:02 GMT
From: reggie <reggie@_reggieband.com>
Subject: Re: OO primer, please!
Message-Id: <2o4S9.355758$ka.9459607@news1.calgary.shaw.ca>
Michele Dondi wrote:
><premise>
> I have no experience in OO programming (in general and) in Perl. I
> know that there are both good reference manpages and tutorials,
> however I'd like to see practically how to work on a task I'm taking
> into account right now.
></premise>
<snip>
> I know that it would be more fair to read the relevant docs and
> possibly ask here if I have any difficulty (I'll do so indeed in case
> I don't receive any answer); nevertheless I'd be very grateful if
> somebody could be so kind and provide a *skeleton* of code...
Interestingly, evolt just posted an article, just for you ;-)
http://evolt.org/article/Camel_POOP_Object_Oriented_Programming_in_Perl/17/50922/index.html
--
regards,
reggie.
------------------------------
Date: Mon, 06 Jan 2003 01:32:05 GMT
From: "Dick Penny" <penny1482@attbi.com>
Subject: Re: OO primer, please!
Message-Id: <p05S9.451736$pN3.49820@sccrnsc03>
I too had no experience writing OO modules. I found several tutorials on
WEB sites. The authors of one was Vilram Vaswani and another was Stas
Bekman. You should be able to locate them through Google. Plus the Perl
Beginners Toot that comes with Active State (maybe other Perls too). I have
now written 3 or 4 modules. Not too hard if you spend time studying the
above refs first.
Dick Penny
"Michele Dondi" <bik.mido@tiscalinet.it> wrote in message
news:a2dh1v0gfful83m25opm6ahrumrpu4dntm@4ax.com...
> <premise>
> I have no experience in OO programming (in general and) in Perl. I
> know that there are both good reference manpages and tutorials,
> however I'd like to see practically how to work on a task I'm taking
> into account right now.
> </premise>
>
> So, the problem is this: I'd like to implement an interface to store
> tables (please don't point me to suitable modules: it's just for
> experimenting/learning) and eventually to print them out.
>
> The interface should work like this:
>
> my $table1=table->new;
> for my $x (1..5) {
> for my $y (1..3) {
> $table1->entry($x,$y)->put(fun($x,$y));
> }
> }
>
> Obviously there should be a corresponding method 'get' and a method
> '$table1->printt()' to print the table once it's filled[*], and
> possibly others to follow (but I'd like to keep it as simple as
> possibe initially).
>
>
> As an aside, I seem to recall that there's a way to make a custom
> defined function return an l-value: I think it would be great to be
> able to store entries with a command like
>
> $table1->entry($x,$y)=fun($x,$y);
>
> and to get them just by referring to them. I doubt that this conflicts
> with the OO approach in general, but it doesn't seem to bad in cases
> like this.
>
>
> I know that it would be more fair to read the relevant docs and
> possibly ask here if I have any difficulty (I'll do so indeed in case
> I don't receive any answer); nevertheless I'd be very grateful if
> somebody could be so kind and provide a *skeleton* of code...
>
>
> [*] To be definite, at this stage a portion of code like this should
> suffice:
>
> {
> local ($,,$\)=("\t","\n");
> print @{$_} for @table;
> }
>
> (this implies that $x and $y are swapped as indexes of 2-dim array
> @table used here - it should be the array used practically to store
> the values)
>
>
> Michele
> --
> >It's because the universe was programmed in C++.
> No, no, it was programmed in Forth. See Genesis 1:12:
> "And the earth brought Forth ..."
> - Robert Israel on sci.math, thread "Why numbers?"
------------------------------
Date: Mon, 06 Jan 2003 04:38:37 -0000
From: Chris Dutton <chris@cmb-enterprises.com>
Subject: Re: OO primer, please!
Message-Id: <20030105233553885-0500@news.fltg.net>
In <a2dh1v0gfful83m25opm6ahrumrpu4dntm@4ax.com> Michele Dondi wrote:
> <premise>
> I have no experience in OO programming (in general and) in Perl.
Try poking around http://www.perlmonks.com.
------------------------------
Date: Mon, 06 Jan 2003 02:51:36 GMT
From: Ron Stephens <rdsteph@earthlink.net>
Subject: Perl City
Message-Id: <3E18F033.1040702@earthlink.net>
Perl City at http://www.awaretek.com/perlcity.html features a web spider
that scrapes the web daily to obtain all new web articles about Perl.
Please give it a few days or weeks as it should get better each day as
it updates the database. Also featuring an online script to help
evaluate various programming languages for various purposes and many
many more programming resources and news articles and databases of
interest. Not a professional site, but rather a home-brew site
containing lots of meaningful content developed over a long time...
------------------------------
Date: Mon, 06 Jan 2003 05:04:48 GMT
From: "mgarrish" <mgarrish@rogers.com>
Subject: Re: Perl City
Message-Id: <Q78S9.205136$F2h1.79789@news01.bloor.is.net.cable.rogers.com>
"Ron Stephens" <rdsteph@earthlink.net> wrote in message
news:3E18F033.1040702@earthlink.net...
> Not a professional site, but rather a home-brew site
> containing lots of meaningful content developed over a long time...
I don't think you need to worry about anyone confusing it for a professional
site in the short term. Why is it that so many of your "Perl" articles are
from the Python Cookbook, though?
Matt
------------------------------
Date: Sun, 5 Jan 2003 20:25:42 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: weberh <weberh@zedat.fu-berlin.de>
Subject: Re: regex code evaluation (??{code})
Message-Id: <Pine.SGI.3.96.1030105202430.8094A-100000@vcmr-64.server.rpi.edu>
[posted & mailed]
On 5 Jan 2003, weberh wrote:
>perl -ne 'while(/([A|B|C|D]{6}).+?(??{reverse \1})/){print "$&\n"}'
>foo
First of all, you want [ABCD]{6}, not [A|B|C|D]{6}. The '|' doesn't mean
anything special inside a character class.
Also, you want $1, not \1. (??{ ... }) is a code block, and you need to
refer to $1 in code.
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Mon, 06 Jan 2003 03:55:32 +0100
From: Robert Spielmann <des64NOSPAM@gmx.de>
Subject: RSA
Message-Id: <avar6v$dhg2f$1@ID-73387.news.dfncis.de>
Hi,
how can I do big number arithmetics in perl, in order to write a RSA
implementation?
Thanks for hints
Robert
------------------------------
Date: Sun, 05 Jan 2003 22:38:56 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: RSA
Message-Id: <3E18FA50.C89B1840@earthlink.net>
Robert Spielmann wrote:
>
> Hi,
>
> how can I do big number arithmetics in perl, in order to write a RSA
> implementation?
use Math::BigInt; # from CPAN.
I would also suggest installing either of Math::BigInt::GMP or
Math::BigInt::Pari, which are pluginable backends, which use Math::GMP
and Math::Pari to do the actual math.
If you don't, then Math::BigInt will use Math::BigInt::Calc, which is
pure-perl and which comes with Mathe::BigInt, as it's backend. This is
rather slower (if more portable) than either of GMP or Pari.
Note that although you *can* use Math::GMP or Math::Pari directly, I
would advise against it -- you'll have difficulties in the future if you
ever need to move to a machine which doesn't have that particular
library, and where you can't compile (or aren't allowed to install)
it... the Math::BigInt package provides a unified interface to both
libraries, so no changes are needed if you need to switch backends.
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Mon, 6 Jan 2003 01:49:04 +0000 (UTC)
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Should I worry about the optimizer.
Message-Id: <avanag$f2e$1@plover.com>
In article <csdg1v04mdel56h0ur09n61adaqjmbriod@4ax.com>,
Teh (tî'pô) <teh@mindless.com> wrote:
>Hi, I'm benchmarking a few things and I'm not sure how much I should
>be worried about the optimizer optimizing away stuff.
If you're worried, use
perl -Dx mybenchmark.pl
and see what it is doing.
------------------------------
Date: Mon, 6 Jan 2003 01:56:17 +0000 (UTC)
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Should I worry about the optimizer.
Message-Id: <avano1$f58$1@plover.com>
In article <igkg1vk4jkbifsolck6decs4ju0u7008g4@4ax.com>,
Teh (tî'pô) <teh@mindless.com> wrote:
>I was hoping someone who knows perl internally could give me a factual
>answer.
There isn't going to be a single factual answer. The whole point of
an optimizer is that it makes changes to the code that are
semantically invisible; because the changes are semantically
invisible, they can change from version to version of Perl without any
warning. The answer to any specific question about optimization will
depend very much on the particular version of Perl you are using.
So the best answer to such questions is that you should use -Dx and
see for yourself what is happening.
For example:
perl5.7.3 -Dx -e 'sub f { foreach (@_) { } }'
{
TYPE = null ===> (12)
FLAGS = (UNKNOWN,KIDS)
{
11 TYPE = and ===> 12
FLAGS = (UNKNOWN,KIDS)
OTHER ===> 7
{
10 TYPE = iter ===> 11
FLAGS = (SCALAR)
}
{
TYPE = lineseq ===> (0)
FLAGS = (SCALAR,KIDS)
{
7 TYPE = nextstate ===> 8
FLAGS = (VOID)
LINE = 1
PACKAGE = "main"
}
{
8 TYPE = unstack ===> 9
FLAGS = (VOID)
}
{
9 TYPE = nextstate ===> 10
FLAGS = (SCALAR)
LINE = 1
PACKAGE = "main"
}
}
}
}
The 'null' items are operations that were optimized away. But the
'iter' (which is iterating on the array) and the 'and' (which is
testing for the end) are both still there.
I hopt this is something like what you wanted.
------------------------------
Date: Sun, 05 Jan 2003 22:58:00 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Should I worry about the optimizer.
Message-Id: <3E18FEC8.6E5C41B7@earthlink.net>
Teh (tî'pô) wrote:
>
> Hi, I'm benchmarking a few things and I'm not sure how much I should
> be worried about the optimizer optimizing away stuff.
[snip]
> Should I worry about perl optimizing away my loops? It doesn't in this
> case but I don't know if I should take precautions against the
> possibility.
A better question is, what are you trying to optomize, and why?
In general, Benchmark isn't really the best tool for speeding up your
perl program -- the profiler is. You want to spend your effort finding
out which parts of the program need to be sped up, before going and
spending your effort on doing the actual speeding up.
PS: To the best of my knowledge, perl rarely optomizes away blocks, even
when it could. Off the top of my head, the only times that blocks are
optomized out are when you wrap them in an if(0) {} block. (Note that
due to constant-folding, 'use constant DEBUG => 0;' results in
'if(DEBUG){stuff}' being optomized away.)
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: 5 Jan 2003 20:15:06 -0800
From: michaelb@championdata.com.au (Michael)
Subject: Solaris 5.8 Perl compilation problem
Message-Id: <d55785d7.0301052015.28c7481e@posting.google.com>
Dear All,
I am trying to build perl 5.8.0 on a SPARC Solaris box (2.8). During
the running of Configure (./Configure -de -Dusethreads -Dcc='gcc
-B/usr/ccs/bin/') I get the following:
....
Checking to see whether you can access character data unalignedly...
try.c: In function `main':
try.c:15: `njs' undeclared (first use in this function)
try.c:15: (Each undeclared identifier is reported only once
try.c:15: for each function it appears in.)
try.c:15: parse error before `{'
try.c:41: parse error before `{'
try.c:51: parse error before `{'
gcc: file path prefix `/usr/ccs/bin/' never used
Can you access character data at unaligned addresses? [n]
....
Configure continues to run to completion, however I then get the same
error when trying to build perl.
....
`sh cflags "optimize='-O'" miniperlmain.o` miniperlmain.c
CCCMD = gcc -B/usr/ccs/bin/ -DPERL_CORE -c -D_REENTRANT
-fno-strict-a
liasing -I/usr/local/include -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64 -O -Wall
miniperlmain.c: In function `main':
miniperlmain.c:75: `njs' undeclared (first use in this function)
miniperlmain.c:75: (Each undeclared identifier is reported only once
miniperlmain.c:75: for each function it appears in.)
miniperlmain.c:75: parse error before `{'
miniperlmain.c:78: parse error before `exit'
miniperlmain.c:85: parse error before `perl_run'
miniperlmain.c:91: parse error before `Perl_croak_nocontext'
gcc: file path prefix `/usr/ccs/bin/' never used
make: *** [miniperlmain.o] Error 1
....
I have built perl successfully on a number of different Solaris
machines before and never had any trouble. I am obviously missing
something. Can anybody point me in the right direction. The output
of 'myconfig' is as follows:
Summary of my perl5 (revision 5.0 version 8 subversion 0)
configuration:
Platform:
osname=solaris, osvers=2.8, archname=sun4-solaris-thread-multi
uname='sunos krusty 5.8 generic sun4u sparc sunw,ultra-5_10 '
config_args='-de -Dusethreads -Dcc=gcc -B/usr/ccs/bin/'
hint=recommended, useposix=true, d_sigaction=define
usethreads=define use5005threads=undef useithreads=define
usemultiplicity=de
fine
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='gcc -B/usr/ccs/bin/', ccflags ='-D_REENTRANT
-fno-strict-aliasing -I/usr
/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O',
cppflags='-D_REENTRANT -fno-strict-aliasing -I/usr/local/include'
ccversion='', gccversion='2.95.3 20010315 (release)',
gccosandvers='solaris2
.8'
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=4321
d_longlong=define, longlongsize=8, d_longdbl=define,
longdblsize=16
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize
=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='gcc -B/usr/ccs/bin/', ldflags =' -L/usr/local/lib '
libpth=/usr/local/lib /usr/lib /usr/ccs/lib
libs=-lsocket -lnsl -ldl -lm -lrt -lpthread -lc
perllibs=-lsocket -lnsl -ldl -lm -lrt -lpthread -lc
libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib'
Cheers,
Michael.
------------------------------
Date: Sun, 05 Jan 2003 22:24:59 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Threads, dynamic loading programs, and using globals?
Message-Id: <3E18F70B.52FFD2AE@earthlink.net>
Joe wrote:
>
> Thanks Benjamin.
>
> First comments, then new twist at the end.
>
> I found out that I was foolish to include the 'package' statement in
> the main file, this complicated package variables for me. And also
> foolishly I lost the 'threads::shared' statement, but the " : shared"
> and lock() didn't complain, hmmmmmmm :(
Perl makes lock() a sort of weak keyword, so I can understand why it
didn't complain about that during compilation. I don't understand why
the ":shared" didn't produce an error, though.
> Once these 2 mistakes were fixed, things started to improve.
>
> Benjamin Goldberg <goldbb2@earthlink.net> wrote in message >
> > If it is to be placed in the main file, then it must be a package
> > variable, not a lexical variable. Declare it with our() instead of
> > my().
>
> Works. I declared 'our $q : shared;' in main, and used $::q in the
> loaded program with no other declarations.
Yes, that's one way to do it. You could also have done (in the plugin):
use vars qw($q);
BEGIN { *q = \$main::q };
Then just used $q in the plugin, without needing the "::" in there.
> > > 2) How do I place this resource just in the loaded file
> > > (preferred)?
> >
> > A variable which is to be shared between multiple threads *must* be
> > declared as such *before* those threads get created.
>
> Works. The only change in 'Main' is to move the 'require' from the
> 'start_thread' subroutine to before the 'create->thread'. The plugin
> only needs 'our $q : shared;'. But see the new issue below :(.
>
> > > 3) If this model can be improved, please advise.
> >
> > Whether it can be improved or not depends on how many different
> > plugins there are to be loaded, and how many *will* be loaded in the
> > lifetime of the process
>
> I will have a look at this approach later.
>
> A new twist:
> Again, my program works as described, just that I am looking for
> convienient way to share resources among same type of the plugins.
>
> There is a little chicken and egg dilema here. In my real application
> the Main program gets the name of the "plugin" to load from a socket.
> So I am already in a thread after the 'accept', and after some more
> processing, when I learn the name of the program to load and run.
> That's why I was using the 'require' in the thread, not in Main.
>
> while( 1 ) {
> my $client = $daemon->accept;
> my $thr = threads->create(\&start_thread, $client );
> $thr->detach();
> }
Ahh, I see. PS: you don't need the $thr temporary variable, you can
just write:
threads->create(\&start_thread, $client)->detatch;
> I do know what plugins are available. I can use a prepared list in
> text file or dynamically scan all .pm in the home directory, so I can
> pre 'require' them all in Main before starting the HTTP daemon. But I
> wanted to do it on-the-fly if possible. I also didn't want to clone
> all plugins in the new threads when I will use only one in the thread.
> A side effect is that I can modify the plugin and it changes for the
> next invocation.
Ok, I get what you're saying.
Hmm... Ok, how about this. Take the following code, and put it into a
file named "threads/shared/vars.pm" somewhere in your @INC path...
package threads::shared::vars;
use strict;
use warnings;
use threads::shared;
my %vars : shared;
sub import {
shift; return unless @_;
my $p = caller;
my $hash = do {
lock %vars;
my $r = $vars{$p};
$vars{$p} = $r = do { my %h : shared; \%h } unless $r;
$r;
};
lock %$hash;
for my $var (@_) {
my ($sigil, $name) = m/^
([\$\@%]) # match the variable's type.
([^\W\d]\w*) # match the variable's name.
\z/x or do {
require Carp;
Carp::croak("Can't declare shared variable $var");
};
my $ref;
$hash->{$var} = $ref = eval qq{
my ${sigil}shared_${name} : shared;
\\ ${sigil}shared_${name};
} or die $@ unless defined($ref = $hash->{$var});
no strict 'refs';
*{$p."::$name"} = $ref;
} # end for $var
} # end sub import
1;
__END__
[untested]
In your main program, insert a line that says:
use threads::shared::vars;
In each of the plugins, declare the variables you want with:
package mypackage;
use threads::shared; # for lock().
use threads::shared::vars qw($q);
The same as you would use a normal 'use vars'... No other declaration
of $q should be needed anywhere.
--
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);
------------------------------
Date: Sun, 5 Jan 2003 17:20:13 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Trying to capture blocks of data
Message-Id: <slrnb1hfdd.9ot.tadmc@magna.augustmail.com>
Vispy <vispy1@attbi.com> wrote:
> So the first block is start of the line & 4 characters, the second block is
> 6 thru 35 characters, the third block is 37 thru 42 characters and the
> fourth block is 44 thru 47 characters.
> Can anyone help?
The Perl Frequently Asked Questions can help:
"How can I manipulate fixed-record-length files?"
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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.
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 V10 Issue 4347
***************************************