Hi
There would be one thing to mention : in Perl there is a function like nowhere else
(*), the
[tt]wantarray[/tt]. It tells to the function in which it is called whether the one which called it intends to assign its return value to an array or not.
In your original code, the value read from file was passed to [tt]split[/tt], so used in a scalar context. So the file reading would read and return one line. If that line would contain the substring
"zz", then @configdata would contain the line split on that. Otherwise @configdata would contain the read line as its only item.
In my modified code, the value read from file was passed directly to the @configdata array. So the file reading would read the entire file content, split it on the [tt]$/[/tt] variable's value ( by default
"\n" ) and place each piece in a separate array item.
In your new code, the value read from file is used as [tt]while[/tt] condition, again a scalar context. So the file reading will read the file line by line. And for each line executes the block that splits the line and prints the first item resulted from the split. Then after the file was exhausted, the last read line's first 4 field are printed.
There would be one more way to read the file : slurp in the entire content without splitting it automatically. For that you simply [tt]
undef [navy]$/[/navy][teal];[/teal][/tt]
(**), then no more automatic splitting is performed and you are free to process the unaltered file content.
BTW, is strongly encouraged to use variable for filehandle as you did in your original code. $configfile will live only in the current block, while FILE is global and if closing is accidentally skipped, the open file will be available from other parts of your script, where FILE may be expected to access other file.
Unfortunately I do not really get your goal. Maybe if you show us a sample of that PoliceLog.txt file and explain which parts from it you need.
_____
(*) As far as I know.
(**) Well, [tt]undef[/tt]ing it is ugly. In practice you temporarily overdeclare a local variable in an anonymous function : [tt][navy]$everything[/navy] [teal]=[/teal]
do [teal]{[/teal]
local [navy]$/[/navy][teal];[/teal]
[green]<$configfile>[/green] [teal]};[/teal][/tt]
Feherke.
feherke.github.io