I have a text file with 240 records separated by "zz". I want to split the file into an array so that each record is in an array slot. Here is the code I am experimenting with.
#!/usr/bin/env perl
use strict;
use warnings;
open(my $configfile, "<", 'PoliceLog.txt') or die "$!";
my @configdata = split('zz',<$configfile>);
print "$configdata[0]\n";
print "$configdata[1]\n";
print "$configdata[2]\n";
close $configfile;
The print "$configdata[0]\n"; command prints the first record correctly. The 2nd and 3rd print commands do not print a record and cause the following error reports.
Use of uninitialized value $configdata[1] in concatenation (.) or string at TestC.pl line 10, <$configfile> line 1.
Use of uninitialized value $configdata[2] in concatenation (.) or string at TestC.pl line 11, <$configfile> line 1.
Any help is appreciated.
#!/usr/bin/env perl
use strict;
use warnings;
open(my $configfile, "<", 'PoliceLog.txt') or die "$!";
my @configdata = split('zz',<$configfile>);
print "$configdata[0]\n";
print "$configdata[1]\n";
print "$configdata[2]\n";
close $configfile;
The print "$configdata[0]\n"; command prints the first record correctly. The 2nd and 3rd print commands do not print a record and cause the following error reports.
Use of uninitialized value $configdata[1] in concatenation (.) or string at TestC.pl line 10, <$configfile> line 1.
Use of uninitialized value $configdata[2] in concatenation (.) or string at TestC.pl line 11, <$configfile> line 1.
Any help is appreciated.