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 element in the > array row

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      - ab is a string in th

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 hash out of it. I got >this code that

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;

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 (

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
The real pain here is that the files have to be in sync otherwise the data becomes a mess. Given the above: my @MyArray1 = qw(5 4 3 2 1 6 9 11 12); my @MyArray2 = qw(cat dog mouse mice tree shrub sap unix max); if ( scalar(@MyArray1) != scalar(@MyArray2) ) { printf "Expecting