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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:38:50+00:00 2026-06-12T17:38:50+00:00

I have written a perl code for processing file ‘Output.txt’ which has below Content.

  • 0

I have written a perl code for processing file ‘Output.txt’ which has below Content.

  new.example.com 28
  new.example.com 28
  example.com 28
  example.com 29
  example.com 29
  example.com 29
  example.com 29
  orginal.com 28
  orginal.com 29
  orginal.com 30
  orginal.com 31
  expand.com  31

And file ‘domain.txt’ has list of domain Names which i need to match against File ‘Output.txt’

new.example.com
example.com
orginal.com
test.com
new.com

I could manage to write PERL code like this

#!/usr/bin/perl
use strict;
open(LOGFILE,"Output.txt") or die("Could not open log file.");
my $domain_name = 'domain.txt' ;
open(DOM, $domain_name);
my @r_contents = <LOGFILE>;
close(LOGFILE);    
while(<DOM>) {
    chomp;
    my $line = $_;
    my @lowercase = map { lc } @r_contents;
    my @grepNames = grep  /^$line/, @lowercase;
    foreach (@grepNames) {
        if ( grep  /^$line/, @lowercase ) {
            $domains{lc($_)}++ ;            }
    }
}

close(DOM) ;    
foreach my $domain (sort keys %domains) {
    my %seen ;
    ($Dname, $WeekNum) = split(/\s+/, $domain);
    my @array1 = grep { ! $seen{ $_ }++ } $WeekNum;
    push @array2, @array1;
    my @array4 = "$domains{$domain} $domain" ;
    push @matrix,@array4 ;
}
   printf "%-10s %-25s %-25s\n", 'DoaminName', "Week $array2[0]" ,"Week $array2[1]","Week $array2[2]";
   print " @matrix \n";

current Output looks like this.

 DoaminName         Week 28        week29   week30  week 31
 2 new.example.com 35
 1 example.com 28
 4 example.com 29
 1 orginal.com 28
 1 orginal.com 29
 1 orginal.com 30
 1 orginal.com 31

But i trying re-write the perl code to print the output like this .Please help me to correct the code.

Domain/WeekNumber   Week28       Week29        Week30        Week31
new.example.com     2            No            No            No
example.com         1            4             NO            NO
orginal.com         1            1              1             1
  • 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-12T17:38:51+00:00Added an answer on June 12, 2026 at 5:38 pm

    This produces the desired output, only I also sorted the output.

    If you have long website names, add tabs in the code as necessary.

    #!/usr/bin/perl
    use warnings;
    use strict;
    open my $fh, "<", "Output.txt" or die "could not open Output.txt\n";
    
    my %data;
    my %weeks;
    while(<$fh>){
        chomp;
        $_=~ m/(.*?)\s++(\d++)/;
        my $site=$1;
        my $week=$2;
        $weeks{$week}++;
        $data{$site}{$week}++;
    }
    
    print "Domain/WeekNumber";
    
    for my $week (sort {$a <=> $b} keys %weeks){
        print"\tWeek$week";
    }
    print"\n";
    
    for my $site(sort keys %data){
        print"$site\t\t";
        for my $week (sort {$a <=> $b} keys %weeks){
                unless(defined $data{$site}{$week} ){
                        print"NO\t";
                }else{
                        print $data{$site}{$week} ."\t";
                }
        }
        print"\n";
    }
    close $fh;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have CSV file which has timestamp in the first column as shown below
I have some encryption code that has been written in Perl (also a code
I have written the following code in Perl. I want to iterate through a
I have written a Perl script to read the configuration file and create CGI
Today, I have written a perl script, as the following code: my @files =
I have written the following code in Perl. I have ActivePerl 5.14 for Windows
I have written the following code.. installFunction(){ perl Makefile.PL flag1 = $? make flag2
I have written a Perl Script which connects to a set of URLs one
The situation I am in is that I have written a perl script which
I have written a script that saves the output in a Perl script, but

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.