[25097] in Perl-Users-Digest
Perl-Users Digest, Issue: 7347 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 1 03:05:59 2004
Date: Mon, 1 Nov 2004 00: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 Mon, 1 Nov 2004 Volume: 10 Number: 7347
Today's topics:
A Reg-exp compendium of frequently occuring matches? <soundz@techie.com>
Re: A Reg-exp compendium of frequently occuring matches <simon@unisolve.com.au>
Re: A Reg-exp compendium of frequently occuring matches <cwilbur@mithril.chromatico.net>
Re: A Reg-exp compendium of frequently occuring matches <soundz@techie.com>
Re: A Reg-exp compendium of frequently occuring matches <abigail@abigail.nl>
Code review request: a better radix sort <none@nowhere.invalid>
Re: Code review request: a better radix sort <uri@stemsystems.com>
Re: Code review request: a better radix sort <none@nowhere.invalid>
Re: Code review request: a better radix sort <uri@stemsystems.com>
Re: Common file operations (Seymour J.)
Emacs modules for Perl programming (Jari Aalto+mail.perl)
FAQ 2.13: Perl on the Net: FTP and WWW Access <comdog@panix.com>
FAQ 4.52: How do I sort an array by (anything)? <comdog@panix.com>
Re: GD.pm install woes (Xevo)
Re: IDEs <Joe.Smith@inwap.com>
Re: list vs array <Joe.Smith@inwap.com>
misc: 4 Millions Domains data with Category josephdomus@internetdrive.com
Net::NNTP <curiousgeorge@curious.comm>
Newbie HTTP::Request->new(POST => URL); question <klevmar@hotmail.com>
Re: OT: perl errors <Joe.Smith@inwap.com>
Re: perl to english (Peter Scott)
Re: print FILE function() <Joe.Smith@inwap.com>
Re: print FILE function() <mritty@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 31 Oct 2004 20:08:59 -0800
From: Mark Day <soundz@techie.com>
Subject: A Reg-exp compendium of frequently occuring matches?
Message-Id: <4185B6DB.9090604@techie.com>
I was wondering if anyone out there had compiled a list
of regular expressions for tasks that occur frequently such as
stripping out HTML tags, validating IP addresses, etc.
Is there anything like this around? If there's a link for something like
that, it would be very handy and helpful, thanks in advance.
------------------------------
Date: Mon, 01 Nov 2004 16:37:28 +1100
From: Simon Taylor <simon@unisolve.com.au>
Subject: Re: A Reg-exp compendium of frequently occuring matches?
Message-Id: <cm4hvj$1tkk$1@otis.netspace.net.au>
Mark Day wrote:
> I was wondering if anyone out there had compiled a list
> of regular expressions for tasks that occur frequently such as
> stripping out HTML tags, validating IP addresses, etc.
> Is there anything like this around? If there's a link for something like
> that, it would be very handy and helpful, thanks in advance.
>
Search for regexp at http://search.cpan.org and you'll see plenty
of examples under the Regexp::Common namespace.
Probably the best starting point is here:
http://search.cpan.org/~abigail/Regexp-Common-2.117/lib/Regexp/Common.pm
Regards,
Simon Taylor
------------------------------
Date: Mon, 01 Nov 2004 06:01:33 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: A Reg-exp compendium of frequently occuring matches?
Message-Id: <87sm7uazrs.fsf@mithril.chromatico.net>
>>>>> "MD" == Mark Day <soundz@techie.com> writes:
MD> I was wondering if anyone out there had compiled a list of
MD> regular expressions for tasks that occur frequently such as
MD> stripping out HTML tags, validating IP addresses, etc.
Both of those are extremely poor uses for regular expressions.
MD> Is there anything like this around? If there's a link for
MD> something like that, it would be very handy and helpful,
MD> thanks in advance.
http://search.cpan.org.
To validate an IP address, Validate::Net.
To strip HTML tags, HTML::Strip.
For generic common regular expressions, Regex::Common.
Charlton
--
cwilbur at chromatico dot net
cwilbur at mac dot com
------------------------------
Date: Sun, 31 Oct 2004 22:37:28 -0800
From: Mark Day <soundz@techie.com>
Subject: Re: A Reg-exp compendium of frequently occuring matches?
Message-Id: <4185D9A8.4030807@techie.com>
Simon Taylor wrote:
> Mark Day wrote:
>
>> I was wondering if anyone out there had compiled a list
>> of regular expressions for tasks that occur frequently such as
>> stripping out HTML tags, validating IP addresses, etc.
>> Is there anything like this around? If there's a link for something
>> like that, it would be very handy and helpful, thanks in advance.
>>
>
> Search for regexp at http://search.cpan.org and you'll see plenty
> of examples under the Regexp::Common namespace.
>
> Probably the best starting point is here:
>
> http://search.cpan.org/~abigail/Regexp-Common-2.117/lib/Regexp/Common.pm
>
>
> Regards,
That's great, thanks.
Looks like there are many such common tasks that could be added here.
------------------------------
Date: 01 Nov 2004 06:55:56 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: A Reg-exp compendium of frequently occuring matches?
Message-Id: <slrncobnfs.cc.abigail@alexandra.abigail.nl>
Mark Day (soundz@techie.com) wrote on MMMMLXXX September MCMXCIII in
<URL:news:4185D9A8.4030807@techie.com>:
`'
`'
`' Simon Taylor wrote:
`' > Mark Day wrote:
`' >
`' >> I was wondering if anyone out there had compiled a list
`' >> of regular expressions for tasks that occur frequently such as
`' >> stripping out HTML tags, validating IP addresses, etc.
`' >> Is there anything like this around? If there's a link for something
`' >> like that, it would be very handy and helpful, thanks in advance.
`' >>
`' >
`' > Search for regexp at http://search.cpan.org and you'll see plenty
`' > of examples under the Regexp::Common namespace.
`' >
`' > Probably the best starting point is here:
`' >
`' > http://search.cpan.org/~abigail/Regexp-Common-2.117/lib/Regexp/Common.pm
`' >
`' >
`' > Regards,
`'
`'
`' That's great, thanks.
`' Looks like there are many such common tasks that could be added here.
`'
Patches welcome.
Abigail
--
$_ = "\nrekcaH lreP rehtona tsuJ"; my $chop; $chop = sub {print chop; $chop};
$chop -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
-> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
------------------------------
Date: Sun, 31 Oct 2004 21:58:24 GMT
From: none <none@nowhere.invalid>
Subject: Code review request: a better radix sort
Message-Id: <4edhd.884$fw2.153@trndny01>
I have written the following radixsort as part of an effort to learn
perl. I'd appreciate any comments, improvements, or suggestions on
making it more perlish.
Thanks,
-Mike
sub radix_sort {
my @nums = map { pack('d', $_); } @_;
for(my $mask = "C"; length($mask) <= 8; $mask = 'x' . $mask ) {
my @bins = ();
foreach(@nums) {
my $radix = unpack $mask, $_;
push @{$bins[$radix]}, $_;
}
@nums = map { @$_ } (grep { defined } @bins);
}
my @sorted;
foreach(@nums) {
my $num = unpack('d', $_);
if( $num < 0 ) {
unshift(@sorted, $num);
} else {
push(@sorted, $num);
}
}
return @sorted;
}
------------------------------
Date: Sun, 31 Oct 2004 22:28:33 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Code review request: a better radix sort
Message-Id: <x7654q7ca6.fsf@mail.sysarch.com>
>>>>> "n" == none <none@nowhere.invalid> writes:
n> sub radix_sort {
n> my @nums = map { pack('d', $_); } @_;
n> for(my $mask = "C"; length($mask) <= 8; $mask = 'x' . $mask ) {
$mask .= 'x'
or
for my $mask_len ( 1 .. 8 ) :
my $mask = 'x' x $mask_len ;
n> my @bins = ();
no need to init that to (). my vars are empty to start
n> foreach(@nums) {
n> my $radix = unpack $mask, $_;
n> push @{$bins[$radix]}, $_;
explain the algorithm you are using. it just seems like you are going
through some complex hoops. also beware of endian ordering as
well. packed floats in native order are machine dependent.
n> }
n> @nums = map { @$_ } (grep { defined } @bins);
that could be done with just map:
@nums = map { defined ? @$_ : () } @bins ;
n> }
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Mon, 01 Nov 2004 02:08:26 GMT
From: none <none@nowhere.invalid>
Subject: Re: Code review request: a better radix sort
Message-Id: <uUghd.2211$OU3.2145@trndny09>
Uri Guttman wrote:
> for my $mask_len ( 1 .. 8 ) :
>
> my $mask = 'x' x $mask_len ;
hrm...I think you meant:
$mask = 'x' x $mask_len . 'C'?
What's the advantage of doing it this way instead of the for loop?
>
> n> my @bins = ();
>
> no need to init that to (). my vars are empty to start
Gotcha...I didn't realize that Perl would re-init the value to empty
each time through the loop.
> n> foreach(@nums) {
>
> n> my $radix = unpack $mask, $_;
> n> push @{$bins[$radix]}, $_;
>
> explain the algorithm you are using. it just seems like you are going
> through some complex hoops. also beware of endian ordering as
> well. packed floats in native order are machine dependent.
I was sorting by bytes, starting from the leftmost/least significant
byte (unpack 'C') up to the rightmost/most significant byte
(unpack 'xxxxxxxC'). I have an array of 256 bins, and each number is
added to the bin corresponding to the value of the current radix.
Afterwards, the array of bins is unrolled into a linear array and I move
on to the next radix.
So, if I had two numbers, (02FF, 01FF), the first iteration of the loop
would be:
bins[255] = [02FF, 01FF]
@nums = (02FF, 01FF)
Then the second iteration would be:
bins[1] = [01FF]
bins[2] = [02FF]
@nums = (01FF, 02FF)
At the end, I have to reverse the negative numbers b/c they end up
sorted at the end in reverse order (since in IEEE FP notation, sign bit
= 1 is negative and sign bit = 0 is positive).
Does that makes sense? Is there a simpler way to do this?
> that could be done with just map:
>
> @nums = map { defined ? @$_ : () } @bins ;
Thanks! That is better! Although I think I need to use defined($_).
Otherwise it gives me an error saying "use of defined without
parenthesis is ambiguous."
So, now I have:
sub radix_sort2 {
my @nums = map { pack('d', $_); } @_;
for my $mask_len ( 0 .. 7 ) {
my $mask = 'x' x $mask_len . 'C';
my @bins;
foreach(@nums) {
my $radix = unpack($mask, $_);
push(@{$bins[$radix]}, $_);
}
@nums = map { defined($_) ? @$_ : () } @bins;
}
my @sorted;
foreach(@nums) {
my $num = unpack('d', $_);
if( $num < 0 ) {
unshift(@sorted, $num);
} else {
push(@sorted, $num);
}
}
return @sorted;
}
------------------------------
Date: Mon, 01 Nov 2004 04:22:06 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Code review request: a better radix sort
Message-Id: <x7y8hm42s1.fsf@mail.sysarch.com>
>>>>> "n" == none <none@nowhere.invalid> writes:
n> Uri Guttman wrote:
>> for my $mask_len ( 1 .. 8 ) :
>> my $mask = 'x' x $mask_len ;
n> hrm...I think you meant:
n> $mask = 'x' x $mask_len . 'C'?
n> What's the advantage of doing it this way instead of the for loop?
yeah, i missed the 'C'. i just don't like c style loops and i avoid them
when possible. there are probably other ways to do that as well. as i
said before, if i understood the algorithm i could help with the code
more. munging floats at the low level is tricky. i had a fun time with
them in Sort::Maker (especially with -0!).
n> my @bins = ();
>> no need to init that to (). my vars are empty to start
n> Gotcha...I didn't realize that Perl would re-init the value to empty
n> each time through the loop.
my has a compile time effect (declaration) and a run time effect (even
when not assigned something).
n> foreach(@nums) {
n> my $radix = unpack $mask, $_;
n> push @{$bins[$radix]}, $_;
>> explain the algorithm you are using. it just seems like you are going
>> through some complex hoops. also beware of endian ordering as
>> well. packed floats in native order are machine dependent.
n> I was sorting by bytes, starting from the leftmost/least significant
n> byte (unpack 'C') up to the rightmost/most significant byte
n> (unpack 'xxxxxxxC'). I have an array of 256 bins, and each number is
n> added to the bin corresponding to the value of the current
n> radix. Afterwards, the array of bins is unrolled into a linear array
n> and I move on to the next radix.
as i said before, endianess should be accounted for if you want a
portable solution. again, if it is just a learning thing, that can be
skipped.
n> So, if I had two numbers, (02FF, 01FF), the first iteration of the
n> loop would be:
n> bins[255] = [02FF, 01FF]
n> @nums = (02FF, 01FF)
n> Then the second iteration would be:
n> bins[1] = [01FF]
n> bins[2] = [02FF]
n> @nums = (01FF, 02FF)
n> At the end, I have to reverse the negative numbers b/c they end up
n> sorted at the end in reverse order (since in IEEE FP notation, sign
n> bit = 1 is negative and sign bit = 0 is positive).
as i said, i have recent and intimate experience with this area. :) you
could use separate bins for negative numbers and merge them later. but
why do you want to do a radix sort on floats? unless this is just an
exercise for you.
n> Does that makes sense? Is there a simpler way to do this?
i would have to study the algorithm a bit more (which i may not do). i
know radix sorts but there could be other ways to implement it.
>> that could be done with just map:
>> @nums = map { defined ? @$_ : () } @bins ;
n> Thanks! That is better! Although I think I need to use
n> defined($_). Otherwise it gives me an error saying "use of defined
n> without parenthesis is ambiguous."
defined() should be fine then. it uses $_ as its default argument.
n> So, now I have:
n> sub radix_sort2 {
n> my @nums = map { pack('d', $_); } @_;
i would rename @nums to something else as they aren't really numbers
anymore but the byte string that represents the (ieee) float format. it
gets confusing below when you convert back to a real num. maybe a better
name would be $float_bytes?
n> for my $mask_len ( 0 .. 7 ) {
n> my $mask = 'x' x $mask_len . 'C';
n> my @bins;
n> foreach(@nums) {
n> my $radix = unpack($mask, $_);
n> push(@{$bins[$radix]}, $_);
n> }
n> @nums = map { defined($_) ? @$_ : () } @bins;
n> }
ok, i see what the algorithm is. using unpack with a rotated mask is
more work than is needed. since you are just grabbing bytes, you can use
substr and ord to get each byte. something like this (untested):
for my $byte_num ( reverse 0 .. 7 ) {
# check if reverse is needed. it could be used to handle endian issues.
foreach my $num ( @nums ) {
my $radix = substr( $num, $byte_num, 1);
push( @{$bins[$radix]}, $num );
}
a bit shorter and more direct.
n> my @sorted;
n> foreach(@nums) {
n> my $num = unpack('d', $_);
n> if( $num < 0 ) {
n> unshift(@sorted, $num);
n> } else {
n> push(@sorted, $num);
n> }
n> }
gotta be a better way to handle negative numbers. maybe this:
my @real_nums = map unpack('d', $_), @nums ;
my @sorted = grep $_ < 0, @real_nums ;
push @sorted = grep $_ >= 0, @real_nums ;
return @sorted;
but maybe doing separate bins would be the best answer. also i think
choosing the bin might be different for negative numbers so check that
out with some test data.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Sun, 31 Oct 2004 17:36:04 -0500
From: "Shmuel (Seymour J.) Metz" <spamtrap@library.lspace.org.invalid>
Subject: Re: Common file operations
Message-Id: <418568d4$1$fuzhry+tra$mr2ice@news.patriot.net>
In <am3852-uch.ln1@osiris.mauzo.dyndns.org>, on 10/28/2004
at 10:07 PM, Ben Morrow <usenet@morrow.me.uk> said:
>regex is the usual spelling in this group, and regexen the usual
>plural.
Ah, so! I should have guessed that by analogy with boxen and vaxen :-(
>...and your shell doesn't do proper quoting and remove the 's for
>you, right?
Perl on OS/2 doesn't use my shell; it uses one that is more
Unix®-like. Otherwise the user wouldn't have to quote specifications
containing "*". Note that in this case allowing the shell to handle
the file globbing is not an option, because it would do so in the
wrong directories.
--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>
Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to spamtrap@library.lspace.org
------------------------------
Date: 01 Nov 2004 05:24:46 GMT
From: <jari.aalto <AT> poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_1099286648@rtfm.mit.edu>
Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://tiny-tools.sourceforge.net/
Maintainer: Jari Aalto A T poboxes com
Announcement: "What Emacs lisp modules can help with programming Perl"
Preface
Emacs is your friend if you have to do anything comcerning software
development: It offers plug-in modules, written in Emacs lisp
(elisp) language, that makes all your programmings wishes come
true. Please introduce yourself to Emacs and your programming era
will get a new light.
Where to find Emacs/XEmacs
o Unix:
http://www.gnu.org/software/emacs/emacs.html
http://www.xemacs.org/
o Unix Windows port (for Unix die-hards):
install http://www.cygwin.com/ which includes native Emacs 21.x.
and XEmacs port
o Pure Native Windows port
http://www.gnu.org/software/emacs/windows/ntemacs.html
ftp://ftp.xemacs.org/pub/xemacs/windows/setup.exe
o More Emacs resources at
http://tiny-tools.sourceforge.net/ => Emacs resource page
Emacs Perl Modules
Cperl -- Perl programming mode
http://www.cpan.org/modules/by-authors/id/ILYAZ/cperl-mode/
http://math.berkeley.edu/~ilya/software/emacs/
by Ilya Zakharevich
CPerl is major mode for editing perl files. Forget the default
`perl-mode' that comes with Emacs, this is much better. Comes
standard in newest Emacs.
TinyPerl -- Perl related utilities
http://tiny-tools.sourceforge.net/
If you ever wonder how to deal with Perl POD pages or how to find
documentation from all perl manpages, this package is for you.
Couple of keystrokes and all the documentaion is in your hands.
o Instant function help: See documentation of `shift', `pop'...
o Show Perl manual pages in *pod* buffer
o Grep through all Perl manpages (.pod)
o Follow POD references e.g. [perlre] to next pod with RETURN
o Coloured pod pages with `font-lock'
o Separate `tiperl-pod-view-mode' for jumping topics and pages
forward and backward in *pod* buffer.
o Update `$VERSION' variable with YYYY.MMDD on save.
o Load source code into Emacs, like Devel::DProf.pm
o Prepare script (version numbering) and Upload it to PAUSE
o Generate autoload STUBS (Devel::SelfStubber) for you
Perl Module (.pm)
TinyIgrep -- Perl Code browsing and easy grepping
[TinyIgrep is included in Tiny Tools Kit]
To grep from all installed Perl modules, define database to
TinyIgrep. There is example file emacs-rc-tinyigrep.el that shows
how to set up dattabases for Perl5, Perl4 whatever you have
installed
TinyIgrep calls Igrep.el to to do the search, You can adjust
recursive grep options, set search case sensitivity, add user grep
options etc.
You can find latest `igrep.el' module at
<http://groups.google.com/groups?group=gnu.emacs.sources> The
maintainer is Jefin Rodgers <kevinr <AT> ihs.com>.
TinyCompile -- To Browse grep results in Emacs *compile* buffer
TinyCompile is a minor mode for *compile* buffer from where
you can collapse unwanted lines or shorten file URLs:
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
/asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT
-->
cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
file1:NNN: MATCHED TEXT
file1:NNN: MATCHED TEXT
End
------------------------------
Date: Mon, 1 Nov 2004 05:03:02 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 2.13: Perl on the Net: FTP and WWW Access
Message-Id: <cm4g26$bsp$1@reader1.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
2.13: Perl on the Net: FTP and WWW Access
To get the best performance, pick a site from the list at
http://www.cpan.org/SITES.html . From there you can find the quickest
site for you.
You may also use xx.cpan.org where "xx" is the 2-letter country code for
your domain; e.g. Australia would use au.cpan.org. [Note: This only
applies to countries that host at least one mirror.]
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: Sun, 31 Oct 2004 23:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 4.52: How do I sort an array by (anything)?
Message-Id: <cm3qv5$5up$1@reader1.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
4.52: How do I sort an array by (anything)?
Supply a comparison function to sort() (described in "sort" in
perlfunc):
@list = sort { $a <=> $b } @list;
The default sort function is cmp, string comparison, which would sort
"(1, 2, 10)" into "(1, 10, 2)". "<=>", used above, is the numerical
comparison operator.
If you have a complicated function needed to pull out the part you want
to sort on, then don't do it inside the sort function. Pull it out
first, because the sort BLOCK can be called many times for the same
element. Here's an example of how to pull out the first word after the
first number on each item, and then sort those words case-insensitively.
@idx = ();
for (@data) {
($item) = /\d+\s*(\S+)/;
push @idx, uc($item);
}
@sorted = @data[ sort { $idx[$a] cmp $idx[$b] } 0 .. $#idx ];
which could also be written this way, using a trick that's come to be
known as the Schwartzian Transform:
@sorted = map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [ $_, uc( (/\d+\s*(\S+)/)[0]) ] } @data;
If you need to sort on several fields, the following paradigm is useful.
@sorted = sort { field1($a) <=> field1($b) ||
field2($a) cmp field2($b) ||
field3($a) cmp field3($b)
} @data;
This can be conveniently combined with precalculation of keys as given
above.
See the sort article in the "Far More Than You Ever Wanted To Know"
collection in http://www.cpan.org/misc/olddoc/FMTEYEWTK.tgz for more
about this approach.
See also the question below on sorting hashes.
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: 31 Oct 2004 15:08:46 -0800
From: x3v0-usenet@yahoo.com (Xevo)
Subject: Re: GD.pm install woes
Message-Id: <359b5621.0410311508.4aaa08fa@posting.google.com>
Ben Morrow <usenet@morrow.me.uk> wrote in message news:<7opc52-v86.ln1@osiris.mauzo.dyndns.org>...
> Quoth x3v0-usenet@yahoo.com (Xevo):
> > I've been trying to install GD.pm for a few days now, but to no avail.
> >
> > I'm not sure exactly what is wrong, but it looks like it can't find
> > libgd.so.2. Any ideas on what is going on and how to fix this error?
>
> Try adding /usr/local/gd/lib to your LD_LIBRARY_PATH.
>
> Ben
Thank you. Setting LD_LIBRARY_PATH helped a lot. I am now getting a
different, less verbose error when doing "make test TEST_VERBOSE=1".
It says it failed test 4. I don't know what test 4 is, so I'm not sure
where to go from here. As before, ./configure and make gave no errors.
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e"
"test_harness(1, 'blib/lib', 'blib/arch')" t/*.t
t/GD..........1..10
ok 1
ok 2
ok 3
not ok 4
ok 5
ok 6
ok 7
ok 8 # Skip, FreeType changes too frequently to be testable
ok 9 # Skip, no XPM support
not ok 10
FAILED tests 4, 10
Failed 2/10 tests, 80.00% okay (less 2 skipped tests: 6 okay,
60.00%)
t/Polyline....1..1
# Running under perl version 5.008003 for linux
# Current time local: Sun Oct 31 18:06:25 2004
# Current time GMT: Sun Oct 31 23:06:25 2004
# Using Test.pm version 1.24
ok 1
ok
Failed Test Stat Wstat Total Fail Failed List of Failed
-------------------------------------------------------------------------------
t/GD.t 10 2 20.00% 4 10
2 subtests skipped.
Failed 1/2 test scripts, 50.00% okay. 2/11 subtests failed, 81.82%
okay.
make: *** [test_dynamic] Error 255
------------------------------
Date: Sun, 31 Oct 2004 20:49:00 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: IDEs
Message-Id: <0dchd.281323$wV.121984@attbi_s54>
daniel kaplan wrote:
> as for the perldoc, still...no grep (is there a dos equiv?)
Have you looked into cygwin? (http://www.cygwin.com)
It gives you a bash shell in Windows and has most of the commands
that you expect on a Unix-like system, including grep.
One disadvantage of cygwin I've come across is that now I have two
installations of perl to maintain: the ActiveState set of modules
and the cygwin set.
-Joe
------------------------------
Date: Sun, 31 Oct 2004 20:04:08 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: list vs array
Message-Id: <Yybhd.551538$8_6.168151@attbi_s04>
daniel kaplan wrote:
> actually what i was refering to here, my apologies as some of these posts i
> ignored, but what i meant was...
>
> "Starting" ActiveState's Komodo (or VisualPerl) ... is slow
True, but starting perl is not slow.
From the command line, perl can be started up several times per second.
C:\Documents and Settings\jms>type perltest.bat
perl -le "print scalar localtime"
perl -le "print scalar localtime"
perl -le "print scalar localtime"
perl -le "print scalar localtime"
perl -le "print scalar localtime"
perl -le "print scalar localtime"
perl -le "print scalar localtime"
perl -le "print scalar localtime"
perl -le "print scalar localtime"
perl -le "print scalar localtime"
perl -le "print scalar localtime"
perl -le "print scalar localtime"
perl -le "print scalar localtime"
perl -le "print scalar localtime"
perl -le "print scalar localtime"
C:\Documents and Settings\jms>perltest.bat
The app runs quite quickly when there isn't an IDE to get in the way.
-Joe
------------------------------
Date: 1 Nov 2004 03:03:42 GMT
From: josephdomus@internetdrive.com
Subject: misc: 4 Millions Domains data with Category
Message-Id: <4185a78e_2@nnrp1.news.uk.psi.net>
Successfull Internet and Direct Marketing products on
www.promotionsite.net
* NEW * DOMUS Domains Toolkit Fall 2004 - Unique on the Net
4 Millions "Whois" Domains data with Expiration Date and Category*.
Ultimate Version (October 2004) - Our best rate starts from US *$149*.
A wonderful tool for Internet and Direct Marketing.
Available in Basic, Advanced and Full Editions.
It contains a domain database with 4 millions *FRESH* October 2004
New records .com, .net, .org.
4 Gigabytes MS Excel data zipped on CD-Roms/Dvd. Compression 3:1.
MS Excel or Text tab delimited data files Available!
Each record include the full "whois" fields info and homepage info:
Domain Name,
Registrant Company, Contact, Address, City, Tel, Fax, Email,
Administrative Company, Contact, Address, City, Tel, Fax, Email,
Technical Company, Contact, Address, City, Tel, Fax, Email,
Billing Company, Contact, Address, City, Tel, Fax, Email,
Zone Company, Contact, Address, City, Tel, Fax, Email,
Name Servers until 6 name servers with IP addresses
Record Created on Date, Record Updated on Date, Record *Expires* on Date
Domain Title, Domain Description, Domain Keywords (*Category*),
First 300 Words in the Domain Website Homepage.
Download Free Demo, Screenshot, see Products Details or Order On-Line
at www.promotionsite.net.
Available On-Line many other Promotion Products.
Instant Shipment or Download On-Line Registered Versions available!
Best Regards,
www.promotionsite.net
The Best place where to find Internet Marketing Resources on the Net.
---
This is a one-time only information.
The enrolled (final) text of S. 877 as it was passed by the Senate on
November 25, 2003, and agreed to by the House of Representatives on
December 8, 2003, allows e-marketers to send UCE as long as the message
contains an opt-out mechanism, a functioning return e-mail address and
the legitimate physical address of the mailer. The bill was signed by
the President on December 16, 2003, and takes effect on January 1, 2004.
Your address isn't in any of our archives, however for Can Spam Act 2003
Compliance, you can remove at http://www.promotionsite.net/remove.html
------------------------------
Date: Sun, 31 Oct 2004 21:23:47 -0000
From: curious <curiousgeorge@curious.comm>
Subject: Net::NNTP
Message-Id: <10oalv3c1c8dt7b@news.supernews.com>
Hi,
I am sending this post by hand via Net::NNTP. I was wondering if anyone can recommend a module or Perl program a step higher than this that will help me manage reading usenet. I want to set up something on my website for me to view postings customized for my own use. Thanks!
------------------------------
Date: Sun, 31 Oct 2004 21:30:45 GMT
From: "qa4ever" <klevmar@hotmail.com>
Subject: Newbie HTTP::Request->new(POST => URL); question
Message-Id: <9Qchd.7602$d5.63916@newsb.telia.net>
Perl gurus,
My Internet provider is providing a login screen before one gets access to
internet.
I was thinking of automate login using following script but it won't login.
Why is it failing?
use strict;
use LWP;
use URI::Escape;
use constant URL => 'http://10.0.0.6/sd/init';
my $ua = LWP::UserAgent->new;
my $newagent = 'search_rfc/1.0 (' . $ua->agent .')';
$ua->agent($newagent);
my $query_string = 'username=joeb&password=lowe';
print "echo $query_string";
my $request = HTTP::Request->new(POST => URL);
$request->content($query_string);
my $response = $ua->request($request);
die $response->message unless $response->is_success;
print "echo $response->as_string\n";
View source of 'http://10.0.0.6/sd/init' >>>>>>>>>>>>>>>>>>>>>>>>>>><
<body onload="document.pwdenter.username.focus();">
<FORM NAME="pwdenter" ACTION="login" METHOD="POST">
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%"
HEIGHT="100%">
<TR><TD>
<CENTER>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
<TR><TD>
<IMG SRC="/bzinfo/catv/logo1.gif" ALT="logo" BORDER="0">
<FONT SIZE="-1" FACE="Geneva, Arial">
<BR><BR>
Enter username and password.<BR>
Thereafter Press "Log on".
<BR><BR>
Användarnamn:
<BR><INPUT NAME="username"><BR>
Lösenord:
<BR><INPUT NAME="password" TYPE=PASSWORD
onBlur="this.form.username.focus();">
<BR>
<INPUT TYPE="SUBMIT" NAME="submitForm" VALUE="Log on">
</TABLE>
</TABLE>
</FORM>
</body>
Thanks,
QA4Ever
------------------------------
Date: Sun, 31 Oct 2004 20:34:19 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: OT: perl errors
Message-Id: <9%bhd.339197$MQ5.195673@attbi_s52>
Jeff Thies wrote:
> use CGI::Carp 'fatalsToBrowser';
>
> The web server (perl 5.8, Enterprise Redhat,Apache/2.0.46) I'm running
> now does not throw those nice explicit errors. What I get now is just a
> plain 500 server error.
It appears that Jeff is experiencing a bug in version 1.24 of CGI::Carp
that was fixed in version 1.26:
1.26 Replaced CORE::GLOBAL::die with the evil $SIG{__DIE__} because the
former isn't working in some people's hands. There is no such thing as
reliable exception handling in Perl.
-Joe
------------------------------
Date: Mon, 01 Nov 2004 03:45:27 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: perl to english
Message-Id: <rjihd.80802$Pl.27782@pd7tw1no>
In article <slrncng4dg.rj.tassilo.von.parseval@localhost.localdomain>,
"Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de> writes:
>Also sprach Paul Lalli:
>> I have to admit I didn't know about this. (I knew about base, it just
>> didn't occur to me to use it here, in contrast to Exporter's docs). I
>> wonder if it might be worth suggesting the documentation for Exporter.pm
>> be updated to reflect this method?
>
>I made this suggestion once in the past and had to learn about some
>urban legends according to which 'use base qw/Exporter/' might not
>always work as one would expect. Of course, no one was able to come with
>an example, let alone explanation, for this alleged dysfunctionality.
How about the thread at http://tinyurl.com/3z669 ?
--
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/
------------------------------
Date: Sun, 31 Oct 2004 20:17:25 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: print FILE function()
Message-Id: <kLbhd.338350$3l3.217911@attbi_s03>
Spin wrote:
> Here's how I solved the problem by changing the second-to-last line of
> the sub:
> printf FILE $format,$offset,$offset,@array,$data;
I hope you mean that you changed the line before the closing curly to be
sprintf FILE $format,$offset,$offset,@array,$data;
so that it returns a string which can be send somewhere other than the terminal.
=Joe
------------------------------
Date: Sun, 31 Oct 2004 15:33:06 -0500
From: Paul Lalli <mritty@gmail.com>
Subject: Re: print FILE function()
Message-Id: <cm3i7i$pvh$1@misc-cct.server.rpi.edu>
Joe Smith wrote:
> Spin wrote:
>
>> Here's how I solved the problem by changing the second-to-last line of
>> the sub:
>> printf FILE $format,$offset,$offset,@array,$data;
>
>
> I hope you mean that you changed the line before the closing curly to be
> sprintf FILE $format,$offset,$offset,@array,$data;
> so that it returns a string which can be send somewhere other than the
> terminal.
> =Joe
sprintf() does not accept a filehandle as a first argument. The OP's
line is intended to print the string to FILE, not the terminal.
Paul Lalli
------------------------------
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 7347
***************************************