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
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
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 hash out of it. I got
>this code that
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;
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 (
>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
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
16 matches
Mail list logo