Gossamer Forum
Home : General : Perl Programming :

help with a script...

Quote Reply
help with a script...
Code:
print "What is the last name of the employee? ";
$LName = <STDIN>;
chomp($LName);
@EmpID = ("$LName");
print "\nWhat is the first name of the employee? ";
$FName = <STDIN>;
@EmpID = ("$LName", "$FName");
select(INFILE);
printf "\n@EmpID";print "Name added, thank you!"; #I DONT WANT THIS PRINT COMMAND TO BE IN THE FILE... I MERELY WANT IT TO SHOW ON THE SCREEN..


how can i get "Name added, thank you!" to appear on the screen, not printed in the file...i've tried putting

close(INFILE) after "printf "\n@EmpID";"

but what happens it an error pops up and says

print() on closed filehandle INFILE at C:/Employee ID 2.txt line 26, <STDIN> line 4.
C:/Employee ID 2.txt did not return a true value at - line 61, <STDIN> line 4.



and if it matters, I run this file from another using the "require" command
Quote Reply
Re: [skateboarder83] help with a script... In reply to
Do you know what your

select(INFILE)

statement is doing?

---> http://www.perldoc.com/...pod/func/select.html

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] help with a script... In reply to
i looked there, then how do i select the TXT file to be written to? do i even need that select() there?
Quote Reply
Re: [skateboarder83] help with a script... In reply to
You'll need to re-select STDOUT to print to the screen as by selecting INFILE you are printing to your file handle. Flush buffers first using:

$| = 1;

Last edited by:

Paul: Feb 26, 2003, 11:05 AM
Quote Reply
Re: [Paul] help with a script... In reply to
where do i put the $ = | in the code? and how do i select the STDOUT and print that>
Quote Reply
Re: [skateboarder83] help with a script... In reply to
Try moving the "select(INFILE)" to below the print statement. Then putting $| = 1; at the top of your script. (It's dollar-pipe equals 1, not dollar-equals-pipe... just in case)
Quote Reply
Re: [skateboarder83] help with a script... In reply to
Or ditch select and just do:

print STDOUT "Name added, thank you";

Not sure why you are messing with select in the first place, you can pass what filehandle you want to print to as the first argument to print.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] help with a script... In reply to
Code:
$NameDB = '>>C:/Perl for Dummies/AuthorCode/edata3.txt';
# Open the database file but quit if it doesn't exist
open(INFILE, $NameDB) or die "The database $NameDB could " .
"not be found.\n"; print "\n\nWould you like to add a Name to the Employee ID List? Yes (Y) or No (N) ";
$AddName = <STDIN>;
chomp($AddName);
$AddName =~ tr/A-Z/a-z/;
if($AddName eq 'n') {print "Program Aborted.";exit;}
unless($AddName eq 'y') {
print "You must enter Y or N, not $AddName";
next;
}
print "What is the LAST name of the employee? ";
$LName = <STDIN>;
chomp($LName);
@EmpID = ("$LName");
print "\nWhat is the FIRST name of the employee? ";
$FName = <STDIN>;
@EmpID = ("$LName", "$FName");
select(INFILE);
printf "\n@EmpID";
print STDOUT "\nName added, thank you\n";


How can i go back to the part where i ask if you would like to input a name to the file without using Goto? ( the part is the very top of the file where it says:

Code:


print "\n\nWould...

Last edited by:

skateboarder83: Feb 26, 2003, 6:20 PM