CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
How to find the index of a null value in a row

 



Tejas
User

Jan 5, 2014, 2:01 AM

Post #1 of 3 (804 views)
How to find the index of a null value in a row Can't Post

my $non_nulls = grep { $_ ne '' } @$row;

I tried finding which row has null field
But how to find the index which has null value
244720457|01-NOV-2013|391|815177629513|-1.99|USD||1|8
8001461415|01-NOV-2013|391|815194715513|-1.99|USD||1|8
1282201|01-NOV-2013|391|815216860513|-1.65|USD||1|8

Here Index 6 has null value,How to get it using the code abve


FishMonger
Veteran / Moderator

Jan 5, 2014, 8:15 AM

Post #2 of 3 (798 views)
Re: [Tejas] How to find the index of a null value in a row [In reply to] Can't Post

See the indexes() function in List::MoreUtils.
http://search.cpan.org/~adamk/List-MoreUtils-0.33/lib/List/MoreUtils.pm


Laurent_R
Veteran / Moderator

Jan 6, 2014, 11:56 AM

Post #3 of 3 (780 views)
Re: [Tejas] How to find the index of a null value in a row [In reply to] Can't Post

Please provide more of your code.


Code
@$row


is probably not doing what you expect.

Additionally:


Code
$non_nulls = grep ...


is most probably wrong: the grep function returns an array. If you evaluate in in scalar constext, you will get the number of elements that satisfied the grep condition.

The code that does what you probably want to do would be something like this:


Code
my @non_nulls = grep { $_ ne '' } split /\|/, $row;


But of course, that will populate the @non_nulls array with the non null values, this will not tell you that Index 6 has a null value.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives