[31881] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3144 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 26 11:09:28 2010

Date: Sun, 26 Sep 2010 08:09:13 -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 Sep 2010     Volume: 11 Number: 3144

Today's topics:
    Re: complex problem <xhoster@gmail.com>
    Re: complex problem <ela@yantai.org>
    Re: Long script "just stops" sometime <derykus@gmail.com>
    Re: Long script "just stops" sometime <hjp-usenet2@hjp.at>
    Re: Long script "just stops" sometime <ben@morrow.me.uk>
        printing the result of a procedure call <hhr-m@web.de>
    Re: printing the result of a procedure call <jurgenex@hotmail.com>
    Re: printing the result of a procedure call <tadmc@seesig.invalid>
    Re: toy list processing problem: collect similar terms <abu@software-lab.de>
    Re: toy list processing problem: collect similar terms <livibetter@gmail.com>
    Re: toy list processing problem: collect similar terms <arnodel@gmail.com>
    Re: toy list processing problem: collect similar terms <rvtol+usenet@xs4all.nl>
    Re: toy list processing problem: collect similar terms <jurgenex@hotmail.com>
    Re: toy list processing problem: collect similar terms <jurgenex@hotmail.com>
    Re: toy list processing problem: collect similar terms (Pascal J. Bourguignon)
    Re: toy list processing problem: collect similar terms <sherm.pendley@gmail.com>
    Re: toy list processing problem: collect similar terms <sherm.pendley@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 25 Sep 2010 15:40:23 -0700
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: complex problem
Message-Id: <4c9ee57d$0$20963$ed362ca5@nr5-q3a.newsreader.com>

ela wrote:
>> Anyway, what I often find myself doing is using two hashes.
>>
>> my %exp;
>> my %sample;
>> while (<>) {
>>   my ($refseq,$expression,$sample)=parse_however($_);
>>   $exp{$refseq}{$sample}=$expression;
>>   $sample{$sample}=();
>> };
>>
>> Now %sample contains an entry for every sample/tissue/file which has at
>> least one second-level entry in %exp.
> 
> sorry but would you mind elaborating why the second hash can do the purpose? 
> I can't quite follow it...

Sorry, but it seems self-evident to me, so I don't see how I can explain 
it.  Maybe I'm not correctly apprehending what the purpose is that you 
have in mind.

Xho


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

Date: Sun, 26 Sep 2010 19:38:06 -0700
From: "ela" <ela@yantai.org>
Subject: Re: complex problem
Message-Id: <i7nbah$amt$1@ijustice.itsc.cuhk.edu.hk>


"Xho Jingleheimerschmidt" <xhoster@gmail.com> wrote in message 
news:4c9ee57d$0$20963$ed362ca5@nr5-q3a.newsreader.com...

> Sorry, but it seems self-evident to me, so I don't see how I can explain 
> it.  Maybe I'm not correctly apprehending what the purpose is that you 
> have in mind.
>
> Xho

Let me give a simple example:

File 1
ID character
1 A
2 T
3 G

File 2
ID character
1 A
3 T

File 3
ID character
2 A
3 T
4 C

processed result
ID File 1 character File 2 character File 3 character
1               A                        A                n/a
2               T                       n/a                 A
3               G                        T                  T
4               n/a                     n/a                 C





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

Date: Sat, 25 Sep 2010 22:16:28 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: Long script "just stops" sometime
Message-Id: <36b262f2-547c-4932-8a74-2587f6813636@z30g2000prg.googlegroups.com>

On Sep 24, 3:11=A0pm, Jerry Krinock <jerrykrin...@gmail.com> wrote:
> I've written a 1500-line script which processes several dozen files of
> source text written in Markdown to html. =A0It takes several minutes to
> run, indicating progress by printf statements. =A0However, about 20% of
> the time, in the middle of processing a Markdown file, it just stops
> progressing, as though it is in an infinite loop. =A0If I kill the
> process and restart, it always completes successfully.
>
> My script is, of course, being a script, not particularly efficient.
> I was thinking that maybe Perl was running out of memory or something,
> although that's not supposed to happen nowadays (Perl 5.10.0, Mac OS X
> 10.6). =A0And when I check it in Apple's Activity Monitor during normal
> operation, I find that its CPU and memory usage are hardly noticeable,
> maybe 3% and a few tens of megabytes.
>
> Are there any conditions under which Perl would "just stop"?
>
> Any suggestions to troubleshoot this would be appreciated.
>

