Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Too much recursion

by jrvd (Novice)
on Jun 27, 2013 at 15:29 UTC ( #1041037=note: print w/replies, xml ) Need Help??


in reply to Re: Too much recursion
in thread Too much recursion

Hi,

Thanks for your help. I have put my entire code so that you may see where my variables were initialized.

#!/usr/bin/perl use strict; use warnings; my $fileName = "version.txt"; my $fileDest = "version_modified.txt"; die "Problème d'ouverture du fichier $fileName" unless open(my $fh, '< +', $fileName); die "Problème de création du fichier $fileDest" unless open(my $fd, '> +', $fileDest); my $tot = 0; my $tot2 = 0; sub hostname; sub hostname{ print $fd $_; while (<$fh>){ if ($_ =~ /^hostname /){ hostname; }else{ # print $_; $tot2++; } } $tot++; } while(<$fh>){ hostname if ($_ =~ /^hostname /); } print $tot."\n"; print $tot2."\n"; close $fh; close $fd;

I am not sure if the code you suggested should only replace a certain part. I might not have correctly expressed what I was looking for however. What I need to do is find the line containing "hostname ", print that, then do some various modifications on the following lines until I find another "hostname " and repeat. Right now, all I was doing was incrementing $tot2 until I got this to work but eventually this will change.

Thanks!

jrvd

Replies are listed 'Best First'.
Re^3: Too much recursion
by mprentice (Sexton) on Jun 27, 2013 at 15:46 UTC

    Seems like you can do the same without a recursion:

    Update: Add "print $fd $_" to preserve original behavior.

    sub hostname{ print $fd $_; while (<$fh>){ if ($_ =~ /^hostname /){ print $fd $_; $tot++; next; }else{ $tot2++; } } $tot++; # keep initial increment }

      Works exactly the way I need it! Thanks!

      jrvd

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1041037]
help
Chatterbox?
[corenth]: I'm a pragmatic free-software advocate. I'll play in a walled sandbox when I need to.
[erix]: hm, there's a FANN perl module - looks a bit old
[Cosmic37]: I'm afraid I don't know the answer to your map question...... what were the references too?
[corenth]: each reference was to a fairly small scaler.
[corenth]: I mean, array of scalers. usually triples.
[Cosmic37]: there is a FANN discussion group but seems to have gone quiet... http://leenissen. dk/fann/forum/ viewforum.php?f=18 &sid=1afc1fb3fa1a3 7f52b03e40d05cdaaa 3

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2018-02-20 18:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (274 votes). Check out past polls.

    Notices?