[17215] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4637 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 17 00:10:36 2000

Date: Mon, 16 Oct 2000 21:10:18 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <971755817-v9-i4637@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 16 Oct 2000     Volume: 9 Number: 4637

Today's topics:
    Re: Packing multiple strings into one string <uri@sysarch.com>
    Re: Packing multiple strings into one string (Mark-Jason Dominus)
    Re: Packing multiple strings into one string (Mark-Jason Dominus)
    Re: Packing multiple strings into one string <phr-n2000@nightsong.com>
    Re: Passing arguments (Gwyn Judd)
    Re: perl objects and methods <godzilla@stomp.stomp.tokyo>
    Re: perl objects and methods (Jerome O'Neil)
    Re: Perl reading e-mail contents <ianb@ot.com.au>
    Re: ping and netping (beginner) (Gwyn Judd)
    Re: POV-Ray file parsing, digestion, and excretion? <nospam@david-steuber.com>
    Re: prob with -F switch (Gwyn Judd)
    Re: Problem assigning keys/values in hashes. <anmcguire@ce.mediaone.net>
    Re: question <joe+usenet@sunstarsys.com>
        Regex with repquota output <adalessandro@odione.com>
    Re: Regex with repquota output <jeffp@crusoe.net>
    Re: Regex with repquota output <adalessandro@odione.com>
    Re: Sorting a list <lr@hpl.hp.com>
    Re: Telling difference between a package and a class? <jeffp@crusoe.net>
    Re: Threads and SMP (Gwyn Judd)
        Trouble setting up perl daemon on Linux sbrown5@my-deja.com
    Re: What is wrong with this subroutine? (Chris Fedde)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 17 Oct 2000 01:52:13 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Packing multiple strings into one string
Message-Id: <x7em1gtesy.fsf@home.sysarch.com>

>>>>> "PR" == Paul Rubin <phr-n2000@nightsong.com> writes:

  PR> I'm wondering if Perl has a good way to pack multiple arbitrary
  PR> strings into a single string, and want to suggest a way if there's
  PR> none already.  By an arbitrary string I mean a binary string that can
  PR> contain any characters including nulls.

  PR> The Camel book says to use the join and split functions and a
  PR> delimiter, but that doesn't seem any good to me, since you then have
  PR> to worry about the delimiter appearing inside the strings, etc.  So it
  PR> seems to me that Perl still has the C disease of specially delimited
  PR> strings.  I'm not a Perl whiz so if someone has a good solution I'd
  PR> like to hear about it.

well, you can't have it both ways. if you want arbitray binary in a
string, how will you tell later where the boundaries are? perl is not
limited like c strings and its null byte terminator but just concatenating
byte strings together loses in any language.

  PR> If there's not something better already, here's my proposal: add a new
  PR> format letter, "D" (for "datum", the structure that dbm/gdbm uses), to
  PR> the pack and unpack functions.  This means a string specified as a
  PR> length (BER-compressed integer) followed by that many bytes.  So to
  PR> pack two strings $s1 and $s2 into a new string $s, you'd just say   

ilya has proposed such a beast for perl5 and perl6. who knows if larry
will accept it.

  PR> Note that you can simulate the packing function:
  PR>     $s = pack ("wPwP", length($s1), $s1, length ($s2), $s2);
  PR> But I don't see any way to do the unpacking that's not a lot clumsier
  PR> (since the BER-compressed lengths are themselves of variable length).

  PR> This makes life a lot easier if you're trying to use dbm as a database
  PR> with arbitrary structures in the records.

you can store arbitrary records with Data::Dumper, Storable and
Freeze/Thaw.

do more searching on cpan. it is out there.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Tue, 17 Oct 2000 02:30:51 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Packing multiple strings into one string
Message-Id: <39ebb9db.2e2$390@news.op.net>

In article <7xitqsgvsh.fsf_-_@ruckus.brouhaha.com>,
Paul Rubin  <phr-n2000@nightsong.com> wrote:
>I'm wondering if Perl has a good way to pack multiple arbitrary
>strings into a single string,

There are a lot of ways.  I like to use Dan Bernstein's 'netstring'
format, which looks something like this:

        sub to_netstring {
          join '', map { length($_) . ':' . $_ } @_;
        }

        sub from_netstring {
          my $s = shift;
          my @result;
          while ($s ne '') {
            $s =~ s/^(\d+):// or die ;
            my $len = $1;
            my $data = substr($s, 0, $len, ''); 
            push @result, $data;
          }
          @result;
        }

One really nice thing about this is that it is even easier to code it
in C than it is in Perl.  (You use sscanf("%9lu") to read in the
length marker, then check for following ':'.)  I frequently have to
write network code that must interoperate with C programs, and
netstrings work well in both C and Perl.  Another benefit is that it's
human-readable and it's easy to edit netstrings with a text editor.

>If there's not something better already, here's my proposal:

That's a good proposal, and guess what?  It's already been adopted.
Except that we write 'w/A*' instead of 'D'.  See the Perl 5.6 'pack'
documentation.  (w/A* is a special case of a more general facility for
packing counted strings.)

>But I don't see any way to do the unpacking that's not a lot clumsier
>(since the BER-compressed lengths are themselves of variable length).

Oh, the unpacking works fine.  The whole point of BER is that the
final byte is explicitly marked.

>Comments?

Isn't it nice when the rest of the world is in harmony with your own
ideas?




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

Date: Tue, 17 Oct 2000 02:33:41 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Packing multiple strings into one string
Message-Id: <39ebba85.2f4$306@news.op.net>

In article <39ebb9db.2e2$390@news.op.net>,
Mark-Jason Dominus <mjd@plover.com> wrote:
>I like to use Dan Bernstein's 'netstring' format...

I forgot to mention:

        http://cr.yp.to/proto/netstrings.txt



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

Date: 16 Oct 2000 19:47:39 -0700
From: Paul Rubin <phr-n2000@nightsong.com>
Subject: Re: Packing multiple strings into one string
Message-Id: <7xr95gkwtw.fsf@ruckus.brouhaha.com>

mjd@plover.com (Mark-Jason Dominus) writes:
> >I'm wondering if Perl has a good way to pack multiple arbitrary
> >strings into a single string,
> 
> There are a lot of ways.  I like to use Dan Bernstein's 'netstring'
> format, which looks something like this:
> 
>         sub to_netstring {
>           join '', map { length($_) . ':' . $_ } @_;
>         }

Thanks.  This is nice, though clearly a lot less efficient than
being able to do everything with a native builtin function.
> >If there's not something better already, here's my proposal:
> 
> That's a good proposal, and guess what?  It's already been adopted.
> Except that we write 'w/A*' instead of 'D'.  See the Perl 5.6 'pack'
> documentation.  (w/A* is a special case of a more general facility for
> packing counted strings.)

Sounds good, I'll check into it.

> >But I don't see any way to do the unpacking that's not a lot clumsier
> >(since the BER-compressed lengths are themselves of variable length).
> 
> Oh, the unpacking works fine.  The whole point of BER is that the
> final byte is explicitly marked.

Yes, of course it works fine, it's just clumsy to implement in Perl,
since you either have to do the BER-decoding in perl or else use
unpack to pick off the BER number, then compute the length of the BER
number either by repacking or by arithmetic, then skip over that many
bytes.

For what I'm doing I'll probably use your netstring suggestion for
now, since it's nice and simple.

Thanks.


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

Date: Tue, 17 Oct 2000 01:41:15 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Passing arguments
Message-Id: <slrn8unbhn.ej1.tjla@thislove.dyndns.org>

I was shocked! How could Ren Maddox <ren.maddox@tivoli.com>
say such a terrible thing:
>tjla@guvfybir.qlaqaf.bet (Gwyn Judd) writes:
>
>> The '[]' operator creates a reference to an anonymous array, copying
>> it's contents. This may be less efficient than just doing @values = keys
>> %lengths since it has to extract the keys and then copy them. hmmm
>> indeed it is unless I made a mistake somewhere, benchmarking being the
>> black art that it is
>
>As far as I can see, the only mistake you made was in interpreting the
>output.  Based on the results given (and recreated), the anonymous
>array is slightly faster.  You seem to be saying the opposite in the
>above paragraph, though I expect you just misstated what you meant.

Well smack me with a kipper. I feel like one of those people who go
looking for the butter or something and go moving the better around to
look behind it and under it and on top of it without actually realising
it is in their hand ;)

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Republicans tend to keep their shades drawn, although there is seldom
any reason why they should.  Democrats ought to, but don't.


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