You might try just setting a timeout around
whatever code section turns up in a stack
trace. (perldoc -f alarm).

Then exec the program again (perldoc -f exec)
if there's a  timeout.. Of  course if memory's
the problem, you may be able to find some way
to reduce memory usage and eliminate the timeout
workaround.

--
Charles DeRykus


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

Date: Sun, 26 Sep 2010 09:05:35 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Long script "just stops" sometime
Message-Id: <slrni9ts5v.21g.hjp-usenet2@hrunkner.hjp.at>

On 2010-09-25 20:50, Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
> On 2010-09-24, Jerry Krinock <jerrykrinock@gmail.com> wrote:
>> operation, I find that its CPU and memory usage are hardly noticeable,
>> maybe 3% and a few tens of megabytes.
>>
>> Are there any conditions under which Perl would "just stop"?
>
> With no CPU usage?  I would say it reads from STDIN.  Did you try to
> press Enter or C-d?

Two tools I find indispensable when trying to figure out "strange"
behaviour of programs are lsof and strace.

lsof lists the open files of a process. It has been ported to lots of 
unixoid systems (I first encountered it on HP-UX) and should be
available on MacOS.

strace prints out the system calls a process invokes. Unfortunately,
while most unixoid systems have a program which does this, it seems to
have a different name on each ("truss" on Solaris, "tusc" on HP-UX, ...)
so the OP will have to find out himself how its called on MacOS.

