in reply to reading the 5th element from file doesn't work.
Hi singho,
There are several things wrong here.
1. According to your post title, do you what the 5th Element of the whole file, or each line in the file?
If your intention is the 5th Element of the whole file, then do this:
2. But it seem, to me you want the 5th element of each line, which in that case you need do this:my @string; open(SYSLOG, "/tmp/log100lines") or die "Can't open file: $!\n"; foreach my $line (<SYSLOG>) { chomp $line; push @string, $line } print $string[4],$/;
NOTE:open(SYSLOG, "/tmp/log100lines") or die "Can't open file: $!\n"; foreach my $line (<SYSLOG>) { chomp $line; my @string = split(/ /, $line); ## remove the function join print "$string[4]\n"; }
open my $fh, '<', "file_to_open" or die "can't open file: $!";
while(<$fh>){ ... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: reading the 5th element from file doesn't work.
by singho (Novice) on Apr 24, 2013 at 08:54 UTC |