Programming :: Perl - Pointers To Arrays From Hashes?

Feb 18, 2010

I'm trying to figure out how to code for this specific type of instance - I want to use a hash and have the key be a reference to an array, and not use the key in the standard way of it being a scalar. Basically, I have a large output that I need to process line by line, and rather have access to it as an array than a big block in a scalar. For the big block hash as a scalar I would do -

Code:
foreach $CONTROLLER (<CONTROLLER_LIST>) {
$ALL_DISKS{$CONTROLLER} = `ssh -n <commands>`;
}

Now I know I could take the scalar and split it to another array after the fact like -

Code:
@TEMP_HOLD = split (/s+/,$ALL_DISKS{$CONTROLLER});

How would I code it that I would have access to the key information as an array and not a scalar? I know it needs to be a pointer and we're going to have -> in there somewhere, but not sure how to approach it. Some of the documentaiton I've been reading about referencing I've found a little confusing so far, and trying to figure out how to use them in context of what I'm working on.

View 1 Replies


ADVERTISEMENT

Programming :: Arrays In The C Programming Language Are Pointers To The First Element Of The Array?

Mar 27, 2010

I wonder why arrays in the C programming language are pointers to the first element of the array, not the first element of the array itself?

View 14 Replies View Related

Programming :: Sort Hash Of Hashes By Value In Perl?

Dec 1, 2010

I have a hash of hashes and I need to sort this by value and write to a javascript array file..Currently I am using the following