In this case, if your guess is right, strace would show that the process
is currently waiting for a read on fd 0 to complete, and then lsof could
be used to find out which file fd 0 is (ok, so for fd 0 you may know
that it's the tty, for for (say) fd 43 you want a tool to look it up).

	hp


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

Date: Sun, 26 Sep 2010 12:56:07 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Long script "just stops" sometime
Message-Id: <nvo3n7-u7d1.ln1@osiris.mauzo.dyndns.org>


Quoth "Peter J. Holzer" <hjp-usenet2@hjp.at>:
> On 2010-09-25 20:50, Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
> > On 2010-09-24, Jerry Krinock <jerrykrinock@gmail.com> wrote:
> >> operation, I find that its CPU and memory usage are hardly noticeable,
> >> maybe 3% and a few tens of megabytes.
> >>
> >> Are there any conditions under which Perl would "just stop"?
> >
> > With no CPU usage?  I would say it reads from STDIN.  Did you try to
> > press Enter or C-d?
> 
> Two tools I find indispensable when trying to figure out "strange"
> behaviour of programs are lsof and strace.
> 
> lsof lists the open files of a process. It has been ported to lots of 
> unixoid systems (I first encountered it on HP-UX) and should be
> available on MacOS.
> 
> strace prints out the system calls a process invokes. Unfortunately,
> while most unixoid systems have a program which does this, it seems to
> have a different name on each ("truss" on Solaris, "tusc" on HP-UX, ...)
> so the OP will have to find out himself how its called on MacOS.

It used to be ktrace, just like FreeBSD, but for reasons best known to
themselves Apple removed it in favour of dtrace. (dtrace is a generic
monitoring framework originally by Sun: it's incredibly flexible, but
rather heavier-weight than I would like as the only option available.)
dtruss is a dtrace script that gives truss-like output, but you need to
be root to run it (even on your own processes).

This being Apple, there are also some rather nifty GUI monitoring tools.

Ben



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

Date: Sun, 26 Sep 2010 15:07:32 +0200
From: Helmut Richter <hhr-m@web.de>
Subject: printing the result of a procedure call
Message-Id: <Pine.LNX.4.64.1009261503140.4521@lxhri01.ws.lrz.de>

What is the difference of

 - calling a procedure to get a result, and *then* printing the result

and

 - calling a procedure as a parameter of print?

Example:

----> cat ./tt
#! /usr/bin/perl

print "\nfirst try:\n";
$z = proc (1);
print $z;

print "\nsecond try:\n";
print (proc (1));

sub proc {
  return "result\n";
};

----> ./tt

first try:
result

second try:

----> 

I expected twice the same result.

-- 
Helmut Richter


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

Date: Sun, 26 Sep 2010 06:52:22 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: printing the result of a procedure call
Message-Id: <6nju96ln2hu1c3r9676pmcdovjrh5e2o4g@4ax.com>

Helmut Richter <hhr-m@web.de> wrote:
>What is the difference of
> - calling a procedure to get a result, and *then* printing the result
>and
> - calling a procedure as a parameter of print?

None.

>Example:
>
>----> cat ./tt
>#! /usr/bin/perl
>
>print "\nfirst try:\n";
>$z = proc (1);
>print $z;
>
>print "\nsecond try:\n";
>print (proc (1));
>
>sub proc {
>  return "result\n";
>};
>
>----> ./tt
>
>first try:
>result
>
>second try:
>
>----> 
>
>I expected twice the same result.

But in the second case you didn't call proc().
 
Why aren't you using strict and warnings? If you had used strict and
warnings then perl would have told you what's wrong.

Solutions:
a: predeclare sub proc;
b: use
	print (proc(1));
instead of 
	print (proc (1)); 	

jue


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

Date: Sun, 26 Sep 2010 09:56:40 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: printing the result of a procedure call
Message-Id: <slrni9unq9.jub.tadmc@tadbox.sbcglobal.net>

Helmut Richter <hhr-m@web.de> wrote:
> What is the difference of
>
>  - calling a procedure to get a result, and *then* printing the result


How is the procedure called? In list context or in scalar context?


> and
>
>  - calling a procedure as a parameter of print?


That cannot be answered with the information given up to this point,
as the behavior of a subroutine depends on what context it was
called in. See the "Context" section in:

    perldoc perldata

print() takes a list, so its arguments are called in list context.


> Example:
>
> ----> cat ./tt
> #! /usr/bin/perl


You should always enable warnings and strict while developing
Perl programs.

    use warnings;
    use strict;

You should most especially enable them before posting to Usenet,
as they often will point out the problem themselves, as they would
have in this case if you had bothered to turn them on.

Have you seen the Posting Guidelines that are posted here frequently?


> print "\nfirst try:\n";
> $z = proc (1);


This calls proc() in a scalar context.

Why the space between "proc" the opening parenthesis? That will bite you
eventually...


> print $z;
>
> print "\nsecond try:\n";
> print (proc (1));


 ...that didn't take long.  :-)

You are not calling the subroutine here, you are using a filehandle
named "proc". 

"use warnings" would have told you this if you had bothered to turn it on.

    print (proc(1));

would have called proc() in a list context.


-- 
Rest In Peace: 
Jonah McClellan gave his life for his country in a
helicopter crash in Afghanistan on September 21,2010.
Please pray for his wife and three children.


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

Date: Sun, 26 Sep 2010 05:29:20 +0000 (UTC)
From: Alexander Burger <abu@software-lab.de>
Subject: Re: toy list processing problem: collect similar terms
Message-Id: <i7mlng$e7c$1@online.de>

In PicoLisp:

(mapcar
   '((X) (apply conc (cdr X)))
   (group List) )

Cheers,
- Alex


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

Date: Sun, 26 Sep 2010 00:47:23 -0700 (PDT)
From: livibetter <livibetter@gmail.com>
Subject: Re: toy list processing problem: collect similar terms
Message-Id: <98dd7708-5842-4ed8-80a6-98135426592c@l38g2000pro.googlegroups.com>

Here is mine for Python:

l = [[0, 'a', 'b'], [1, 'c', 'd'], [2, 'e', 'f'], [3, 'g', 'h'], [1,
'i', 'j'], [2, 'k', 'l'], [4, 'm', 'n'], [2, 'o', 'p'], [4, 'q', 'r'],
[5, 's', 't']]
d = {}
for idx, items in [(e[0], e[1:]) for e in l]: d[idx] = d[idx] + items
if idx in d else items
print d.values()

Output:
[['a', 'b'], ['c', 'd', 'i', 'j'], ['e', 'f', 'k', 'l', 'o', 'p'],
['g', 'h'], ['m', 'n', 'q', 'r'], ['s', 't']]


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

Date: Sun, 26 Sep 2010 01:29:53 -0700 (PDT)
From: Arnaud Delobelle <arnodel@gmail.com>
Subject: Re: toy list processing problem: collect similar terms
Message-Id: <10e80524-3d6e-4655-8b2b-f82e38531966@m15g2000yqm.googlegroups.com>

On 26 Sep, 08:47, livibetter <livibet...@gmail.com> wrote:
> Here is mine for Python:
>
> l = [[0, 'a', 'b'], [1, 'c', 'd'], [2, 'e', 'f'], [3, 'g', 'h'], [1,
> 'i', 'j'], [2, 'k', 'l'], [4, 'm', 'n'], [2, 'o', 'p'], [4, 'q', 'r'],
> [5, 's', 't']]
> d = {}
> for idx, items in [(e[0], e[1:]) for e in l]: d[idx] = d[idx] + items
> if idx in d else items
> print d.values()
>
> Output:
> [['a', 'b'], ['c', 'd', 'i', 'j'], ['e', 'f', 'k', 'l', 'o', 'p'],
> ['g', 'h'], ['m', 'n', 'q', 'r'], ['s', 't']]

from itertools import groupby
from operator import itemgetter

l = [[0, 'a', 'b'], [1, 'c', 'd'], [2, 'e', 'f'], [3, 'g', 'h'], [1,
'i', 'j'], [2, 'k', 'l'], [4, 'm', 'n'], [2, 'o', 'p'], [4, 'q',
'r'],
[5, 's', 't']]

[
    [x for g in gs for x in g[1:]]
    for _, gs in groupby(sorted(l), itemgetter(0))
]

--
Arnaud


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

Date: Sun, 26 Sep 2010 11:41:23 +0200
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: toy list processing problem: collect similar terms
Message-Id: <4c9f1543$0$41105$e4fe514c@news.xs4all.nl>

On 2010-09-26 06:05, Xah Lee wrote:

> I have a list of lists, where each sublist is labelled by
> a number. I need to collect together the contents of all sublists
> sharing the same label. So if I have the list
>
> ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q r) (5 s t))
>
> where the first element of each sublist is the label, I need to
> produce:
>
> output:
> ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t))

