UNIX Script - snipet meaning?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers UNIX Script - snipet meaning?
# 1  
Old 09-18-2014
UNIX Script - snipet meaning?

What would the below code snippet mean?

Code:
my ($_configParam, $_paramValue) = split(/\s*=\s*/, $_, 2);
    $configParamHash{$_configParam} = $_paramValue;


Last edited by Scrutinizer; 09-18-2014 at 08:17 AM.. Reason: CODe tags
# 2  
Old 09-18-2014
Quote:
Originally Posted by MaKha
What would the below code snippet mean?
That depends on what language this is supposed to be. It is definitely no UNIX shell script language that i know of. My best guess is that it is PERL, which is common on UNIX systems but in fact ubiquitous.

I hope this helps.

bakunin
# 3  
Old 09-18-2014
It's definitely PERL code and it's generating key/value pairs and putting them in a PERL hash.
I'd also say this snippet was found within a loop which was reading from a file while $_ is representing the current line.
The split part splits the current line in 2 pieces putting the stuff before "=" sign in the $_configParam variable and the stuff after the "="
sign in the $_paramValue variable.

I replaced $_ with a fixed string and created a small demonstration code:
Code:
#!/usr/bin/perl

use strict;
use warnings;

my $string="param 1=value1 value2 value3";
my %configParamHash;

my ($_configParam, $_paramValue) = split(/\s*=\s*/, $string, 2);

print "Accessing PERL variables:\n";
print "\$_configParam: $_configParam\n";
print "\$_paramValue: $_paramValue\n";

$configParamHash{$_configParam} = $_paramValue;

print "Accessing PERL hash through key 'param 1':\n";
print "$configParamHash{'param 1'}\n";

Code:
$ ./perltest.pl
Accessing PERL variables:
$_configParam: param 1
$_paramValue: value1 value2 value3
Accessing PERL hash through key 'param 1':
value1 value2 value3
$

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

What is the meaning of ## in UNIX shell script?

Hi All, I am new to unix shell scripting and I was documenting one of the unix script and encountered below statements - for ii in `ls -1rt /oracle/admin/MARSCOPY/ext_files/fpm-ifpm/*.small.txt | tail -1 | awk '{print $1}'` do smallssim=${ii##/oracle/admin/MARSCOPY/ext_files/fpm-ifpm/}... (2 Replies)
Discussion started by: shuklajayb4
2 Replies

2. UNIX for Dummies Questions & Answers

Meaning of awk script

what does this mean? awk '!a||a>$1 {a=$1} END {for (i in a) print a,i}' file (6 Replies)
Discussion started by: osama ahmed
6 Replies

3. Shell Programming and Scripting

Meaning of each term in stty -a in unix

Hi, Can someone help me with the meaning of each term in the below command in unix: stty-aRegds, I have searched google for a lot for this, but didnt get any success in this. Kunwar (2 Replies)
Discussion started by: kunwar
2 Replies

4. Shell Programming and Scripting

Meaning of '$#' in Unix

All, In the below mentioned piece of code : if test $# -eq 1 then echo "Input parameter passed into DMI_weekly.ksh..." | tee -a $RUNLOG typeset -u ORACLE_SID export ORACLE_SID="$1" else echo "ERROR 060: Arguments passed... (3 Replies)
Discussion started by: Oracle_User
3 Replies

5. UNIX for Dummies Questions & Answers

meaning of script

hello every one i want to know meaning of following line INST_PARA=$HOME/install/Install.Para SAVEMEDIUM=`awk '$2=="ArchiveSave"{print$4}' $INST_PARA` (4 Replies)
Discussion started by: kaydream
4 Replies

6. Shell Programming and Scripting

Meaning of this line in script

Can anyone explain me the meaning of line #2 in these lines of shell script: if ; then ${EXPR} " ${MACTIONS } " : ".* ${ACTION} " >/dev/null 2>&1 || die "$USAGE" else Sorry in case this is a trivial thing (I am not an expert in this). (3 Replies)
Discussion started by: radiatejava
3 Replies

7. UNIX for Dummies Questions & Answers

Oot: Level 2 Unix Support? meaning

Hi all, I am sorry, I know this is not correct forum/silly question (usually this is requirement in some vacancies), but i hope someone can explain to me, what is the meaning of : SUN Tier 3 Support Tier 3 Application Installation Level 2 Solaris Level 2 AD MOM + DBA Thank you. (0 Replies)
Discussion started by: blesets
0 Replies

8. Programming

C snipet on char Pointers

I have small Dout. please respond. char *p; p=" I am a Very good boy"; Is this valid or not? If not valid why is it so? It is not giving any compilation error. Thanks Vinod (3 Replies)
Discussion started by: gandhevinod
3 Replies

9. UNIX for Dummies Questions & Answers

Meaning of ; in UNIX file?

Hello. I'm looking at a file that has a ; at the beginning of certain lines. Could someone please tell me what that means? Is it a comment? Is it an execute? Thank You (1 Reply)
Discussion started by: willdaw3
1 Replies

10. UNIX for Dummies Questions & Answers

Meaning of unix-rt ldp file type

Hello I was wondering what this file type means... assuming it is some type of data. Is ldp - Linux Doc Program? What type of program would be used to read or interpret this file type? As you can see I'm not a developer, and don't review these types of files. But would like to view... (1 Reply)
Discussion started by: jfmrts
1 Replies
Login or Register to Ask a Question