foreach my $key(sort { keys %{$trans{$a}} <=> keys %{$trans{$b}}} keys %transmission)
{
foreach my $role(sort {$trans{$key}{$a} cmp $trans{$key}{$b}} keys %{$trans{$key}})

[code]...

View 2 Replies View Related

Programming :: Perl - Store And Access An Array In A Hash Of Hashes?

Jul 7, 2010

I am in need of some syntax help. I'm trying to figure out how to store and retrieve an array out of a hash of hashes. For this example, I'm trying to access the city list for a particular state for a particular country. I understand I could do a join and split on the hash key to combine Country and State, but trying to keep things separated.The code I have gets in all the information for the Countries, and states, and gets the list of cities together, no problem. I store all the city names in an array, then make an anonymous pointer to the array for the hash, like this - $MY_CITIES{$COUNTRY}{$STATE} = [@CITIES]I believe that syntax is correct, or is it? What I'd like to do is I need to cycle through every hash to find if a city exists or not. If it exists in 3 states, then it should print 3 times. Here is the code block to search -

Code:
for $COUNTRY (@LIST_OF_COUNTRIES) {
for $STATE ( keys %MY_CITIES{$COUNTRY){$STATE} ) {

[code]...

View 4 Replies View Related

Programming :: Extracting Last Section Of File (Separated By Hashes)

Feb 22, 2011

I have a file which looks something like this:

##########
some
text
text also includes empty lines
##########
some
more
text
##########

Basically all sections are separated by 10 hashes and I need to somehow only print all lines in the last section (the "some more text" part in the example above"). I tried all kind of things with sed and awk but I didn't find any way to identify the last "section".

View 8 Replies View Related

Programming :: C With Gcc: Are All Variables Defined Like Pointers

Sep 13, 2010

i'm practicing in very basic c programs using the gcc compiler.I found that when i create two variables let's say

Code:

int a,b and Code: a=15;
b=3;
a=b;
b--;

then a equals 2.I thought that this isn't normal in C isn't it?I haven't had the time to read the gcc documentation yet...so i think it has something to do with my compiler's default settings.I use the

Code: gcc filename.c -o filename command to compile

Are all variables defined like pointers?

View 5 Replies View Related

Programming :: C - Segfault During Malloc. How To Use The Pointers

Mar 23, 2010

So the place where I'm having a problem is here:

Code:
typedef struct {
void **Mem_Chunk;

[code]...

View 10 Replies View Related

Programming :: Difference Between Two Arithmetic Pointers

Jun 1, 2010

What is the difference between *ptr++ and (*ptr)++. In my opinion the terminology is all over the place so if you could give an example it would be better.

View 8 Replies View Related

Programming :: Function Pointers To Class Members Cpp

May 23, 2010

i'm a bit stuck playing with the following class setup for glut. The actual issue is with the function pointers.Basically the following code is the opengl redbook cube example slightly modified.

View 2 Replies View Related

Programming :: Function Pointers With Variable Arguments

Jul 14, 2011

I need to call functions that match an input string (if input str = "func1", call func1), so I have this:

Code:
#include <stdio.h>
#include <string.h>
void function_a(void) { printf("Function A
"); }

[Code].....

In the above example, the functions take no input arguments. Can they take a different number of arguments, for example, function_a(int), function_c(int, int), function_e(int, char, int)? How can I do that?

View 3 Replies View Related

Programming :: Passing Local Variable Pointers In ASM

Apr 12, 2010

I want to know is there some more efficient way of passing a pointer to a local variable as a parameter to a function in x86 asm? Right now I have to move the base pointer to a temp register, subtract from the register and pass that, like this (assuming a local var at esp-4):

Code:
mov eax, ebp
sub eax, 4
push eax
Is there a better way?

View 8 Replies View Related

Programming :: Is Spacing As Used Non-factor When Declaring Pointers?

Jul 3, 2010

I've seen all three uses:

type * pointer
type *pointer
type* pointer

Are these 3 forms essentially the same, i.e., is the spacing as used here a non-factor when declaring pointers?

View 2 Replies View Related

Programming :: How To Pull Node Pointers Out Of The Model

Mar 25, 2010

I am trying to find a way to pull Node Pointers out of the model, for use in other areas of the program. The solution is probably simple but I haven't had any luck finding it.

Model for a QTreeView:

Code:

class testModel : public QAbstractItemModel
{
public:
testModel();
~testModel();

[code]....

View 2 Replies View Related

Programming :: Two Pointers, That Have The Same Address Point To Different Values?

Feb 17, 2011

I have the most strange problem ever in programming. I fork a process into a parent and a child. In every forked process i declare a pointer, malloc and define a different value for every pointer.When i printf the value and the address guess what? They both have the SAME ADDRESS but DIFFERENT values, as assigned..Here's the portion of my code:

pid = fork ();
switch (pid)
{

[code]....

View 8 Replies View Related

Programming :: Sizeof Struct With Function Pointers As A Member?

Jul 2, 2010

I following structure
typedef struct
{

[code]...

View 5 Replies View Related

Programming :: Adding Two Arrays?

Mar 1, 2010

I have a problem on a program,the problem take a very long time when i try to add two big arrays element by elementI know that matlab make adding vectors more faster than adding element by element but I don't know how!!!do any body knew how matlab make vectors operations more faster than element by element???I want to make my calculation more faster because the program is very big

View 8 Replies View Related

Programming :: Character Arrays In C?

Nov 3, 2010

I was reading Kernighan Ritchie book chapter 4 which deals with character pointers.I am not able to understand following different type of declarations

Code:
char aname[][15] = { "Illegal month", "Jan", "Feb", "Mar" };
char amessage[] = "now is the time";

[code]...

View 1 Replies View Related

Programming :: Using Of Arrays In Loops?

Sep 3, 2009

need to process files within multiple directories and transfer these to a remote server. What I had in mind was to use arrays for this; code pasted below (explains it better):

Code:
#set the arrays
array_A=( fileA* pathtodestA hostA passwordA )

[code]...

View 8 Replies View Related

Programming :: Double Pointers / Matrix GCC (fill It One Column With Zeros And The Other With Ones)

May 26, 2011

I have a 10x2 matrix, I create said matrix and fill it one column with zeros and the other with ones, now when I print the matrix I get this:

column 1:
0,0,0,0,0,0,0,0,1,1
column 2:
1,1,1,1,1,1,1,1,1,1

The first two rows of the second column are being replaced into the last two rows of the first column, now I even checked in visual studio and it works fine there. A friend tried my code and he gets it even worse:
column 1:

0,0,0,0,1,1,1,1,1,1
column 2:
1,1,1,1,1,1,1,1,1,1

As far as I've seen it must be a problem with GCC, unfortunately I need to have this up and running in GCC no matter what.

[Code].....

View 6 Replies View Related

Programming :: Can Diff Take Arrays As Input

Jun 19, 2010

Does diff not like arrays? How do achieve the following?

Code:

stuart@stuart:~/music transfer$ diff file1.txt file2.txt
1c1
< bonkers_in_phoenix.mp3

[code]....

View 14 Replies View Related

Programming :: Initializing Arrays In The Bash?

Mar 12, 2009

I'm making script for automated compiling of one program which would output builds optimized for many architectures. For clearancy, I do each build in it's own catalogue and list of builds with their respective catalogues would be stored as array. I'm using this guide as reference. It describes making array as naming a variable with additional brackets denoting it's position in array.

In my code, it looks exactly like this:

Code:

mtune[1]="build/mtune/athlon"
mtune[2]="build/mtune/athlon-4"
mtune[3]="build/mtune/athlon-mp"

[code]....

But upon invoking $mtune or any $mtune[x] variable, output is blank, like the variable(s) were never initialized. What am I doing wrong?

View 1 Replies View Related

Programming :: Printing 2 Arrays To 2 Columns?

Jun 16, 2010

I have a Perl script that has two arrays - they are related. I would like to print out the contents into two columns next to each other.

#!/usr/bin/perl
open(PINGFILE, </home/casper/pingdata.txt") or die " can not open file ";
my @totalfile=<PINGFILE>;
foreach $string(@totalfile) {
if ($string =~ m/(^1sping)(?=.*max))/) {
push(usecstring,"$string");

[Code]...

View 2 Replies View Related

Programming :: Structures And String Arrays, C?

Apr 18, 2011

I am working on a project that needs to use structures and I'm pretty sure string arrays. First I declare my structures and they must be exactly like this.

typedef struct
{
int hour;

[code]....

View 4 Replies View Related

Programming :: Create A Small Array Of 3x3 Arrays?

Jul 12, 2009

I'm trying to figure how to create an small array of 3x3 arrays such I can do

Code:

SUM1(i) = SUM1(i) + SUM2

where i goes from 1 to 8 and SUM2 is a 3x3 array.

View 2 Replies View Related

Programming :: Read Text File Using Arrays In C++?

Oct 19, 2010

a project using bluetooth to send data byte by byte to external devices buti'm not familiar using arrays to read file from another location before sending the data.If you could,do correct my codes.Here's my code,

void loop(){
char Msg[]={"Hello"};
char *start;

[code]...

View 2 Replies View Related

Programming :: Get Number Of Elements In A Hash Of Arrays?

Dec 10, 2008

I have something like this:

$arr_hash{'produce'}{'veggies'}[0] = Broccoli
$arr_hash{'produce'}{'veggies'}[1] = Cauliflower
$arr_hash{'produce'}{'veggies'}[2] = Carrots

[code]...

View 2 Replies View Related

Programming :: If Test Validation - Using Char Arrays

Jun 9, 2010

I'm writing a code to get the index of the last occurrence of a given substring in a string.

Code:
int StringHandler::lastIndexOf(string src, const string s) {
unsigned int lastIndex = string::npos;
if (src.find(s, 0) == string::npos) {
return -1; } else {
bool isLast = false; unsigned int i = 0; do {
lastIndex = src.find(s, i);
if (lastIndex != string::npos) { i = lastIndex + 1;
if (i == src.size()) { isLast = true;
} } else { isLast = true;
} } while (!isLast);
} return lastIndex;
}

My problem is: execution steps into an if with a false condition! Check the values of i and src.size() at the right panel. How could be possible for the program to run the highlighted statement? The if condition above is false! [URL]. I could use char arrays, for example, but this kind of false validation has happened to me more than once, I'm using G++ 4.5 with these flags: -O0 -g -Wall -c

View 3 Replies View Related

Programming :: PHP - Sorting Multi Dimensional Arrays By One Column

Mar 17, 2009

I just started programming in PHP so I haven't figured out how to do this yet, but I have a multi-dimensional array that I need to sort by one column. That's fine...but I need the sort to ignore case! Right now I have it sorted by 'name' (the other column is 'uid').

The problem is that by the default the sort is case-sensitive so the array looks like this:
Code:
Apple 4015
Banana 4011
Cherry 4045
avocado 4046

I want to be able to sort the the 'name' column in a case-insensitive manner so that the array actually looks like:
Code:
Apple 4015
avocado 4046
Banana 4011
Cherry 4045

How to accomplish this? Just FYI I'm not actually sorting the PLUs for fruits...but it was a simple example. I'm actually doing this for a Facebook application.

View 2 Replies View Related

Programming :: Bash: Combine Arrays & Delete Duplicates?

May 23, 2011

I would like to combine two arrays and delete duplicates that might occur. I tried to solve it like this:

Code:
combined=( "${results1[@]}" "${results2[@]}" )
printf "${combined[@]}" | sort -n | uniq
Example:
result1 (4 elements):

[Code]....

In my code printf seems to have a problem with elements that have the same letters but a space inbetween. For instance "new foo", "newfoo" are the same for printf

View 5 Replies View Related

Programming :: Bash Scripting Arrays And Indirect Referencing

Feb 23, 2010

I've got a situation. I'm having GNU bash version 3.00.16(1) on Solaris 10. I need to declare an array say arr1 which will be populated by an output of a command.

declare -a arr1
arr1=( $(/some/command) )

Supposing it will eventually (after executing the command) have element values as -

arr1[0]=1234
arr1[1]=5678
arr1[2]=7890

Now, I need to declare another set of arrays, one for each of the element values above - e.g.

declare -a arr1_1234
declare -a arr1_5678
declare -a arr1_7890

And I also need to populate elements of each of above 3 arrays with output of another command in a loop. So, these arrays will hold values something like -

arr1_1234[0]="abc"
arr1_1234[1]="def"
arr1_1234[2]="ghi"

arr1_5678[0]="jkl"
arr1_5678[1]="mno"
arr1_5678[2]="pqr"
arr1_7890[0]="tuv"
arr1_7890[1]="xyz"
arr1_7890[2]="aab"

I'm able to declare and populate arr1[*]. My question is how do I declare, populate and print the subsequent arrays and their elements?I am feeling rather thick to get this working.

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved