- 论坛徽章:
- 0
|
ms我讲错了
又挂在context上面了
$hash{$_} = split;
左边是一个scalar的context
可以用下面的代码
- #!/usr/bin/perl
- #===============================================================================
- #
- # FILE: readin.pl
- #
- # USAGE: ./readin.pl
- #
- # DESCRIPTION: hash
- #
- # OPTIONS: ---
- # REQUIREMENTS: ---
- # BUGS: ---
- # NOTES: ---
- # AUTHOR: Leenux (Mr), <[email]firefoxelectric@gmail.com[/email]>
- # COMPANY: Debian GNU/Linux
- # VERSION: 1.0
- # CREATED: 02/14/2008 09:52:10 PM CST
- # REVISION: ---
- #===============================================================================
- use strict;
- use warnings;
- my %hash;
- open my $file, "<", "data" or die "fail to open $!";
- while (<$file>) {
- my @tmp = split;
- $hash{$.} = \@tmp;
- }
- foreach ( sort keys %hash ) {
- print "$_ value one: $hash{$_}->[0]\n";
- print "$_ value two: $hash{$_}->[1]\n";
- }
复制代码
运行结果
kernel@fairland:~/chinaunix$ cat data
bb cc
ee ff
kernel@fairland:~/chinaunix$ ./readin.pl
1 value one: bb
1 value two: cc
2 value one: ee
2 value two: ff |
|