Date: Mon, 16 Oct 2000 18:59:51 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: perl objects and methods
Message-Id: <39EBB297.76F8D386@stomp.stomp.tokyo>

Uri Guttman whined and cried:
 
> > Godzilla! tells it like it is:
 
> > I can write troll articles infinitely better than
> > yours with half my brain tied behind my back, Frank.
 
> at least you admit you troll, so why do you still do it? it does not
> contribute anything of value here. but you have never contributed
> anything of value here so far. it has been 6+ months and you still are
> deluded about your abilities. take you cargo-cult half brain and troll
> elsewhere. other than the occasional newbie, no one here will fall for
> your shit.


I can write troll articles infinitely better than
yours with my entire brain tied behind my back.

Godzilla!
-- 
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class


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

Date: Tue, 17 Oct 2000 02:29:15 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: perl objects and methods
Message-Id: <%POG5.1785$gu5.481490@news.uswest.net>

"Godzilla!" <godzilla@stomp.stomp.tokyo> elucidates:

> 
> I can write troll articles infinitely better than
> yours with my entire brain tied behind my back.

It's pretty well established that your brain is located immediately
below your back, not behind it.

-- 
"Civilization rests on two things: the discovery that fermentation 
produces alcohol, and the voluntary ability to inhibit defecation.  
And I put it to you, where would this splendid civilization be without 
both?" --Robertson Davies "The Rebel Angels" 


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

