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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:14:29+00:00 2026-06-10T03:14:29+00:00

I am using List::Compare to compare two files and print out the output in

  • 0

I am using List::Compare to compare two files and print out the output in html, but since I’m using arrays the output is coming out in one row instead of different rows.

example

file1.txt
aaaa
bbbb
cccc
dddd 

file2.txt
aaaa
bbbb
cccc
eeee

code

use strict;
use warnings;
use Getopt::Long;
use List::Compare;

my $f1 = 'file1.txt';
open FILE1, "$f1" or die "Could not open file $f1 \n";
my $f2= 'file2.txt';
open FILE2, "$f2" or die "Could not open $f2 \n";
my $outputFile = 'finaloutput.txt';

my @body="";
push(@body, "<html> \n");
push(@body, "<head> \n");
push(@body, "<TABLE BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\" WIDTH=\"100%\"  \n");
push(@body, " <TD>");
push(@body, "<div align=\"left\"><Table border=2 bordercolor= \"black\"> \n");
push(@body, "<tr bgcolor=\"ORANGE\"><TH><b>uniq in file1</b></TH><TH>uniq in file 2</TH><TH>common</TH></TR>");
push(@body, "<br>\n");

my @latest=<FILE1>;
my @pevious=<FILE2>;
my $compare = List::Compare->new(\@latest, \@pevious);

my @intersection = $compare->get_intersection;
my @firstonly = $compare->get_unique;
my @secondonly = $compare->get_complement;

print "Common in both:\n"."@intersection"."\n";
push(@body, "<tr><td>@intersection</td>\n");
print "uniq in first file:\n"."@firstonly"."\n";
push(@body, "<td>@firstonly</td>\n");
print "Items uniq in Second File:\n"."@secondonly"."\n";
push(@body, "<td>@secondonly</td></tr>\n");

push(@body, "</div></Table>" );  
my $Joining= join('', @body);
push(@body, "</body></font>");
push(@body, "</html>");  
print FILE"$Joining";
close FILE;
close FILE1;
close FILE2;

Here is the html output that I get for the first column:

<tr><td>aaaa 
bbbb
cccc </td></tr>

I want to have:

<tr><td>aaaa</td> <td>bbbb</td><td>cccc</td></tr>

I hope I have explained it properly.

  • 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-10T03:14:31+00:00Added an answer on June 10, 2026 at 3:14 am

    Change this line:

    push(@body, "<tr><td>@intersection</td>\n");
    

    to:

    push @body, '<tr>', (map{'<td>'.$_.'</td>'}@intersection), '</tr>';
    

    and the same for other arrays @firstonly and @secondonly

    If you want to remove the line-feed, you can do:

    my @latest=<FILE1>;
    chomp @latest;
    my @pevious=<FILE2>;
    chomp @pevious;
    

    edit

    According to your comment and if I well understand, try this:

    Replace this bock

    print "Common in both:\n"."@intersection"."\n";
    push(@body, "<tr><td>@intersection</td>\n");
    print "uniq in first file:\n"."@firstonly"."\n";
    push(@body, "<td>@firstonly</td>\n");
    print "Items uniq in Second File:\n"."@secondonly"."\n";
    push(@body, "<td>@secondonly</td></tr>\n");
    

    with this one:

    my $nbrows = @intersection;
    $nbrows = @firstonly if @firstonly > $nbrows;
    $nbrows = @secondonly if @secondonly > $nbrows;
    push @intersection, ("&nbsp;")x($nbrows - @intersection);
    push @firstonly, ("&nbsp;")x($nbrows - @firstonly);
    push @secondonly, ("&nbsp;")x($nbrows - @secondonly);
    for my $i(0..$nbrows-1) {
        push @body, "<tr>";
        push @body, "<td>$firstonly[$i]</td>";
        push @body, "<td>$secondonly[$i]</td>";
        push @body, "<td>$intersection[$i]</td>";
        push @body, "<tr>\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to compare two lists. Since we code to interface using List ,
I have two directories with the same list of files. I need to compare
How to sort two objects in a list by using two properties one by
My question is like this one: c# list compare but the only thing to
I'm currently using this compare options to sort a list of strings: [self compare:aString
I am using Sectioned List in my activity which extends ListActivity but now as
This is my first script, and I am trying to compare two genome files,
How would I compare two dates to see which is later, using Python? For
I have two lists of files, one from a local drive and one from
I have two long list, one from a log file that contains lines formatted

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.