in reply to line numbers and line content into hash
Hello. You don't need or want a hash. You want an ordinary array. Arrays have indexes, and you don't need while to get all the lines from a file into an array.....
my @lines = <DATA>; chomp(@lines); my $line_num = 3; my $ary_index = $line_num -1; printf "Line number %d is '%s'\n", $line_num, $lines[$ary_index]; __DATA__ line 1 index 0 line 2 index 1 line 3 index 2 line 4 index 3 line 5 index 5
Note that a Perl array starts with index 0, not one.
cheers
tachyon
|
|---|