I got the error "Use of uninitialized value in subroutine entry at ./test.pl line 20." when I run the below code.

INPUT

2015-05-01 abc serv1 X View impl details 34 33 2 0 1 0 4552 3312 0 72 0 0 0 0 0 0 0 0 1 576 3 1 0 0 0 0 0 0 0 0 0.0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 381 671 1 2015-05-01 def serv2 X Assessment for next exam preview 22 22 0 0 1 0 1195 3577 0 3053 0 0 0 2 2 0 0 0 26 163 10 2 0 0 0 0 0 0 0 0 0.0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 5 21 1

OUTPUT

The first 4 fields separated by spaces have to be printed as it is. However, as you can see ,5th field on wards, there can be any number of space separated words. I want to club them all together as 5th field until a number is found as the next field. In the above sample input, I want "View impl details" as 5th field instead of "view" as 5th,"impl" as 6th and details as 7th fields. The same goes with 2nd row of data. I would like "Assessment for next exam preview" to appear as 5th field & the rest as their own fields.

#!/usr/bin/perl use strict; use warnings; use POSIX; my $i_file='../out/test.out'; my $o_file='../sql/test.out'; my $text_cont=""; open (FILE, $i_file) or die "Could not read from $i_file, program halting."; while(<FILE>) { (my $fl_1, my $fl_2, my $fl_3, my $fl_4, my @subfields) = split; my @join_fields; my $l=0; for (my $k=5; $k <= 53; $k++) { $join_fields[$l] = ""; if(isdigit($subfields[$k])) { $join_fields[$l] = $subfields[$k]; $l = $l + 1; } else { $join_fields[$l] = $join_fields[$l] . $subfields[$k]; } } } close FILE;

I want to read thousands of lines from a file each line containing more than 50 fields separated by space. I'm reading each line, splitting the data by space as delimiter to start with. From the 5th field on wards, until I get a field with digits, I want to append the fields to the 5th field. Then finally print out the output.

I'm new to Perl. My understanding of the error is that it is unable to find definition for "isdigit". However, looking at few solutions on the internet, I used the POSIX package. It doesn't seem to help. Could someone please help me achieve my requirement?

UPDATED SCRIPT