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 |