[24107] in Perl-Users-Digest
Perl-Users Digest, Issue: 6301 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 25 14:06:17 2004
Date: Thu, 25 Mar 2004 11: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 Thu, 25 Mar 2004 Volume: 10 Number: 6301
Today's topics:
Re: Accessing OS Message Loop (Bryan Castillo)
Assertions in perl <jtc@shell.dimensional.com>
Re: Counting elements in array <tore@aursand.no>
Re: Declaring variables outside subroutines (Malcolm Dew-Jones)
easier way for $scalar = /regexp/ ??? <PerlGuRu2b@bobotheclown.org>
Re: easier way for $scalar = /regexp/ ??? <dwall@fastmail.fm>
Re: easier way for $scalar = /regexp/ ??? <remorse@partners.org>
Re: easier way for $scalar = /regexp/ ??? <PerlGuRu2b@bobotheclown.org>
Re: easier way for $scalar = /regexp/ ??? (Anno Siegel)
how to check if a table already exists? <bdu@iastate.edu>
Re: how to check if a table already exists? <glex_nospam@qwest.invalid>
Re: I want to scanf, dammit! <mitia.nospam@northwestern.edu.invalid>
Re: parsing config file <dwall@fastmail.fm>
problem with index not matching string exactly (G)
Re: Puzzling Socket::inet_ntoa problem axel@white-eagle.co.uk
q: regex: parse <length><value>? <"dbwood at acm dot org">
Re: q: regex: parse <length><value>? <tassilo.parseval@rwth-aachen.de>
Re: Regular Expressions Question <tore@aursand.no>
Re: Removing folders recursively <dwall@fastmail.fm>
Re: Switching .... <tore@aursand.no>
Re: Switching .... (Anno Siegel)
Re: The "value" of a block in 'map' (Anno Siegel)
Re: The "value" of a block in 'map' <uri.guttman@fmr.com>
Unix sokets and signal handling <online-toglimi@carpani-toglimi.net>
Re: Unix sokets and signal handling <nobull@mail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 25 Mar 2004 08:07:52 -0800
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: Accessing OS Message Loop
Message-Id: <1bff1830.0403250807.7c096ad3@posting.google.com>
p_jacobson@hotmail.com (Phil Jacobson) wrote in message news:<2453019.0403241834.10e55fe9@posting.google.com>...
> > What is it you're really hoping to achieve?
>
> One of the things I'd like to do is point perl at a file and say
> "under no circumstances are you to let this file be modified, copied
> over or deleted." And while I was thinking about if I could achieve
> this, I began to explore the main Windows message loop as an option.
> Could it even be possible to allow perl to read the message loop and,
> if it sees an instruction regarding a particular file, prevent that
> instruction from taking place.
>
Which message loop? A windows program has a message loop related to
GUI events like mouse move and key presses. I do not the message loop
I'm speaking of has anything to do with file access. There is a
utility called filemon that might give you a direction in which to
search http://www.sysinternals.com/ntw2k/source/filemon.shtml
I believe it has to act like a file system driver. The win95/98
version says it uses a virtual file system filter to show access to
files, I assume you can deny file operations from that type of filter.
I don't much about NT/w2k/XP, except that is uses some other
mechanism.
In any case, I think you will have to go the C route.
(I'd be interested to hear if you find a sollution)
> Phil Jacobson
------------------------------
Date: 25 Mar 2004 09:49:11 -0700
From: Jim Cochrane <jtc@shell.dimensional.com>
Subject: Assertions in perl
Message-Id: <slrnc663c7.rrb.jtc@shell.dimensional.com>
There appear to be several modules in CPAN that support assertions. Which
modules have people found to be best in terms of the following criteria (in
order of importance)?:
- completeness (e.g., pre- and post-conditions are supported well)
- standardization (which packages, if any, have become defacto standards
for assertion checking facilities?)
- quality of the module (both in terms of the design of the interface and of
the implementation)
Thanks!
--
Jim Cochrane; jtc@dimensional.com
[When responding by email, include the term non-spam in the subject line to
get through my spam filter.]
------------------------------
Date: Thu, 25 Mar 2004 18:41:32 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Counting elements in array
Message-Id: <pan.2004.03.25.17.15.39.483403@aursand.no>
On Tue, 23 Mar 2004 16:25:56 +1100, meme wrote:
> #!/usr/bin/perl -w
>
> use strict;
>
> my $logfile = "./maillog";
>
> my ( @logbuffer, @vir, $vir, $line, $count, @count, %saw);
>
> open( LOGFILE, "<$logfile" )
> || die "Error opening local log file: $!";
> @logbuffer = <LOGFILE>;
>
> foreach my $line (@logbuffer) {
> unless ( $line !~ /INFECTED/ ) {
> $vir = ( split(/ /, $line ) )[7];
> push @vir, $vir;
> }
> }
> close LOGFILE;
>
> undef %saw;
> @count = grep(!$saw{$_}++, @vir);
> foreach (keys %saw) {
> print "$_ = $saw{$_}\n";}
Better, IMO:
#!/usr/bin/perl
#
use strict;
use warnings;
my $logfile = './maillog';
my %viruses;
open( LOG, '<', $logfile ) or die "$!\n";
while ( <LOG> ) {
next unless ( /INFECTED/ );
my $vir = ( split(/ /, $_) )[7];
$viruses{$vir}++;
}
close( LOG );
foreach ( keys %viruses ) {
print $_ . ' = ' . $viruses{$_} . "\n";
}
--
Tore Aursand <tore@aursand.no>
"I didn't have time to write a short letter, so I wrote a long one
instead." -- Mark Twain
------------------------------
Date: 25 Mar 2004 09:59:54 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Declaring variables outside subroutines
Message-Id: <40631e1a@news.victoria.tc.ca>
Appoooh (anon@ics.mq.edu.au) wrote:
: I'm no guru, and I haven't been programming professionally for long, but I
: can't help finding it disturbing that in the code below, $var is in scope
: within the subroutine foo. This is a bit eccentric compared to C++ or Java
huh? that isn't right.
------------------------------
Date: Thu, 25 Mar 2004 16:02:27 GMT
From: Rocky <PerlGuRu2b@bobotheclown.org>
Subject: easier way for $scalar = /regexp/ ???
Message-Id: <pan.2004.03.25.16.08.59.588839@bobotheclown.org>
if ($_ =~ /^Job\sserver:\s+(.*)$/) { $servername = $1;}
isn't it possible to just say
$servername = ???
I can't seem to find a good example.
Thank you
Rocky Allen
------------------------------
Date: Thu, 25 Mar 2004 16:08:15 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: easier way for $scalar = /regexp/ ???
Message-Id: <Xns94B7714AE691Adkwwashere@216.168.3.30>
Rocky <PerlGuRu2b@bobotheclown.org> wrote:
> if ($_ =~ /^Job\sserver:\s+(.*)$/) { $servername = $1;}
> isn't it possible to just say
> $servername = ???
> I can't seem to find a good example.
my $servername = $1 if /^Job\sserver:\s+(.*)$/;
------------------------------
Date: Thu, 25 Mar 2004 11:17:58 -0500
From: Richard Morse <remorse@partners.org>
Subject: Re: easier way for $scalar = /regexp/ ???
Message-Id: <remorse-5B7DAD.11175825032004@plato.harvard.edu>
In article <pan.2004.03.25.16.08.59.588839@bobotheclown.org>,
Rocky <PerlGuRu2b@bobotheclown.org> wrote:
> if ($_ =~ /^Job\sserver:\s+(.*)$/) { $servername = $1;}
> isn't it possible to just say
> $servername = ???
> I can't seem to find a good example.
According to the docs, in a scalar context, m// returns the number of
matches, but in a list context it returns the actual matches.
So this is what you're after:
my ($servername) = m/^Job\sserver:\s+(.*)$/;
By putting the variable name into the parens, we force in into list
context.
HTH,
Ricky
------------------------------
Date: Thu, 25 Mar 2004 16:17:22 GMT
From: Rocky <PerlGuRu2b@bobotheclown.org>
Subject: Re: easier way for $scalar = /regexp/ ???
Message-Id: <pan.2004.03.25.16.23.52.610486@bobotheclown.org>
On Thu, 25 Mar 2004 16:08:15 +0000, David K. Wall wrote:
Thanks.
> Rocky <PerlGuRu2b@bobotheclown.org> wrote:
>
>> if ($_ =~ /^Job\sserver:\s+(.*)$/) { $servername = $1;}
>> isn't it possible to just say
>> $servername = ???
>> I can't seem to find a good example.
>
> my $servername = $1 if /^Job\sserver:\s+(.*)$/;
------------------------------
Date: 25 Mar 2004 17:02:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: easier way for $scalar = /regexp/ ???
Message-Id: <c3v3bs$5b9$1@mamenchi.zrz.TU-Berlin.DE>
Richard Morse <remorse@partners.org> wrote in comp.lang.perl.misc:
> In article <pan.2004.03.25.16.08.59.588839@bobotheclown.org>,
> Rocky <PerlGuRu2b@bobotheclown.org> wrote:
>
> > if ($_ =~ /^Job\sserver:\s+(.*)$/) { $servername = $1;}
> > isn't it possible to just say
> > $servername = ???
> > I can't seem to find a good example.
>
> According to the docs, in a scalar context, m// returns the number of
> matches, but in a list context it returns the actual matches.
>
> So this is what you're after:
>
> my ($servername) = m/^Job\sserver:\s+(.*)$/;
>
> By putting the variable name into the parens, we force in into list
> context.
This is indeed often preferable to using $1 etc. The original code had
a conditional, which is essential with the use of regexes. To restore
it:
if ( my ( $servername) = /.../ ) {
# use $servername here
}
That limits the scope of $servername to the if-block(s).
Anno
------------------------------
Date: Thu, 25 Mar 2004 09:34:13 -0600
From: Bing Du <bdu@iastate.edu>
Subject: how to check if a table already exists?
Message-Id: <c3uu5r$au2$1@news.iastate.edu>
Greetings,
This is perl, v5.8.0 built for i386-linux-thread-multi.
DBI
DBD::mysql
Is there an easy way to check if a table already exists before creating
a new table? Do I have to do 'show tables' and then check if the target
table exists in the list of tables returned?
Appreciate any help,
Bing
------------------------------
Date: Thu, 25 Mar 2004 10:12:37 -0600
From: "J. Gleixner" <glex_nospam@qwest.invalid>
Subject: Re: how to check if a table already exists?
Message-Id: <VxD8c.55$kn.21252@news.uswest.net>
Bing Du wrote:
> Greetings,
>
> This is perl, v5.8.0 built for i386-linux-thread-multi.
> DBI
> DBD::mysql
>
> Is there an easy way to check if a table already exists before creating
> a new table? Do I have to do 'show tables' and then check if the target
> table exists in the list of tables returned?
>
> Appreciate any help,
>
> Bing
>
Yes, however this has nothing at all to do with perl. Read the MySQL
documentation.
------------------------------
Date: 25 Mar 2004 18:56:20 GMT
From: Dmitry Epstein <mitia.nospam@northwestern.edu.invalid>
Subject: Re: I want to scanf, dammit!
Message-Id: <Xns94B7844D354D7mitianorthwesternedu@63.218.45.22>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in
news:c3u5gn$elj$1@mamenchi.zrz.TU-Berlin.DE:
> Dmitry Epstein <mitia.nospam@northwestern.edu.invalid> wrote
> in comp.lang.perl.misc:
[snip]
>> possibly duplicating it while applying split). Oh sure, I
>> could read line by line, split each line, and count the
>> number of words read. But that's not nearly as simple, and
>> besides, if I have to continue working with the file, then
>> the issue of having read more numbers than was needed may
>> come up (remember, that target number may have been in the
>> middle of a line).
>>
>> So there.
>
> my $n = 500;
> my @line;
> while ( <DATA> ) { last if ( $n -= @line = split) < 0 }
> print "$line[ $n]\n";
>
I think your $n is negative by the time you get to the last
statement, no?
------------------------------
Date: Thu, 25 Mar 2004 16:12:22 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: parsing config file
Message-Id: <Xns94B771FEE4772dkwwashere@216.168.3.30>
Simon Lee <Simon.Lee@asia.ing.com> wrote:
> I'd like to parse a config file
[snip]
> I guess "Parse::RecDescent" can do this but does anyone show me
> some sample code ?
There's a short intro to Parse::RecDescent at
http://www.stonehenge.com/merlyn/UnixReview/col40.html
------------------------------
Date: 25 Mar 2004 10:54:28 -0800
From: bay_dar@yahoo.com (G)
Subject: problem with index not matching string exactly
Message-Id: <cad04083.0403251054.35945d27@posting.google.com>
I'm looping through a sales_file looking for matches to $code. Note
the file contains no spaces after the "|". Duplicates are allowed on
different lines, but not the same line. The file has a number of
entries such as the following (sample $sales_file):
sales item aaa|543,m423a
sales item bbb|m423,543 #Note how code 543 is on the 1st 2ndline.
sales item ccc|m423b
sales item ddd|423,423b,m523,652
- Also note we have entires of m423, m423a and m423b. The problem with
my code, is that it matches the $entered_code of m423 to m423, m423a,
and m423b but I want it to only match up to m423. Of course 423 should
only match up to 423 and so on. Anyone have a suggestion to fix this?
Here is the code segment:
open FILE, "<$sales_file" or die "could not open '$sales_file' $!";
while (<FILE>) {
chomp;
my ($sales_item, $code) = split /\|/;
my @code = split /,/, $exits;
if (index($code, $entered_code) != -1) {
$list .="<ul>" if !($list);
$list .= "<li><p>$sales_item</li>";
}
}
Thanks,
------------------------------
Date: Thu, 25 Mar 2004 14:42:42 GMT
From: axel@white-eagle.co.uk
Subject: Re: Puzzling Socket::inet_ntoa problem
Message-Id: <CdC8c.15019$1x2.6674@news-binary.blueyonder.co.uk>
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> > I am trying to figure out why saving the result of gethostbyname in a
> > variable and then using inet_ntoa on that variable works fine, whereas
> > trying to pass the result directly to inet_ntoa bombs out. I can't find
> > anything in the documentation.
> Context. The get* functions return different results in list and scalar
> context, as the doc clearly states. Try (untested)
> inet_ntoa(scalar gethostbyname($ip))
Thanks, that solves the mystery.
Axel
------------------------------
Date: Thu, 25 Mar 2004 09:25:58 -0500
From: "dbwood at acm dot org" <"dbwood at acm dot org">
Subject: q: regex: parse <length><value>?
Message-Id: <w7ednVkv5cNqdv_dRVn-sw@comcast.com>
Is there a regular expression that will extract a field value when the
field has a length indicator describing how many characters are in the
field? e.g. 7abcd123 refers to the value abcd123 and 3abcd123 refers to abc
I know that unpack() is probably a better way, but the only regular
expression we can figure out is to use something like the extended
regular espression (??{ code }) as in (concept only):
qr/(\d+)(??{ qr/.{$1}/ } )/
and I think using unpack() twice is faster.
thanks
David Wood
------------------------------
Date: 25 Mar 2004 15:02:45 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: q: regex: parse <length><value>?
Message-Id: <c3usal$dpp$1@nets3.rz.RWTH-Aachen.DE>
Also sprach dbwood at acm dot org:
> Is there a regular expression that will extract a field value when the
> field has a length indicator describing how many characters are in the
> field? e.g. 7abcd123 refers to the value abcd123 and 3abcd123 refers to abc
>
> I know that unpack() is probably a better way, but the only regular
> expression we can figure out is to use something like the extended
> regular espression (??{ code }) as in (concept only):
>
> qr/(\d+)(??{ qr/.{$1}/ } )/
>
> and I think using unpack() twice is faster.
Why using it twice? This can be done with one unpack:
my $field = unpack "A/A", "3abcd123";
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Thu, 25 Mar 2004 18:41:33 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Regular Expressions Question
Message-Id: <pan.2004.03.25.17.07.32.198323@aursand.no>
On Mon, 22 Mar 2004 21:25:52 -0600, Aaron Baugher wrote:
>> This one will print all lines, except those beginning with 'Diaplay':
>>
>> while ( <FILE> ) {
>> next unless ( /^Display/ );
>> print;
>> }
> That prints only lines that match. To print the ones that don't match:
>
> while ( <FILE> ) {
> print unless ( /^Display/ );
> }
You are perfectly correct, of course. Seems like I couldn't decide which
of 'unless', 'if' and everything on one line I should use. :)
Anyway: As Hoel van der Steen pointed out. It might be faster if you
avoid using a regular expression in this case.
--
Tore Aursand <tore@aursand.no>
"A teacher is never a giver of truth - he is a guide, a pointer to the
truth that each student must find for himself. A good teacher is
merely a catalyst." -- Bruce Lee
------------------------------
Date: Thu, 25 Mar 2004 14:25:55 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Removing folders recursively
Message-Id: <Xns94B75FF2236AEdkwwashere@216.168.3.30>
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> David K. Wall <dwall@fastmail.fm> wrote in comp.lang.perl.misc:
>> Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>>
[re File::Remove]
>> I'd rather call it like this:
>>
>> remove(recurse=>1, files=>\@list);
>>
>> This would be easy to change, and IMHO would be a little easier
>> to use. More to type, but easier to read. What do you think?
>
> Better, yes, easy to change too, but awkward to make compatible.
> (You'd end up with a function whose behavior depends on the
> presence of an arrayref among its first four parameters -- a bit
> eerie.)
Agreed, but I find the scalar ref a bit eerie, too.
> If something must be done, I'd additionally permit a hashref for
No "must" to it, just an offhand idea. :-)
> the optional first parameter, allowing the format
>
> remove( { recurse => 1 }, file1, ...)
>
> Other options (verbose, dry run, logging, ahhh, featuritis) could
> also be passed that way.
>
> It is my impression that a CPAN module has about the same
> obligation to remain compatible through changes that Perl itself
> has followed in its development. So incompatible changes just
> because you have had second thoughts are out. (Of course, nothing
> is enforced on CPAN, authors are free to do otherwise.)
All too reasonable. Usually I'm the only one who uses the modules I
write, so I'm free to change them as I please. Unlike Perl or CPAN
authors (or Microsoft :-) I've never had to worry much about
backwards compatibility. Oh well.
--
David Wall
------------------------------
Date: Thu, 25 Mar 2004 18:41:33 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Switching ....
Message-Id: <pan.2004.03.25.17.21.36.131901@aursand.no>
On Wed, 24 Mar 2004 10:07:04 +0000, Anno Siegel wrote:
> "Getting rusty" in one language while you are using another is a
> protective mechanism. You don't *want* concepts and structures from
> another language to pop up in your head, so you block them.
I don't think I agree on that one; I think it's _useful_ to know to solve
the same problem in multiple programming languages. Knowing one language
sometimes makes you better in another language.
My primary programming language is Perl, but I'm also programming in C#.
There have been many times where I have a C# problem and solves it very
clever (IMO, of course) by thinking on how I would've done it in Perl.
So: Thinking in many languages makes you better in any language. I think
that also relates to written/spoken languages.
--
Tore Aursand <tore@aursand.no>
"Why shouldn't truth be stranger than fiction? Fiction, after all, has
to make sense." -- Mark Twain
------------------------------
Date: 25 Mar 2004 18:18:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Switching ....
Message-Id: <c3v7qf$8dh$1@mamenchi.zrz.TU-Berlin.DE>
Tore Aursand <tore@aursand.no> wrote in comp.lang.perl.misc:
> On Wed, 24 Mar 2004 10:07:04 +0000, Anno Siegel wrote:
> > "Getting rusty" in one language while you are using another is a
> > protective mechanism. You don't *want* concepts and structures from
> > another language to pop up in your head, so you block them.
>
> I don't think I agree on that one; I think it's _useful_ to know to solve
> the same problem in multiple programming languages. Knowing one language
> sometimes makes you better in another language.
>
> My primary programming language is Perl, but I'm also programming in C#.
> There have been many times where I have a C# problem and solves it very
> clever (IMO, of course) by thinking on how I would've done it in Perl.
Yes, but that applies to the design part of programming. When you're
actually coding, lapsing into another language is an error.
This problem gets harder when the "intruding" language is very similar.
Switching between Pascal, Modula and Oberon is harder than switching
between either of them an C, or Fortran, or Lisp.
> So: Thinking in many languages makes you better in any language. I think
> that also relates to written/spoken languages.
I quite agree, and use the technique too. I sometimes "think about the
problem in Lisp" when I can't get a recursion right. I also know that
it is quite possible to be proficient in more than one language at the
same time. It is also true that people rapidly forget even elementary
details about a language they don't use for a while, and that's just as
well. You re-learn a language you once knew as rapidly.
Anno
------------------------------
Date: 25 Mar 2004 14:15:22 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: The "value" of a block in 'map'
Message-Id: <c3uphq$qai$2@mamenchi.zrz.TU-Berlin.DE>
Bernie Cosell <bernie@fantasyfarm.com> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>
> } Bernie Cosell <bernie@fantasyfarm.com> wrote in comp.lang.perl.misc:
> } > Is there any way, other than "the last expression evaluated" to set the
> } > 'value' of a BLOCK done in a map {BLOCK} list; ?...
>
> } > is there any other way for map [probably also grep, etc] to provide a value
> } > other than the very last statement in the block?
> }
> } If you want to return something, turn the block into a sub block:
> }
> } map sub { stuff; return something if BADNESS; more stuff }->(), ...;
>
> Thanks for all the replies. Along the line of the suggestion above,
> wouldn't it work OK for me just to go to the 'expression' form of map,
> instead of the BLOCK form and just use an eval? that is:
>
> map eval {stuff, return(whatever) for badness, do whatever I want},LIST
>
> Basically the same as your suggestion, with one level of indirection
> removed...
I'd say it should work, but you have the problem that "eval" suppresses
errors, and you don't have a good chance to examine $@ (except for the
last step).
Anno
------------------------------
Date: 25 Mar 2004 13:52:31 -0500
From: Uri Guttman <uri.guttman@fmr.com>
Subject: Re: The "value" of a block in 'map'
Message-Id: <siscad24iwsw.fsf@tripoli.fmr.com>
>>>>> "BC" == Bernie Cosell <bernie@fantasyfarm.com> writes:
BC> I had a simple 'map' but it got more complicated, and instead of
BC> moving the complexity out to a subroutine [which would've worked
BC> fine] I tried to use
BC> the BLOCK form to put the mess in-line, and so I had:
BC> map { my ($vars) = bunth of stuff;
BC> bunch of tests on $_, with bailouts to returned assorted
BC> canned values
BC> processing of $_
BC> VALUE;
BC> }
BC> <LIST>
that level of complexity screams sub! i often use subs just to get
better flow control via early returns. anno showed a couple of ways to
do it (the anon sub called right there was neat). another though would
be to just use a sub and no map. map isn't for complex operations but
simpler conversions of a list to another list. now you say you return
various things based on bailouts. just convert the whole thing to a
classic foreach loop and use push for map results and next for
bailouts. you aren't saving much in map if the code is that complex, so a
for loop is a better way to express it.
something like:
my @results ;
foreach my $data ( @input ) {
if ( ... ) {
push @results, 'BAAAAD' ;
next ;
}
push @results, $data ;
}
with all your extra code added in. this would be much clearer to read
than a complex map. the other plus is the use of a named variable
instead of $_ which is one of my style things. i avoid $_ in most
places.
uri
------------------------------
Date: Thu, 25 Mar 2004 18:36:48 +0100
From: ".a.c." <online-toglimi@carpani-toglimi.net>
Subject: Unix sokets and signal handling
Message-Id: <pan.2004.03.25.17.36.48.562592@carpani-toglimi.net>
I've got a piece of code that waits on a (unix) socket ready to accept
connections. This code should be able to catch a USR1 signal and do
something and, at the end, go back to the accept.
The problem I've got is that after handling the signal the
while (accept(CLI, SRVR)) {
...
}
loop exits.
Any clues/help appreciated.
Thanks
---
.a.c.
------------------------------
Date: 25 Mar 2004 18:01:03 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Unix sokets and signal handling
Message-Id: <u9smfwerhc.fsf@wcl-l.bham.ac.uk>
".a.c." <online-toglimi@carpani-toglimi.net> writes:
> I've got a piece of code that waits on a (unix) socket ready to accept
> connections. This code should be able to catch a USR1 signal and do
> something and, at the end, go back to the accept.
>
> The problem I've got is that after handling the signal the
>
> while (accept(CLI, SRVR)) {
> ...
> }
>
> loop exits.
>
> Any clues/help appreciated.
Check $! when accept() returns false. If it's Errno::EINTR then don't
exit the loop.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 6301
***************************************