Date: Tue, 17 Oct 2000 13:36:37 +1100
From: Ian Boreham <ianb@ot.com.au>
Subject: Re: Perl reading e-mail contents
Message-Id: <39EBBB35.D02D868B@ot.com.au>

Dean Banko wrote:

> Hello!
>
> Does anyone know how to access the POP e-mail account,
> read the e-mail subject
> and read e-mail's contents.
>
> I need this for reading e-mail and delete an account if in
> the e-mail's body stands the word 'unsubscribe'

It sounds like you really want a mailing list manager like ezmlm or
majordomo...

If you do implement something yourself, be careful not to delete just
any message containing the word "unsubscribe" (Like, "I don't want to
unsubscribe now, but if I did want to, how do I do it?").

Regards,


Ian




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

Date: Tue, 17 Oct 2000 02:46:25 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: ping and netping (beginner)
Message-Id: <slrn8unfbs.f7l.tjla@thislove.dyndns.org>

I was shocked! How could joe cipale <jcipale@hotmail.com>
say such a terrible thing:
>I am new to this forum. I have a question regarding the use of ping (Unix
>system) and netping.

What is netping?

>I have a set of networked hosts throughout my company that I would like to
>have the status displayed
>on a regular basis.

ok

>is this: My Unix hosts can be pinged, either from ping or netping without a
>problem. But, I have a handful of VAX hosts that always fail to return from
>the CGI. If I perform the ping operation as part of a perl script and use

What do you mean, they fail to return from the CGI? I thought you were
pinging them in which case it doesn't matter if you do it from a CGI or
from the command line.

>the system ping, the VAX hosts respond. The VAX host do not respond to a
>netping() query.

Doctor, it hurts when I do this...

>Is there a secret handshake or special incantation that must be performed to
>get VAX hosts to respond to CGI?

Yes. You need to install a webserver on them. I do not think that this
solution will solve your problem.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
A sine curve goes off to infinity or at least the end of the blackboard
		-- Prof. Steiner


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

Date: Tue, 17 Oct 2000 01:54:50 GMT
From: David Steuber <nospam@david-steuber.com>
Subject: Re: POV-Ray file parsing, digestion, and excretion?
Message-Id: <m3aec4fd06.fsf@solo.david-steuber.com>

David Steuber <nospam@david-steuber.com> writes:

' I'm wondering if anyone has done any kind of Perl code that reads,
' processes, and generates POV-Ray code.

Following up on myself here (tacky, isn't it?), I've since discovered,
and it took all day to do, that a major problem with reading a POV-Ray
scene description language files is tesselating certain CSG
constructs.  IOW, generating a POV-Ray compativle .pov file from a
modeler written in Perl would not be a major problem.  Importing a
 .pov file into a modeler can be, no matter what language it is written
in.

I've already gone and subscribed to comp.graphics.rendering.raytracing
and comp.graphics.rendering.renderman.

-- 
David Steuber | Perl apprentice, Apache/mod_perl user,
NRA Member    | and general Internet web wannabe.
ICQ# 91465842
***         http://www.david-steuber.com/          ***


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

Date: Tue, 17 Oct 2000 03:06:46 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: prob with -F switch
Message-Id: <slrn8ungi0.f7l.tjla@thislove.dyndns.org>

I was shocked! How could stevezaz@my-deja.com <stevezaz@my-deja.com>
say such a terrible thing:
>I am trying to run Perl with -a -n switches to read through a text file
>and split each line into the @F array.I would like to change the
>default field delimiter with -F switch but it doesn't work.I have tried
>quotes backslashes and everything else.
>Has anyone had this problem and what is the solution.

Yes actually the -F switch doesn't work at all. It's all a huge
conspiracy by the perl maintainers to suck in the newbies. Your best bet
is to give up and take up flower arranging instead. That or actually
post some code :)

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Many people feel that if you won't let them make you happy, they'll make you
suffer.


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

Date: Mon, 16 Oct 2000 22:16:35 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: Problem assigning keys/values in hashes.
Message-Id: <Pine.LNX.4.21.0010162211550.25428-100000@hawk.ce.mediaone.net>

On Mon, 16 Oct 2000, Larry Rosler quoth:

LR> In article <Pine.LNX.4.21.0010152114490.24401-
LR> 100000@hawk.ce.mediaone.net> on Sun, 15 Oct 2000 21:16:19 -0500, Andrew 
LR> N. McGuire  <anmcguire@ce.mediaone.net> says...
LR> 
LR> ...
LR> 
LR> > my $form = @_;    # $form contains length of @_ ( 1 ).
LR> > my $form = shift; # $form contains HASH ref.
LR> 
LR> Alternatively (one keystroke shorter :-):
LR> 
LR>   my ($form) = @_;  # $form contains HASH ref.


One shorter:

      my $form = pop;

but with admittedly poor form.

anm
-- 
$ # = "%.6g" ; stat $0 or die $! ;
_ = q.Just another Perl Hacker.  ;
print $ #                        ;
main'_ . v10                     ;




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

Date: 16 Oct 2000 21:26:24 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: question
Message-Id: <m37l78p8an.fsf@mumonkan.sunstarsys.com>

"Andrew N. McGuire " <anmcguire@ce.mediaone.net> writes:

> On Mon, 16 Oct 2000, Jim Mauldin quoth:
> 
> JM> Joe Schaefer wrote:
> JM> > 
> JM> > "Christian Gersch" <c.gersch@iglusoft.com> writes:
> JM> > 
> JM> > >   If ($. = 4) $text = $_;
> JM> > 
> JM> > this should read
> JM> > 
> JM> > if ($. == 4) { $text = $_; } #GOOD
> JM> > 
> JM> > or you could do the whole loop in one line:
> JM> > 
> JM> > $text = <FILE> while ($. <= 4); #BAD
> JM> > 
> JM> > but using $. really isn't a good idea
> JM> > since it makes your code difficult to
> JM> > read (most perlies don't know what $.
> JM> > does- I had to look it up myself). Put
> JM> > your own line counter variable in, and
> JM> > name it as such, and break your code up
> JM> > so each line does one thing.
> JM> > 
> JM> > Remember, code is for humans (especially
> JM> > you) to read, so keep simplicity and
> JM> > clarity higher values than cleverness and
> JM> > obscurity.
> JM> > 
> JM> 
> JM> At the risk of incurring the ire of some people I respect a great deal
> JM> in this ng, and in light of the discussion subsequent to tbe above-cited
> JM> post, I have to agree with the general principles that Joe Schaefer is
> JM> promoting.
> JM> 
> JM> Perl's strength arises not from shortcuts that are useful, valid but
> JM> sometimes obscure (e.g. $.), but from
> 
> I just cant agree that $. is obscure.  That is like saying $?
> is obscure.  Both are well documented in perlvar and other places,
> they behave as documented, so how can that be obscure?  As I posted
> before, the docs even say:
> 
> (Mnemonic: many programs use "." to mean the current line number.)
> 

Although my intent was not to imply that $. is "obscure",
it is certainly fair to read my statement that way, and 
post a civil disagreement about such a claim.  You would
find in fact that I would fall on your side of that argument,
since "." it's part of the heritage of both perl and Unix.
And there's lots of good examples of it's use throughout 
the docs, all I was saying that I wasn't familiar with
it (until a few days ago :)

"perlie" = "perl newbie" (at least in my little locale) - maybe 
that's an _obscure_ lingo, but that's what I was basing my 
statement on.  It appeared to me that OP was spending too much time
picking up shortcuts and not enough time focusing on the core
of the language. That's a judgement call, but I felt offering
no advice would have been worse.

I hope that's easier to swallow :)

-- 
Joe Schaefer


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

Date: Mon, 16 Oct 2000 22:56:47 -0400
From: "Arthur Dalessandro" <adalessandro@odione.com>
Subject: Regex with repquota output
Message-Id: <sung01eqsr2t02@corp.supernews.com>

I am trying to finish an overquota warning system for our unix file store by
going through an array which contains a bunch of the following data:
<uid><file quota><inode quota> <actual used> <softlimit> <hard limit>
<acutal inodes> <soft inodes> <hard inodes>
odione.adalessandro--   13334   50000       0             39     0     0
where -- means that file and inodes are below quota
-+ means inodes are above quota
+- means the files (K) are above quota
++ both are above quota..


I need to split this line into the headings shown, it would be nice to use
the + - as triggers but not neccessary.

An alternative is to take the whole first part <uid><file quota><inode
quota>  as one variable, and break all the others out, then compare the
actual to the limits and see if the user is over quota.

Any ideas??  I am not sure how to split by white space since the spacing
changes for each user, but the delimeter is always going to be spaces..






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

Date: Mon, 16 Oct 2000 23:21:33 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Regex with repquota output
Message-Id: <Pine.GSO.4.21.0010162318360.25707-100000@crusoe.crusoe.net>

[posted & mailed]

On Oct 16, Arthur Dalessandro said:

><uid><file quota><inode quota> <actual used> <softlimit> <hard limit>
><acutal inodes> <soft inodes> <hard inodes>
>odione.adalessandro--   13334   50000       0             39     0     0

>An alternative is to take the whole first part <uid><file quota><inode
>quota>  as one variable, and break all the others out, then compare the
>actual to the limits and see if the user is over quota.

>Any ideas??  I am not sure how to split by white space since the spacing
>changes for each user, but the delimeter is always going to be spaces..

Then split on multiple spaces.

  @fields = split ' ', $string;  # split ' ' is magical/special

Then split $fields[0] even more, as per your request:

  $q2 = chop $fields[0];
  $q1 = chop $fields[0];

Now $fields[0] is the UID, and you have $q1 and $q2.  Another way you
could do it is:

  $len = length($fields[0]) - 2;
  ($fields[0], $q1, $q2) = unpack "A$len A A", $fields[0];

That does the same thing, but differently. ;)

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: Mon, 16 Oct 2000 23:35:25 -0400
From: "Arthur Dalessandro" <adalessandro@odione.com>
Subject: Re: Regex with repquota output
Message-Id: <suni8c4qi44q75@corp.supernews.com>

