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

  • Home
  • SEARCH
  • 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 8065887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:48:38+00:00 2026-06-05T11:48:38+00:00

I have to modify some Perl scripts for a piped run and write a

  • 0

I have to modify some Perl scripts for a piped run and write a wrapper script to run them with a given set of input parameters. Before I can do that, I have to understand what is going in the first program. I need help deciphering this code:

# declare and initialise an empty hash
my %to_keep= ();

# an array
@line = ('some\one', 'two', 'three', 'four');

# trim the identifier
$line[0]=~s/\/[1]$//;

# store this into an array
@{$to_keep{$line[0]}{'1'}}=($line[1],$line[2]);
print @;

I’m familiar with the perl substitute function, s///. It goes:

s/text-regex_to_be_replaced/replacement/modifier. 

However, I’m not too sure what the code above is doing. If I understand correctly, it replaces every occurrence of of ‘\’ with line[1], until the end of the string (indicated by the ‘$/’). Is this correct?

The other part I’m unsure about is the code below the ‘store’ comment. I think it’s storing a hash of array into an array. Can someone explain how the code works and what it prints out given the variables? Also, how can I retrieve the data I store in the array?

Bonus question: Can someone explain how modifying a perl script for a piped run works?

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-05T11:48:39+00:00Added an answer on June 5, 2026 at 11:48 am

    hmm, this is wired.

    s/\/[1]$//; 
    

    would will only match and remove /1 at the end of a string. So in your example it has no influence.

    @{$to_keep{$line[0]}{'1'}}=($line[1],$line[2]);
    

    broken down, on the left side you got
    $to_keep{'some\one'}{1} which is undefined in the example! But if we say it would give you the value foo, then you take this value and replaces in to @{foo} which basically means use the value foo as the array name, hence @foo.

    on the right side you save the second and third element of $line as a list into this variable name, @foo.

    If we ignore the undefined and try to guess the intention, you got a script that defines its own variable names. Using the first element of list as the variable name, and setting it equal to the rest of the list

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

Sidebar

Related Questions

I have a perl script using CGI. The browser calls it with some parameters.
I'm using a Perl script to modify some files inside a .tar, and the
If I have a set method in which I want to modify some values,
I have to modify some code in a application I am working on that
I have a command line that I'm trying to modify to remove some of
I have some filter and one grid.And grid have some buttons like modify/edit.I am
I have implemented an application for modify the xml layout with some properties. I
I have an app that can make modify images. In some cases, this makes
I need to write some scripts to carry out some tasks on my server
I have a small awk script that does some in-place file modifications (to 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.