The input is a string on STDIN,
and the output is a string on STDOUT?


Use a hash:

perl -MData::Dumper -wle '$Data::Dumper::Sortkeys = 1;
   my $t = "((0 a b) (1 c d) (2 e f) (3 g h) (1 i j)"
         . " (2 k l) (4 m n) (2 o p) (4 q r) (5 s t))";

   push @{ $h{ $1 } }, $2 while $t =~ /(\w+)([^)]*)/g;  # gist

   print Dumper \%h;
'

or an array:

perl -wle '
   my $t = "((0 a b) (1 c d) (2 e f) (3 g h) (1 i j)"
         . " (2 k l) (4 m n) (2 o p) (4 q r) (5 s t))";

   push @{$a[$1]},$2 while $t =~ /(\w+)\s+([^)]*)/g; # gist.1
   print "((".join(") (",map join(" ",@$_),@a )."))";  # gist.2
'


Or if the list is not just a string, but a real data structure in the 
script:

perl -wle'
   my $t = [ [qw/0 a b/], [qw/1 c d/], [qw/2 e f/], [qw/3 g h/],
             [qw/1 i j/], [qw/2 k l/], [qw/4 m n/], [qw/2 o p/],
             [qw/4 q r/], [qw/5 s t/] ];

   push @{ $a[ $_->[0] ] }, [ @$_[ 1, 2 ] ] for @$t;  # AoAoA

   printf "((%s))\n", join ") (",
                        map join( " ",
                          map join( " ", @$_ ), @$_
                        ), @a;
