Re: Need help... packages

2005-09-02 Thread JupiterHost.Net



Luinrandir wrote:

OK.. maybe I'm trying to be too fancy.



use tsruic

the package is:
###
package Names;
@Countries(Ireland,Wales);


Don;t double quote string that have nothing being interpolated, use 
single quotes or q()



%Lord{Ireland}=(Bob,Tom);


$Lord{Ireland} not %Lord{...


%Lord{Wales}=(Ted,Ned);


Don't assign an array to a scalar, you'll get the number of items in the 
list not the list, use refernces.


Don't store your data in 2 places (IE an array *and* they keys of a 
Hash), then you have to maintain it:


package Names;

use strict;
use warnings;

our %Lord = (
  Ireland = ['Bob','Tom'],
  Wales = ['Ted','Ned']
);

1;

#!/usr/bin/perl

use strict;
use warnings;
use Names;

for my $country (keys %Names::Lord) {
   for(@{ $Names::Lord{$country} }){
  print $country: $_\n;
   }
}


return 1;
#
the program is:
###
foreach $Country(@Names::Countries)
{
print qq|$Names::$Lord{$Country}|;


$Names::Lord

use strict;
use warnings;

Alway always always do those 1st thing.

They would have told you the problem with your code right off.


}


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




Re: Need help... packages

2005-09-01 Thread John W. Krahn
Luinrandir wrote:
 OK.. maybe I'm trying to be too fancy.
 
 the package is:
 ###
 package Names;
 @Countries(Ireland,Wales);

The '@' sigil can only be in front of an array or a slice.  You probably meant:

@Countries = ( Ireland, Wales );


 %Lord{Ireland}=(Bob,Tom);
 %Lord{Wales}=(Ted,Ned);

The '%' sigil can only be in front of a hash.  You probably meant:

$Lord{ Ireland } = [ Bob, Tom ];
$Lord{ Wales }   = [ Ted, Ned ];

Or:

%Lord = (
Ireland = [ Bob, Tom ],
Wales   = [ Ted, Ned ],
);


 return 1;

You can only return fron a subroutine.  You probably meant:

1;


 #
 the program is:
 ###
 foreach $Country(@Names::Countries)
 {
 print qq|$Names::$Lord{$Country}|;
 ^^^
Another syntax error.  And you don't need to quote scalars.

print $Names::Lord{ $Country };


 }
 ###

perldoc perl

[snip]

   perlsyn Perl syntax
   perldataPerl data structures

   perldsc Perl data structures intro
   perllol Perl data structures: arrays of arrays

   perlmod Perl modules: how they work
   perlmodlib  Perl modules: how to write and use
   perlmodstylePerl modules: how to write modules with style



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: Need help... packages

2005-09-01 Thread Charles K. Clarkson
Luinrandir mailto:[EMAIL PROTECTED] wrote:
: OK.. maybe I'm trying to be too fancy.
:
: the package is:
: ###
: package Names;
: @Countries(Ireland,Wales);
: %Lord{Ireland}=(Bob,Tom);
: %Lord{Wales}=(Ted,Ned);
:
: return 1;
: #
: the program is:
: ###
: foreach $Country(@Names::Countries)
: {
: print qq|$Names::$Lord{$Country}|;
: }
: ###
:
: I have tried several variation on this.. can't get it to work.
: I need it to print the array of Ireland and then Wales.

And later:

: my alternative is this, in the program:
:
:@[EMAIL PROTECTED]::Countries;

I assume that should be Names and not NamesList.


package Names;

%Lords = (
Wales   = [ qw( Ted Ned ) ],
Ireland = [ qw( Bob Tom ) ],
);


use Names;

{
# Use a shorter name to access %Names::Lord
my $lords = \%Names::Lords;

foreach my $Country ( qw( Wales Ireland ) ) {

print @{ $lords-{ $Country } }\n
if exists $lords-{ $Country };
}
}

__END__


If you don't know the country names ahead of time
you can use the keys from %Names::Lord. @Names::Countries
array is not necessary.

use Names;

{
# Use a shorter name to access %Names::Lord
my $lords = \%Names::Lords;

foreach my $country ( keys %$lords ) {

print @{ $lords-{ $country } }\n;
}
}


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328


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




Re: Need help... packages again -more

2005-09-01 Thread Luinrandir
Clark.. thanks for the help, I have to decode (look in my book and figure
out what you wrote) some of the code you wrote.
just wanna says thanks, but its way over my head :)  but look at the seconf
loop! i'm begining to understand how to use
those hidden , double secret invisable vars!-Lou

In the package:

@Countries=(Ireland,Iceland);

$Lord{Ireland}=Ambros:Baird:Cabhan:Dahey:Eirnin:Fergus:Glendan:Hugh:Innis:L
iam:Murtagh:Orin:Pierce:Quinn:Ronan:Scolaighe:Turlach:Luinrandir;

$Lord{Iceland}=Sigurður:Guðmundur:Jón:Gunnar:Ólafur:Magnús:Einar:Kristján:B
jörn:Bjarni;


in the program:

   foreach $Country(@NameList::Countries)
   {
   my @Lords=split (/:/,$NameList::Lord{$Country});
   print qq|1-$CountryBR|;
   print qq|2-$NameList::Lord{$Country}BR|;
   foreach (@Lords)
   {
  print;
  print qq|BR|;
   }
   }
results in HTML:
-Ireland
2-Ambros:Baird:Cabhan:Dahey:Eirnin:Fergus:Glendan:Hugh:Innis:Liam:Murtagh:Or
in:Pierce:Quinn:Ronan:Scolaighe:Turlach:Luinrandir
Ambros
Baird
Cabhan
Dahey
Eirnin
Fergus
Glendan
Hugh
Innis
Liam
Murtagh
Orin
Pierce
Quinn
Ronan
Scolaighe
Turlach
Luinrandir
1-Iceland
2-Sigurður:Guðmundur:Jón:Gunnar:Ólafur:Magnús:Einar:Kristján:Björn:Bjarni
Sigurður
Guðmundur
Jón
Gunnar
Ólafur
Magnús
Einar
Kristján
Björn
Bjarni

so I finally got it to work...
comments/thoughts?




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




Re: Need help... packages

2005-08-31 Thread Luinrandir
my alternative is this, in the program:

   @[EMAIL PROTECTED]::Countries;
   foreach $Country(@Countries)
   {
  if ($Country eq Ireland)
  [EMAIL PROTECTED]@NameList::IrelandLord}
  if ($Country eq Wales)
  [EMAIL PROTECTED]@NameList::WalesLord}
print @Lords;
}

but this means I have to adjust the code in the program each time 
and I was hoping to only adjust
the info in the package and let a loop in the program do the rest.
Lou


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