I am new to Perl and trying to decode a Perl script which reads an Excel file and export the data into a text file. One of the steps in the script is performing weirdly. This is the step:
@array_name = grep {$_} @array_name;
This step just truncates the last column if the value is 0; otherwise it works properly. If I remove this step, the last column with value 0 is back, but it includes some dummy NULL columns in my extract which are not part of my source Excel file.
Can someone please help me understand this step?
The grep command filters non empty content. So everything that does not evaluate as true will be discarded. Empty cells and cells containing 0 will be removed. If you just want to remove empty cells you could use
@array_name = grep { defined && length } @array_name ;
instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With