'

Etc.

-- 
Ruud



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

Date: Sun, 26 Sep 2010 06:53:41 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: toy list processing problem: collect similar terms
Message-Id: <12ku961maljpqr0vpecl4cc1m4r34addt6@4ax.com>

Alexander Burger <abu@software-lab.de> wrote:
>In PicoLisp:

What the f**** does PicoLisp have to with Perl?

jue


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

Date: Sun, 26 Sep 2010 06:54:17 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: toy list processing problem: collect similar terms
Message-Id: <f3ku96dtl7o2go6dcneuvelces87qbfsnh@4ax.com>

livibetter <livibetter@gmail.com> wrote:
>Here is mine for Python:

What the f*** does Python have to do with Perl?

jue


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

Date: Sun, 26 Sep 2010 16:24:46 +0200
From: pjb@informatimago.com (Pascal J. Bourguignon)
Subject: Re: toy list processing problem: collect similar terms
Message-Id: <87d3s0zioh.fsf@kuiper.lan.informatimago.com>

Xah Lee <xahlee@gmail.com> writes:


> here's a interesting toy list processing problem.
>
> I have a list of lists, where each sublist is labelled by
> a number. I need to collect together the contents of all sublists
> sharing
> the same label. So if I have the list
>
> ((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) (2 o p) (4 q
> r) (5 s t))
>
> where the first element of each sublist is the label, I need to
> produce:
>
> output:
> ((a b) (c d i j) (e f k l o p) (g h) (m n q r) (s t))
>
> a Mathematica solution is here:
> http://xahlee.org/UnixResource_dir/writ/notations_mma.html
>
> R5RS Scheme lisp solution:
> http://xahlee.org/UnixResource_dir/writ/Sourav_Mukherjee_sourav.work_gmail.scm
> by Sourav Mukherjee
>
> also, a Common Lisp solution can be found here:
> http://groups.google.com/group/comp.lang.lisp/browse_frm/thread/5d1ded8824bc750b?

It's too complex. Just write:

(let ((list '((0 a b) (1 c d) (2 e f) (3 g h) (1 i j) (2 k l) (4 m n) 
              (2 o p) (4 q r) (5 s t))))

  (mapcar (lambda (class) (reduce (function append) class :key (function rest)))
           (com.informatimago.common-lisp.list:equivalence-classes list :key (function first)))

   )

--> ((S T) (Q R M N) (G H) (O P K L E F) (I J C D) (A B))


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/


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

Date: Sun, 26 Sep 2010 10:56:07 -0400
From: Sherm Pendley <sherm.pendley@gmail.com>
Subject: Re: toy list processing problem: collect similar terms
Message-Id: <m2zkv4r1tk.fsf@sherm.shermpendley.com>

Jürgen Exner <jurgenex@hotmail.com> writes:

> Alexander Burger <abu@software-lab.de> wrote:
>>In PicoLisp:
>
> What the f**** does PicoLisp have to with Perl?

It's Xah. He cross-posts in an attempt to start a language feud.

Please don't feed the troll.

sherm--

-- 
Sherm Pendley
                                   <http://camelbones.sourceforge.net>
Cocoa Developer


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

Date: Sun, 26 Sep 2010 10:56:48 -0400
From: Sherm Pendley <sherm.pendley@gmail.com>
Subject: Re: toy list processing problem: collect similar terms
Message-Id: <m2vd5sr1sf.fsf@sherm.shermpendley.com>

Jürgen Exner <jurgenex@hotmail.com> writes:

> livibetter <livibetter@gmail.com> wrote:
>>Here is mine for Python:
>
> What the f*** does Python have to do with Perl?

Xah is a cross-posting troll. Please don't feed the troll.

sherm--

-- 
Sherm Pendley
                                   <http://camelbones.sourceforge.net>
Cocoa Developer


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

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 3144
***************************************


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