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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:58:32+00:00 2026-05-17T14:58:32+00:00

I am writing a Perl script which does this : Reads the values of

  • 0

I am writing a Perl script which does this :

  1. Reads the values of the environment variables a to z in a loop.
  2. Depending on the value of the environment variables, generates a result file similar to

    a - 1,2,3,4
    b - a,b,c
    c - $234.34,$123.12
    keyword1 %a%
    keyword2 %b%
    keyword3 %c%
    

    The point to note is that all the declarations have to come before the usages.

  3. The problem is that for example I read a, and generate this result file

    a - 1,2,3,4
    keyword3 %c%
    

    Now when I read b , I need the result file to look like this

    a - 1,2,3,4
    b - a,b,c
    keyword1 %a%
    keyword2 %b%
    

How should I do this using Perl?

One way I can think of is to generate two different files – one with the declarations and other with the usages, and then concatenate the files at the end of execution of the script.

Is there a better way?

  • 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-17T14:58:33+00:00Added an answer on May 17, 2026 at 2:58 pm

    No need for separate files. Accumulate the declarations and usages in two different array variables, @declarations and @usages. After you’ve read all your environment variables and determined the contents of the two arrays, print them:

    say for @declarations;
    say for @usages;
    

    You might even be able to omit the first array. Once you figure out what a declaration should be, print it out immediately. You only need to accumulate the usages until you know there will be no more declarations.

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

Sidebar

Related Questions

I'm writing a Perl script and would like to use a n-ary tree data
I'm writing a Perl script and I've come to a point where I need
I am writing a perl script that manipulates password protected zip files. Consequently I
I'm writing some tests in Perl which have a fair amount of set up.
My current project involves writing Perl code inside a Solaris VMWare appliance (hosted on
I am writing a Perl module, and I am using carp to throw a
I've been benchmarking the performance of a framework I'm writing in Perl and I'm
I'm writing my first Perl app -- an AOL Instant Messenger bot that talks
I'm writing a basic planet viewer OpenGL Perl application, just for fun. I have
I am writing a JSON response from a perl/cgi program. The header's content type

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.