10-06-2009
perl - how can we name a variable base on value of another variable
Hey all,
perl - how can we name a variable base on the value of another variable?
for example in ksh/bash we do :
export c="100"
export x`echo $c`=2000
echo $x100
x100=2000
is it possible to do something similar for perl?
I already tried many ways but nothing is working.
I am trying to solve a issue in an perl script and the solution that i am trying to do should have different variables.
Can someone please help me on this?
Thanks in advance.
Carlos
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I need a non-perl (bash) way to strip the path from a list of "find" results. Below is the perl version which I could use, if I could figure out how to call the script with a variable (like in sh, $1 is the variable passed in ./script variable)
$file = "/path/to/file.txt";
# How do I... (2 Replies)
Discussion started by: TheCrunge
2 Replies
2. Shell Programming and Scripting
Hi All,
I am trying to convert the below Csh while loop into Perl while loop but the problem is that in this csh script, i have 2 variables inside a variable -> $count is a variable {SB$count} as a whole is another variable. Csh is able to assign values to such variable like the below but i do... (3 Replies)
Discussion started by: Raynon
3 Replies
3. UNIX for Dummies Questions & Answers
hi,
i'm trying to create a script in ksh that will check build logs for errors.
i'm using a variable to hold the grep, somthing like:
grepErr=`echo "grep -i -e ' error ' -e ' errors ' -e 'rror(s)' -e 'Unsatisfied ' -e 'Undefined symbol' -e 'No rule ' -e 'Cannot' -e 'rror:' -e 'Could not find... (2 Replies)
Discussion started by: lavinia_f
2 Replies
4. Shell Programming and Scripting
hi i have following code
my $a1 = "A" ;
my $a2 = "B" ;
my $a3 = "C" ;
foreach my $k ( 1,2,3 )
{
my $msg = ${a{$k}} # this should be at runtime i am creating variable a1 and assigning it value to msg .
print "$msg\n" ;
}
above thing is not working !!!
i want when k = 1... (4 Replies)
Discussion started by: zedex
4 Replies
5. Shell Programming and Scripting
hi there, I have a question about a snippet of code i have which runs localtime() to convert the current date/time into a mysql happy format
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
printf "%4d-%02d-%02d ... (4 Replies)
Discussion started by: rethink
4 Replies
6. Shell Programming and Scripting
Hi all,
I have a variable say var1 (output from somewhere, which I can't change)which store something like this:
echo $var1
name=fred
age=25
address="123 abc"
password=pass1234
how can I make the variable $name, $age, $address and $password contain the info?
I mean do this in a... (1 Reply)
Discussion started by: freddy1228
1 Replies
7. Shell Programming and Scripting
Hi,
I want to count the number of occurences of a character in a string variable ($str). The character is stored in a another variable ($sepchr). I am using tr as :
$count = ($str =~ tr/$sepchr//);
This did not work. I found in another thread about using eval. I used eval as :
... (13 Replies)
Discussion started by: sinpeak
13 Replies
8. Shell Programming and Scripting
Hi,
I have the following lines that I would like to see in an array for easy comparisons and printing:
Example 1:
field1,field2,field3,field4,field5
value1,value2,value3,value4,value5Example 2:
field1,field3,field4,field2,field5,field6,field7... (7 Replies)
Discussion started by: ejdv
7 Replies
9. Shell Programming and Scripting
Hi, guys, i have a script i inherited from a coworker but i'm not perl savy. The script works but i would like it to work better. I want to run this command
./ciscomgrtest.pl -r "show version" -h hosts.router
and have the script goto each router in the hosts.router file and run the command... (2 Replies)
Discussion started by: whipuras
2 Replies
10. Shell Programming and Scripting
In PERL , $0 variable displays program name ( if we use inside script) .likewise is there a way to display program name and it's arguments passed to script .
e.g.
test.pl -a1 -b3 -c4
inside test.pl , if I use $0 , it gives me test.pl ..but I am looking for command to get complete program... (1 Reply)
Discussion started by: talashil
1 Replies
shift(1) User Commands shift(1)
NAME
shift - shell built-in function to traverse either a shell's argument list or a list of field-separated words
SYNOPSIS
sh
shift [n]
csh
shift [variable]
ksh
* shift [n]
DESCRIPTION
sh
The positional parameters from $n+1 ... are renamed $1 ... . If n is not given, it is assumed to be 1.
csh
The components of argv, or variable, if supplied, are shifted to the left, discarding the first component. It is an error for the variable
not to be set or to have a null value.
ksh
The positional parameters from $n+1 $n+1 ... are renamed $1 ..., default n is 1. The parameter n can be any arithmetic expression that
evaluates to a non-negative number less than or equal to $#.
On this man page, ksh(1) commands that are preceded by one or two * (asterisks) are treated specially in the following ways:
1. Variable assignment lists preceding the command remain in effect when the command completes.
2. I/O redirections are processed after variable assignments.
3. Errors cause a script that contains them to abort.
4. Words, following a command preceded by ** that are in the format of a variable assignment, are expanded with the same rules as a vari-
able assignment. This means that tilde substitution is performed after the = sign and word splitting and file name generation are not
performed.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Availability |SUNWcsu |
+-----------------------------+-----------------------------+
SEE ALSO
csh(1), ksh(1), sh(1), attributes(5)
SunOS 5.10 15 Apr 1994 shift(1)