hash access

2006-09-14 Thread Xavier Mas i Ramón
Hi all!,

I'm trying to create a sorted (ASCII) hash file but get all time a syntax 
error in line my $abreviatures{$clau} = 1; at  $abreviatures{ --. Sure 
is an stupid mistake but I'm not able to see it even checking with my 
Learning Perl book.

Pls, can someone tell me where is the syntax error?

...
while (ABREVIATURES) {
chomp;
my $clau = $_;
my $abreviatures{$clau} = 1;
}
close ABREVIATURES;
...

Many thanks,

-- 
Xavier Mas

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: hash access

2006-09-14 Thread John W. Krahn
Xavier Mas i Ramón wrote:
 Hi all!,

Hello,

 I'm trying to create a sorted (ASCII) hash file but get all time a syntax 
 error in line my $abreviatures{$clau} = 1; at  $abreviatures{ --. Sure 
 is an stupid mistake but I'm not able to see it even checking with my 
 Learning Perl book.
 
 Pls, can someone tell me where is the syntax error?
 
 ...
 while (ABREVIATURES) {
 chomp;
 my $clau = $_;
 my $abreviatures{$clau} = 1;

You can't use my() with hash or array elements, only with the hash or array
itself.

my %abreviatures = ( $clau = 1 );



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: hash access

2006-09-14 Thread Mumia W.

On 09/14/2006 01:18 AM, Xavier Mas i Ramón wrote:

Hi all!,

I'm trying to create a sorted (ASCII) hash file but get all time a syntax 
error in line my $abreviatures{$clau} = 1; at  $abreviatures{ --. Sure 
is an stupid mistake but I'm not able to see it even checking with my 
Learning Perl book.


Pls, can someone tell me where is the syntax error?

...
while (ABREVIATURES) {
chomp;
my $clau = $_;
my $abreviatures{$clau} = 1;
}
close ABREVIATURES;
...

Many thanks,



The my command doesn't work that way. You have to my the 
entire hash like so:


...
my $abreviatures;
while (ABREVIATURES) {
  chomp $_;
  my $clau = $_;
  $abreviatures{$clau} = 1;
}
close ABREVIATURES;
...


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: hash access

2006-09-14 Thread John W. Krahn
Mumia W. wrote:
 On 09/14/2006 01:18 AM, Xavier Mas i Ramón wrote:

 I'm trying to create a sorted (ASCII) hash file but get all time a
 syntax error in line my $abreviatures{$clau} = 1; at 
 $abreviatures{ --. Sure is an stupid mistake but I'm not able to
 see it even checking with my Learning Perl book.

 Pls, can someone tell me where is the syntax error?

 ...
 while (ABREVIATURES) {
 chomp;
 my $clau = $_;
 my $abreviatures{$clau} = 1;
 }
 close ABREVIATURES;
 
 The my command doesn't work that way. You have to my the entire hash
 like so:
 
 ...
 my $abreviatures;

That is not a hash, that is a scalar.  ITYM:

my %abreviatures;



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: hash access

2006-09-14 Thread Mumia W.

On 09/14/2006 07:17 AM, John W. Krahn wrote:

Mumia W. wrote:

The my command doesn't work that way. You have to my the entire hash
like so:

...
my $abreviatures;


That is not a hash, that is a scalar.  ITYM:

my %abreviatures;



John


Oops, thanks :-)



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: hash access

2006-09-14 Thread Xavier Mas i Ramón
A Dijous 14 Setembre 2006 08:31, John W. Krahn va escriure:
 Xavier Mas i Ramón wrote:
  Hi all!,

 Hello,

  I'm trying to create a sorted (ASCII) hash file but get all time a syntax
  error in line my $abreviatures{$clau} = 1; at  $abreviatures{ --.
  Sure is an stupid mistake but I'm not able to see it even checking with
  my Learning Perl book.
 
  Pls, can someone tell me where is the syntax error?
 
  ...
  while (ABREVIATURES) {
  chomp;
  my $clau = $_;
  my $abreviatures{$clau} = 1;

 You can't use my() with hash or array elements, only with the hash or array
 itself.

 my %abreviatures = ( $clau = 1 );



 John
 --
 use Perl;
 program
 fulfillment

Thank you John!
-- 
Xavier Mas

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: hash access

2006-09-14 Thread Xavier Mas i Ramón
A Dijous 14 Setembre 2006 11:38, Mumia W. va escriure:
 On 09/14/2006 01:18 AM, Xavier Mas i Ramón wrote:
  Hi all!,
 
  I'm trying to create a sorted (ASCII) hash file but get all time a syntax
  error in line my $abreviatures{$clau} = 1; at  $abreviatures{ --.
  Sure is an stupid mistake but I'm not able to see it even checking with
  my Learning Perl book.
 
  Pls, can someone tell me where is the syntax error?
 
  ...
  while (ABREVIATURES) {
  chomp;
  my $clau = $_;
  my $abreviatures{$clau} = 1;
  }
  close ABREVIATURES;
  ...
 
  Many thanks,

 The my command doesn't work that way. You have to my the
 entire hash like so:

 ...
 my $abreviatures;
 while (ABREVIATURES) {
chomp $_;
my $clau = $_;
$abreviatures{$clau} = 1;
 }
 close ABREVIATURES;
 ...

Many thanks!.
-- 
Xavier Mas

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Hash Access Query

2002-12-03 Thread Ben Crane
Hi,

right, my first attempt at a hash of arrays appears to
have some success...but I have a query:

sub HoA
{
foreach $arb (@uniqueroadname)
{
foreach $doublearb (@contents)
{
if ($doublearb =~ m|$arb|)
{
print $arb   $doublearb\n;
push @temparray, $doublearb;
}
}
}
 $arrayref{$arb} = [@temparray];
}

as far as I've tested, %arrayref contains ARRAY0x23233
- etc...but I'm trying access that array:

$arrayref{$arb}[0] = will access the first array after
following a specific reference? Therefore, do I
access individual elements of that array through
$arrayref{$arb}[0][1]??

at the moment, the structure looks (i hope :) like
this:

%HASH -  Reference (roadname) - Array 1
   - Array 2
   - Array 3

i reference the roadname which takes me to the next
tier, and then I can access all the arrays containing
info about that particular roadname (reference)...I
guess it's a one-many relationship...

Ben

__
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Hash Access Query

2002-12-03 Thread Beau E. Cox
Hi Ben -

I have three general suggestions:

use strict;
use strict;
use strict;

'strict' forces you to pre-define your variables;
it makes the code more readable, AND will save you
many times over from misspelling errors (when this
happens, perl merrily creates a new variable with
the misspelled name and continues on its way - your
intended variable is not used - hard to find this
type of problem).

Your code would look like this with strict:

use strict;
use warnings; # put this guy in too - he will alert you to possible problems

sub HoA
{
  my @temparray;
  foreach my $arb (@uniqueroadname) {
foreach my $doublearb (@contents) {
  if ($doublearb =~ m|$arb|) {
print $arb   $doublearb\n;
push @temparray, $doublearb;
  }
}
  }
  my %arrayref; # this is actually a hash from the syntax you use below
# oops! $arb is out of context! it was defined within
# the first foreach loop above!!?? - and has no meaning here,,,
  $arrayref{$arb} = [@temparray];
}

Now, where do @uniqueroadmap and @contents
come from?

To answer you arrayref access question, get the
elements with this syntax:

my $ele0 = $arrayref{$arb}-[0];
my $ele1 = $arrayref{$arb}-[1];

You seem to be making all of this too hard. Maybe
you should start at the beginning again, an I will
help you simplify the solution.

Aloha = Beau.

-Original Message-
From: Ben Crane [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, December 03, 2002 12:05 AM
To: [EMAIL PROTECTED]
Subject: Hash Access Query


Hi,

right, my first attempt at a hash of arrays appears to
have some success...but I have a query:

sub HoA
{
foreach $arb (@uniqueroadname)
{
foreach $doublearb (@contents)
{
if ($doublearb =~ m|$arb|)
{
print $arb   $doublearb\n;
push @temparray, $doublearb;
}
}
}
 $arrayref{$arb} = [@temparray];
}

as far as I've tested, %arrayref contains ARRAY0x23233
- etc...but I'm trying access that array:

$arrayref{$arb}[0] = will access the first array after
following a specific reference? Therefore, do I
access individual elements of that array through
$arrayref{$arb}[0][1]??

at the moment, the structure looks (i hope :) like
this:

%HASH -  Reference (roadname) - Array 1
   - Array 2
   - Array 3

i reference the roadname which takes me to the next
tier, and then I can access all the arrays containing
info about that particular roadname (reference)...I
guess it's a one-many relationship...

Ben

__
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Hash Access Query

2002-12-03 Thread Todd W

Ben Crane [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Hi,

 right, my first attempt at a hash of arrays appears to
 have some success...but I have a query:

 sub HoA
 {
 foreach $arb (@uniqueroadname)
 {
 foreach $doublearb (@contents)
 {
 if ($doublearb =~ m|$arb|)
 {
 print $arb   $doublearb\n;
 push @temparray, $doublearb;
 }
 }
 }
  $arrayref{$arb} = [@temparray];
 }


snip /


 at the moment, the structure looks (i hope :) like
 this:

 %HASH -  Reference (roadname) - Array 1
- Array 2
- Array 3


no need to hope. Find out for sure:

use Data::Dumper;
...
print( Dumper \%HASH );

http://search.cpan.org/search?query=Data::Dumpermode=all

hth

Todd W.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




hash access issue

2001-10-18 Thread F.H

Hi there,

Here is my dilema:
%HoH = (
flintstones = {
lead1  = fred,
pal1   = barney,
},
jetsons = {
lead2  = george,
wife2  = jane,
his boy3 = elroy,
},
simpsons= {
lead3  = homer,
wife3  = marge,
kid3   = bart,
},
 );

$HoH{$key1}{$key2} is the basic structure of my hash. while I am reading from another 
file
that provides 3 variables if $var1 eq flintsones and $var2 eq pal1, then:
$HoH{$var1}{$var2} = barney.
Is ther a way that if $var1 eq anything and $var2 eq pal1 I can still get barney.

Any help is highly appreciated

I.S


__
Your favorite stores, helpful shopping tools and great gift ideas. Experience the 
convenience of buying online with Shop@Netscape! http://shopnow.netscape.com/

Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: hash access issue

2001-10-18 Thread Brian Arnold

You could probably do something like

sub checkanything {
  my $var2 = shift;
  foreach (keys %HoH) {
return $HoH{$_}{$var2} if $HoH{$_}{$var2};
  }
}

Then in your main body of code, just say something like

if ($var1 eq anything) { $return = checkanything($var2); }

I think that should do it - good luck =)


Brian Arnold
[EMAIL PROTECTED]

-Original Message-
From: F.H [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, October 18, 2001 11:59 AM
To: [EMAIL PROTECTED]
Subject: hash access issue


Hi there,

Here is my dilema:
%HoH = (
flintstones = {
lead1  = fred,
pal1   = barney,
},
jetsons = {
lead2  = george,
wife2  = jane,
his boy3 = elroy,
},
simpsons= {
lead3  = homer,
wife3  = marge,
kid3   = bart,
},
 );

$HoH{$key1}{$key2} is the basic structure of my hash. while I am reading
from another file
that provides 3 variables if $var1 eq flintsones and $var2 eq pal1,
then:
$HoH{$var1}{$var2} = barney.
Is ther a way that if $var1 eq anything and $var2 eq pal1 I can still
get barney.

Any help is highly appreciated

I.S


__
Your favorite stores, helpful shopping tools and great gift ideas.
Experience the convenience of buying online with Shop@Netscape!
http://shopnow.netscape.com/

Get your own FREE, personal Netscape Mail account today at
http://webmail.netscape.com/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


_
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]