Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to enter series of data in active perl

Status
Not open for further replies.

kushasri

Programmer
Jan 18, 2007
2
0
0
US
I am working on a windows XP machine.
I have installed active perl on it.
Whenever I require to write programs such that the prog needs to accept a series of data,am not able to end the series properly.
Ctrl+C,Ctrl+Z nothing is working..
Everytime I say Ctrl+C a message "Terminating on signal SIGINT(2) comes and the program ends abruptly.
can you please let me know how may I solve this?
 
ending the series" makes no sense to me, post your code, maybe the code will make it clearer. But, CTRL^C is doing what it should, interrupt and end the program.

- Kevin, perl coder unexceptional!
 
what I mean here is :
say suppose I have the code:

print "enter a series of text on separate lines";
chomp(@text=<STDIN>);
@rev=reverse @text;

when I run the program in the command prompt,once I enter the series of data,what should be the way I need to signal perl that am done with my data>
I found somewhere that Ctrl+C should work but that doesnt work for me.
 
Modify your logic.

Instead of slurping in all lines, process one line at a time. Then simply look for a condition that indicates that the user is done inputting text. Such as a blank line in the below example:

Code:
print "enter a series of text on separate lines\n";
while (<STDIN>) {
	chomp;
	/^$/ && last;
	push @text, $_;
}
@rev = reverse @text;
 
*nix STDIN normally accepts Ctrl-D as EOF. Might be worth a try.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top