Re: how to recursion

2017-03-29 Thread PYH
I asked this just b/c I want to do matrix calculation in perl. I found under some conditions a recursion is more effective. Thanks everybody. On 2017/3/29 23:31, Chas. Owens wrote: On Tue, Mar 28, 2017 at 9:27 PM PYH mailto:p...@vodafonemail.de>> wrote: Hi, what's the be

Fw: how to recursion

2017-03-29 Thread Shlomi Fish
Forwarding to the list. Begin forwarded message: Date: Wed, 29 Mar 2017 11:32:08 -0400 From: Shawn H Corey To: Shlomi Fish Subject: Re: how to recursion On Wed, 29 Mar 2017 17:22:36 +0300 Shlomi Fish wrote: > my_recursion accepts $self as its first argument, so you should pass > it

Re: how to recursion

2017-03-29 Thread Chas. Owens
On Tue, Mar 28, 2017 at 9:27 PM PYH wrote: > Hi, > > what's the better way to write a recursion in perl's class? > > sub my_recursion { > my $self = shift; > > if (...) { > $self->my_recursion; > } > } > > this

Re: how to recursion

2017-03-29 Thread Shlomi Fish
Hi Shawn! On Wed, 29 Mar 2017 08:09:12 -0400 Shawn H Corey wrote: > On Wed, 29 Mar 2017 09:25:06 +0800 > PYH wrote: > > > sub my_recursion { > > my $self = shift; > > > > if (...) { > > $self->my_recursion; > > # you don't need $self. subroutine lookup starts >

Re: how to recursion

2017-03-29 Thread Shawn H Corey
nough. my_recursion(); > } > } More thoughts on recursion: https://lookatperl.blogspot.ca/2012/11/a-look-at-recursion.html -- Don't stop where the ink does. Shawn H Corey -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: how to recursion

2017-03-28 Thread Uri Guttman
On 03/28/2017 09:25 PM, PYH wrote: Hi, what's the better way to write a recursion in perl's class? sub my_recursion { my $self = shift; if (...) { $self->my_recursion; } } this one? i am not sure what you mean by better. your code would work if you

how to recursion

2017-03-28 Thread PYH
Hi, what's the better way to write a recursion in perl's class? sub my_recursion { my $self = shift; if (...) { $self->my_recursion; } } this one? thanks. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail

Re: generate XML from recursion

2015-07-08 Thread Andy Bach
On Wed, Jul 8, 2015 at 10:51 AM, Nagy Tamas (TVI-GmbH) < tamas.n...@tvi-gmbh.de> wrote: > How can it be? I call the subroutine in the middle of a tag. How can be > the document closed? > Well, I don't get that (could it be that call to Travers($dir,$writer); before the sub def?) but to get your

generate XML from recursion

2015-07-08 Thread Nagy Tamas (TVI-GmbH)
Hi, Thanks for the solutions of the recent problems. I would like to traverse a dir on the HDD at a part of the XML generation. So I generated about 75% of an xml file with xml::writer, and it comes a Projectstructure tag. Between these tag I simply list a dir into empty tags . If recursion is

Re: Can recursion eliminate nested foreach() loops?

2012-03-05 Thread Dr.Ruud
On 2012-02-27 03:52, Shawn H Corey wrote: There is no simplify way of doing this. perl -wle ' my $s = "{red,green,blue},{small,large},{light,dark}"; print for glob $s; ' -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl

Re: Can recursion eliminate nested foreach() loops?

2012-02-27 Thread Paul Johnson
On Sun, Feb 26, 2012 at 09:30:44PM -0500, Steve Bertrand wrote: > I came across a question early this morning on a forum that > intrigued me. I literally spent about five hours trying everything > to solve it, but I couldn't. Sometimes Perl is just a means to get at the corect tool: my $attribute

Re: Can recursion eliminate nested foreach() loops?

2012-02-26 Thread Steve Bertrand
On 2012-02-26 23:55, Rob Dixon wrote: On 27/02/2012 02:30, Steve Bertrand wrote: I know this isn't a beginner's question, but I know there are geniuses here. Is there a way to simplify this within Perl? Hi Steve Much of the complexity comes from working with the nested data structure. Writi

Re: Can recursion eliminate nested foreach() loops?

2012-02-26 Thread Rob Dixon
On 27/02/2012 02:30, Steve Bertrand wrote: I came across a question early this morning on a forum that intrigued me. I literally spent about five hours trying everything to solve it, but I couldn't. Every attempt at recursion, counting, numbering, hashing etc failed. Is there a way t

Re: Can recursion eliminate nested foreach() loops?