Ahh, got it.... Thanks, I was missing the chop function, I've never used it
to grab the last part of a variable before, just used it to trim down a
variable....  Thanx..

-Art

"Jeff Pinyan" <jeffp@crusoe.net> wrote in message
news:Pine.GSO.4.21.0010162318360.25707-100000@crusoe.crusoe.net...
> [posted & mailed]
>
> On Oct 16, Arthur Dalessandro said:
>
> ><uid><file quota><inode quota> <actual used> <softlimit> <hard limit>
> ><acutal inodes> <soft inodes> <hard inodes>
> >odione.adalessandro--   13334   50000       0             39     0     0
>
> >An alternative is to take the whole first part <uid><file quota><inode
> >quota>  as one variable, and break all the others out, then compare the
> >actual to the limits and see if the user is over quota.
>
> >Any ideas??  I am not sure how to split by white space since the spacing
> >changes for each user, but the delimeter is always going to be spaces..
>
> Then split on multiple spaces.
>
>   @fields = split ' ', $string;  # split ' ' is magical/special
>
> Then split $fields[0] even more, as per your request:
>
>   $q2 = chop $fields[0];
>   $q1 = chop $fields[0];
>
> Now $fields[0] is the UID, and you have $q1 and $q2.  Another way you
> could do it is:
>
>   $len = length($fields[0]) - 2;
>   ($fields[0], $q1, $q2) = unpack "A$len A A", $fields[0];
>
> That does the same thing, but differently. ;)
>
> --
> Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
> PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
> The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
> CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/
>
>
>




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

