How do i prompt the user for input and add it to the end of a file?
-
Link: http://perldoc.perl.org/functions/open.html
To demonstrate the reading in from standard input and appending it to the end text file, by way of the open function
Text file before running the program
$ cat datafile 10.70.50.1 jennifer 10.70.50.2 nicole 10.70.50.3 cameron
The program
#!/usr/bin/perl $filename = 'datafile'; open($fh, ">>", $filename); $fb = <STDIN>; chomp($fb); print($fh "$fb\n"); close($fh);
Run the program
$ ./myperl8 10.70.50.4 susan
Text file after running the program
$ cat datafile 10.70.50.1 jennifer 10.70.50.2 nicole 10.70.50.3 cameron 10.70.50.4 susan
© Lightnetics 2024