when I open the file like : open(RELFILE,">$file") || die ("error opening file \"$file\"");
...... and print the change in sam efiel I get a 0 size file . @array = <RELFILE>; while (@array) { chomp($_); $_=~ s/(#define SW_VERSION_MAJOR)(.*)/$1\t$major/; $_=~ s/(#define SW_VERSION_MINOR)(.*)/$1\t$minor/; $_=~ s/(#define SW_VERSION_PATCH)(.*)/$1\t$patch/; $_=~ s/(#define SW_VERSION_BUILD)(.*)/$1\t$build/; $_=~ s/(#define SW_VERSION_STR)(.*)/$1\t$string/; $_=~ s/(#define SW_RELEASE_MONTH)(.*)/$1\t$month/; $_=~ s/(#define SW_RELEASE_DAY)(.*)/$1\t\t$day/; $_=~ s/(#define SW_RELEASE_YEAR)(.*)/$1\t\t$year/; print RELFILE "$_ \n"; } close (RELFILE); do you what is the problem? Roger Layani -----Original Message----- From: Wiggins d Anconia [mailto:[EMAIL PROTECTED] Sent: Wednesday, May 05, 2004 5:35 PM To: Aviram, Shy; [EMAIL PROTECTED] - Sharing Perl Questions; Perl (E-mail); Layani, Roger Subject: Re: Problem changing the content of a file Please don't cross post... > > The code: > sub mkrelease_dot_h{ > $devlabel = shift (@_); > $file = shift (@_); Why are these not lexically scoped (my'd)? > my ($major,$minor,$patch,$build) = ExtractRelease($devlabel); > my ($month,$day,$year) = GetCurrentDate(); > chomp($year); > > open(RELFILE,"$file") || die ("error opening file \"$file\""); You are opening the above file for reading. To change a file you have to open it for writing. perldoc -f open perldoc perlopentut > $string = "\"$major.$minor.$patch.$build\""; > while (<RELFILE>) { > > chomp($_); > $_=~ s/(#define SW_VERSION_MAJOR)(.*)/$1\t$major/; > $_=~ s/(#define SW_VERSION_MINOR)(.*)/$1\t$minor/; > $_=~ s/(#define SW_VERSION_PATCH)(.*)/$1\t$patch/; > $_=~ s/(#define SW_VERSION_BUILD)(.*)/$1\t$build/; > $_=~ s/(#define SW_VERSION_STR)(.*)/$1\t$string/; > $_=~ s/(#define SW_RELEASE_MONTH)(.*)/$1\t$month/; > $_=~ s/(#define SW_RELEASE_DAY)(.*)/$1\t\t$day/; > $_=~ s/(#define SW_RELEASE_YEAR)(.*)/$1\t\t$year/; This just changes the local $_ variable, it doesn't do anything to the file once that line is read in. You will have to 'print' the line back into the file, don't forget to tack your new line back on since you have chomped it. > } > > close (RELFILE); > return $file; > } > > The question: > > Why this code does not change the content of file $file ? > HTH, http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>