读 《C程序员精通Perl》http://book.douban.com/subject/1232075/ 3.4节 笔记
#!/usr/bin/perl
use strict;
use warnings;
my @array = ();
while (1) {
print "input a number or <enter> to finish: ";
my $a=<STDIN>;
chomp ($a);
if ($a eq "") {
last;
}
print "input $a\n";
push(@array, $a);
}
print "array=@array\n";
my $line = join("\t", @array);
open JOIN_FILE, ">join.file" or die("Could not open join.file");
print JOIN_FILE $line;
close(JOIN_FILE);
运行结果:
[root@localhost perl_practice]# ./join.pl
input a number or <enter> to finish: 1
input 1
input a number or <enter> to finish: 2
input 2
input a number or <enter> to finish: 3
input 3
input a number or <enter> to finish: 4
input 4
input a number or <enter> to finish: 5
input 5
input a number or <enter> to finish:
array=1 2 3 4 5
[root@localhost perl_practice]# cat join.file
1 2 3 4 5[root@localhost perl_practice]#