Deb wrote:
>
> Wait.  Using this construct, I can't seem to get the change to write
> out to the file, like I can to stdout.
>
[snip]
>
> Here's my code.
>
> sub editConfSettings {
>
> open (IN, "tmpconf") or die "cannot open for reading: $!\n";
> open (OUT, "conf")    or die "cannot open for writing: $!\n";
>
> while (<IN>) {
> unless ($approve eq "none") {
> s/^attendant/attendant  =   $approves/g;
> }
> unless ($to   eq "none") {
> s/^Appl.*$/Appl  =  $to/g;
> }
> unless ($shield   eq "none") {
> chomp;
> $_ .= " :time=43.43\n" if (/^shield/);
>
> }
> print OUT $_;
> }
> close (IN);
> close (OUT);
> }
>
> What am I missing here?  Should I do another s///g; ?

Hi Deb.

John's fix is correct, but you may prefer the following, which
uses a s// in every case and is a little more visible.

You are using both $approve and $approves. If you add
'use strict' to the top of your source then it will pick up
any undeclared variables that you try to use.

By the way, if you don't put a \n on the end of the 'die' string
then, if the die is executed, Perl will add the file name and
line number of the die statement, followed by its own \n. It
makes debugging easier.

HTH,

Rob

    use strict;    # !!!!!!!!!!

    sub editConfSettings {

        open (IN, "< tmpconf") or die "cannot open for reading: $!";
        open (OUT, "> conf")    or die "cannot open for writing: $!";

        while (<IN>) {

            s/^(attendant)/attendant  =   $approve/
                    unless $approve eq "none";

            s/^(Appl).*$/$1  =  $to/
                    unless $to eq "none";

            s/^(shield.*)$/$1 :time=43.43/
                    unless $shield eq "none";

            print OUT;
        }

        close (IN);
        close (OUT);
    }




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to