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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:17:07+00:00 2026-05-30T07:17:07+00:00

Sorry to post another question that is similar to the question that I posted

  • 0

Sorry to post another question that is similar to the question that I posted earlier. I realised that my question is not very clear and it might have led to some misunderstanding in the answers. So I thought of rephrasing it and ask again.

My task is to read in 2 files (base config file and config file). Both files can have any number of lines. The order of the lines need not be in sequence. I need to ignore things after “!” and “^”. However, I am stuck at the part on ignoring the “!” and “^”. I am able to store each line into keys in a hash (without the things after “!” or “^”) but it fails when I am comparing.

For example, if I have a line “hello!123” in the file, I need to store only “hello” in the hash and compare the string “hello” with another key from another hash. If there is a “hello” key in the other hash, I need to print it out or put it into another hash. My program can only put the “hello” from the line “hello!123” but failed at the part when it is comparing with another key in the other hash.

I have checked my regular expression by writing another short program that just takes in user input and remove the things after “!” and “^” symbols and compare with another key of the other hash.

Here is my faulty code:

my %common=();
my %different=();
#open config file and load them into the config hash
open CONFIG_FILE, "< script/".$CONFIG_FILENAME or die;
my %config;
while (<CONFIG_FILE>) {
    chomp $_;
    $_ =~ s/(!.+)|(!.*)|(\^.+)|(\^.*)//;
    $config{$_}=$_;
    print "_: $_\n";
    #check if all the strings in BASE_CONFIG_FILE can be found in CONFIG_FILE
    $common{$_}=$_ if exists $base_config{$_};#stored the correct matches in %common
    $different{$_}=$_ unless exists $base_config{$_};#stored the different lines in %different
}
close(CONFIG_FILE);

Does anyone has the same problem as me before? What do you do to solve it?

  • 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-30T07:17:09+00:00Added an answer on May 30, 2026 at 7:17 am

    I am not exactly sure what your problem is Sakura, but I think it may be that you aren’t finding matches between the $config and $base_config when you should. I suspect this may be because of leading/trailing whitespace, and suggest you write

    while (<CONFIG_FILE>) {
      s/[!^].*//;           # Remove comments
      s/^\s+//;             # and clear leading
      s/\s+$//;             # and trailing whitespace
      next if length == 0;  # Ignore empty lines
      $config{$_} = $_;
      print "_: $_\n";
      if ( $base_config{$first} ) {
        $common{$first} = $first;
      }
      else {
        $different{$first} = $first;
      }
    }
    

    You also need to make sure that $base_config has the same treatment before you compare its values.

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

Sidebar

Related Questions

Sorry but yet another question on JavaScript. From my previous post, I was able
I'm sorry to post another question on this, but I just seem to be
I am sorry to post question hich was here before, but this is driving
Sorry if the post title wasn't clear, I will try to explain a little
Sorry I cannot post any source code... I have a code running a master/slave
It's my first post so sorry if I may not respect all the conventions
Sorry for this long post. The question is however small but requires full detail.
Sorry for the double post, I will update this question if I can't get
Sorry is this is not the correct forum to post this, but I'm running
sorry for the long question. I am trying to ajax post to collect a

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.