I have code that contains:
use strict;
use warnings;
use List::Util;
my $index = first { $ARGV[$_] eq "something"; } 0..$#ARGV;
but I get
Use of uninitialized value $_ in array element at a.pl line 4.
What could cause this ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As your question lacks information, I can only guess at the real problem, but I managed to get a similar error with:
The error does not appear if I
use List::Util qw/first/explicitly, or if I use the full package name:List::Util::first. So, my guess is that thefirstfunction is not properly imported, and does not recognize the list after the code block, leaving$_uninitialized.The error most likely lies elsewhere in your code.