Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8819249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:18:32+00:00 2026-06-14T05:18:32+00:00

I have an array of strings that comes from data in a hash table.

  • 0

I have an array of strings that comes from data in a hash table. I am trying to remove any (apparently) empty elements, but for some reason there seems to be an obstinate element that refuses to go.

I am doing:

# Get list array from hash first, then
@list = grep { $_ ne ' ' } @list; 
@list = uniq @list;
return sort @list;

At the grep line I get the Use of uninitialized value in string ne... message with the rest of the array printed correctly below.

I’ve tried doing it the ‘long’ way:

foreach (@list) {
    if ($_ ne ' ') {
        push @new_list, $_;
    }
}

But this produces exactly the same result. I tried using defined with the expected result (nothing).

I could sort the array beforehand and delete the first element, but that seems very risky as I cannot guarantee that the data set will always have blank elements. It also seems excessive to resort to regular expressions, but perhaps I’m wrong. I’m sure I’m missing something ridiculously simple, as usual.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:18:34+00:00Added an answer on June 14, 2026 at 5:18 am

    My answer assumes that you do not want strings that are either empty (meaning undefined or have a length of 0) or consist solely of spaces.

    Your grep line only tests for strings that equal exactly one space. However, the warning implies that at least one array element is indeed undefined. Comparing an undefined value with eq will only yield true for an empty string, not for a single space.

    So in order to remove all entries that are either undefined or consist only of spaces you could do something like this:

    @list = grep { defined && m/[^\s]/ } @list;

    Note that an empty space is trueish for Perl. Therefore a simple grep defined, @list will actually not throw out the entries that consist solely of spaces.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two product tables. Table A is the default table (comes from data
I have an array of strings that I want to use for button titles
I have an array of input strings that contains either email addresses or account
Currently, I have an array of Strings, each with random characters in it that
I have a variable that contains : Sometimes array of strings and sometimes array
I have a variable length array of strings declared in javascript that contains Dungeons
I have a For Each loop that is looping through an array of strings
I have string that look like Array that fetched from other webservice like this
I have a large array in PHP. It contains strings that are split into
I have an application that reads string data in from a stream. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.