On Jul 13, 12:54 pm, [EMAIL PROTECTED] ([EMAIL PROTECTED]) wrote:
There's nothing wrong with using shorthand descriptions provided you
don't forget what they are short for. It seems to me that your
problems arise from using shorthand descriptions then basing your
expectations on a literal
Inventor wrote:
I agree, its just what I happened to create - what would you suggest,
and what would be the syntax for that?
The internal structures of your program should reflect the input, or the
output, or some well-defined internal structure. And by well-defined, I
mean a convention
Hi,
Thanks for helping with my question the other day, now I have
another. In my class I have an array of hashes and it seems to work
just fine. I use the zeroth element to store individual variables and
all the other elements to store variables that change over time. For
example, i have the
On 7/13/07, Inventor [EMAIL PROTECTED] wrote:
snip
$self-[0]{'teams'} = @teams;
and
@self-[0]{'teams'} = @teams;
but when I try to access the array with
foreach $team ($self-[0]{'teams'}) {
print $team.' ';
}
or
foreach $team (@self-[0]('teams')) {
print $team.' ':
}
i get nothing
Inventor wrote:
Hi,
Thanks for helping with my question the other day, now I have
another. In my class I have an array of hashes and it seems to work
just fine. I use the zeroth element to store individual variables and
all the other elements to store variables that change over time. For
On Jul 13, 12:03 pm, [EMAIL PROTECTED] (Inventor) wrote:
Thanks for helping with my question the other day, now I have
another. In my class I have an array of hashes
In Perl, when we say array of hashes we are using it as shorthand
for array of references to hashes.
99% of the time everyone
Chas Owens schreef:
[put an array @teams into the 0th element of $self]
The proper syntax is
$self-[0]{teams} = [ @teams ];
That makes a copy. If you don't want that, for example because it could
contain millions of items, you can use
$self-[0]{teams} = [EMAIL PROTECTED];
--
On Tue, 28 Oct 2003 20:40:07 -0800, Richard Heintze wrote:
I have an array stored in an object and I trying to
compute the length of the array. This seemed to work
initially:
my $nColumns = [EMAIL PROTECTED]{component_titles}}}+1;
$#array gives to the index of the _last_ element. If you
I had emailed this query out previously but since I
never saw my own email in the digest, I'm assuming
that it never made it to the [EMAIL PROTECTED] list.
Please forgive me if it did and I did not see it (my
SPAM filter might have eaten it).
Question #1
---
I have an array stored in an
On Oct 28, Richard Heintze said:
I have an array stored in an object and I trying to
compute the length of the array. This seemed to work
initially:
The LENGTH of an array is @array or @{ $ref_to_array }. The LAST INDEX of
an array is $#array or $#{ $ref_to_array }.
my $nColumns = [EMAIL
R. Joseph Newton wrote:
Rob Dixon wrote:
James Edward Gray II wrote:
On Friday, June 6, 2003, at 03:32 AM, R. Joseph Newton wrote:
The player's name IS the number. No other numbering system is
needed. The players name is NEVER stored in the hash, AFAIK. The
name is used
R. Joseph Newton wrote:
Rob Dixon wrote:
James Edward Gray II wrote:
On Friday, June 6, 2003, at 03:32 AM, R. Joseph Newton wrote:
The player's name IS the number. No other numbering system is
needed. The players name is NEVER stored in the hash, AFAIK. The
name is used
On Friday, June 6, 2003, at 07:05 PM, R. Joseph Newton wrote:
The point here is that the essential purpose of the key is that of a
pointer, rather thanas data in itself.
There are applications of a Perl hash where one does not even need to
use the value, finding all the unique words in a
Stuart White wrote:
Right now my array is just like that, minus the
numbers. So what I want to do is assign the array to
a hash. If I were to do that, my understanding is
that the names would be keys and the numbers values,
and doing such an assignment in a loop would cause
some entries
Stuart White wrote:
Hey, thanks that worked!
--- James Edward Gray II [EMAIL PROTECTED]
wrote:
snip
I don't seen any reason to use the array at all, so
I've removed it.
If you had one that I just didn't know about, send
it on back.
That's how I tried to solve this piecewise, I
Stuart White wrote:
Ok, I think I get it. the $_ is printing the player
name, (though I don't know why I'm not using $1
$1 is a special-purpose variable used only in relation to regexes.
The default variable for looping structures will be contained in $_.
instead for that) and the
Stuart White wrote:
This does make it clearer, but not entirely. Is this
what is happening: the loop starts, and goes
immediately into the if statement. when the regex
finds a line with Jump Shot it stores that in $2,
and the player name in $1. The next thing it does,
and I'm not quite
On Friday, June 6, 2003, at 03:32 AM, R. Joseph Newton wrote:
The player's name IS the number. No other numbering system is
needed. The players name is NEVER stored in the hash, AFAIK. The
name is used to feed a hashing function, which renders an index into
the storage of the hash structure.
James Edward Gray II wrote:
On Friday, June 6, 2003, at 03:32 AM, R. Joseph Newton wrote:
The player's name IS the number. No other numbering system is
needed. The players name is NEVER stored in the hash, AFAIK. The
name is used to feed a hashing function, which renders an index into
R. Joseph Newton wrote:
Stuart White wrote:
This does make it clearer, but not entirely. Is this
what is happening: the loop starts, and goes
immediately into the if statement. when the regex
finds a line with Jump Shot it stores that in $2,
and the player name in $1. The next
James Edward Gray II wrote:
On Friday, June 6, 2003, at 03:32 AM, R. Joseph Newton wrote:
The player's name IS the number. No other numbering system is
needed. The players name is NEVER stored in the hash, AFAIK. The
name is used to feed a hashing function, which renders an index into
Rob Dixon wrote:
James Edward Gray II wrote:
On Friday, June 6, 2003, at 03:32 AM, R. Joseph Newton wrote:
The player's name IS the number. No other numbering system is
needed. The players name is NEVER stored in the hash, AFAIK. The
name is used to feed a hashing function,
On Monday, June 2, 2003, at 08:10 PM, Stuart White wrote:
Ok, I think I get it. the $_ is printing the player
name, (though I don't know why I'm not using $1
instead for that)
$1 contains the first capture of the last match we did. When you're
using match variables like that, store them
On Monday, June 2, 2003, at 10:06 PM, Stuart White wrote:
This does make it clearer, but not entirely. Is this
what is happening: the loop starts, and goes
immediately into the if statement. when the regex
finds a line with Jump Shot it stores that in $2,
and the player name in $1.
Yes, this
This is good explanation. Thanks.
Hi Stuart,
This is so useful and easy that it's worth really
understanding. Here's a
non-programming metaphor:
As each player makes a shot he calls out his name
($1): smith. The
scorekeeper says, ah, smith ($score{smith}) - let's
add 1 to Smith's
Since it seemed like a nice exercise to work on I played with this some
myself. Goals being to try to avoid global variables, use subroutines and
keep MAIN 'uncluttered' and pass arguments to subs as needed.
I think I did okay (holding breath), but I'm wondering about things like:
my
On Tue, Jun 03, 2003 at 08:36:05PM +0200 Kevin Pfeiffer wrote:
Since it seemed like a nice exercise to work on I played with this some
myself. Goals being to try to avoid global variables, use subroutines and
keep MAIN 'uncluttered' and pass arguments to subs as needed.
I think I did okay
In article [EMAIL PROTECTED], Tassilo Von Parseval wrote:
[...]
If you from then on referred to elements of the hash with something like
$score_ref-{ key };
then this would be it. It depends on what you want. By dereferencing the
whole data-structure you're essentially creating a copy.
I am reading in a file of one line sentences, and then
selecting to store several sentences into an array
based upon the presence of some key words. I then
want to assign the array to a hash. The output of the
array will look something like this:
Player1: 1
Player2: 1
Player3: 1
Player1: 2
On Monday, June 2, 2003, at 04:02 PM, Stuart White wrote:
Also, to get the numbers to the right of the colon,
I'd have to have a count for each occurrence of each
player, how might I do that?
Perhaps with something like:
my %hash;
$hash{ (split /:/, $_)[0] }++ foreach (@array);
That just walks
Hmm, this might actually be more productive I showed
less abstract example lines. (I couldn't do this
before as I didn't have the code in front of me.)
Here is an example of the lines that my code is
selecting and then extracting a player name and jump
shot attempt(working on this part) then
PROTECTED]To: [EMAIL PROTECTED]
m cc:
Subject: Re: arrays
:
Subject: Re: arrays and hashes
06/02/2003 05:12
You should probably use an array to keep the correct
order and a hash to
keep the count:
I don't really understand what you mean.
__
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com
--
To
On Monday, June 2, 2003, at 05:12 PM, Stuart White wrote:
Hmm, this might actually be more productive I showed
less abstract example lines.
Not sure I understand perfectly yet, but I'll give it another go.
I don't seen any reason to use the array at all, so I've removed it.
If you had one
Hey, thanks that worked!
--- James Edward Gray II [EMAIL PROTECTED]
wrote:
snip
I don't seen any reason to use the array at all, so
I've removed it.
If you had one that I just didn't know about, send
it on back.
That's how I tried to solve this piecewise, I thought
an array was necessary,
Hey, thanks that worked!
--- James Edward Gray II [EMAIL PROTECTED]
wrote:
snip
I don't seen any reason to use the array at all, so
I've removed it.
If you had one that I just didn't know about, send
it on back.
That's how I tried to solve this piecewise, I thought
an array was necessary,
One more thing, if I want to sort the hash
alphabetically by key where do I put the sort
function?
I tried it before the while loop that does the
printing and on the each function
(sort(each(%linehash))) and that just gave me numbers
first, colon, player names. and I figure that it
wouldn't
On Monday, June 2, 2003, at 06:54 PM, Stuart White wrote:
I don't understand this syntax:
$linehash{$1}++;
Could you explain it to me?
Absolutely.
This is a common Perl technique, often used with a hash named '%seen'
because that's exactly what it's keeping track of. $1 is where you
were
Print it like this, it's easier:
print $_ : $linehash{$_}\n foreach (sort keys %linehash);
James
On Monday, June 2, 2003, at 07:03 PM, Stuart White wrote:
One more thing, if I want to sort the hash
alphabetically by key where do I put the sort
function?
I tried it before the while loop that
Ok, I think I get it. the $_ is printing the player
name, (though I don't know why I'm not using $1
instead for that) and the $linehash{$_} means, in
English, the value of the key stored in $_ is that
right?
Thanks for all your help.
--- James Edward Gray II [EMAIL PROTECTED]
wrote:
Print it
This does make it clearer, but not entirely. Is this
what is happening: the loop starts, and goes
immediately into the if statement. when the regex
finds a line with Jump Shot it stores that in $2,
and the player name in $1. The next thing it does,
and I'm not quite sure how, is it populates a
In article [EMAIL PROTECTED], Stuart
White wrote:
This does make it clearer, but not entirely. Is this
James wrote:
This is a common Perl technique, often used with a
hash named '%seen'
because that's exactly what it's keeping track of.
$1 is where you
were capturing your names, I just
John W. Krahn wrote at Mon, 02 Jun 2003 14:44:41 -0700:
You should probably use an array to keep the correct order and a hash to
keep the count:
Or to use Tie::IxHash.
Greetings,
Janek
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
On Sat, Sep 29, 2001 at 11:08:11AM -0400, Darfler, Jim (J.E.) wrote:
How would I go about sending to a file the volume names and dates sorted
by the date?
Open the file, iterate through your data structure, write what data you want
to the file, close the file.
I had thought to put the
Hi Jim,
I'm not entirely clear on what you have in the first array, but it sounds
like it won't be of much use since you already have a hash with all the
information you need.
You're probably going to have to create a new data structure that keys off
of the date so you can search/sort based on
--- Bryan Gmyrek [EMAIL PROTECTED] wrote:
I've written a program where I need to use an array of hashes. The
basic code I am having problems with is:
sub read_from_file{
#input: file name that holds lines of info in the form key: value
#action: add these to an array of hashes
#return:
On Jun 8, Bryan Gmyrek said:
if(/separator/){
$i++;
}
seperator
Your spelling is inconsistent.
--
Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the
Is it possible to have an array of associative arrays?
---
[EMAIL PROTECTED] (Galactic Hero)
Diplomacy: The art of saying good doggie
while searching for a big rock.
--- David H. Adler [EMAIL PROTECTED] wrote:
On Thu, May 17, 2001 at 12:08:56PM -0500, John Storms wrote:
Is it possible to have an array of associative arrays?
Technically, that's not *literally* possible. But you can have an
array of *references* to hashes (as assoc. arrays tend
50 matches
Mail list logo