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 3598228
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:12:58+00:00 2026-05-18T20:12:58+00:00

There is probably an easy solution to this, but I can’t figure it out.

  • 0

There is probably an easy solution to this, but I can’t figure it out. I am looking to:

  • take a CSV file into an array
  • loop through the array and split fields into variables
  • if the array field is empty then set the variable to “N/A”

Note: It is only setting the $variable to “N/A” that I cannot get working.

For example:

foreach $var (@list) {

($name,$date,$size, etc...)=split(/,\"/,$var);

}

How would I set $date to “N/A” if the field in the array is empty?

so to produce:

$name = Jim
$date = N/A
$size = small

I hope this makes sense and is easy to fix.
-Thanks

  • 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-05-18T20:12:59+00:00Added an answer on May 18, 2026 at 8:12 pm

    Assuming the variable $date is undefined when “empty”:

    if (!defined($date)) {
      $date = 'N/A';
    }
    

    Or more concisely:

    $date //= 'N/A';
    

    Or if it really is an empty string, i.e. $date = ''; (this will also work in the case where $date is undefined, but you don’t want to use this if you only want to identify the case where it is undefined):

    if ($date eq '') {
      $date = 'N/A';
    }
    

    Or more concisely (note that this will also set $date to N/A if $date is '0' due to Perl’s weak typing):

    $date ||= 'N/A';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is blowing my mind because it's probably an easy solution, but I can't
I'm still kindof new to jQuery, so there probably is an easy solution, but
I've got a problem that probably has a very easy solution, but I can't
I'm new with Objective-C, so there probably is a simple solution to this. I
There is probably is simple fix for this but I currently have code similar
I'm using .Net 2.0 and this is driving me crazy but there's probably some
Ok I have a question and it is probably very easy but I can
This is probably easy as well. But I have this listview which contains exe
Probably an easy one: Are there any rules of thumb or pointers that could
this is probably a fairly easy question and I think it's more amusing than

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.