[32160] in Perl-Users-Digest
Perl-Users Digest, Issue: 3425 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 27 00:09:26 2011
Date: Sun, 26 Jun 2011 21:09:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 26 Jun 2011 Volume: 11 Number: 3425
Today's topics:
Re: [RegEx] Optional parameter <tzz@lifelogs.com>
Re: Module to check overlap? <ela@yantai.org>
open letter to Sherm Pendley about ShuX jaialai.technology@gmail.com
Other half of 'CGI file upload' <rweikusat@mssgmbh.com>
Re: Other half of 'CGI file upload' <rweikusat@mssgmbh.com>
Re: Perl definition of newline? <whynot@pozharski.name>
Re: Perl definition of newline? <kst-u@mib.org>
Re: Perl definition of newline? <uri@StemSystems.com>
Re: Perl definition of newline? <tadmc@seesig.invalid>
Re: Perl definition of newline? <uri@StemSystems.com>
Re: Perl definition of newline? <tzz@lifelogs.com>
Re: Perl definition of newline? <tzz@lifelogs.com>
Re: Perl definition of newline? <mvdwege@mail.com>
Re: Perl definition of newline? <uri@StemSystems.com>
sort scientific notation value after alphabet <ela@yantai.org>
Re: sort scientific notation value after alphabet <uri@StemSystems.com>
Re: sort scientific notation value after alphabet <jurgenex@hotmail.com>
Re: sort scientific notation value after alphabet (Randal L. Schwartz)
Re: upload file rom solaris to debian using perl base i <rvtol+usenet@xs4all.nl>
Re: upload file rom solaris to debian using perl base i <rweikusat@mssgmbh.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 24 Jun 2011 13:50:56 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: [RegEx] Optional parameter
Message-Id: <87d3i3rrlb.fsf@lifelogs.com>
On Fri, 24 Jun 2011 18:59:32 +0100 Rainer Weikusat <rweikusat@mssgmbh.com> wrote:
RW> Printing an 'undefined' value is a well-defined operation in Perl: It
RW> is semantically equivalent to 'printing an empty string'.
Thank you for clarifying that.
RW> there is little reason to assume that your re-publishment is
RW> motivated by anything but intentional malice on your part.
You're right. That's how I roll.
RW> Consequently, I claim that whatever other assertions you make in
RW> public, such as 'this has helped me with real-world code', are to be
RW> distrusted on the grounds that you demonstrably don't care for the
RW> truth insofar it happens to get in your way.
No need to sugar-coat it. I have complete disregard for the truth, even
when it doesn't get in my way.
RW> NB: This is actually one of those rare examples of a valid ad hominem
RW> argument and certainly a sufficient reason to not waste any time on
RW> discussing anything with you.
Oh good. I knew we were having a discussion.
Ted
------------------------------
Date: Mon, 27 Jun 2011 12:37:47 -0700
From: "ela" <ela@yantai.org>
Subject: Re: Module to check overlap?
Message-Id: <iu8tqo$n9f$1@ijustice.itsc.cuhk.edu.hk>
"Ted Zlatanov" <tzz@lifelogs.com> wrote in message
news:871uyjv0ej.fsf@lifelogs.com...
> You can try inversion lists, which are very good for long runs of data.
> Your set B would become (1 101 139 601 1000 1201) and you can easily
> find the overlap of two such lists. Check out
> http://www.perlmonks.org/?node_id=908453 for more.
>
> Ted
Ted, you are very correct, http://www.perlmonks.org/?node_id=908453 HAS a
solution, yet, mentions little about how to pass data to use (No
confirmation letter received after registration until now). Would you mind
helping shed some light which part is talking about input data to match
against a database (again, which part)? I could run the codes smoothly but
just don't know how to format my data (and the database) in order to get the
ball rolling!
use warnings;
use strict;
use Devel::Size qw/total_size/;
use Benchmark;
++$|;
print ">>Strings:\n";
my $t0 = Benchmark->new;
for (10e3, 10e4, 10e5,){
my %r;
my($i,$l,$g) = (0) x 3;
for( 1 .. $_ ) {
$r{ int( $i / 10e3 ) } .=
qq[ $i -@{[ $i + ( $l = 1500 + int( -500 + rand 1000 ) ) ]} ];
$i+=$l + 25 + int( rand 25 );
}
print "$_ : " . (total_size(\%r) ) . "\n";
}
my $t1 = Benchmark->new;
my $td = timediff($t1, $t0);
print "String took:",timestr($td),"\n";
print ">>AoA:\n";
$t0 = Benchmark->new;
for (10e3, 10e4, 10e5,){
my %r;
my($i,$l,$g) = (0) x 3;
for( 1 .. $_ ) {
push @{ $r{ int( $i / 10e3 ) } },
[ $i, @{[ $i + ( $l = 1500 + int( -500 + rand 1000 ) ) ]} ];
$i+=$l + 25 + int( rand 25 );
}
print "$_ : " . (total_size(\%r) ) . "\n";
}
$t1 = Benchmark->new;
$td = timediff($t1, $t0);
print "Array took:",timestr($td),"\n";
print system('perl -v');
------------------------------
Date: Sat, 25 Jun 2011 19:56:53 -0400
From: jaialai.technology@gmail.com
Subject: open letter to Sherm Pendley about ShuX
Message-Id: <iu5sk6$rfp$1@speranza.aioe.org>
Sherm,
I see you are a regular here and anted to make a request of you in
the open forum.
First, I love he fact that I can use "ShuX" like I did 10+ years ago
with MacPerl!
My request: Back in the day when ShuX would open a small sound file
would play. Some hickish voice saying "Awww Shucks!". I am feeling
a bit of nostalgia here but could you bring that back?
Maybe leave it as an option (off by default?) for people
with a bit of nostalgia?
Anyone else second this request? Anyone else remember that little
bit of fun with the old shux?
------------------------------
Date: Fri, 24 Jun 2011 21:14:29 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Other half of 'CGI file upload'
Message-Id: <87liwroul6.fsf@sapphire.mobileactivedefense.com>
For sake of completeness, this is the CGI script used for testing the
'post file to CGI script' script I posted earlier. It will put the
content of the 'data' parameter into the file /tmp/out.
------------
#!/usr/bin/perl
#
use CGI;
$cgi = CGI->new();
open($fh, '>', '/tmp/out');
print $fh ($cgi->param('data'));
print("Content-Type: text/plain\n\nOk\n");
------------------------------
Date: Sat, 25 Jun 2011 15:21:24 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: Other half of 'CGI file upload'
Message-Id: <878vsqrnyz.fsf@sapphire.mobileactivedefense.com>
Rainer Weikusat <rweikusat@mssgmbh.com> writes:
[...]
> open($fh, '>', '/tmp/out');
Additional warning: This must not be used on a system with untrusted
and possibily maliscious users because it will happily kill whatever a
possibly existing symlink /tmp/out points to provided the user the
script runs as can write to it.
------------------------------
Date: Sat, 25 Jun 2011 09:09:32 +0300
From: Eric Pozharski <whynot@pozharski.name>
Subject: Re: Perl definition of newline?
Message-Id: <slrnj0aut5.spj.whynot@orphan.zombinet>
with <87r56jrwm0.fsf@lifelogs.com> Ted Zlatanov wrote:
*SKIP*
UG>> i agree to that need but indexing local text isn't trivial. there
UG>> are plenty of such animals out there but which should perl use and
UG>> ship with? most are in c or other langs and that means more
UG>> issues.
> Seriously? grep -l -i isn't good enough? No need to index, just
> search the damn things. They are tiny documents.
No, it's not. That would work for one word queries. grep(1) is
linewise, you know. And space in query could be newline in file. Then
local documentation could be compressed.
Someone would probably mention perl as substitute. No need for grep
then.
*CUT*
--
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom
------------------------------
Date: Sat, 25 Jun 2011 15:11:09 -0700
From: Keith Thompson <kst-u@mib.org>
Subject: Re: Perl definition of newline?
Message-Id: <lnwrg9blz6.fsf@nuthaus.mib.org>
"Uri Guttman" <uri@StemSystems.com> writes:
>>>>>> "TZ" == Ted Zlatanov <tzz@lifelogs.com> writes:
> TZ> On Thu, 23 Jun 2011 17:08:20 -0400 "Uri Guttman" <uri@StemSystems.com> wrote:
> UG> perldoc.perl.org has a search engine. it also has been upgraded to be
> UG> somewhat smarter too.
> TZ> ...
> UG> the perldoc.perl.org search engine needs to be promoted more.
>
> TZ> I don't think a web resource should be the answer to searching local
> TZ> documentation. IMHO perldoc needs a global search facility since it
> TZ> knows where everything is.
>
> i agree to that need but indexing local text isn't trivial. there are
> plenty of such animals out there but which should perl use and ship
> with? most are in c or other langs and that means more issues. i don't
> use the web site as i usually know which doc has what i am looking
> for. but for many perldoc.perl.org is very accessible and useful. it
> should always be mentioned when how best to search the docs is asked.
First approximation: something that works just like "perldoc -q", but
isn't restricted to perlfaq[1-9].pod.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
------------------------------
Date: Sat, 25 Jun 2011 21:38:21 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Perl definition of newline?
Message-Id: <87vcvt9xte.fsf@quad.sysarch.com>
>>>>> "KT" == Keith Thompson <kst-u@mib.org> writes:
KT> "Uri Guttman" <uri@StemSystems.com> writes:
>>>>>>> "TZ" == Ted Zlatanov <tzz@lifelogs.com> writes:
TZ> On Thu, 23 Jun 2011 17:08:20 -0400 "Uri Guttman" <uri@StemSystems.com> wrote:
UG> perldoc.perl.org has a search engine. it also has been upgraded to be
UG> somewhat smarter too.
TZ> ...
UG> the perldoc.perl.org search engine needs to be promoted more.
>>
TZ> I don't think a web resource should be the answer to searching local
TZ> documentation. IMHO perldoc needs a global search facility since it
TZ> knows where everything is.
>>
>> i agree to that need but indexing local text isn't trivial. there are
>> plenty of such animals out there but which should perl use and ship
>> with? most are in c or other langs and that means more issues. i don't
>> use the web site as i usually know which doc has what i am looking
>> for. but for many perldoc.perl.org is very accessible and useful. it
>> should always be mentioned when how best to search the docs is asked.
KT> First approximation: something that works just like "perldoc -q", but
KT> isn't restricted to perlfaq[1-9].pod.
i looked at the code for perldoc and it won't be too easily done. there
is a sub that collects the files to scan/print and for -f and -q it
hardwires them. else it uses the command line args. there would have to
be a way to find all the pod files (scan the dir they are located in)
and do a simple grep on them and print the matching file names. it may
be easier to scan perltoc for the headings which match the query and
print the perldoc names that contain the headings. that could be done
without much effort i think. i will mention it at yapc and maybe pull
together a hackthon for it.
uri
--
Uri Guttman -- uri AT perlhunter DOT com --- http://www.perlhunter.com --
------------ Perl Developer Recruiting and Placement Services -------------
----- Perl Code Review, Architecture, Development, Training, Support -------
------------------------------
Date: Sun, 26 Jun 2011 10:02:42 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Perl definition of newline?
Message-Id: <slrnj0ei3n.lug.tadmc@tadbox.sbcglobal.net>
Keith Thompson <kst-u@mib.org> wrote:
> "Uri Guttman" <uri@StemSystems.com> writes:
>>>>>>> "TZ" == Ted Zlatanov <tzz@lifelogs.com> writes:
>> TZ> On Thu, 23 Jun 2011 17:08:20 -0400 "Uri Guttman" <uri@StemSystems.com> wrote:
>> UG> perldoc.perl.org has a search engine. it also has been upgraded to be
>> UG> somewhat smarter too.
>> TZ> ...
>> UG> the perldoc.perl.org search engine needs to be promoted more.
>>
>> TZ> I don't think a web resource should be the answer to searching local
>> TZ> documentation. IMHO perldoc needs a global search facility since it
>> TZ> knows where everything is.
>>
>> i agree to that need but indexing local text isn't trivial. there are
>> plenty of such animals out there but which should perl use and ship
>> with? most are in c or other langs and that means more issues. i don't
>> use the web site as i usually know which doc has what i am looking
>> for. but for many perldoc.perl.org is very accessible and useful. it
>> should always be mentioned when how best to search the docs is asked.
>
> First approximation: something that works just like "perldoc -q", but
> isn't restricted to perlfaq[1-9].pod.
If we call it "perldoc-search", then
perldoc-search newline
or
perldoc-search portable
Would have helped this OP.
--------------------------
#!/usr/bin/perl
use warnings;
use strict;
die "must provide 1 argument\n" unless @ARGV == 1;
my $pat = shift;
(my $dir = qx/perldoc -l perlfunc/) =~ s/\/perlfunc.pod\s//;;
local @ARGV = grep !/perl(func|faq\d+)\.pod$/, glob "$dir/*.pod";
while (<> ) {
if (/^=.*$pat/i) {
(my $fname = $ARGV) =~ s#.*/##;
print "$fname: $_";
}
}
--------------------------
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Sun, 26 Jun 2011 21:23:10 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Perl definition of newline?
Message-Id: <87boxknk3l.fsf@quad.sysarch.com>
>>>>> "TM" == Tad McClellan <tadmc@seesig.invalid> writes:
TM> Keith Thompson <kst-u@mib.org> wrote:
>> "Uri Guttman" <uri@StemSystems.com> writes:
>>>>>>>> "TZ" == Ted Zlatanov <tzz@lifelogs.com> writes:
TZ> On Thu, 23 Jun 2011 17:08:20 -0400 "Uri Guttman" <uri@StemSystems.com> wrote:
UG> perldoc.perl.org has a search engine. it also has been upgraded to be
UG> somewhat smarter too.
TZ> ...
UG> the perldoc.perl.org search engine needs to be promoted more.
>>>
TZ> I don't think a web resource should be the answer to searching local
TZ> documentation. IMHO perldoc needs a global search facility since it
TZ> knows where everything is.
>>>
>>> i agree to that need but indexing local text isn't trivial. there are
>>> plenty of such animals out there but which should perl use and ship
>>> with? most are in c or other langs and that means more issues. i don't
>>> use the web site as i usually know which doc has what i am looking
>>> for. but for many perldoc.perl.org is very accessible and useful. it
>>> should always be mentioned when how best to search the docs is asked.
>>
>> First approximation: something that works just like "perldoc -q", but
>> isn't restricted to perlfaq[1-9].pod.
i have proposed a yapc hackathon to add full search to perldoc. i have a
design (i looked inside perldoc) that should be doable to search perltoc
with a regex (and no line issues) and print out doc names and header
sections that match. doing a full search will take some more work as you
need to get a list of the core pod files. even better would be a search
that scanned every installed module but that need file::find and such
and could be slow. anyhow, if this starts to get done, maybe we can get
p5p to take a patch to perldoc.
uri
------------------------------
Date: Sun, 26 Jun 2011 22:43:13 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Perl definition of newline?
Message-Id: <87r56gx7la.fsf@lifelogs.com>
On Sat, 25 Jun 2011 09:09:32 +0300 Eric Pozharski <whynot@pozharski.name> wrote:
EP> with <87r56jrwm0.fsf@lifelogs.com> Ted Zlatanov wrote:
EP> *SKIP*
UG> i agree to that need but indexing local text isn't trivial. there
UG> are plenty of such animals out there but which should perl use and
UG> ship with? most are in c or other langs and that means more
UG> issues.
>> Seriously? grep -l -i isn't good enough? No need to index, just
>> search the damn things. They are tiny documents.
EP> No, it's not. That would work for one word queries. grep(1) is
EP> linewise, you know. And space in query could be newline in file.
It's not hard to switch between the two search methods as needed, using
the simpler faster one for one-word queries.
EP> Then local documentation could be compressed.
I guess it could be encrypted too :)
We have zgrep on most modern system for grepping compressed files.
EP> Someone would probably mention perl as substitute. No need for grep
EP> then.
grep is really fast because it does just one thing, really well. But
certainly we could use a tool like `ack' (written in Perl) if it made
sense for the searching.
Ted
------------------------------
Date: Sun, 26 Jun 2011 22:45:51 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Perl definition of newline?
Message-Id: <87mxh4x7gw.fsf@lifelogs.com>
On Sun, 26 Jun 2011 21:23:10 -0400 "Uri Guttman" <uri@StemSystems.com> wrote:
UG> i have proposed a yapc hackathon to add full search to perldoc.
Wonderful. I can't attend this year, unfortunately, or I would have
joined.
UG> even better would be a search that scanned every installed module
UG> but that need file::find and such and could be slow.
I've been pleasantly surprised by `ack': it's fast, reliable, and does
everything I need. So maybe it will work for this as well.
Ted
------------------------------
Date: Mon, 27 Jun 2011 05:47:17 +0200
From: Mart van de Wege <mvdwege@mail.com>
Subject: Re: Perl definition of newline?
Message-Id: <86aad4kkai.fsf@gareth.avalon.lan>
"Uri Guttman" <uri@StemSystems.com> writes:
>>>>>> "TM" == Tad McClellan <tadmc@seesig.invalid> writes:
>
> TM> Keith Thompson <kst-u@mib.org> wrote:
> >> "Uri Guttman" <uri@StemSystems.com> writes:
> >>>>>>>> "TZ" == Ted Zlatanov <tzz@lifelogs.com> writes:
> TZ> On Thu, 23 Jun 2011 17:08:20 -0400 "Uri Guttman" <uri@StemSystems.com> wrote:
> UG> perldoc.perl.org has a search engine. it also has been upgraded to be
> UG> somewhat smarter too.
> TZ> ...
> UG> the perldoc.perl.org search engine needs to be promoted more.
> >>>
> TZ> I don't think a web resource should be the answer to searching local
> TZ> documentation. IMHO perldoc needs a global search facility since it
> TZ> knows where everything is.
> >>>
> >>> i agree to that need but indexing local text isn't trivial. there are
> >>> plenty of such animals out there but which should perl use and ship
> >>> with? most are in c or other langs and that means more issues. i don't
> >>> use the web site as i usually know which doc has what i am looking
> >>> for. but for many perldoc.perl.org is very accessible and useful. it
> >>> should always be mentioned when how best to search the docs is asked.
> >>
> >> First approximation: something that works just like "perldoc -q", but
> >> isn't restricted to perlfaq[1-9].pod.
>
> i have proposed a yapc hackathon to add full search to perldoc. i have a
> design (i looked inside perldoc) that should be doable to search perltoc
> with a regex (and no line issues) and print out doc names and header
> sections that match. doing a full search will take some more work as you
> need to get a list of the core pod files. even better would be a search
> that scanned every installed module but that need file::find and such
> and could be slow. anyhow, if this starts to get done, maybe we can get
> p5p to take a patch to perldoc.
Hmm. On Debian systems there is perlindex that builds a list of POD
documents. It actually doesn't run all that long on my laptop, which has
quite a bit of extra modules installed for development purposes.
Mart
--
"We will need a longer wall when the revolution comes."
--- AJS, quoting an uncertain source.
------------------------------
Date: Mon, 27 Jun 2011 00:04:56 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Perl definition of newline?
Message-Id: <87sjqvnclz.fsf@quad.sysarch.com>
>>>>> "TZ" == Ted Zlatanov <tzz@lifelogs.com> writes:
TZ> On Sun, 26 Jun 2011 21:23:10 -0400 "Uri Guttman" <uri@StemSystems.com> wrote:
UG> i have proposed a yapc hackathon to add full search to perldoc.
TZ> Wonderful. I can't attend this year, unfortunately, or I would have
TZ> joined.
UG> even better would be a search that scanned every installed module
UG> but that need file::find and such and could be slow.
TZ> I've been pleasantly surprised by `ack': it's fast, reliable, and does
TZ> everything I need. So maybe it will work for this as well.
it isn't a core thing and i would expect perldoc to be only relying on
core stuff.
uri
--
Uri Guttman -- uri AT perlhunter DOT com --- http://www.perlhunter.com --
------------ Perl Developer Recruiting and Placement Services -------------
----- Perl Code Review, Architecture, Development, Training, Support -------
------------------------------
Date: Sun, 26 Jun 2011 09:39:28 -0700
From: "ela" <ela@yantai.org>
Subject: sort scientific notation value after alphabet
Message-Id: <iu5v0d$kb1$1@ijustice.itsc.cuhk.edu.hk>
I have a very large table (1 million+ records) that has five fields and the
first two rows are shown:
Identity End C-value Score ID
_113_TTAG 26831 8.00E-38 163 282859772
_193_TTAG 26831 8.00E-68 163 282859772
I wanna sort the file first by the field "Identity" then "C-value" in
ascending order (the smallest comes first). While it can achieved by:
awk 'NR==1; NR > 1 {print $0 | "sort -k1,1 -k3,3g"}' infile > infile.sort
the code cannot be incorporated in Perl and so I was kindly suggested to
study something like:
http://en.wikipedia.org/wiki/Schwartzian_transform
http://www.perlhowto.com/sort_ordering_by_multiple_columns
but neither of them suggests an integrated solution to sort this kind of
alphabetical and scientific-notation based table. Since this problem appears
to be common, I wonder there has already any built-in syntax to handle this.
------------------------------
Date: Sat, 25 Jun 2011 21:44:33 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: sort scientific notation value after alphabet
Message-Id: <87r56h9xj2.fsf@quad.sysarch.com>
>>>>> "e" == ela <ela@yantai.org> writes:
e> I have a very large table (1 million+ records) that has five fields and the
e> first two rows are shown:
e> Identity End C-value Score ID
e> _113_TTAG 26831 8.00E-38 163 282859772
e> _193_TTAG 26831 8.00E-68 163 282859772
e> I wanna sort the file first by the field "Identity" then "C-value" in
e> ascending order (the smallest comes first). While it can achieved by:
e> awk 'NR==1; NR > 1 {print $0 | "sort -k1,1 -k3,3g"}' infile > infile.sort
e> the code cannot be incorporated in Perl and so I was kindly suggested to
e> study something like:
e> http://en.wikipedia.org/wiki/Schwartzian_transform
e> http://www.perlhowto.com/sort_ordering_by_multiple_columns
e> but neither of them suggests an integrated solution to sort this
e> kind of alphabetical and scientific-notation based table. Since
e> this problem appears to be common, I wonder there has already any
e> built-in syntax to handle this.
try Sort::Maker. it has the ability to generate sorts based upon key
descriptions similar to what you have there. you write the code to
extract a key and describe how you want to sort it (up/down,
text/number, etc.)
uri
--
Uri Guttman -- uri AT perlhunter DOT com --- http://www.perlhunter.com --
------------ Perl Developer Recruiting and Placement Services -------------
----- Perl Code Review, Architecture, Development, Training, Support -------
------------------------------
Date: Sat, 25 Jun 2011 19:04:47 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: sort scientific notation value after alphabet
Message-Id: <4f4d07lb3cgah6vdckn39m1hkivenp3v8t@4ax.com>
"ela" <ela@yantai.org> wrote:
>I have a very large table (1 million+ records) that has five fields and the
>first two rows are shown:
>
> Identity End C-value Score ID
> _113_TTAG 26831 8.00E-38 163 282859772
> _193_TTAG 26831 8.00E-68 163 282859772
>
>I wanna sort the file first by the field "Identity" then "C-value" in
>ascending order (the smallest comes first).
What have you tried so far? Where are you stuck? Did you read (and
understand) the FAQ entry
How do I sort an array by (anything)?
>[...] I was kindly suggested to
>study something like:
>
>http://en.wikipedia.org/wiki/Schwartzian_transform
The Schwartzian Transformation is a great optimization if the comparion
function is expensive. In your case it is not: it is just one string
compare, one numerical compare, and the result combined with an or. It
can't get much cheaper than that.
In other words: you won't gain much speed but add quite some complexity
if you apply a Schwartzian Transformation.
>http://www.perlhowto.com/sort_ordering_by_multiple_columns
What's wrong with the FAQ answer that comes with your Perl installation?
>but neither of them suggests an integrated solution to sort this kind of
>alphabetical and scientific-notation based table. Since this problem appears
>to be common, I wonder there has already any built-in syntax to handle this.
No, there is no build-in syntax because that would be rather
restrictive. Instead Perl offers something much more flexible and much
more powerful: you can define your own comparison function and thus sort
any table by any criteria you could imagine. The FAQ contains several
examples.
jue
------------------------------
Date: Sat, 25 Jun 2011 21:55:10 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: sort scientific notation value after alphabet
Message-Id: <86k4c9kx8x.fsf@red.stonehenge.com>
>>>>> "ela" == ela <ela@yantai.org> writes:
ela> I have a very large table (1 million+ records) that has five fields
ela> and the first two rows are shown:
Sounds like you could use a *database*!
Unless you have a gazillion bytes of RAM you don't mind wasting.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.posterous.com/ for Smalltalk discussion
------------------------------
Date: Sat, 25 Jun 2011 11:43:56 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: upload file rom solaris to debian using perl base install
Message-Id: <4e05addc$0$4266$e4fe514c@news.xs4all.nl>
On 2011-06-24 19:17, Rainer Weikusat wrote:
> $url = $ARGV[0];
> $url || die("Usage: post-file<url>");
Alternative:
$url = $ARGV[0]
or die "Usage: post-file<url>";
--
Ruud
------------------------------
Date: Sun, 26 Jun 2011 20:33:44 +0100
From: Rainer Weikusat <rweikusat@mssgmbh.com>
Subject: Re: upload file rom solaris to debian using perl base install
Message-Id: <87d3i05qw7.fsf@sapphire.mobileactivedefense.com>
"Dr.Ruud" <rvtol+usenet@xs4all.nl> writes:
> On 2011-06-24 19:17, Rainer Weikusat wrote:
>
>> $url = $ARGV[0];
>> $url || die("Usage: post-file<url>");
>
> Alternative:
>
> $url = $ARGV[0]
> or die "Usage: post-file<url>";
I usually prefer to have different things (like operation and error
handling) on different lines of text because this makes the code
easier to deal with with text editors and debuggers and also helps with
'debuggerless debugging' with the help of suitable debugging code.
One of the things I considered to be a good idea when starting to
learn C, coming from a Pascal-background, was the consistent syntax for
subroutine invocation: There is always at least an empty parenthesis
pair because this is 'the function call operator', meaning, the syntax
makes it immediately clear where in the code control transfers to
other parts of it occur. This is less helpful in Perl than in Pascal
because variable names and subroutine names are not in the same
namespace but still enables easy distinction between 'subroutines in
disguise' aka 'constants' and real subroutines. By the time I started
to use Perl, I read through a fairly complicated sounding explanation
of different types of operators and their precedence which contained
the statement 'if it looks like a function, it will work like a
function'. After reading this, I thought: 'Fine. That's good enough for
me at the moment because I have other things to worry about'. I have
since mostly preferred to continue worrying about those other things.
I also tend to avoid default parameters except in a few cases: I'm not
so much interested in dazzling people who read the code with my
knowledge of the Perl documentation but rather want to communicate
clearly which operation is applied to what. I've read through Tad
MacClellans remarkably complicated way to say
cd $(dirname $(perldoc -l perlfunc))
grep -i "^=.* $1" *
(yes, I know that this is not an exact equivalent) with some interest
because I wanted to understand what the code is doing but consider the
amount of time this took way too large for twelve lines of code
performing a trivial text search operation.
NB: This is a set of opinion statements. While I'm convinced that the
opinions presented in them are sensible, I don't claim that other
standpoints are necessarily completely without merit.
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 V11 Issue 3425
***************************************