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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:36:13+00:00 2026-05-25T13:36:13+00:00

I want to extract values from music structure directories using File::Find::Rule and I’m having

  • 0

I want to extract values from music structure directories using File::Find::Rule and I’m having difficulties getting the total discs of each album if present, e.g if an album contains 3 subdirectories DISC1, DISC2, DISC3 – the total discs value should be 3. If I grep these directories before the “For” statement it gets the total of all found, and if I try within the “For” statement it counts one at a time. How to extract total discs for each album if present. Thanks.

use autodie;
use strict; 
use warnings;
use File::Find::Rule;
use File::Spec;

my $dir = 'D:\Test';
$dir =~ s#\\#/#g;

my @fd = File::Find::Rule->directory()
->name( qr/\(\d+\)/ )
->in( $dir );

my $grep_totaldiscs = grep /DISC\d+/, @fd;
print "$grep_totaldiscs\n";

for my $fd ( @fd ) {

    my ($genre, $artist, $album, $disc) = (File::Spec->splitdir($fd))[2..5];

    my ($discnumber, $totaldiscs);
    if ($fd =~ /DISC(\d+)/) {
        $discnumber = $1;
            $totaldiscs = $1 if ( defined($totaldiscs) < $1 );
        print "$album $totaldiscs\n";
    }

}
  • 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-25T13:36:14+00:00Added an answer on May 25, 2026 at 1:36 pm

    In outline:

    • Before the loop: declare a hash to hold the maximum – i.e. total disc number – for each album.
    • Inside the loop: update the hash entry for the album, if it is a new maximum for that one.
    • After the loop: iterate over the hash to process or display.

    I’ve used artist and album combined to disambiguate in the keys of the hash here.

    For example:

    my %album_discs;
    for my $fd ( @fd ) {
    
        my ($genre, $artist, $album, $disc) = (File::Spec->splitdir($fd))[2..5];
        my $aakey = "${artist}~${album}";
    
        my ($discnumber, $totaldiscs);
        if ($fd =~ /DISC(\d+)/) {
            $discnumber = $1;
            $album_discs{$aakey} = $discnumber
                if ( ! exists $album_discs{$aakey} || $album_discs{$aakey} < $discnumber );
        }
    }
    
    for my $aakey ( keys %album_discs ) {
        my ( $artist, $album ) = split( /~/, $aakey );
        print "Number of discs for album $album by $artist is $album_discs{$aakey}\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to extract values from an XML file using linq to create
I want to parse the input string and extract the values from it. My
I want extract the path of images from a html page using PHP-preg_match_all(), the
I want to extract values from built in boxplot function. In A1 there are
how can I extract proper nouns / numeric values from a string using PHP
I am writing xsl stylesheet to extract information from iTunes Music Library. xml file.
I want to extract variables from math expression using c#. I wrote this code
I have situation where I want to extract multiple values from multiple source objects
I want the regular expression to extract the &[1], &[2},&[3],&[4] values from the following
I need to extract information from iTunes Music Library.xml file. Since the xml is

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.