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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:50:22+00:00 2026-05-17T19:50:22+00:00

I have these three lines in bash that work really nicely. I want to

  • 0

I have these three lines in bash that work really nicely. I want to add them to some existing perl script but I have never used perl before ….

could somebody rewrite them for me? I tried to use them as they are and it didn’t work

note that $SSH_CLIENT is a run-time parameter you get if you type set in bash (linux)

users[210]=radek       #where 210 is tha last octet from my mac's IP
octet=($SSH_CLIENT)    # split the value on spaces 
somevariable=$users[${octet[0]##*.}]        # extract the last octet from the ip address
  • 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-17T19:50:22+00:00Added an answer on May 17, 2026 at 7:50 pm

    These might work for you. I noted my assumptions with each line.

    my %users = ( 210 => 'radek' ); 
    

    I assume that you wanted a sparse array. Hashes are the standard implementation of sparse arrays in Perl.

    my @octet = split ' ', $ENV{SSH_CLIENT}; # split the value on spaces
    

    I assume that you still wanted to use the environment variable SSH_CLIENT

    my ( $some_var ) = $octet[0] =~ /\.(\d+)$/; 
    

    You want the last set of digits from the '.' to the end.

    • The parens around the variable put the assignment into list context.
    • In list context, a match creates a list of all the “captured” sequences.
    • Assigning to a scalar in a list context, means that only the number of scalars in the expression are assigned from the list.

    As for your question in the comments, you can get the variable out of the hash, by:

    $db = $users{ $some_var };
    
    # OR--this one's kind of clunky...
    
    $db = $users{ [ $octet[0] =~ /\.(\d+)$/ ]->[0] };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an iphone app where I call these three functions in appDidFinishLaunching: glMatrixMode(GL_PROJECTION);
Anyone have any comparative thoughts on these three technologies? Each addresses a different VM,
I have writtent some Oracle storedprocedures in these there are more then 20 input
I have been under the impression that processes on the operating system have three
I have a C file running on Linux. It prints some lines in red
I would like to extract some lines from a text file, I have started
I have a script that appends some rows to a table. One of the
I have a bash script that does several tasks, including python manage.py syncdb on
Is there a way to have a statement across multiple lines without the underscore
is there an easy away to combine fields in awk? Specifically, I have lines

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.