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
These might work for you. I noted my assumptions with each line.
I assume that you wanted a sparse array. Hashes are the standard implementation of sparse arrays in Perl.
I assume that you still wanted to use the environment variable
SSH_CLIENTYou want the last set of digits from the
'.'to the end.As for your question in the comments, you can get the variable out of the hash, by: