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
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
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
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
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
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 = (
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
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
-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
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
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
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;
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;
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);
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;
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
Anthony Vanelverdinghe wrote:
Hi
Could anyone explain why the output of the hash isn't: 1 a
2 b
3 c
How can
On Sun, 22 Feb 2004, Anthony Vanelverdinghe wrote:
> Hi
>
> Could anyone explain why the output of the hash isn't: 1 a
>
>2 b
>
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
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
[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
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
> [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
[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 (
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,
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
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
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
>
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
>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
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
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
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
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
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
> 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
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
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(/\|/,"$
> 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
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
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
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
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
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
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
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
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
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
48 matches
Mail list logo