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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:24:53+00:00 2026-05-24T21:24:53+00:00

I have a request for some advice on how to approach this script I

  • 0

I have a request for some advice on how to approach this script I want to write in Perl. Basically I have a file that looks like :

  id: 1
  Relationship: ""
  name: shelby
  pet: 1
  color:4

There are certain keywords such as pet and color that have numbers after then. I want to be able to take in a file and look for these keywords (there are 5 or 6 of them) and then change the number to the word that number corresponds to. That is to say for the keyword “Pet”—> 0 =dog, 1 = cat, 2=fish. And for the keyword “color” 0 = red, 1=blue,2=purple,3=brown,4=white. The script should find and change these numbers. The goal should be an output file that looks like:

      id: 1
      Relationship: ""
      name: shelby
      pet: cat
      color:white

I’ve been struggling with how to do this for a while. I looked up online maybe I could do an array of hashes or something but I’m relatively new to Perl and don’t know exactly how to even approach this problem…. Any advice would be much appreciated!

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-05-24T21:24:54+00:00Added an answer on May 24, 2026 at 9:24 pm

    Usage: script.pl file.txt > output.txt

    use strict;
    use warnings;
    
    my %tags = (
        "pet" => [ qw(dog cat fish) ],
        "color" => [ qw(red blue purple brown white) ],
    );
    
    my $rx = join '|', keys %tags;
    
    while (<>) {
        s/^\s*($rx):\s*(\d+)/$1: $tags{$1}[$2]/;
        print;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a request for some contract work from an organization that uses Excel
I have a website that i did some time ago now they request some
I have a web request that can take 30-90 seconds to complete in some
We have some legacy ASP.NET code that detects if a request is secure, and
I have some code that gets the current logged in user. userID = request.session.get(_auth_user_id)
I have an jQuery JSON request, that loads some JSON from another server (ex.
I would like some advice. I have encountered the following error in Python 2.6:
Ok I have to parse out a SOAP request and in the request some
I'm using httpc:request to post some data to a remote service. I have the
I have written some jQuery ajax code where I am sending a request to

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.