Date: Mon, 16 Oct 2000 18:03:23 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Sorting a list
Message-Id: <MPG.1455453663014fd998ae39@nntp.hpl.hp.com>

In article <8sfs0o$4dv$1@riva.ucam.org> on 16 Oct 2000 21:30:00 GMT, 
Colin Watson <cjw44@flatline.org.uk> says...
> Sylvain Perreault <sylvain2k@sympatico.ca> wrote:
> >I have this file:
> >
> >celinedi:Celine Dion - I want you to need me:3:
> >larafabi:Lara Fabian - I will love again:6:
> >etc...
> >
> >I wanna sort it with the second part of each line...
> 
> You may not want to do it this way, but, just to show that you can,
> here's a (squeezed onto) one-line way using a Schwartzian Transform:

If you insist, though the GRT is faster.  :-)

>   print join'',map{$$_[0]}sort{$$a[1] cmp $$b[1]}map{[$_,(split /:/)[1]]}<>;
> 
> Expanded, that's:
> 
>   1) <>
>      Read the whole file and return an array of its lines, since this is
>      in list context.

No array there.  The <> operator returns a list of lines, which is what 
gets sorted.

>   2) map { [$_, (split /:/)[1]] }
>      Produce list of array references, each of which points to a line
>      and the second field out of that line.
> 
>   3) sort { $$a[1] cmp $$b[1] }
>      Sort this list by lexicographic comparison of the second element of
>      the referenced array, that is, the second field in each line.

