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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:41:25+00:00 2026-06-06T12:41:25+00:00

Looking for an nice (short & elegant) one liner for the next perl script:

  • 0

Looking for an nice (short & elegant) one liner for the next perl script:

use strict;
use warnings;

my %all;
while(<DATA>) {
    chomp;
    my ($name, $x, $path) = split /\s+/;
    push @{$all{$path}}, $name;
}
foreach my $path (sort keys %all) {
    my $cnt = scalar @{$all{$path}};
    print "$path $cnt @{$all{$path}}\n" if $cnt > 1;
}
__DATA__
Atxt  x     a/b/c
Btxt x a/d/x
Ctxt x i/t/a
Dtxt x i/y/a
Etxt  x     i/t/a
Ftxt x a/d/x
Gtxt x a/d/x

ofc, the one-liner should read from STDIN not from DATA.

In short, the script read 3 fields (name, x, path), and should output summary for duplicated paths in a form: path dup_count name1 ... namex. Each name is different.

So, looking for something like:

my_command | perl -F '\s+' -nle 'shorter_variant_of_the_above_script'
  • 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-06T12:41:27+00:00Added an answer on June 6, 2026 at 12:41 pm

    There are probably ways to shorten this, but here’s an attempt:

    perl -lane 'push@{$h{$F[2]}},$F[0]}{map{$n=@v=@{$h{$_}};print"$_ $n @v"if$n>1}keys%h'
    

    Output with provided data:

    a/d/x 3 Btxt Gtxt Ftxt
    i/t/a 2 Etxt Ctxt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for a good and useful code example that would be nice, short
I'm looking for nice loading indicators for Silverlight. I found a few, but all
I'm looking for a nice API to use for implementing algorithms on the GPU.
I am looking for a set of nice plugins to use when developing software.
I'm looking for a nice template engine or short piece of code to expand
I am looking for a nice quick live search/filter. Anybody use this? http://rikrikrik.com/jquery/quicksearch/#usage Also
I'm looking for a nice way to sort a hash in Perl by value
I am looking for nice looking sites that are good in terms of look
library(ggplot2) This code produces a nice looking plot: qplot(cty, hwy, data = mpg, colour
I am developing a multilingual web application that has a nice looking UI. I

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.