You will have to use "eval", because variable expansion is done in one step in the shell and you need a two-time expansion: you need to expand "A_$MYHOST" to "A_HOSTNAME" and then "$A_HOSTNAME[<nr>]" to the value. See this post for a detailed explanation.
The following example code should tell you what you need:
I am trying to reference a two dimensional array in a
subroutine and can't seem to figure this one out in Perl.
Does anybody know? Please enlighten me.
#!/usr/bin/perl -w
use constant DIM => 4;
sub Shift_elements_right{
my (@Input, @Output) = @_;
for ($i = 0 ; $i <= DIM ;... (5 Replies)
I've created a series of arrays named as follows:
row1
row2
row3
.
.
.
row10
Each has 4 elements.
I'm trying to echo the array elements out in a for loop. Here's what I have:
for ((i=1;i<=10;i++))
do
for ((j=1;j<=4;j++))
do
eval out=${row`echo $i`}
echo -n $out (3 Replies)
I've made a habit of including a four-letter "tail" on image file names I download from the Web, so I can both match them with IPTC Transmission References of my own making and rename them later using either a GUI renamer or a script I've written myself. Now I want to automate the process of... (2 Replies)
Hello All,
I am having this issue...where I am actually having hard time understanding the problem:
The code is as follows:
#include<iostream.h>
void fxn(char*** var)
{
int i =4;
*var = (char**)malloc(i*sizeof(char*));
for(int j =0; j<4; j++)
{
*var = "name";
cout<<*var;... (6 Replies)
Here is the question...
Create a new script, sub2, taking three parameters...
1.) the string to be replaced
2.) the string with which to replace it
3.) the name of the file in which to make the substitution
...that treats the string to be replaced as plain text instead of as a regular... (1 Reply)
Guys,
May i know how can we de reference the code reference variable.?
my $a = sub{$a=shift;$b=shift;print "SUM:",($a+$b),"\n";};
print $a->(4,5);
How can we print the whole function ?
Please suggest me regarding this.
Thanks for your time :)
Cheers,
Ranga :) (0 Replies)
Hello, all
For a 1-dimensional array, such as
myarr_1=1
myarr_1=2
myarr_1=3I know I can write a loop as below to show the array member one by one:
for (i in myarr_1){print i, myarr_1}Now, suppose I have a two dimensional array such as:
myarray_2=1 myarray_2=2
myarray_2=10 myarray_2=20My... (3 Replies)
Discussion started by: littlewenwen
3 Replies
LEARN ABOUT DEBIAN
log::dispatch::array
Log::Dispatch::Array(3pm) User Contributed Perl Documentation Log::Dispatch::Array(3pm)NAME
Log::Dispatch::Array - log events to an array (reference)
VERSION
version 1.001
SYNOPSIS
use Log::Dispatch;
use Log::Dispatch::Array;
my $log = Log::Dispatch->new;
my $target = [];
$log->add(Log::Dispatch::Array->new(
name => 'text_table',
min_level => 'debug',
array => $target,
));
$log->warn($_) for @events;
# now $target refers to an array of events
DESCRIPTION
This provides a Log::Dispatch log output system that appends logged events to an array reference. This is probably only useful for testing
the logging of your code.
METHODS
"new"
my $table_log = Log::Dispatch::Array->new(\%arg);
This method constructs a new Log::Dispatch::Array output object. Valid arguments are:
array - a reference to an array to append to; defaults to an attr on
$table_log
array
This method returns a reference to the array to which logging is being performed.
log_message
This is the method which performs the actual logging, as detailed by Log::Dispatch::Output.
AUTHOR
Ricardo Signes, "<rjbs@cpan.org>"
BUGS
Please report any bugs or feature requests through the web interface at <http://rt.cpan.org>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
COPYRIGHT
Copyright 2008 Ricardo SIGNES, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
perl v5.10.1 2008-04-29 Log::Dispatch::Array(3pm)