2012-02-26 Thread Steve Bertrand
and cross-product it with a recursive call to the rest. Like this: fyi: http://forums.devshed.com/perl-programming-6/recursion-help-882763.html Steve -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: Can recursion eliminate nested foreach() loops?

2012-02-26 Thread Steve Bertrand
On 2012-02-26 21:52, Shawn H Corey wrote: On 12-02-26 09:30 PM, Steve Bertrand wrote: I know this isn't a beginner's question, but I know there are geniuses here. Is there a way to simplify this within Perl? There is no simplify way of doing this. Separate off the first attribute and cross-pro

Re: Can recursion eliminate nested foreach() loops?

2012-02-26 Thread Shawn H Corey
On 12-02-26 09:30 PM, Steve Bertrand wrote: I know this isn't a beginner's question, but I know there are geniuses here. Is there a way to simplify this within Perl? There is no simplify way of doing this. Separate off the first attribute and cross-product it with a recursive call to the rest.

Can recursion eliminate nested foreach() loops?

2012-02-26 Thread Steve Bertrand
I came across a question early this morning on a forum that intrigued me. I literally spent about five hours trying everything to solve it, but I couldn't. Every attempt at recursion, counting, numbering, hashing etc failed. Is there a way to use recursion to eliminate the repeated and

Re: [PBML] Help needed in recursion with objects in perl !

