Odd problem with output re-direction 
Author Message
 Odd problem with output re-direction

I'm having a problem with re-directing output.  Here's my script:

------- Start
#!/usr/bin/perl


open(NEW_ALIASES, ">> new_aliases");


  chop($alias);
  ($expanded_name, $login) = split(/:/, $alias);

    print NEW_ALIASES "$alias\n";
 }

Quote:
}

close(NEW_ALIASES);
--------- End

As you can see, it's pretty simple.  I load two files into separate
arrays,

The problems is that I can't get the output to a file.  The file
"new_aliases" gets created, but stays empty.

I removed the filehandle from the print statement, and matches did
indeed show up on the screen.  I then tried

           trim_aliases.pl > new_aliases

and new_aliases still remained empty.

I then ran script in debug mode, with the filehandle back in the print
statement, and everything worked.

Arrrgggggghhhhh!

Any help would be GREATLY appreciated!

(I'm running Digital UNIX V3.2A, and have tried both perl 4.036 and 5.001.)

===============================================================
Dave Brady                          Phone: 617-373-4579
Sr Systems Programmer               FAX: 617-373-8600

Northeastern University
Boston, MA 02115
===============================================================



Mon, 27 Oct 1997 03:00:00 GMT  
 Odd problem with output re-direction

Quote:
> I'm having a problem with re-directing output.  Here's my script:

> ------- Start
> #!/usr/bin/perl



> open(NEW_ALIASES, ">> new_aliases");


>   chop($alias);
>   ($expanded_name, $login) = split(/:/, $alias);

>     print NEW_ALIASES "$alias\n";
>  }
> }

> close(NEW_ALIASES);
> --------- End

This would probably be much better if written:

open(CURRENT_USERS, "user_list");  # Current users on system
open(OLD_ALIASES, "aliases");    # Current mail aliases

open(NEW_ALIASES, ">>new_aliases");# open file for writing/appending to

while ($users = <CURRENT_USERS>) { # load all current users from file
                                   # into an array
        chop ($users);

Quote:
}

while ($alias = <OLD_ALIASES>) {   #read the old aliases
        chop ($alias);
        ($expanded_name, $login) = split(/:/, $alias);  #find the login

                                                        #exists among current
                                                        #users.

                print NEW_ALIASES "$alias\n"; #if so, print to file
        }

Quote:
}

close (CURRENT_USERS);  # close all the Filehandles
close (OLD_ALIASES);
close (NEW_ALIASES);

This is completely untested code, so it may not work as is, but I think
I've got the right idea.  I'm sure some one else can come up with a
shorter, more efficient way of doing this, maybe using a seek() to see if
the old alias exists among those currently on the system.  But in
general, this should work better just having eliminated the system calls
to cat!

Hope this helps,
Paul

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- Paul Lussier          =   It is a good day    =The next best thing to doing -
= Raytheon MSD SWL      -    to put slinkies    -something smart is not doing =

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
   =                           Quote of the week:                          =
   -          *God pressed "M-x light-mode" and there was light*           -
   =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=



Fri, 31 Oct 1997 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. An odd problem... Disappearing output

2. Output redirection and output to a file

3. command-line output re-direction in winNT

4. CGI.pm odd output under NT

5. odd output duplication

6. combining Curses.pm with output redirection

7. Question: Output redirection

8. Detecting output redirection in Perl

9. output redirection

10. Output Redirection

11. Crontab output Redirection

12. output redirection on NT

 

 
Powered by phpBB® Forum Software