[17627] in Perl-Users-Digest
Perl-Users Digest, Issue: 5047 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 6 14:10:44 2000
Date: Wed, 6 Dec 2000 11:10:15 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <976129815-v9-i5047@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 6 Dec 2000 Volume: 9 Number: 5047
Today's topics:
simple one (James McCallum)
Re: simple one (Flint Slacker)
Re: simple one nobull@mail.com
Re: simple one (Tad McClellan)
Re: Size of a folder <jboes@eoexchange.com>
SMTP Sockets mbutt@my-deja.com
Sorting a hash of hashes by values <g.soper@soundhouse.co.uk>
Re: Sorting a hash of hashes by values (Tad McClellan)
Re: Sorting a hash of hashes by values nobull@mail.com
Re: Sorting a hash of hashes by values <stampes@xilinx.com>
Thanks for the great suggestions! <ted_graham@my-deja.com>
threaded process going defunct <mwoodyard@earthlink.net>
Re: threaded process going defunct <dan@tuatha.sidhe.org>
Re: Ugh! I hope I can explain this... <bart.lateur@skynet.be>
Re: Use PERL or Java? Which is faster? <raypendergraph@my-deja.com>
Re: Use PERL or Java? Which is faster? <niceguy@abraxis.com>
Re: Use PERL or Java? Which is faster? <smatta@acm.org>
Re: Your help please (Tad McClellan)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 06 Dec 2000 16:58:23 GMT
From: james.mccallum@bradford.gov.uk (James McCallum)
Subject: simple one
Message-Id: <3a2e6f2f.28618531@newscore.theplanet.net>
Hi,
I've got a line called $line, I want to split it up and print the
fouth work and the sixth word how can I do it.
$line="This is a line of text"
@fields = split(/\s/, $line);
It the next bit I'm not sure about
Thanks
------------------------------
Date: Wed, 06 Dec 2000 17:07:28 GMT
From: flint@flintslacker.com (Flint Slacker)
Subject: Re: simple one
Message-Id: <3a357210.180650011@news.tcn.net>
On Wed, 06 Dec 2000 16:58:23 GMT, james.mccallum@bradford.gov.uk
(James McCallum) wrote:
>I've got a line called $line, I want to split it up and print the
>fouth work and the sixth word how can I do it.
>
>$line="This is a line of text"
>@fields = split(/\s/, $line);
>
print "$fields[3] $fields[5]\n";
Flint
------------------------------
Date: 06 Dec 2000 17:45:45 +0000
From: nobull@mail.com
Subject: Re: simple one
Message-Id: <u9g0k178ae.fsf@wcl-l.bham.ac.uk>
james.mccallum@bradford.gov.uk (James McCallum) writes:
> I've got a line called $line, I want to split it up and print the
> fouth work and the sixth word how can I do it.
>
> $line="This is a line of text"
> @fields = split(/\s/, $line);
>
> It the next bit I'm not sure about
The way to extract elements from an array is to use something called a
subscript. See "perldoc perldata" for details.
Perl array subscripts count from zero[note:1] so the to get the fourth
and sixth elements of the array use 3 and 5 respectively.
The syntax to get a single element, say the fourth, is $fields[3].
The syntax to get a multiple elements is @fields[3,5].
To print these with nothing between[note:2] you could use:
print @fields[3,5];
Alteratively to print with spaces between[note:3] you could use:
print "@fields[3,5]";
Notes:
[1] Assuming you've not messed with $[
[2] Assuming you've not messed with $,
[3] Assuming you've not messed with $"
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 6 Dec 2000 11:24:07 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: simple one
Message-Id: <slrn92sq17.q47.tadmc@magna.metronet.com>
James McCallum <james.mccallum@bradford.gov.uk> wrote:
>I've got a line called $line, I want to split it up and print the
>fouth work and the sixth word how can I do it.
print( (split /\s+/, $line)[3,5], "\n"); # a "list slice"
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 06 Dec 2000 13:04:57 -0500
From: "Jeff Boes" <jboes@eoexchange.com>
Subject: Re: Size of a folder
Message-Id: <3a2e80f9$0$30002$44a10c7e@news.net-link.net>
Unless my newsreader has been taken over by the Illuminati, I think "IJ"
<meej@sol.dk> babbled:
> Hi everybody,
>
> Any body knows how can I get size of a folder, seems to be completely
> different than file handling. If somebody have a ready script/suggestion
> for this please drop it to me as soon as possible. meej@sol.dk
>
What's a folder? Are you referring to a directory? The answer is probably
highly OS-dependent, so you'll need to be more specific. On Unix, for
example, there's a difference between the size of the file used to
represent the directory, and the size of the *contents* of the directory.
The first can be obtained quite handily with
$size = -s '/full/path/to/directory';
while the second requires globbing the filenames from the directory and
summing up the sizes, e.g.,
$contents_size = 0;
$contents_size += -s for <*>;
--
Jeff Boes <jboes@eoexchange.com> Tel: (616) 381-9889 x.18
Sr. Software Engineer, EoExchange, Inc. http://www.eoexchange.com/
Search, Monitor, Notify. http://www.eomonitor.com/
------------------------------
Date: Wed, 06 Dec 2000 17:07:10 GMT
From: mbutt@my-deja.com
Subject: SMTP Sockets
Message-Id: <90lrnm$g9s$1@nnrp1.deja.com>
Has anyone got some example code using Socket.pm (not IO::Socket or
anything else). Whick simply opens a socket on port 25 and sends out
mail using SMTP commands. Or just a simple example of opening a socket
using perl.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 06 Dec 2000 16:37:44 +0000 (GMT)
From: Geoff Soper <g.soper@soundhouse.co.uk>
Subject: Sorting a hash of hashes by values
Message-Id: <4a28bb5865g.soper@soundhouse.co.uk>
I have a hash of hashes with a structure something like this:
$database{"dave"}{"age"}=47
$database{"dave"}{"hair"}="grey"
$database{"frank"}{"age"}=32
$database{"frank"}{"hair"}="black"
$database{"jim"}{"age"}=22
$database{"jim"}{"hair"}="ginger"
Previously I have been happy to sort on their names
with:
foreach $name (sort keys %database){
...
}
but now I want to sort by age and for the life of me can't work out how to
do it. I've looked in the FAQ and in my Programming Perl book but with no
luck.
Can somebody help me?
Thanks
--
Geoff Soper
g.soper@soundhouse.co.uk
Take a look at the Soundhouse page http://www.soundhouse.co.uk/
------------------------------
Date: Wed, 6 Dec 2000 11:40:18 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Sorting a hash of hashes by values
Message-Id: <slrn92sqvi.q5j.tadmc@magna.metronet.com>
Geoff Soper <g.soper@soundhouse.co.uk> wrote:
>I have a hash of hashes with a structure something like this:
>
>$database{"dave"}{"age"}=47
>$database{"frank"}{"age"}=32
>$database{"jim"}{"age"}=22
>but now I want to sort by age and for the life of me can't work out how to
>do it. I've looked in the FAQ and in my Programming Perl book but with no
>luck.
>
>Can somebody help me?
----------------------------------------------
foreach my $name (sort by_age keys %database){
print "$name\n";
}
sub by_age {
$database{$a}{age} <=> $database{$b}{age};
}
----------------------------------------------
or if that is too slow:
----------------------------------------------
foreach my $name ( sort_by_age(keys %database) ){
print "$name\n";
}
sub sort_by_age { # Schwartzian Transform
map { $_->[0] }
sort { $a->[1] <=> $b->[1] }
map { [ $_, $database{$_}{age} ] } @_;
}
----------------------------------------------
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 06 Dec 2000 17:58:58 +0000
From: nobull@mail.com
Subject: Re: Sorting a hash of hashes by values
Message-Id: <u9elzl77od.fsf@wcl-l.bham.ac.uk>
Geoff Soper <g.soper@soundhouse.co.uk> writes:
> Subject: Sorting a hash of hashes by values
You cannot really sort a hash. You can only sort a list, for examples
the list of keys of a hash.
> I have a hash of hashes with a structure something like this:
>
> $database{"dave"}{"age"}=47
> $database{"dave"}{"hair"}="grey"
> $database{"frank"}{"age"}=32
> $database{"frank"}{"hair"}="black"
> $database{"jim"}{"age"}=22
> $database{"jim"}{"hair"}="ginger"
>
> Previously I have been happy to sort on their names
> with:
>
> foreach $name (sort keys %database){
> but now I want to sort by age
foreach my $name (sort { $database{$a}{age} <=> $database{$b}{age} } keys %database){
BTW: You sould always my() your loop control variable in the for
statement unless you have a compelling reason not to.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 06 Dec 2000 11:13:54 -0700
From: Jeff Stampes <stampes@xilinx.com>
Subject: Re: Sorting a hash of hashes by values
Message-Id: <3A2E81E2.96D7CA44@xilinx.com>
Geoff Soper wrote:
> $database{"dave"}{"age"}=47
> $database{"dave"}{"hair"}="grey"
> $database{"frank"}{"age"}=32
> $database{"frank"}{"hair"}="black"
> $database{"jim"}{"age"}=22
> $database{"jim"}{"hair"}="ginger"
>
> but now I want to sort by age
TMTOWDTI, but here's the way I fall back onto:
@sorted =
map { $_->[1] }
sort { $a->[0] <=> $b->[0] }
map { [ $database{$_}{age} , $_ ] }
keys %database
Explanation (read the code from end to beginning):
- Get the list of the keys of the database (names)
- Map them into anonymous arrays, each one consisting of the
value you will sort by (age) and the original key (name)
- Sort those anonymous arrays by the first element (ages)
- in the final map, dereference the array element where you
stashed the original keys (names)
------------------------------
Date: Wed, 06 Dec 2000 16:51:25 GMT
From: Ted <ted_graham@my-deja.com>
Subject: Thanks for the great suggestions!
Message-Id: <90lqq9$fi6$1@nnrp1.deja.com>
This was just the kind of discussion I was hoping for. Many thanks!
Ted
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 06 Dec 2000 17:01:30 GMT
From: Matt Woodyard <mwoodyard@earthlink.net>
Subject: threaded process going defunct
Message-Id: <B653DAE2.F67%mwoodyard@earthlink.net>
I have a thread that inturn executes an external program then parses the
programs output. about 1/6 of the time that thread (which is executed many
times in parallel) goes defunct whats the deal on that?
------------------------------
Date: Wed, 06 Dec 2000 18:06:15 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: threaded process going defunct
Message-Id: <revX5.82260$P82.9068632@news1.rdc1.ct.home.com>
Matt Woodyard <mwoodyard@earthlink.net> wrote:
> I have a thread that inturn executes an external program then parses the
> programs output. about 1/6 of the time that thread (which is executed many
> times in parallel) goes defunct whats the deal on that?
There's a race condition in threaded perl that sometimes whacks the array
perl keeps that holds the information about subprocesses. This affects both
processes spawned via backticks and via magic open. It's fixed in
the development version of perl, and the fix should be in 5.6.1 when that
gets out.
In the mean time, you can protect yourself like so:
my $results;
{
lock $main::subprocess_lock;
$results = `some_command`;
}
and
{
lock $main::subprocess_lock;
open FOO, "thingie |";
}
{
lock $main::subprocess_lock;
close FOO;
}
Yes, it does mean that you can't fire up any more processes while
the backtick command is executing, and you do need to protect
both the magic open *and* the close of that filehandle, and
you need to use the same (global) variable to protect both
backticks and magic opens.
This is, as you might imagine, a pain to do. It is fixed, as I said,
in perl 5.6.1 and all the 5.7.0 dev versions.
Dan
------------------------------
Date: Wed, 06 Dec 2000 17:17:40 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Ugh! I hope I can explain this...
Message-Id: <f6ts2tk0tgfme5ugdshscip1njfh2ig5qc@4ax.com>
cputek1@my-deja.com wrote:
>I'm calling a subroutine in a perl script from other perscripts
>(using "required"). How do I tell which script called the subroutine
>from within the subroutine?
caller()?
--
Bart.
------------------------------
Date: Wed, 06 Dec 2000 16:55:05 GMT
From: Ray Pendergraph <raypendergraph@my-deja.com>
Subject: Re: Use PERL or Java? Which is faster?
Message-Id: <90lr14$fkt$1@nnrp1.deja.com>
Depends on what you are doing... but I can say that PERL can run pretty
darn fast. I developed a parsing application that read a file of test
vectors generated by a mathematical test tool, translated the data,
packed it into a bitstream the application (being tested) could read
and sent it off in frames through a socket. I was able to supply the
frames fast enough to test a real time system moving at 32Hz. If you
are not familiar with real time, please do not confuse 32Hz with you
x86 xxxMHz processor... not the same measurement. To say that a
scripting lang can supply data to a process running at this rate is
damn impressive even though 32Hz is not blazing in a RT sense.
i tried to mimick the process in Java and it probably could handle all
other transactions as well as the PERL, but lacked in the parsing arena
(probably due to sloppy buffereing). It came out several times slower
than the PERL.
Like I said... depends on what you are doing. I was parsing and this is
what PERL does best. That is what it was designed for. But don't
underestimate its speed because it's a scripting language.
FYI:We were on Solaris.
Like I said it depends on what
In article <3A2E6155.C2273626@yahoo.com>,
Al Dev <alavoor@yahoo.com> wrote:
> I am planning to use either or PERL or Java for a new web application
> which will
> run on RedHat Linux.
>
> Any suggestions on which runs faster - PERL or Java??
> Speed is more important (top priority)
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 06 Dec 2000 11:31:12 -0500
From: Jim Sculley <niceguy@abraxis.com>
Subject: Re: Use PERL or Java? Which is faster?
Message-Id: <3A2E69D0.685B2BC@abraxis.com>
Al Dev wrote:
>
> I am planning to use either or PERL or Java for a new web application
> which will run on RedHat Linux.
An application to do what?
>
> Any suggestions on which runs faster - PERL or Java??
> Speed is more important (top priority)
This is like asking 'Which is faster: a Corvette or a snow plow?' Then
answer seems quite clear until you learn that the person who posed the
question regularly drives in two feet of snow.
Jim S.
------------------------------
Date: Wed, 06 Dec 2000 18:13:13 GMT
From: Sunil Matta <smatta@acm.org>
Subject: Re: Use PERL or Java? Which is faster?
Message-Id: <90lvji$jv9$1@nnrp1.deja.com>
No comparison. Perl is blindingly fast. Java is slow.
But the point is that both languages have their uses.
For text processing or even db access, I have found perl to be
extremely useful and super fast.
However I have not created servers using perl and therefore dont know
what that would be like, so for this I would prefer a more readable
language like Java, which offers me quite a bit of data structures
options.
In article <3A2E6155.C2273626@yahoo.com>,
Al Dev <alavoor@yahoo.com> wrote:
> I am planning to use either or PERL or Java for a new web application
> which will
> run on RedHat Linux.
>
> Any suggestions on which runs faster - PERL or Java??
> Speed is more important (top priority)
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 6 Dec 2000 11:13:54 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Your help please
Message-Id: <slrn92spe2.q25.tadmc@magna.metronet.com>
Katie Foster <katie.foster@bt.com> wrote:
>sorry I should havem put 5.03 sorry
Keep trying.
there is no 5.03 version of perl either :-)
Why don't you just ask perl to tell you what version it is?
perl -v
>"Peter Sundstrom" <peter.sundstrom@eds.com> wrote in message
>news:90jl8p$cnu$1@hermes.nz.eds.com...
>>
>> Katie Foster <katie.foster@bt.com> wrote in message
>> news:90if3b$61i$1@pheidippides.axion.bt.co.uk...
>> >
>> > My group have upgraded from Perl 3 to Perl 5.05. Some of our scripts no
>>
>> Are you absolutely sure you had Perl 3? I would be *very* surprised if
>that
>> was the case.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
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 5047
**************************************