2010-08-07 Thread Chas. Owens
On Sat, Aug 7, 2010 at 09:36, Amit Saxena wrote: snip > The purpose of this activity is to model a hierarchical representation of > dependent components, each of one will be represented as a service. > > I had a look at the Graph module ( > http://search.cpan.org/~jhi/Graph-0.94/lib/Graph.pod) but

Re: [PBML] Help needed in recursion with objects in perl !

2010-08-07 Thread Amit Saxena
On Fri, Aug 6, 2010 at 8:09 PM, Randal L. Schwartz wrote: > > "Amit" == Amit Saxena writes: > > Amit> I am working on a tree implementation (with any number of parent > Amit> and child nodes) in perl. Every node is defined as a object of a > Amit> "Node" class which I have created as a ".pm"

Re: [PBML] Help needed in recursion with objects in perl !

2010-08-06 Thread Randal L. Schwartz
> "Amit" == Amit Saxena writes: Amit> I am working on a tree implementation (with any number of parent Amit> and child nodes) in perl. Every node is defined as a object of a Amit> "Node" class which I have created as a ".pm" module. Unless this is for a student exercise, you probably just wa

Help needed in recursion with objects in perl !

2010-08-06 Thread Amit Saxena
Hi all, I am working on a tree implementation (with any number of parent and child nodes) in perl. Every node is defined as a object of a "Node" class which I have created as a ".pm" module. I have defined a method "getParentNodes" which returns reference to an array having all the (immediate) pa

Re: File::Find NO RECURSION Howto

2010-03-03 Thread Shlomi Fish
On Monday 01 Mar 2010 19:31:15 Shawn H Corey wrote: > Shlomi Fish wrote: > > Well, Matt S. Trout shared his sentiments about "I cannot use CPAN" here: > > > > http://www.shadowcat.co.uk/blog/matt-s-trout/but-i-cant-use-cpan/ > > Well, Matt is wrong. You can't always use CPAN. Yes, you can set i

Re: File::Find NO RECURSION Howto

2010-03-01 Thread Shawn H Corey
Shlomi Fish wrote: > Well, Matt S. Trout shared his sentiments about "I cannot use CPAN" here: > > http://www.shadowcat.co.uk/blog/matt-s-trout/but-i-cant-use-cpan/ > Well, Matt is wrong. You can't always use CPAN. Yes, you can set it up so you can use it in development, but that doesn't mean

Re: File::Find NO RECURSION Howto

2010-03-01 Thread Shlomi Fish
On Monday 01 Mar 2010 15:00:26 raphael() wrote: > On Mon, Mar 1, 2010 at 6:18 PM, Shawn H Corey wrote: > > raphael() wrote: > > > Hi, > > > > > > How can I stop File::Find to go below current dir? i.e. no recursion. > > > > > > Although

Re: File::Find NO RECURSION Howto

2010-03-01 Thread raphael()
On Mon, Mar 1, 2010 at 6:18 PM, Shawn H Corey wrote: > raphael() wrote: > > Hi, > > > > How can I stop File::Find to go below current dir? i.e. no recursion. > > > > Although I can use glob or <*> to get file names in current dir. > > But I wanted to

Re: File::Find NO RECURSION Howto

2010-03-01 Thread Shlomi Fish
On Monday 01 Mar 2010 13:23:16 raphael() wrote: > Hi, > > How can I stop File::Find to go below current dir? i.e. no recursion. > > Although I can use glob or <*> to get file names in current dir. > But I wanted to know if File::Find has a maxdepth limit like linux &q

Re: File::Find NO RECURSION Howto

2010-03-01 Thread Shawn H Corey
raphael() wrote: > Hi, > > How can I stop File::Find to go below current dir? i.e. no recursion. > > Although I can use glob or <*> to get file names in current dir. > But I wanted to know if File::Find has a maxdepth limit like linux "find". > > The scri

File::Find NO RECURSION Howto

2010-03-01 Thread raphael()
Hi, How can I stop File::Find to go below current dir? i.e. no recursion. Although I can use glob or <*> to get file names in current dir. But I wanted to know if File::Find has a maxdepth limit like linux "find". The script I created uses a switch which decides if recursion i

Re: Understanding recursion

2009-07-10 Thread Ken Slater
Dermot wrote: >Hi, > >I was reading Higher Order Perl[1] last night and, dishearteningly, >got stuck on chapter one. > >Mark Dominus offers the following as a binary string conversion >example of how recursion can work. > > >use strict; >use warnings; > >

Re: Understanding recursion

2009-07-10 Thread Dermot
2009/7/10 Telemachus : > On Fri Jul 10 2009 @  9:26, Dermot wrote: >> The algorithm works perfectly but my understanding of it's workings is amiss. >> >> When I look at this I see $E initialised and then concatenate with the >> the modulus of > > It helps for me to walk through it visually, indenti

Re: Understanding recursion

2009-07-10 Thread Telemachus
On Fri Jul 10 2009 @ 9:26, Dermot wrote: > The algorithm works perfectly but my understanding of it's workings is amiss. > > When I look at this I see $E initialised and then concatenate with the > the modulus of > 37 % 2 =1 > 18 % 2 = 0 > 9 % 2 = 1 > 4 % 2 = 0 > 2 % 2 = 0 > > That by my reckoni

Re: Understanding recursion

2009-07-10 Thread Shawn H. Corey
On Fri, 2009-07-10 at 13:42 +0100, Dermot wrote: > Why is $E getting assigned the value from $k? my $E = binary($k); I said $E will be assigned the string that represents $k, not it's value. > $E is initialised and > then assigned the return value of the binary(18) during the first > invocation

Re: Understanding recursion

2009-07-10 Thread Dermot
2009/7/10 Shawn H. Corey : > On Fri, 2009-07-10 at 09:26 +0100, Dermot wrote: >> The algorithm works perfectly but my understanding of it's workings is amiss. >> >> When I look at this I see $E initialised and then concatenate with the >> the modulus of >> 37 % 2 =1 >> 18 % 2 = 0 >> 9 % 2 = 1 >> 4

Re: Understanding recursion

2009-07-10 Thread Shawn H. Corey
On Fri, 2009-07-10 at 09:26 +0100, Dermot wrote: > The algorithm works perfectly but my understanding of it's workings is amiss. > > When I look at this I see $E initialised and then concatenate with the > the modulus of > 37 % 2 =1 > 18 % 2 = 0 > 9 % 2 = 1 > 4 % 2 = 0 > 2 % 2 = 0 > > That by my

Understanding recursion

2009-07-10 Thread Dermot
Hi, I was reading Higher Order Perl[1] last night and, dishearteningly, got stuck on chapter one. Mark Dominus offers the following as a  binary string conversion example of how recursion can work. use strict; use warnings; my $bstr = binary(37); print "$bstr\n";              

Randal's columns (was Re: HOWTO: File Renaming and Directory Recursion)

2004-04-02 Thread Randal L. Schwartz
> "Morbus" == Morbus Iff <[EMAIL PROTECTED]> writes: Morbus> The script was mindlessly simple, and I felt it would be a good HOWTO Morbus> for the perl beginners crowd, if not to show some good code practices, Morbus> but also to counteract the . .. .. . "controversial" HOWTO that had Morbus>

Re: HOWTO: File Renaming and Directory Recursion

2004-04-01 Thread Morbus Iff
>> while (@files) { > >Are you sure that's not: > > for (@files) { Yup, "for" is right. An error in my memory recall. -- Morbus Iff ( evil is my sour flavor ) Technical: http://www.oreillynet.com/pub/au/779 Culture: http://www.disobey.com/ and http://www.gamegrene.com/ icq: 2927491 / aim: aka

Re: HOWTO: File Renaming and Directory Recursion

2004-04-01 Thread Randy W. Sims
On 4/1/2004 7:05 PM, Morbus Iff wrote: # and here is that subroutine. it's nearly exactly # the same as our previous code, only this time, we # move into the directory that contains a file to # be renamed. this is actually a quick hack because # I knew this wouldn't be production-code: a more

Re: HOWTO: File Renaming and Directory Recursion

2004-04-01 Thread Paul Johnson
On Thu, Apr 01, 2004 at 07:05:51PM -0500, Morbus Iff wrote: > Earlier this morning, a friend of mine asked me for a script that would > "given a list of files, replace underscores with spaces", to take this: > > Artist_Name-Track_Name.mp3 > > and rename it to this: > > Artist Name-Track Nam

HOWTO: File Renaming and Directory Recursion

2004-04-01 Thread Morbus Iff
ersion, and whether that would be "hard to do". While I wasn't around to help him out, the weak solution was easy: just move the script into each new directory and run it again. But, there are two other solutions to this new request: the bad one, and the good one. The bad one is t

Re: Size of dir (with recursion)

2003-12-29 Thread Shawn
While you're at it, write a parallel version of du.pl... Modern hard drives do scatter gather, and reading lots (say 10 or so) of dirs' contents' block sizes at a time would be interesting... It would be cool if a parent kept 20 children pre-forked, and only told 10 children at a time to do their

Re: Size of dir (with recursion)

2003-12-29 Thread John W. Krahn
Jesper Noehr wrote: > > On Mon, 29 Dec 2003 13:19:29 -0800, John W. Krahn <[EMAIL PROTECTED]> wrote: > > > > $ ls -l test.txt > > -rw-r--r--1 john users 187 Jul 9 11:54 test.txt > > $ perl -le'print +(lstat shift)[11]' test.txt > > 4096 > > $ du -b test.txt > > 4096test.txt >

Re: Size of dir (with recursion)

2003-12-29 Thread Jesper Noehr
On Mon, 29 Dec 2003 13:19:29 -0800, John W. Krahn <[EMAIL PROTECTED]> wrote: Jesper Noehr wrote: Hey list. Hello, I'm having a problem reading the size of a directory with recursive directories. The problem is that du -s shows a different bytecount than my program does. $ man du NAME du

Re: Size of dir (with recursion)

2003-12-29 Thread John W. Krahn
Jesper Noehr wrote: > > Hey list. Hello, > I'm having a problem reading the size of a directory with recursive > directories. > The problem is that du -s shows a different bytecount than my program does. $ man du NAME du - estimate file space usage SYNOPSIS du [OPTION]... [FILE]

Size of dir (with recursion)

2003-12-29 Thread Jesper Noehr
Hey list. I'm having a problem reading the size of a directory with recursive directories. The problem is that du -s shows a different bytecount than my program does. Here's my code: #!/usr/gnu/bin/perl -w use File::Find; @ARGV = ('.') unless @ARGV; my $sum = 0; find sub { $sum += -s }, @ARGV;

Re: Recursion

2003-11-03 Thread Steve Grazzini
On Tue, Nov 04, 2003 at 12:45:58AM +0100, Paul Johnson wrote: > On Mon, Nov 03, 2003 at 11:16:02PM -, Rob Dixon wrote: >> Steve Grazzini wrote: >>> The problem is that "-d $path" will return true if $path is a symlink >>> to a directory. >> >> Thanks Steve, but are you certain? I can't test it

Re: Recursion

2003-11-03 Thread Paul Johnson
On Mon, Nov 03, 2003 at 11:16:02PM -, Rob Dixon wrote: > Steve Grazzini wrote: > > > > On Mon, Nov 03, 2003 at 09:48:55AM -, Rob Dixon wrote: > > > Steve Grazzini wrote: > > > > That's fine if you *want* to skip the dotfiles. But you *always* > > > > skip "." and "..". More robust code wi

Re: Recursion

2003-11-03 Thread Rob Dixon
Steve Grazzini wrote: > > On Mon, Nov 03, 2003 at 09:48:55AM -, Rob Dixon wrote: > > Steve Grazzini wrote: > > > That's fine if you *want* to skip the dotfiles. But you *always* > > > skip "." and "..". More robust code will also check for cycles, but > > > since File::Find does all this alre

Re: Recursion

2003-11-03 Thread Steve Grazzini
On Mon, Nov 03, 2003 at 09:48:55AM -, Rob Dixon wrote: > Steve Grazzini wrote: > > That's fine if you *want* to skip the dotfiles. But you *always* > > skip "." and "..". More robust code will also check for cycles, but > > since File::Find does all this already, it's usually better just to >

Re: Recursion

2003-11-03 Thread James Edward Gray II
On Monday, November 3, 2003, at 03:43 AM, Rob Dixon wrote: Recursion can always be eliminated by hard-coding the stacking of context variables that the compiler provides and using a loop instead of a recursive call. In fact this is exactly what File::Find itself does. But recursive code will

Re: Recursion

2003-11-03 Thread Rob Dixon
R. Joseph Newton wrote: > > Rob Dixon wrote: > > > Jeff Westman wrotenews:[EMAIL PROTECTED] > > > > > > I've never liked "recursion" but of course there are times where it is > > > needed. > > > > > > I have a simpl

Re: Recursion

2003-11-03 Thread Rob Dixon
Steve Grazzini wrote: > > On Sun, Nov 02, 2003 at 05:32:35PM -0600, James Edward Gray II wrote: > > On Sunday, November 2, 2003, at 06:19 AM, Rob Dixon wrote: > > > sub printdir { > > > > > >my $dir = shift; > > > > > >opendir DIR, $dir or die $!; > > >my @dirs = grep /[^.]/, readdir D

Re: Recursion

2003-11-03 Thread Rob Dixon
James Edward Gray II wrote: > > On Sunday, November 2, 2003, at 06:19 AM, Rob Dixon wrote: > > > Jeff Westman > > wrotenews:[EMAIL PROTECTED] > >> Hi, > >> > >> I've never liked "recursion" but of course there are times where it is

Re: Recursion

2003-11-02 Thread Steve Grazzini
On Sun, Nov 02, 2003 at 05:32:35PM -0600, James Edward Gray II wrote: > On Sunday, November 2, 2003, at 06:19 AM, Rob Dixon wrote: > > sub printdir { > > > >my $dir = shift; > > > >opendir DIR, $dir or die $!; > >my @dirs = grep /[^.]/, readdir DIR; > > I'm not sure this grep() is wha

Re: Recursion

2003-11-02 Thread James Edward Gray II
On Sunday, November 2, 2003, at 06:19 AM, Rob Dixon wrote: Jeff Westman wrotenews:[EMAIL PROTECTED] Hi, I've never liked "recursion" but of course there are times where it is needed. I'm not sure I would say recursion is "needed", but it sure makes some thi

Re: Recursion

2003-11-02 Thread James Edward Gray II
On Sunday, November 2, 2003, at 06:19 AM, Rob Dixon wrote: File::Find would do it for you, but the revursion is very simple really: use strict; use warnings; printdir('/usr'); sub printdir { my $dir = shift; opendir DIR, $dir or die $!; my @dirs = grep /[^.]/, readdir DIR; I

Re: Recursion

2003-11-02 Thread R. Joseph Newton
Rob Dixon wrote: > Jeff Westman wrotenews:[EMAIL PROTECTED] > > Hi, > > > > I've never liked "recursion" but of course there are times where it is > > needed. > > > > I have a simple task that I am trying to do. Basically, I just want to

Re: Recursion

2003-11-02 Thread Rob Dixon
Jeff Westman wrotenews:[EMAIL PROTECTED] > Hi, > > I've never liked "recursion" but of course there are times where it is > needed. > > I have a simple task that I am trying to do. Basically, I just want to list > out my directories on disk, and then chdir to

Re: Recursion

2003-11-01 Thread Kevin Old
On Sat, 2003-11-01 at 20:20, Jeff Westman wrote: > Hi, > > I've never liked "recursion" but of course there are times where it is > needed. > > I have a simple task that I am trying to do. Basically, I just want to list > out my directories on disk, and then

Re: Recursion

2003-11-01 Thread Steve Grazzini
On Sat, Nov 01, 2003 at 05:20:39PM -0800, Jeff Westman wrote: > I have a simple task that I am trying to do. Basically, I just want > to list out my directories on disk, and then chdir to each one, print > it out, and so on. use File::Find; find sub { print "$File::Find::name\n" if -d },

Recursion

2003-11-01 Thread Jeff Westman
Hi, I've never liked "recursion" but of course there are times where it is needed. I have a simple task that I am trying to do. Basically, I just want to list out my directories on disk, and then chdir to each one, print it out, and so on. Pretty basic, but I have a total men

recursion and memory use... a lot of memory use.

2001-06-01 Thread Peter Cornelius
I have this program that recurses through a directory structure building Default.htm files. The idea here was to quickly generate a bunch of these things to replace the default index listing you normally see. The part that's giving me trouble is the navbar that should have a nested structure lik