I find it much easier to understand that if written using the 
dereferencing operator ->:

    3) sort { $a->[1] cmp $b->[1] }
 
>   4) map { $$_[0] }
>      Map all the array references back to the original list in the new
>      order.

Similarly:

    4) map { $_->[0] }

>   5) join ''
>      We never bothered getting rid of newlines, so glue 'em back
>      together like this.

Why bother?  The print() function handles lists just fine.

>   6) print
>      Does what it says on the tin.

And on the tin it says it handles lists.

Oh, yes, the GRT, just for exercise:

       print map substr($_, 1 + index $_, ':') =>
             sort
             map +(split /:/)[1] . ":$_" => <>;

Note the reintroduction of ':' to separate the sortkey from the data, 
chosen because ':' is guaranteed not to appear in the sortkey.

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


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

Date: Mon, 16 Oct 2000 23:11:19 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Telling difference between a package and a class?
Message-Id: <Pine.GSO.4.21.0010162249020.25707-100000@crusoe.crusoe.net>

[posted & mailed]

On Oct 16, trollis@my-deja.com said:

>I'm trying to identify whether a file is a Perl package or a class.
>I have been thinking about checking for "@ISA" or "sub new", but either
>could exist for both types, right? So, is there a proper way to do it?
>Is there a near catch-all way to do it, e.g. 90% of all packages have
>no "new" sub?

