Ask Question Forum:
Model Library:2025-02-08 Updated:A.I. model is online for auto reply question page
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by pvinodp
at 2024-08-08 07:19:09
Point:500 Replies:6 POST_ID:828714USER_ID:11610
Topic:
Linux;Perl Programming Language;Shell Scripting
I have a hash variable in perl
my %myhash = {};
# many values are written to it.
#Some values are like string1 , string2 , string3
push (@{myHash{$key} }, $value);
now in the same file I have to call a shell script
system "/pathToShellScript/xyz.sh" , $myHash{"myArray"};
How do i access each string [comma separated] within the shell script?
my %myhash = {};
# many values are written to it.
#Some values are like string1 , string2 , string3
push (@{myHash{$key} }, $value);
now in the same file I have to call a shell script
system "/pathToShellScript/xyz.sh" , $myHash{"myArray"};
How do i access each string [comma separated] within the shell script?
Author: pvinodp replied at 2024-08-26 23:40:50
thanks all. I have been unblocked with your help
Assisted Solution
Expert: wilcoxon replied at 2024-08-09 08:16:07
250 points EXCELLENT
If the hash is valid and the value of THREE_IP is the arrayref (indicated by your "push @" statement) of '9.9.9.9,8.8.8.8' (plus possibly other values), my original suggestion will work fine:
Accepted Solution
Expert: ozo replied at 2024-08-09 07:18:42
250 points EXCELLENT
myHASH = {ONE_IP}->{9.9.9.9}
{TWO_IP}->{9.9.9.9}
{THREE_IP}->{9.9.9.9,8.8.8.8}
does not look like valid perl code
what do you get with
print "@{$myHash{THREE_IP}}";
or
{local $"=","; system "/pathToShellScript/xyz.sh","{@{$myHash{THREE_IP}}}";
{TWO_IP}->{9.9.9.9}
{THREE_IP}->{9.9.9.9,8.8.8.8}
does not look like valid perl code
what do you get with
print "@{$myHash{THREE_IP}}";
or
{local $"=","; system "/pathToShellScript/xyz.sh","{@{$myHash{THREE_IP}}}";
Author: pvinodp replied at 2024-08-09 07:08:29
okay I will explain how my hash looks like
myHASH = {ONE_IP}->{9.9.9.9}
{TWO_IP}->{9.9.9.9}
{THREE_IP}->{9.9.9.9,8.8.8.8}
Now I have to pass the value to the shell script whose key is THREE_IP.
I executed== system /pathTOMYShell/xyz.sh , $myHash{"THREE_IP"};
in my shell script I receive it as $1.
I echo it to see what I got, I get vector X290943845...
How do i get the string {9.9.9.9,8.8.8.8} here?
myHASH = {ONE_IP}->{9.9.9.9}
{TWO_IP}->{9.9.9.9}
{THREE_IP}->{9.9.9.9,8.8.8.8}
Now I have to pass the value to the shell script whose key is THREE_IP.
I executed== system /pathTOMYShell/xyz.sh , $myHash{"THREE_IP"};
in my shell script I receive it as $1.
I echo it to see what I got, I get vector X290943845...
How do i get the string {9.9.9.9,8.8.8.8} here?
Expert: duncanb7 replied at 2024-08-08 07:40:26
it seems you topic is similar to this link ?
http://stackoverflow.com/questions/2911192/how-can-i-process-a-perl-array-element-in-a-shell-script
http://stackoverflow.com/questions/2911192/how-can-i-process-a-perl-array-element-in-a-shell-script
Expert: wilcoxon replied at 2024-08-08 07:37:54
I don't follow the "comma separated" paren in your question. Are you saying you want to retrieve string2 separate from string1 or string3 (which requires another change to your code) or that you want to retrieve "string1, string2, string3" as a single argument?
That will pass an array reference - no idea if/how to get that in the shell. If you do:
That will pass an array reference - no idea if/how to get that in the shell. If you do:
then you should be able to reference the strings as normal arguments in your shell script. Each shell handles arguments a little differently (and you don't say which you are using). Most common is $1 $2 $3 $4 ... but some allow things like $argv[x] or other constructs.
If you do want to get string2 by itself, then you need to change your push line to: