Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl Excel parser truncating columns

Tags:

file

excel

perl

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?

like image 212
user1415006 Avatar asked Feb 26 '26 03:02

user1415006


1 Answers

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.

like image 192
dgw Avatar answered Feb 27 '26 18:02

dgw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!