I'm trying to figure out WHY you need/want to do this, but anyway.

By "package", you mean just a module with variables and functions defined
in its own namespace, right?  And by "class", you mean such a package that
is expected to have its functions called as methods?

Hmm, I don't know if there's a sure-fire way to do it.

  sub is_class {
    my $pkg = shift;
    my $IS_CLASS = 0;
    local $@;

    eval {
      $IS_CLASS = 0;
      my $obj = $pkg->new;
      $IS_CLASS = UNIVERSAL::isa($obj,$packagename);
    };

    return $@ ? 0 : $IS_CLASS;
  }

That's probably crappy, though.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/





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

Date: Tue, 17 Oct 2000 04:01:12 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Threads and SMP
Message-Id: <slrn8unjo1.f7l.tjla@thislove.dyndns.org>

I was shocked! How could Louis Z <louis@trapezoid.com>
say such a terrible thing:
>Thank you all for the help.  Allow me to be more specific in my
>question...
>
>Does Perl support any message passing between threads?  I can use fork to
>duplicate the running process, but unless the two are working togehter,
>then they are just competing for the same CPU cycles.

Well I know nothing about paralell programming in this manner but if you
go on CPAN I see there is a Paralell::Pvm and a Pvm module, one of which
may help solve your problem.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Time is that quality of nature which keeps events from happening all at
once. Lately it doesn't seem to be working.


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

Date: Tue, 17 Oct 2000 01:00:39 GMT
From: sbrown5@my-deja.com
Subject: Trouble setting up perl daemon on Linux
Message-Id: <8sg8bl$gdv$1@nnrp1.deja.com>

I am having trouble setting up a perl daemon as a SYSV service on a
RedHat 6.1 Linux system.

I am following the directions on
http://www.webreference.com/perl/tutorial/9/ (which I think is a pretty
good tutorial).  After having no luck with a more complex daemon, I
tried using the simple daemon below:

use POSIX qw(setsid);

     chdir '/'                 or die "Can't chdir to /: $!";
     umask 0;
     open STDIN, '/dev/null'   or die "Can't read /dev/null: $!";
     #open STDOUT, '>/dev/null' or die "Can't write to /dev/null: $!";
     open STDERR, '>/dev/null' or die "Can't write to /dev/null: $!";
     defined(my $pid = fork)   or die "Can't fork: $!";
     exit if $pid;
     setsid                    or die "Can't start a new session: $!";

     while(1) {
        sleep(5);
        print "Hello...\n";
     }

For my init.d file, I copied the crond file and changed the name (to
'scotd').  I then used chkconfig to set the run levels, and they look
OK.  When I start the daemon (/etc/rc.d/init.d/scotd start), it says
that it started OK, but when I do a status is says "scotd dead but
subsys locked".  However my process is not dead, I can see it in using
"ps -A".  (Interestingly I <i>cannot</i> see it if I use pidof.)

Any ideas what I'm doing wrong or what I need to do?

Please help!

- Scott



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 17 Oct 2000 03:16:41 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: What is wrong with this subroutine?
Message-Id: <twPG5.23$T3.171034112@news.frii.net>

In article <4a0e6f5483g.soper@soundhouse.co.uk>,
Geoff Soper  <g.soper@soundhouse.co.uk> wrote:
>
>Anybody got any ideas?
>

Write a little driver program that calls this with the expected
arguments and see if it returns the expected results.  If it does
then put a few print statements in it to see what it is called with
and what it is returning in the webserver context. 

chris
-- 
    This space intentionally left blank


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4637
**************************************


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