I want to put a the value of
$temp_arr[0] $temp_arr[1] $temp_arr[2] $temp_arr[3] $temp_arr[4] $temp_arr[5] $temp_arr[6] $temp_arr[7] $temp_arr[8] $temp_arr[9] $temp_arr[10] $temp_arr[11] $temp_arr[12] in splited_line array, but I don't know how.
my script is :
#!/usr/bin/perl use DBI; use Data::Dumper; use DBD::mysql; use POSIX;
#use strict; use warnings;
#"/mnt/toto/titi.log" or die $!;
open(FILE,"<titi.log"); print "file loaded \n"; my @lines=<FILE>; #tout les valeurs du fichier se trouve dans le tableau lines close(FILE);
#my @all_words; my @temp_arr;
#my @splited_line;
print "$lines[0]"; print "$lines[83000]";
foreach my $line(@lines) {
@temp_arr=split('\s',$line);
push(@temp_arr);
print "$temp_arr[0] $temp_arr[1] $temp_arr[2] $temp_arr[3] $temp_arr[4] $temp_arr[5] $temp_arr[6] $temp_arr[7] $temp_arr[8] $temp_arr[9] $temp_arr[10] $temp_arr[11] $temp_arr[12]\n";
@splited_line = "$temp_arr[0] $temp_arr[1] $temp_arr[2] $temp_arr[3] $temp_arr[4] $temp_arr[5] $temp_arr[6] $temp_arr[7] $temp_arr[8] $temp_arr[9] $temp_arr[10] $temp_arr[11] $temp_arr[12]\n"; #this line don't work
print $splited_line[2];
}
I want a result as $splited_line[2], thanks for any information.
update
I do this :
foreach my $line(@lines) {
@temp_arr=split('\s',$line);
push(@temp_arr);
#print "$temp_arr[0] $temp_arr[1] $temp_arr[2] $temp_arr[3] $temp_arr[4] $temp_arr[5] $temp_arr[6] $temp_arr[7] $temp_arr[8] $temp_arr[9] $temp_arr[10] $temp_arr[11] $temp_arr[12]\n";
@splited_line = "$temp_arr[0] $temp_arr[1] $temp_arr[2] $temp_arr[3] $temp_arr[4] $temp_arr[5] $temp_arr[6] $temp_arr[7] $temp_arr[8] $temp_arr[9] $temp_arr[10] $temp_arr[11] $temp_arr[12]\n";
push(@splited_line);
print $splited_line[2];
}
output:
Use of uninitialized value in print at test7.pl line 35.
Use of uninitialized value in print at test7.pl line 35.
Use of uninitialized value in print at test7.pl line 35.
Use of uninitialized value in print at test7.pl line 35.
Use of uninitialized value in print at test7.pl line 35.
Use of uninitialized value in print at test7.pl line 35.
Use of uninitialized value in print at test7.pl line 35.
Use of uninitialized value in print at test7.pl line 35.
Use of uninitialized value in print at test7.pl line 35.
Use of uninitialized value in print at test7.pl line 35.
Use of uninitialized value in print at test7.pl line 35.
Use of uninitialized value in print at test7.pl line 35.
I don't know why
$split_lineis not an array, it's a scalar. Do you mean@split_line?my @splited_line = @temp_arr[0 .. 12];Note the my: Please turn on strict and warnings.my @temp_array = split(' ', $line)or= split(/\s+/, $line)my @interesting_array = @temp_array[3,4,5,10,11], i.e.@interesting_arraygets fields 4, 5, 6, 11 and 12 from$line