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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:45:33+00:00 2026-05-29T11:45:33+00:00

I am writing a Perl script which needs to perform some validations. I have

  • 0

I am writing a Perl script which needs to perform some validations. I have a file available which contains following information

patchname subpatch1,subpatch2,subpatch3...

Content of the files are to be read and the subpatches are to be placed in array. These subpatches may contain more subpatches which need to be traversed using either DFS or BFS which comes later into picture.
But, these subpatches need to be mapped to a hash while these are read from the file, i.e.:

$list->{subpatch1} = \subpatch1
$list->{subpatch2} = \subpatch2
$list->{subpatch3} = \subpatch3 ....

Using split does not help.

($a1,$2)=split;

gives me $2=subpath1,subpatch2,... which needs to be further split. It’s getting really confusing here specially since I am new to Perl.

Is there a better way of performing the action above or is there is any module with which this can be achieved?

  • 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-29T11:45:33+00:00Added an answer on May 29, 2026 at 11:45 am

    I think that you are confusing the lists and hashes. A list is basically an array… it’s a set of elements that’s indexed by number. Its elements can only be accessed by index:

    my $list = [ 'foo', 'bar', 'baz' ];
    print $list->[0], "\n";   #prints foo
    print $list->[2], "\n";   #prints baz
    

    A hash is a collection that’s indexed by a key, which you decide. Elements are looked up by this key (as opposed to an index, like in a list):

    my $hash = { fookey => "foo", barkey => "bar", bazkey => "baz" };
    print $hash->{'fookey'}, "\n";  # prints foo
    print $hash->{'barkey'}, "\n";  # prints bar
    

    If I understand your requirement correctly, you’re looking for a way to store data in the following form:

    patchname1 --relies on--> patchname2, patchname2, ...
    

    So what you really want is one hash, where the keys are the patch names and the values are lists of patchnames:

    my $patch_hash = {
        patchname1 => [ 'patchname2', 'patchname4' ],
        patchname2 => [ 'patchname3', 'patchname4' ],
        patchname3 => [ 'patchname4' ],
        patchname4 => [],
    };
    

    Where each unique patchname is a key in patch_hash who’s value is a list of its dependencies.

    As toolic suggests, the actual parsing can be done with split if you tell it what delimiters to split on. From there, you can populate your hash with something like:

    my $patch_hash = {};
    while( <FILE> ){
        my( $name, @subs ) = split /[\s,]+/;
        push( @{$patch_hash->{$name}}, @subs );
    }
    

    This is a nice article on Perl arrays.

    This is a nice list of the functions for Perl arrays.

    This is a nice article on Perl hashes.

    And this is a nice summary of Perl regex.

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

Sidebar

Related Questions

I am writing Perl script. In that I have to read log4j.xml file from
I am writing a Perl script that needs to extract some data from an
I am writing a Perl script (in Windows) that is using File::Find to index
I have a quite simple perl script, that in one function does the following:
I am writing a Perl script that needs to transfer files between computers using
I am writing a script in Perl which searches for a motif(substring) in protein
I'm relatively new to Perl, writing some XML parsing scripts. I have done two
I'm writing a script in Perl that needs to run at the same time
I am writing a Perl/Tk script which displays Excel worksheets using the ss2tk example
I'm writing a Bash script in which I am running a perl script which

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.