Re: array to hash array

2010-07-27 Thread C.DeRykus
On Jul 26, 3:22 am, sharan.basa...@gmail.com (Sharan Basappa) wrote: > Hi, > > Can someone tell me how to convert an array to hash. > > Each array entry has a row of values > e.g. a(0) = ab cd ef; a(1) = mn de fg > > The hash array needs to be constructed with one of the el

Re: array to hash array

2010-07-26 Thread Teo
Dear Sharan, > Can someone tell me how to convert an array to hash. > > Each array entry has a row of values > e.g. a(0) = ab cd ef; a(1) = mn de fg > > The hash array needs to be constructed with one of the element in the > array row as the key. > e.g. hash{ab} = cd ef

AW: array to hash array

2010-07-26 Thread Thomas Bätzler
Sharan Basappa asked: > Can someone tell me how to convert an array to hash. > > Each array entry has a row of values > e.g. a(0) = ab cd ef; a(1) = mn de fg > > The hash array needs to be constructed with one of the element in the > array row as the key. > e.g. hash{ab

array to hash array

2010-07-26 Thread Sharan Basappa
Hi, Can someone tell me how to convert an array to hash. Each array entry has a row of values e.g. a(0) = ab cd ef; a(1) = mn de fg The hash array needs to be constructed with one of the element in the array row as the key. e.g. hash{ab} = cd ef - ab is a string in the array row

Re: Array to Hash

2007-08-13 Thread Ken Foskey
On Mon, 2007-08-13 at 07:47 -0700, Paul Lalli wrote: > On Aug 13, 9:40 am, [EMAIL PROTECTED] (Ken Foskey) wrote: > > On Sun, 2007-08-12 at 22:55 -0400, yitzle wrote: > > > I got an array of values where the order is relevent, eg the ages of > > > Alice, Bob and Charles, and I want to make a hash ou

Re: Array to Hash

2007-08-13 Thread Paul Lalli
On Aug 13, 9:40 am, [EMAIL PROTECTED] (Ken Foskey) wrote: > On Sun, 2007-08-12 at 22:55 -0400, yitzle wrote: > > I got an array of values where the order is relevent, eg the ages of > > Alice, Bob and Charles, and I want to make a hash out of it. I got > > this code that does it: > > my %ages = (

Re: Array to Hash

2007-08-13 Thread Mr. Shawn H. Corey
Ken Foskey wrote: On Sun, 2007-08-12 at 22:55 -0400, yitzle wrote: I got an array of values where the order is relevent, eg the ages of Alice, Bob and Charles, and I want to make a hash out of it. I got this code that does it: my %ages = (alice => $r[0], bob => $r[1], charles => $r[2]); Is the

Re: Array to Hash

2007-08-13 Thread Ken Foskey
On Sun, 2007-08-12 at 22:55 -0400, yitzle wrote: > I got an array of values where the order is relevent, eg the ages of > Alice, Bob and Charles, and I want to make a hash out of it. I got > this code that does it: > my %ages = (alice => $r[0], bob => $r[1], charles => $r[2]); > Is there a more e

Re: Array to Hash

2007-08-12 Thread Jeff Pang
-Original Message- >From: yitzle <[EMAIL PROTECTED]> >Sent: Aug 12, 2007 10:55 PM >To: "beginners@perl.org" >Subject: Array to Hash > >I got an array of values where the order is relevent, eg the ages of >Alice, Bob and Charles, and I want to make a

Array to Hash

2007-08-12 Thread yitzle
I got an array of values where the order is relevent, eg the ages of Alice, Bob and Charles, and I want to make a hash out of it. I got this code that does it: my %ages = (alice => $r[0], bob => $r[1], charles => $r[2]); Is there a more elegent way to do it? -- To unsubscribe, e-mail: [EMAIL PR

Re: Array to Hash

2007-04-18 Thread Rob Dixon
yitzle wrote: Any tips on compacting this sub? sub readFile($) { my $fileName = shift; open FILE, "<", $fileName; while () { my($name,$oldCount,$oldNum) = split /~/; $dHash{$name}{'oldCount'} = $oldCount; $dHash{$name}{'oldNum'} = $oldNum; } close FIL

Re: Array to Hash

2007-04-18 Thread Chas Owens
On 4/18/07, yitzle <[EMAIL PROTECTED]> wrote: Any tips on compacting this sub? sub readFile($) { my $fileName = shift; open FILE, "<", $fileName; while () { my($name,$oldCount,$oldNum) = split /~/; $dHash{$name}{'oldCount'} = $oldCount;

Array to Hash

2007-04-18 Thread yitzle
Any tips on compacting this sub? sub readFile($) { my $fileName = shift; open FILE, "<", $fileName; while () { my($name,$oldCount,$oldNum) = split /~/; $dHash{$name}{'oldCount'} = $oldCount; $dHash{$name}{'oldNum'} = $oldNum;

Re: map array to hash

2006-05-29 Thread John Ackley
Jenda Krynicky wrote: From: John Ackley <[EMAIL PROTECTED]> there is more than one way to do it is there an easier way to do this map: my $index = 0; while( my @a = $SQL->fetchrow_array) { my %a = map { $fieldnames[$index++] => $_ } @a; print "$_ => $a{$_}\n" for (keys %a);

Re: map array to hash

2006-05-29 Thread Paul Johnson
On Mon, May 29, 2006 at 09:16:00AM -0400, John Ackley wrote: > there is more than one way to do it > is there an easier way to do this map: > > my $index = 0; > while( my @a = $SQL->fetchrow_array) { >my %a = map { $fieldnames[$index++] => $_ } @a; my %a; @[EMAIL PROTECTED] = @a;

map array to hash

2006-05-29 Thread John Ackley
there is more than one way to do it is there an easier way to do this map: my $index = 0; while( my @a = $SQL->fetchrow_array) { my %a = map { $fieldnames[$index++] => $_ } @a; print "$_ => $a{$_}\n" for (keys %a); } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional comma

Re: converting array to hash

2004-02-22 Thread Andrew Gaffney
Anthony Vanelverdinghe wrote: Hi Could anyone explain why the output of the hash isn't: 1 a 2 b 3 c How can

Re: converting array to hash

2004-02-22 Thread John McKown
On Sun, 22 Feb 2004, Anthony Vanelverdinghe wrote: > Hi > > Could anyone explain why the output of the hash isn't: 1 a > >2 b >

converting array to hash

2004-02-22 Thread Anthony Vanelverdinghe
Hi Could anyone explain why the output of the hash isn't: 1 a 2 b 3 c How can i make that the order remains

Re: Array to hash with reverse split?

2003-08-20 Thread John W. Krahn
Linux Rocks wrote: > > John> Perl has the tools to do most of that without running an external > John> program like 'ls' or 'grep'. > > Yes, thank you, I know. I will be dealing with data that is arranged SIMILAR > TO THE OUPUT OF ls -l, NOT THE ACTUAL OUTPUT OF THAT COMMAND and it will have > N

Re: Array to hash with reverse split?

2003-08-20 Thread linux . rocks
[SNIP] John> #/usr/local/bin -w John> ^^ John>I see no 'perl' there. Typo. [SNIP] John> my (@ARRAY, %TEST, $FILTER) = ""; John> John> Why are you assigning "" to the first element of @ARRAY? 'Cause I'm an idiot... [SNIP] John> Perl has the tools to do most of that without runnin

Re: Array to hash with reverse split?

2003-08-18 Thread John W. Krahn
Linux Rocks wrote: > > Hi All, Hello, > I want to read contents of a dir, filtered, into a hash. I have this: > > #/usr/local/bin -w ^^ I see no 'perl' there. > use strict; > my (@ARRAY, %TEST, $FILTER) = ""; Why are you assigning "" to the first element of @ARRAY? > print

RE: Array to hash with reverse split?

2003-08-18 Thread Dan Muey
> [EMAIL PROTECTED] wrote: > > Hi All, > > > > I want to read contents of a dir, filtered, into a hash. I > have this: > > > > #/usr/local/bin -w > > use strict; > > my (@ARRAY, %TEST, $FILTER) = ""; > > You may want to make sure $FILTER isn't anythign harmful here: For instance what if Someo

RE: Array to hash with reverse split?

2003-08-18 Thread Bob Showalter
[EMAIL PROTECTED] wrote: > Hi All, > > I want to read contents of a dir, filtered, into a hash. I have this: > > #/usr/local/bin -w > use strict; > my (@ARRAY, %TEST, $FILTER) = ""; > > print "Enter filter:"; > $FILTER = ; > chomp $FILTER; > @ARRAY = ` ls -l /foo/bar | grep "$FILTER" `; > for (

Array to hash with reverse split?

2003-08-18 Thread linux . rocks
Hi All, I want to read contents of a dir, filtered, into a hash. I have this: #/usr/local/bin -w use strict; my (@ARRAY, %TEST, $FILTER) = ""; print "Enter filter:"; $FILTER = ; chomp $FILTER; @ARRAY = ` ls -l /foo/bar | grep "$FILTER" `; for (@ARRAY) { chomp; } This gets just the info I want,

Re: convert an array to hash

2002-11-28 Thread Ramprasad A Padmanabhan
goofing again. Thanks for the reply Ram Sudarshan Raghavan wrote: On Thu, 28 Nov 2002, Ramprasad A Padmanabhan wrote: Which is the quickest way of converting an array to hash keys I have an array @ARRAY = qw ( a b c d e ); # Convert array to hash keys , so can easily check for exists # The

Re: convert an array to hash

2002-11-28 Thread Sudarshan Raghavan
On Thu, 28 Nov 2002, Ramprasad A Padmanabhan wrote: > Which is the quickest way of converting an array to hash keys > > I have an array > @ARRAY = qw ( a b c d e ); > > # Convert array to hash keys , so can easily check for exists > # The values of the hash are immate

Re: convert an array to hash

2002-11-28 Thread Paul Johnson
Ramprasad A Padmanabhan said: > Which is the quickest way of converting an array to hash keys > > I have an array > @ARRAY = qw ( a b c d e ); > > # Convert array to hash keys , so can easily check for exists > # The values of the hash are immaterial to me >

convert an array to hash

2002-11-28 Thread Ramprasad A Padmanabhan
Which is the quickest way of converting an array to hash keys I have an array @ARRAY = qw ( a b c d e ); # Convert array to hash keys , so can easily check for exists # The values of the hash are immaterial to me @HASH{@ARRAY}=@ARRAY; foreach (@SOME_OTHER_ARRAY) { next if(exists

Re: @array to %hash

2002-11-20 Thread Larry Coffin
>I have 2 arrays I would like to make into a (one) hash. > >One array for keys. >One array for values. > >I'm sure this may be an easy thing, but my lack of imagination is killing me >(and I need something a little more comprehensive than Beginners Perl) A quick easy way to do it given @ke

RE: @array to %hash

2002-11-20 Thread Wagner, David --- Senior Programmer Analyst --- WGO
le Cpl Shawn B [mailto:[EMAIL PROTECTED]] Sent: Wednesday, November 20, 2002 13:48 To: '[EMAIL PROTECTED]' Subject: @array to %hash I have 2 arrays I would like to make into a (one) hash. One array for keys. One array for values. I'm sure this may be an easy thing, but my lack of

@array to %hash

2002-11-20 Thread Fogle Cpl Shawn B
I have 2 arrays I would like to make into a (one) hash. One array for keys. One array for values. I'm sure this may be an easy thing, but my lack of imagination is killing me (and I need something a little more comprehensive than Beginners Perl) tia shawn -- To unsubscribe, e-mail: [EMAIL PRO

Re: assigning array to hash

2002-04-29 Thread Chas Owens
On Tue, 2002-04-30 at 00:22, drieux wrote: > > On Monday, April 29, 2002, at 08:29 , Chas Owens wrote: > > > > > TMTOWTDI: > > > > my @array = qw(first second last); > > my %hash; > > #the $" var controls what characters separate elements of > > #an interpolated array > > { local $" = '|'; $hash

Re: assigning array to hash

2002-04-29 Thread drieux
On Monday, April 29, 2002, at 08:29 , Chas Owens wrote: > > TMTOWTDI: > > my @array = qw(first second last); > my %hash; > #the $" var controls what characters separate elements of > #an interpolated array > { local $" = '|'; $hash{somekey} = "@array"; } can You get Your Brilliant Flashes in Ge

Re: assigning array to hash

2002-04-29 Thread drieux
On Monday, April 29, 2002, at 02:50 , Shaun Fryer wrote: > >> http://www.wetware.com/drieux/CS/lang/Perl/Beginners/BenchMarks/loopVjoin. >> txt >> drieux > > Thanks Drieux, > I had no idea this could even be done. [..] thanks for the catch on that !!! I had been off working on the new va

Re: assigning array to hash

2002-04-29 Thread Shaun Fryer
> http://www.wetware.com/drieux/CS/lang/Perl/Beginners/BenchMarks/loopVjoin.txt > drieux Thanks Drieux, I had no idea this could even be done. --- $hash{$jref_key} = \@array; my @new_array = @{$hash{$jref_key}}; --- Guess why I'm on this list? ;) I have one tiny question tho

Re: assigning array to hash

2002-04-29 Thread Chas Owens
On Sat, 2002-04-27 at 12:14, drieux wrote: > > On Friday, April 26, 2002, at 03:49 , Shaun Fryer wrote: > [..] > > > > foreach $value (@array) { > > $scalar_array .= "$value|"; > > } > > chop($scalar_array); > > my %hash; > > $hash{some_key} = $scalar_array; > > > > Then if you want to get

Re: assigning array to hash

2002-04-27 Thread drieux
On Friday, April 26, 2002, at 03:49 , Shaun Fryer wrote: [..] > > foreach $value (@array) { > $scalar_array .= "$value|"; > } > chop($scalar_array); > my %hash; > $hash{some_key} = $scalar_array; > > Then if you want to get the array from the key's value later > on, you just split(/\|/,"$

Re: assigning array to hash

2002-04-26 Thread Shaun Fryer
> Below is part of some code that reads from a file to an array and then > attempts to assign the array to a hash. I get no compiling errors, but > %label_hash is empty. No doubt I am being stupid. Has anyone a > suggestion how to fill the hash variable? Well, I'm not totally certain wha

RE: assigning array to hash

2002-04-26 Thread Shah, Urmil
lto:[EMAIL PROTECTED]] Sent: Friday, April 26, 2002 9:17 AM To: [EMAIL PROTECTED] Subject: Re: assigning array to hash on Fri, 26 Apr 2002 14:09:24 GMT, [EMAIL PROTECTED] (Richard Noel Fell) wrote: > Below is part of some code that reads from a file to an array and > then attempts to assign the

Re: assigning array to hash

2002-04-26 Thread drieux
On Friday, April 26, 2002, at 10:28 , richard noel fell wrote: > Drieux - > Thanks. I altered the LABEL_FILE data format as you suggested and all > works just fine now. > Dick you could of course generate the file in the form key val key1 val1 and then do the simpler shot to the hash

Re: assigning array to hash

2002-04-26 Thread richard noel fell
Drieux - Thanks. I altered the LABEL_FILE data format as you suggested and all works just fine now. Dick Drieux wrote: > > On Friday, April 26, 2002, at 06:55 , Jeff 'japhy' Pinyan wrote: > > > The hash is not empty -- printing "%foo" does nothing special. To dump a > > hash, do someth

Re: assigning array to hash

2002-04-26 Thread richard noel fell
Drieu : Whoops. I forgot the chomp. The data in the LABEL_FILE is formatted as: "key"=>"val", "key1"=>"val1", which seems to work since the for loop prints as expected. Dick Drieux wrote: > > On Friday, April 26, 2002, at 06:55 , Jeff 'japhy' Pinyan wrote: > > > The hash is not empty -- prin

Re: assigning array to hash

2002-04-26 Thread drieux
On Friday, April 26, 2002, at 06:55 , Jeff 'japhy' Pinyan wrote: > The hash is not empty -- printing "%foo" does nothing special. To dump a > hash, do something like: > > for (keys %hash) { > print "$_ => $hash{$_}\n"; > } we of course presume that Richard already remembers two small n

Re: assigning array to hash

2002-04-26 Thread Felix Geerinckx
on Fri, 26 Apr 2002 14:09:24 GMT, [EMAIL PROTECTED] (Richard Noel Fell) wrote: > Below is part of some code that reads from a file to an array and > then attempts to assign the array to a hash. I get no compiling > errors, but %label_hash is empty. No doubt I am being stupid. Has > anyone a sug

Re: assigning array to hash

2002-04-26 Thread richard noel fell
Jeff - Thanks for your reply. Now, on to solve the remaining problems. Dick Fell Jeff 'Japhy' Pinyan wrote: > > On Apr 26, richard noel fell said: > > >Below is part of some code that reads from a file to an array and then > >attempts to assign the array to a hash. I get no com

Re: assigning array to hash

2002-04-26 Thread Jeff 'japhy' Pinyan
On Apr 26, richard noel fell said: >Below is part of some code that reads from a file to an array and then >attempts to assign the array to a hash. I get no compiling errors, but >%label_hash is empty. No doubt I am being stupid. Has anyone a >suggestion how to fill the hash variable? The hash

assigning array to hash

2002-04-26 Thread richard noel fell
Below is part of some code that reads from a file to an array and then attempts to assign the array to a hash. I get no compiling errors, but %label_hash is empty. No doubt I am being stupid. Has anyone a suggestion how to fill the hash variable? Thanks, Dick Fell open LABEL_FILE, "$cur