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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:57:07+00:00 2026-06-07T10:57:07+00:00

I have a txt file like this $CHUNK_QTY = 50000; $CLIENT = hi all;

  • 0

I have a txt file like this
$CHUNK_QTY = “50000”;
$CLIENT = “hi all”;
$CLIENT_CODE = “NMB”;
$COMPOSER = “DIALOGUE”;
$CONTROL_FILE_NAME = “NMBM725.XML”;
$COPY_BASE = “01”;
$CSITE = “NSH”;
$DATA_TYPE = “MET”;
$DIALOGUE_VERSION = “V7R0M624”;
$DISABLE = “N”;
$DPI = “300”;
$DP_BAR_START = “A”;
$DP_BAR_STOP = “Z”;
$DUPLEX = “N”;
$Dialogue_Version = “V7R0M624”;
$EMAIL_ERROR = “Y”;
$EMAIL_ON = “N”;

I have many variables up to 500. I would like to access value for corresponding variable. For example if I want to access $DPI it should print 300 . How do I do that in perl. Any help will be appreciated. I would like something different than regex.

Thanks

  • 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-07T10:57:09+00:00Added an answer on June 7, 2026 at 10:57 am

    Here’s a quick example showing how to take lines in the format that you gave above and put them into a hash:

    #!/usr/bin/env perl    
    
    use strict;
    use warnings;
    
    my %vars;
    while (my $line = <DATA>) {
      chomp $line;          # remove linebreak
      $line =~ s/^\$//;     # Optional: remove $ from start of variable name
    
      my ($key, $value) = $line =~ /^(\w+)\s*=\s*(.*)$/;
      $value =~ s/;$//;     # Remove trailing semicolon
      $value =~ s/^"//;     # Remove leading double-quotes
      $value =~ s/"$//;     # Remove trailing double-quotes
      $vars{$key} = $value;
    } 
    
    for my $key (sort keys %vars) {
      print "$key has value $vars{$key}\n";
    }
    
    print "CLIENT says $vars{CLIENT}\n";
    
    __DATA__
    $CHUNK_QTY = "50000";
    $CLIENT = "hi all";
    $CLIENT_CODE = "NMB";
    $COMPOSER = "DIALOGUE";
    $CONTROL_FILE_NAME = "NMBM725.XML";
    $COPY_BASE = "01";
    $CSITE = "NSH";
    $DATA_TYPE = "MET";
    $DIALOGUE_VERSION = "V7R0M624";
    $DISABLE = "N";
    $DPI = "300";
    $DP_BAR_START = "A";
    $DP_BAR_STOP = "Z";
    $DUPLEX = "N";
    $Dialogue_Version = "V7R0M624";
    $EMAIL_ERROR = "Y";
    $EMAIL_ON = "N";
    

    There should be enough here to get you started, but you’ll need to read up on how to open an actual file (instead of using the __DATA__ section as I did here) for yourself. I recommend checking perldoc open for examples and full details.

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

Sidebar

Related Questions

I have a CMakeLists.txt file that looks like this: add_executable(exec1 exec1.c source1.c source2.c source3.c)
I have a ID.txt file that looks like this: http://something.net/something-ak/41389_718783565_1214898307_q.jpg http://something.net/something-ak/372142_106502518141813_1189943482_q.jpg and so on
I have a file like this. rm a.txt mkdir foo cp a.doc docs I
I have an array of file path components like this: [ ['some', 'dir', 'file.txt'],
I'm creating a Shell Script, and I have a file like this called expressions.txt
So I currently have this code to read an accounts.txt file that looks like
I have txt file with content like this /home/username/Desktop/folder/folder3333/IMAGw488.jpg /home/username/Desktop/folder/folder3333/IMAG04f88.jpg /home/username/Desktop/folder/folder3333/IMAGe0488.jpg /home/username/Desktop/folder/folder3333/IMAG0r88.jpg /home/username/Desktop/folder/folder3333/ /home/username/Desktop/folder/
I have rjecnik.txt file that looks like this mate sime, jure stipica gujo, prvi
I have a txt file like this: 5 1 3 6 9 I want
I have a .txt file that is like this: Title: Test Author: zad0xsis Date:

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.