First thing I noticed, was that you would echo out $Cat_name. You didn't define Cat_name. The other thing I did was to add another \ to the sed statement, along with the -e option... Hope that helps...
Hi everyone,
I have a simple question to ask :
In a script that I'm writting, I need to create variables on-the-fly.
For instance, for every iterartion of the following loop a var_X variable should be generated :
#!/bin/ksh
a="1 2 3"
for i in $a
do
var_${i}=$i
echo "${var_$i}"
done
... (1 Reply)
I have run into a wall with my iptables firewall scripting.
I am blocking all of the private side IP addresses on the
WAN interface on systems running NAT. However, if the
system is not running NAT and needs to allow access to
the local LAN on the WAN interface, I need to block all
but one of... (2 Replies)
Hello,
i have another sed question.. I'm trying to do variable substition with sed and i'm running into a problem.
my var1 is a string constructed like this:
filename1 filerev1 filepath1
my var2 is another string constructed like this:
filename2 filerev2 filepath2
when i do... (2 Replies)
Hi,
That might be pretty simple.
How can I generate a variable name and get their value ?
Thanks a lot.
Something like:
>CUSTOMER_NF=26
> object=CUSTOMER
> echo ${object}_NF
CUSTOMER_NF
> echo ${${object}_NF}
ksh: ${${object}_NF}: 0403-011 The specified substitution is... (7 Replies)
file1.ksh
#!/bin/ksh
test5_create="I am a man" # test5 will be dynamic and the value will be passed from command line
a=${1}_create
echo $a # i need the output as "I am a man"
./file1.ksh test5 # i run the script like this
any suggessions guys... (1 Reply)
Hi ,
I have a variable as follows,
Temp=`cat ABC.txt | cut -c5-`
This will yeild a part of the date. say , 200912.
I would like to substitute this variable's value in a filename.
eg: File200912F.zip
when i say File$TempF.zip , it is not substituting.
Any help ?
Thanks in... (2 Replies)
For example I have variable like below
echo $OUTPUT
/some/path/`uname -n`
when I try to use the variable OUTPUT like below
cd $OUTPUT or cd ${OUTPUT}
I am getting bad substituion error message
$ cd $OUTPUT
ksh: cd: bad substitution
$ cd ${OUTPUT}
ksh: cd: bad substitution
... (1 Reply)
Hi,
I have to write a shell script in which I have to substitute a variable within a variable. For example,
var1=aaa
var2=file.$var1.txt
The output should be,
echo $var2
file.aaa.txt
Can someone please help me in getting this. I tried using eval, but it didnt work. I might be using it... (2 Replies)
Allright so a quick question.
I'm building a script that will eventually do a full IP subnet scan.
It starts off by first entering an IP address, (capturing host and net ID comes after that) and I want it to use the current IP address if no input is given.
Is there a quick way to define the... (1 Reply)
Hi all,
I have a script with the following gist:
declare -a index=(0 1 2 3 4);
declare -a animals=(dog cat horse penguin cow);
declare -a fruits=(orange apple grapes peach mango);
declare -a drinks=(juice milk coffee tea coke);
declare -a cities=(toronto paris london glasgow... (18 Replies)
Discussion started by: Kingzy
18 Replies
LEARN ABOUT DEBIAN
padwalker
PadWalker(3pm) User Contributed Perl Documentation PadWalker(3pm)NAME
PadWalker - play with other peoples' lexical variables
SYNOPSIS
use PadWalker qw(peek_my peek_our peek_sub closed_over);
...
DESCRIPTION
PadWalker is a module which allows you to inspect (and even change!) lexical variables in any subroutine which called you. It will only
show those variables which are in scope at the point of the call.
PadWalker is particularly useful for debugging. It's even used by Perl's built-in debugger. (It can also be used for evil, of course.)
I wouldn't recommend using PadWalker directly in production code, but it's your call. Some of the modules that use PadWalker internally are
certainly safe for and useful in production.
peek_my LEVEL
peek_our LEVEL
The LEVEL argument is interpreted just like the argument to "caller". So peek_my(0) returns a reference to a hash of all the "my"
variables that are currently in scope; peek_my(1) returns a reference to a hash of all the "my" variables that are in scope at the
point where the current sub was called, and so on.
"peek_our" works in the same way, except that it lists the "our" variables rather than the "my" variables.
The hash associates each variable name with a reference to its value. The variable names include the sigil, so the variable $x is
represented by the string '$x'.
For example:
my $x = 12;
my $h = peek_my(0);
${$h->{'$x'}}++;
print $x; # prints 13
Or a more complex example:
sub increment_my_x {
my $h = peek_my(1);
${$h->{'$x'}}++;
}
my $x=5;
increment_my_x;
print $x; # prints 6
peek_sub SUB
The "peek_sub" routine takes a coderef as its argument, and returns a hash of the "my" variables used in that sub. The values will
usually be undefined unless the sub is in use (i.e. in the call-chain) at the time. On the other hand:
my $x = "Hello!";
my $r = peek_sub(sub {$x})->{'$x'};
print "$$r
"; # prints 'Hello!'
If the sub defines several "my" variables with the same name, you'll get the last one. I don't know of any use for "peek_sub" that
isn't broken as a result of this, and it will probably be deprecated in a future version in favour of some alternative interface.
closed_over SUB
"closed_over" is similar to "peek_sub", except that it only lists the "my" variables which are used in the subroutine but defined
outside: in other words, the variables which it closes over. This does have reasonable uses: see Data::Dump::Streamer, for example (a
future version of which may in fact use "closed_over").
set_closed_over SUB, HASH_REF
"set_closed_over" reassigns the pad variables that are closed over by the subroutine.
The second argument is a hash of references, much like the one returned from "closed_over".
var_name LEVEL, VAR_REF
var_name SUB, VAR_REF
"var_name(sub, var_ref)" returns the name of the variable referred to by "var_ref", provided it is a "my" variable used in the sub. The
"sub" parameter can be either a CODE reference or a number. If it's a number, it's treated the same way as the argument to "peek_my".
For example,
my $foo;
print var_name(0, $foo); # prints '$foo'
sub my_name {
return var_name(1, shift);
}
print my_name($foo); # ditto
AUTHOR
Robin Houston <robin@cpan.org>
With contributions from Richard Soberberg, Jesse Luehrs and Yuval Kogman, bug-spotting from Peter Scott, Dave Mitchell and Goro Fuji, and
suggestions from demerphq.
SEE ALSO
Devel::LexAlias, Devel::Caller, Sub::Parameters
COPYRIGHT
Copyright (c) 2000-2009, Robin Houston. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified
under the same terms as Perl itself.
perl v5.14.2 2012-06-26 PadWalker(3pm)