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

  • SEARCH
  • Home
  • 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 8999057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:07:41+00:00 2026-06-16T00:07:41+00:00

i have a problem. This perl program should open all files and map them

  • 0

i have a problem. This perl program should open all files and map them together, something similiar to paste command in unix system.

my @files;
for (@fileList ? @fileList : qw(-)) {
open  $files[@files], '<', $_; #}
}
while (grep defined, (my @lines = map {scalar <$_>;} @files)) {
    chomp @lines;
    print join("\t", @lines), "\n";
}

The problem is that, when it comes to two different files like

One 
Two 
Three

And:

Apple
Banana
Orange
Kiwi

It throws me an error of uninitialized value.

Use of uninitialized value $lines[0] in chomp 
Use of uninitialized value $lines[0] in join 

Also same error vice versa, when files are Apple,Banana.. and One two three.

Thank you in advance

  • 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-16T00:07:42+00:00Added an answer on June 16, 2026 at 12:07 am

    The problem is that since your files have a different length, you will get some undefined values in your @lines array. You cannot filter them out in the while condition, but you can filter them out afterwards, inside the loop:

    while (grep defined, (my @lines = map {scalar <$_>;} @files)) {
        @lines = map defined($_) ? $_ : "", @lines;
    

    This will replace undefined values with the empty string, removing any uninitialized warnings for those values, while keeping your tabs correctly aligned.

    Note that your code actually does what it is meant to do, because undef will stringify to the empty string. It is only because you have warnings on that you get the warnings about it. However, it is a very good idea to have warnings on, so errors such as this can be found and fixed properly.

    You should note that using open without checking its return value is not a good idea, unless you explicitly handle the failed cases. The proper way is to do this:

    open $files[@files], '<', $_ or die $!;
    

    For simplicity one can also use

    use autodie;
    

    The autodie module will produce fatal errors for critical function calls such as open.

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

Sidebar

Related Questions

We have an installation program that runs in Perl 32-bit. This program needs to
Hey all, I have a question about perl objects and threading. My program is
I have a perl script that prepares files for input to a binary program
i have written this program to pass a variable in the embedded perl script
I have problem with this code: file = tempfile.TemporaryFile(mode='wrb') file.write(base64.b64decode(data)) file.flush() os.fsync(file) # file.seek(0)
I really have problem with this one. So I have a jar with a
Hi i have problem with this code, i found it on the internet and
i am a beginner and i have a problem : this code doesnt compile
I'm developing an Android application with a spinner. I have this problem: This is
I have this problem: I want to generate a new source code file from

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.