Click to See Complete Forum and Search --> : Perl syntax problem


gschimek
06-20-2005, 09:13 PM
I'm trying to simplify some code that looks like this:


@sorted_team1 = sort { $a cmp $b } @team1_emails;
@team1_emails = @sorted_team1;

@sorted_team2 = sort { $a cmp $b } @team2_emails;
@team2_emails = @sorted_team2;

@sorted_team3 = sort { $a cmp $b } @team3_emails;
@team3_emails = @sorted_team3;



I've tried using something like this but I get errors (not surprisingly):


@teams = (team1, team2, team3);
foreach $item (@teams) {
@sorted_$item = sort { $a cmp $b } @$item_emails;
@$item_emails = @sorted_$item;
}


I'm sure it's getting confused by the variables inside the array names. How can I accomplish what I want and still make Perl happy?

chrism01
06-21-2005, 03:12 AM
What are you trying to accomplish? One big sorted list?

@team_emails = (@team1_emails, @team2_emails, @team3_emails);
@sorted = sort { $a cmp $b } @team_emails;

gschimek
06-21-2005, 07:12 AM
Sorry, I guess I thought it was more apparent with the code. I'm actually trying to get a lot of different sorted lists. Earlier in the program, I've taken a list of names from a database, and depending on which group a person is in, it puts their email address into an array (team1, team2, team3, etc). But it doesn't sort them. So I want to sort all those separate arrays.

The two commands I noted above in the first set of code will do it if I use them for each team, but I've got about 10 different teams and I know there's got to be an easier way then typing out the code 10 different times.

bburton
06-21-2005, 10:30 AM
It seems to me that it might be easier to sort this data as it's being assigned, earlier on in the code.

@emails = sort ((@emails = ($items, $from, $dbase)));


Maybe you could post more of the script, specifically the part where these email arrays are loaded up?

gschimek
06-21-2005, 02:08 PM
Here's the entire subroutine that reads the text file containing the list, and puts their email addresses into separate arrays based on the team that they are on.


sub createTeamLists {
#split the text file up into separate values and place them in an array
foreach $email_entry (@raw_data)
{
($first_name,$last_name,$address,$city,$state,$zip ,$phone,$team,$gender,$grad_year,$email,$tec_numbe r,$rector)=split(/\,/,$email_entry);





#read the data and add to separate team lists
#=~ comparison operator matches if the variable simply contains the string. Does not
#need to be an exact match.
#/i option ignores case
if ($team =~ /atl/i)
{
if ($email ne "") {push (@atl_emails, "$email");}
$atl_members++;
}


elsif ($team =~ /ytl/i)
{
if ($email ne "") {push (@ytl_emails, "$email");}
$ytl_members++;
}


elsif ($team =~ /music/i)
{
if ($email ne "") {push (@music_emails, "$email");}
$music_members++;
}


elsif ($team =~ /photo/i)
{
if ($email ne "") {push (@music_emails, "$email");}
$music_members++;
}


elsif ($team =~ /Wheat/i)
{
if ($email ne "") {push (@wheat_emails, "$email");}
$wheat_members++;
}


elsif ($team =~ /support/i)
{
if ($email ne "") {push (@support_emails, "$email");}
$support_members++;
}


elsif ($team =~ /kitchen/i)
{
if ($email ne "") {push (@kitchen_emails, "$email");}
$kitchen_members++;
}


elsif ($team =~ /SD/i)
{
if ($email ne "") {push (@sd_emails, "$email");}
$sd_members++;
}



if ($team != /^[ \t]*$/)
{
if ($email ne "") {push (@team_emails, "$email");}
$team_members++;
}

if ($grad_year =~ /adult/i && $team !~ /atl/i)
{
if ($email ne "") {push (@leadership_emails, "$email");}
$leadership_members++;
}



if ($rector =~ /Y/i)
{
if ($email ne "") {push (@leadership_emails, "$email");}
$leadership_members++;
}
}

gschimek
06-21-2005, 08:04 PM
Anybody have any ideas?

flukshun
06-21-2005, 11:40 PM
@teams = (team1, team2, team3);
foreach $item (@teams) {
@sorted_$item = sort { $a cmp $b } @$item_emails;
@$item_emails = @sorted_$item;
}

i dont think you can include variables in the name of another variable. at the very least i dont think it would be good practice. it's not necessary anyway. here's a lazy solution, certainly not the most efficient method but no worse than creating new arrays from the unsorted emails really

#!/usr/bin/perl

my @team_emails1 = ('poo2@team1.com','poo1@team1.com','poo3@team1.com ');
my @team_emails2 = ('poo5@team2.com','poo6@team2.com','poo4@team2.com ');
my @team_emails3 = ('poo9@team3.com','poo8@team3.com','poo7@team3.com ');
my @array_of_unsorted_emails = (\@team_emails1, \@team_emails2, \@team_emails3);
my %hash_of_sorted_emails;
my $team_number = 1;

#sort emails and store each as an anonymous array in %hash_of_sorted_emails
foreach my $team_emails (@array_of_unsorted_emails) {
$hash_of_sorted_emails{$team_number++} = [sort {$a cmp $b} @$team_emails];
}

#output contents of %hash_of_sorted_emails
for my $team (sort keys %hash_of_sorted_emails) {
print "Emails for Team $team:\n";
for ( @{$hash_of_sorted_emails{$team}} ) {
print "$_\n";
}
}

__DATA__
Emails for Team 1:
poo1@team1.com
poo2@team1.com
poo3@team1.com
Emails for Team 2:
poo4@team2.com
poo5@team2.com
poo6@team2.com
Emails for Team 3:
poo7@team3.com
poo8@team3.com
poo9@team3.com

i thought it was gonna look prettier when i started heh

gschimek
06-22-2005, 04:16 PM
OK, something's just not right. Here's the subroutine I'm working on. I tried your code from above by itself and it works great. When I enter it into my subroutine, it doesn't sort anything.


sub createTeamLists {
#split the text file up into separate values and place them in an array
foreach $email_entry (@raw_data)
{
($first_name,$last_name,$address,$city,$state,$zip ,$phone,$team,$gender,$grad_year,$email,$tec_numbe r,$rector)=split(/\,/,$email_entry);





#read the data and add to separate team lists
#=~ comparison operator matches if the variable simply contains the string. Does not
#need to be an exact match.
#/i option ignores case
if ($team =~ /Kitchen/i)
{
if ($email ne "") {push (@kitchen_emails, "$email");}
$kitchen_members++;
}


elsif ($team =~ /support/i)
{
if ($email ne "") {push (@support_emails, "$email");}
$support_members++;
}


if ($rector =~ /Y/i)
{
if ($email ne "") {push (@leadership_emails, "$email");}
$leadership_members++;
}
}


my @array_of_unsorted_emails = (\@leadership_emails, \@support_emails, \@kitchen_emails);
my %hash_of_sorted_emails;
my $team_number = 1;


#sort emails and store each as an anonymous array in %hash_of_sorted_emails
foreach my $team_emails (@array_of_unsorted_emails) {
$hash_of_sorted_emails{$team_number++} = [sort {$a cmp $b} @$team_emails];
}

}


If I add these lines immediately before the last curly bracket, it sorts the @support_emails array just fine.


@sorted_support = sort { $a cmp $b } @support_emails;
@support_emails = @sorted_support;



What am I ,missing?

flukshun
06-22-2005, 06:50 PM
looks like it should work. how are you testing the code? the data structure is a little tricky to access, can you post the full code and output?

bryan.6
06-22-2005, 07:45 PM
What you really want is a hash of arrays.

my %emails;

# you don't need to initialize these,
# but I thought I would to show you
# that each element in the hash is
# an anonymous array

my %emails = (
'atl' => [],
'ytl' => [],
'music' => [],
...
);

if ( $team =~ /atl/i ) {
if ($email ne "") {
# also, you can just push $email, no need to stringify it ( "$email" )
push @{ $emails{ 'atl' } }, $email;
}
$atl_members++;
}
elsif ($team =~ /ytl/i)
{
if ($email ne "") {
push @{ $emails{ 'ytl' } }, $email;
}
$ytl_members++;
}
...


# then later you can print them:

for $key ( sort keys %emails ) {
print "Team: $key\n";
for $email ( sort @{ $emails{ $key } } ) {
print " $email\n";
}
}

gschimek
06-22-2005, 07:45 PM
Here's the code. There's a lot of time/date checking because it's time sensitive data that's displayed. You can ignore a lot of the subroutines.

I'll post the results next.


#!/usr/local/bin/perl
use CGI qw(:standard);
use Fcntl ':flock';
use CGI::Carp qw(fatalsToBrowser);

#Takes team list consisting of first name, last name, team, and email address in that order
#and creates lists of email addresses in separate windows by team.
#data file must be a comma separated value file called "teamdata.dat"



$data_file="teamdatatest.dat";

open(DAT, $data_file) || die("Could not open file!");
@raw_data=<DAT>;
close(DAT);

open(WEEKEND_DAT, "../weekends/weekends.dat") || die("Could not open file!");
@weekend_data=<WEEKEND_DAT>;
close(WEEKEND_DAT);









#Uses localtime function to get the current time and date
&GetCurrentDate;

#Gets the date of the next weekend
&GetWeekendDate;

#variables to be set for testing purposes
#$candidate_arrival_date='4/25/05';
#$RealMonth=5;

#Changes date from mm/dd/yyyy format to 3 separate variable for month, date, and year
&ParseWeekendDate;

#Changes month notation from text to number. ex. Apr becomes 4
&Change_Current_Month_To_Number;



#Creates a variable for when to change the display and not show the most recently completed weekend
$CutOffDate=$CADate+2;




&createTeamLists;
&tallyNumbers;




&PrintHeader;

#print "hello<br>weekend month $weekend_month_number<br>current month $RealMonth<br>todays date $Day<br>cutoffdate $CutOffDate<br>";
#print "tec# $tec_number<br>weekend $weekend<br>";

if ($weekend_month_number<=$RealMonth && $Day>$CutOffDate && $tec_number>=$weekend) {
print "Current team list is not available until closer to the next TEC weekend. Please check back later.";
}
else {
&printResults;
}











################################################## #############################


sub createTeamLists {
#split the text file up into separate values and place them in an array
foreach $email_entry (@raw_data)
{
($first_name,$last_name,$address,$city,$state,$zip ,$phone,$team,$gender,$grad_year,$email,$tec_numbe r,$rector)=split(/\,/,$email_entry);





#read the data and add to separate team lists
#=~ comparison operator matches if the variable simply contains the string. Does not
#need to be an exact match.
#/i option ignores case
if ($team =~ /atl/i)
{
#open atllist, '>> atllist.dat';
#print atllist "$email\n";
#close atllist;
if ($email ne "") {push (@atl_emails, "$email");}
$atl_members++;
}


elsif ($team =~ /ytl/i)
{
#open ytllist, '>> ytllist.dat';
#print ytllist "$email\n";
#close ytllist;
if ($email ne "") {push (@ytl_emails, "$email");}
$ytl_members++;
}


elsif ($team =~ /music/i)
{
#open musiclist, '>> musiclist.dat';
#print musiclist "$email\n";
#close musiclist;
if ($email ne "") {push (@music_emails, "$email");}
$music_members++;
}


elsif ($team =~ /photo/i)
{
#open musiclist, '>> musiclist.dat';
#print musiclist "$email\n";
#close musiclist;
if ($email ne "") {push (@music_emails, "$email");}
$music_members++;
}


elsif ($team =~ /Wheat/i)
{
#open wheatlist, '>> wheatlist.dat';
#print wheatlist "$email\n";
#close wheatlist;
if ($email ne "") {push (@wheat_emails, "$email");}
$wheat_members++;
}


elsif ($team =~ /support/i)
{
#open supportlist, '>> supportlist.dat';
#print supportlist "$email\n";
#close supportlist;
if ($email ne "") {push (@support_emails, "$email");}
$support_members++;
}


elsif ($team =~ /kitchen/i)
{
#open kitchenlist, '>> kitchenlist.dat';
#print kitchenlist "$email\n";
#close kitchenlist;
if ($email ne "") {push (@kitchen_emails, "$email");}
$kitchen_members++;
}


elsif ($team =~ /SD/i)
{
#open sdlist, '>> sdlist.dat';
#print sdlist "$email\n";
#close sdlist;
if ($email ne "") {push (@sd_emails, "$email");}
$sd_members++;
}



if ($team != /^[ \t]*$/)
{
#open entireteam, '>> entireteam.dat';
#print entireteam "$email\n";
#close entireteam;
if ($email ne "") {push (@team_emails, "$email");}
$team_members++;
}

if ($grad_year =~ /adult/i && $team !~ /atl/i)
{
#open leaderlist, '>> leaderlist.dat';
#print leaderlist "$email\n";
#close leaderlist;
if ($email ne "") {push (@leadership_emails, "$email");}
$leadership_members++;
}



if ($rector =~ /Y/i)
{
#open leaderlist, '>> leaderlist.dat';
#print leaderlist "$email\n";
#close leaderlist;
if ($email ne "") {push (@leadership_emails, "$email");}
$leadership_members++;
}
}


my @array_of_unsorted_emails = (\@leadership_emails, \@support_emails, \@kitchen_emails);
my %hash_of_sorted_emails;
my $team_number = 1;


#sort emails and store each as an anonymous array in %hash_of_sorted_emails
foreach my $team_emails (@array_of_unsorted_emails) {
$hash_of_sorted_emails{$team_number++} = [sort {$a cmp $b} @$team_emails];
}

#@sorted_support = sort { $a cmp $b } @support_emails;
#@support_emails = @sorted_support;

}

sub tallyNumbers {
$num_atl_emails=@atl_emails;
$num_ytl_emails=@ytl_emails;
$num_support_emails=@support_emails;
$num_wheat_emails=@wheat_emails;
$num_kitchen_emails=@kitchen_emails;
$num_music_emails=@music_emails;
$num_leadership_emails=@leadership_emails;
$num_sd_emails=@sd_emails;
$num_team_emails=@team_emails;
}



sub printResults {
#print "Content-type: text/html\n\n";
#print "<html><head><title>Email Lists</title></head><body bgcolor=4e7aa8 text=FFFFFF>";

#&open_data;

print "<table width=700><tr><td align=center><br><font size=+2 font face=arial><b>TEC $tec_number Team Member Email List By Team</b></font></td></tr></table>";

print "<form name=form1 method=post action=emaillist.pl>
<form name=form1 method=post action=>
<table width=800>
<tr>
<td valign=top> Leadership ($num_leadership_emails\/$leadership_members)<br>
<textarea name=textfield cols=40 rows=10 wrap=OFF>";
foreach $leaders (@leadership_emails){
print "$leaders\n";
}
print "</textarea>
</td>
<td> Entire Team ($num_team_emails\/$team_members)<br>
<textarea name=textarea2 cols=40 rows=10 wrap=OFF>";
foreach $team (@team_emails){
print "$team\n";
}
print "</textarea>
</td>
</tr>
<tr>
<td valign=top>Support ($num_support_emails\/$support_members)<br>
<textarea name=textarea3 cols=40 rows=10 wrap=OFF>";
foreach $support (@support_emails){
print "$support\n";
}
print "</textarea>
</td>
<td> Wheat ($num_wheat_emails\/$wheat_members)<br>
<textarea name=textarea4 cols=40 rows=10 wrap=OFF>";
foreach $wheat (@wheat_emails){
print "$wheat\n";
}
print "</textarea>
</td>
</tr>
<tr>
<td valign=top>Kitchen ($num_kitchen_emails\/$kitchen_members)<br>
<textarea name=textarea5 cols=40 rows=10 wrap=OFF>";
foreach $kitchen (@kitchen_emails){
print "$kitchen\n";
}
print "</textarea>
</td>
<td> Music ($num_music_emails\/$music_members)<br>
<textarea name=textarea6 cols=40 rows=10 wrap=OFF>";
foreach $music (@music_emails){
print "$music\n";
}
print "</textarea>
</td>
</tr>
<tr>
<td valign=top> ATLs ($num_atl_emails\/$atl_members)<br>
<textarea name=textarea7 cols=40 rows=10 wrap=OFF>";
foreach $atl(@atl_emails){
print "$atl\n";
}
print "</textarea>
</td>
<td> YTLs ($num_ytl_emails\/$ytl_members)<br>
<textarea name=textarea8 cols=40 rows=10 wrap=OFF>";
foreach $ytl (@ytl_emails){
print "$ytl\n";
}
print "</textarea>
</td>
</tr>
<tr>
<td valign=top> Spiritual Directors ($num_sd_emails\/$sd_members)<br>
<textarea name=textarea9 cols=40 rows=10 wrap=OFF>";
foreach $sd (@sd_emails){
print "$sd\n";
}
print "</textarea>
</td>
</tr>
</table>";

#output contents of %hash_of_sorted_emails
foreach $support_team_email (@support_emails) {
print "$support_team_email<br>\n";
}


print "<p>\n</p>
</form>
</body>

</html>";

}




sub open_data {
open LEADERS, "leaderlist.dat" or DIE || "Can't open File";
@leaders=<LEADERS>;
close LEADERS;

open TEAM, "entireteam.dat" or DIE || "Can't open File";
@team=<TEAM>;
close TEAM;

open SUPPORT, "supportlist.dat" or DIE || "Can't open File";
@support=<SUPPORT>;
close SUPPORT;

open KITCHEN, "kitchenlist.dat" or DIE || "Can't open File";
@kitchen=<KITCHEN>;
close KITCHEN;

open WHEAT, "wheatlist.dat" or DIE || "Can't open File";
@wheat=<WHEAT>;
close WHEAT;

open MUSIC, "musiclist.dat" or DIE || "Can't open File";
@music=<MUSIC>;
close MUSIC;

open SD, "sdlist.dat" or DIE || "Can't open File";
@sd=<SD>;
close SD;

open ATL, "atllist.dat" or DIE || "Can't open File";
@atl=<ATL>;
close ATL;

open YTL, "ytllist.dat" or DIE || "Can't open File";
@ytl=<YTL>;
close YTL;
}











sub PrintHeader {
print "Content-type: text/html\n\n";
print "<HTML><BODY bgcolor=4e7aa8 text=FFFFFF>";

open (FILE, '../header/Header.lbi') || die("Can't open File");
@stuff=<FILE>;
close FILE;

print "@stuff";
print "<br><br>";
}



sub Change_Current_Month_To_Number {
if ($weekend_month eq 'Jan')
{$weekend_month_number = 1}
elsif ($weekend_month eq 'Apr')
{$weekend_month_number = 4}
elsif ($weekend_month eq 'July')
{$weekend_month_number = 7}
elsif ($weekend_month eq 'Oct')
{$weekend_month_number = 10}
}


sub GetCurrentDate {
($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime();
$RealMonth=$Month+1;
$RealYear=$Year-100;
}


sub GetWeekendDate {
for $weekend_info (@weekend_data)
{
chop($weekend_info);
($weekend,$weekend_month,$weekend_start_date,$week end_end_date,$weekend_year,$church,$church_website ,$address,$address_url,$city,$state,$zip,$phone,$t eam_arrival_date,$candidate_arrival_date,$departur e_date,$leadership_date,$meeting_1,$meeting_2,$mee ting_3,$reunion_date,$application_deadline)=split(/\|/,$weekend_info);
return (1);
}
}




sub ParseWeekendDate {
($CAMonth, $CADate, $CAYear)=split(/\//,$candidate_arrival_date);
}

gschimek
06-22-2005, 07:47 PM
I've tested 2 ways. Via command line with perl emaillistbak.pl, and also by posting it to my site. It displays fine in both places, except for not sorting.

I've used fake email addresses for the results below.


Results:
[code]
Content-type: text/html

<HTML><BODY bgcolor=4e7aa8 text=FFFFFF><html>
<head>
<!-- #BeginEditable "doctitle" -->
<title>Southern Minnesota Teens Encounter Christ</title>
<!-- #EndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<script language="JavaScript">
<!--
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->

function P7_autoLayers() { //v1.1 PVII
var g,b,k,f,args=P7_autoLayers.arguments;
if(!document.p7setc) {p7c=new Array();document.p7setc=true;}
for(k=0; k<p7c.length; k++) {
if((g=MM_findObj(p7c[k]))!=null) {
b=(document.layers)?g:g.style;b.visibility="hidden";}}
for(k=0; k<args.length; k++) {
if((g=MM_findObj(args[k])) != null) {
b=(document.layers)?g:g.style;b.visibility="visible";f=false;
for(j=0;j<p7c.length;j++) {
if(args[k]==p7c[j]) {f=true;}}
if(!f) {p7c[p7c.length++]=args[k];}}}
}

function pviiW3Cbg(obj, pviiColor) { //v1.1 by Project VII
obj.style.backgroundColor=pviiColor
}

function MM_popupMsg(msg) { //v1.0
alert(msg);
}
//-->
</script>
</head>
<body text="#FFFFFF" onLoad="MM_preloadImages('../../images/masthead2004_over_05.gif','../../images/masthead2004_over_09.gif','../../images/masthead2004_over_08.gif','../../images/masthead2004_over_07.gif','../../images/masthead2004_over_06.gif','../../images/masthead2004_over_10.gif')" bgcolor="#4E7AA8" link="#FFFF33" vlink="#FFFF33" alink="#FFFF33">
<div id="Layer1" style="position:absolute; width:272px; height:110px; z-index:5; left: 378px; top: -4px; visibility: visible">
</div>
<div id="CouncilMenu" style="position:absolute; width:200px; height:20; z-index:21; left: 253px; top: 196px; visibility: hidden">
<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF" onMouseOver="pviiW3Cbg(this, '#99CCFF')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')"><a href="../../teccouncil.htm"><img src="../../images/coucil_images/councilmembers.gif" width="200" height="20" onMouseOver="P7_autoLayers('CouncilMenu')" border="0"></a></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" onMouseOver="pviiW3Cbg(this, '#99CCFF')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')"><a href="../../email.htm"><img src="../../images/coucil_images/emailcouncil.gif" width="200" height="20" border="0" onMouseOver="P7_autoLayers('CouncilMenu')"></a></td>
</tr>
</table>
</div>
<div id="Apps" style="position:absolute; width:125; height:20; z-index:37; left: 146px; top: 296px; visibility: hidden">
<table width="125" border="0" cellspacing="0" cellpadding="0" onMouseOver="P7_autoLayers('Apps','InfoMenu')" onMouseOut="P7_autoLayers()">
<tr>
<td onMouseOver="pviiW3Cbg(this, '#99CCFF');P7_autoLayers('Apps','InfoMenu')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')" bgcolor="#FFFFFF"><a href="../applications/application.pl"><img src="../../images/candidateonlineappbutton.gif" width="125" height="20" border="0"></a></td>
</tr>
<tr>
<td onMouseOver="pviiW3Cbg(this, '#99CCFF');P7_autoLayers('Apps','InfoMenu')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')" bgcolor="#FFFFFF"><a href="../../applications/candidate.pdf" target="_blank"><img src="../../images/candidateapplicationbutton.gif" width="125" height="20" border="0"></a></td>
</tr>
<tr>
<td onMouseOver="pviiW3Cbg(this, '#99CCFF')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')" bgcolor="#FFFFFF"><a href="../../applications/team.pdf" target="_blank"><img src="../../images/youthteambutton.gif" width="125" height="20" border="0"></a></td>
</tr>
<tr>
<td onMouseOver="pviiW3Cbg(this, '#99CCFF')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')" bgcolor="#FFFFFF"><a href="../../applications/adult.pdf" target="_blank"><img src="../../images/adultteam.gif" width="125" height="20" border="0"></a></td>
</tr>
<tr>
<td onMouseOver="pviiW3Cbg(this, '#99CCFF')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')" bgcolor="#FFFFFF"><a href="../../applications/Financial_Assistance.pdf"><img src="../../images/scholarship.gif" width="125" height="20" border="0"></a></td>
</tr>
<tr>
<td onMouseOver="pviiW3Cbg(this, '#99CCFF')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')" bgcolor="#FFFFFF"><a href="http://www.adobe.com/products/acrobat/readstep2.html" target="_blank"><img src="../../images/getacrobat.gif" width="125" height="20" border="0"></a></td>
</tr>
</table>
</div>
<div id="TeamOnlyMenu" style="position:absolute; left:628px; top:199px; width:125; z-index:38; visibility: hidden">
<table width="125" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF" onMouseOver="pviiW3Cbg(this, '#99CCFF')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')"><a href="../../teamonly.htm"><img src="../../images/whyteamonly.gif" width="125" height="20" border="0" onMouseOver="P7_autoLayers('TeamOnlyMenu')"></a></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" onMouseOver="pviiW3Cbg(this, '#99CCFF')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')"><a href="../yabb/YaBB.cgi"><img src="../../images/forums.gif" width="125" height="20" border="0" onMouseOver="P7_autoLayers('TeamOnlyMenu')"></a></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" onMouseOver="pviiW3Cbg(this, '#99CCFF')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')" height="13"><a href="#"><img src="../../images/evaluations.gif" width="125" height="20" onMouseOver="P7_autoLayers('TeamOnlyMenu','Evaluations')" border="0"></a></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" onMouseOver="pviiW3Cbg(this, '#99CCFF')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')"><a href="../../teamonly/outlines/index.htm"><img src="../../images/talkoutlines.gif" width="125" height="20" border="0" onMouseOver="P7_autoLayers('TeamOnlyMenu')"></a></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" onMouseOver="pviiW3Cbg(this, '#99CCFF')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')"><a href="../../teamonly/councilnews/index.htm"><img src="../../images/councilnews.gif" width="125" height="20" border="0"></a></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" onMouseOver="pviiW3Cbg(this, '#99CCFF')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')"><a href="../../teamonly/documents"><img src="../../images/tecdocuments.gif" width="125" height="20" border="0" onClick="MM_popupMsg('For TEC Council Members only')"></a></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" onMouseOver="pviiW3Cbg(this, '#99CCFF')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')"><img src="../../images/password.gif" width="125" height="20" onClick="MM_popupMsg('Team Only Area Access Information:\rUsername: tec\rPassword: The name of Saturday night\'s dinner')"></td>
</tr>
</table>
</div>
<div id="Evaluations" style="position:absolute; width:125; z-index:39; left: 504px; top: 239px; visibility: hidden">
<table width="125" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF" onMouseOver="pviiW3Cbg(this, '#99CCFF')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')"><a href="../../teameval.htm"><img src="../../images/tecevalbutton.gif" width="125" height="20" border="0" onMouseOver="P7_autoLayers('TeamOnlyMenu','Evaluations')"></a></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" onMouseOver="pviiW3Cbg(this, '#99CCFF')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')"><a href="../../tableeval.htm"><img src="../../images/atlytlbutton.gif" width="125" height="20" border="0"></a></td>
</tr>
</table>
</div>
<table width="743" border="0" cellpadding="0" cellspacing="0" mm:layoutgroup="true" align="left">
<tr>
<td height="938" valign="top">
<table width="100%" border="0" cellpadding="0" cellspacing="0" height="164">
<tr>
<td width="138" height="175" valign="top">
<div align="center">
<div id="Logo" style="position:absolute; width:141px; height:160px; z-index:7; left: 10px; top: 12px; visibility: visible" onClick="P7_autoLayers()"><img src="../../images/masthead2004_02.gif" width="165" height="160"></div>
</div>
</td>
<td width="605" valign="top" height="175">
<div align="center">
<div id="DatesMenu" style="position:absolute; width:125; z-index:20; left: 93px; top: 196px; visibility: hidden" onMouseOver="P7_autoLayers('DatesMenu')">
<table width="125" border="0" cellspacing="0" cellpadding="0">
<tr>

<td bgcolor="#FFFFFF" onMouseOver="pviiW3Cbg(this, '#99CCFF')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')"><a href="../weekends/weekends.pl"><img src="../../images/alldates.gif" width="125" height="20" border="0"></a></td>
</tr>
<tr>

<td bgcolor="#FFFFFF" onMouseOver="pviiW3Cbg(this, '#99CCFF')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')"><a href="../teamlist/team.pl"><img src="../../images/current_team_button.gif" width="125" height="20" border="0"></a></td>
</tr>
</table>
</div>
<div id="TeamOnly" style="position:absolute; width:144px; height:29; z-index:17; left: 625px; top: 168px; visibility: visible"><a href="../../teamonly/index.htm"><img name="Other" src="../../images/masthead2004_10.gif" width="137" height="31" onMouseOut="MM_swapImgRestore()" border="0" onMouseOver="P7_autoLayers('TeamOnlyMenu');MM_swapImage('Other' ,'','../../images/masthead2004_over_10.gif',1)"></a></div>
<div id="Guestbook" style="position:absolute; width:107; height:29; z-index:16; top: 168px; left: 496px; visibility: visible"><a href="../guestbook.cgi" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Pictures','','../../images/masthead2004_over_09.gif',1)"><img name="Pictures" border="0" src="../../images/masthead2004_09.gif" width="132" height="31" onMouseOver="P7_autoLayers()"></a></div>
<div id="Pictures" style="position:absolute; width:47px; height:29px; z-index:15; left: 389px; top: 168px; visibility: visible"><a href="../../pictures.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Council','','../../images/masthead2004_over_08.gif',1)"><img name="Council" border="0" src="../../images/masthead2004_08.gif" width="107" height="31" onMouseOver="P7_autoLayers()"></a></div>
<div id="Dates" style="position:absolute; width:115px; height:29px; z-index:18; left: 252px; top: 168px; visibility: visible"><a href="../../teccouncil.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Dates','','../../images/masthead2004_over_07.gif',1)"><img name="Dates" border="0" src="../../images/masthead2004_07.gif" width="137" height="31" onMouseOver="P7_autoLayers('CouncilMenu')"></a></div>
<div id="Info" style="position:absolute; width:89px; z-index:14; left: 88px; top: 168px; visibility: visible"><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Info','','../../images/masthead2004_over_06.gif',1)"><img name="Info" border="0" src="../../images/masthead2004_06.gif" width="165" onMouseOver="P7_autoLayers('DatesMenu')" height="31"></a>
</div>
<div id="Information" style="position:absolute; width:75px; height:29px; z-index:13; left: 10px; top: 168px; visibility: visible"><a href="../../info.htm" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Home','','../../images/masthead2004_over_05.gif',1)"><img name="Home" border="0" src="../../images/masthead2004_05.gif" width="78" height="31" onMouseOver="P7_autoLayers('InfoMenu')"></a>
</div>
<div id="InfoMenu" style="position:absolute; width:125; height:20; z-index:19; left: 21px; top: 197px; visibility: hidden">
<table width="125" border="0" cellspacing="0" cellpadding="0">
<tr>
<td onMouseOver="pviiW3Cbg(this, '#99CCFF')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')" bgcolor="#FFFFFF"><a href="../../info.htm"><img src="../../images/general.gif" width="125" height="20" border="0" onMouseOver="P7_autoLayers('InfoMenu')" onMouseOut="P7_autoLayers()"></a></td>
</tr>
<tr>
<td onMouseOver="pviiW3Cbg(this, '#99CCFF');P7_autoLayers('InfoMenu')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')" bgcolor="#FFFFFF"><a href="../../faq.htm"><img src="../../images/faq.gif" width="125" height="20" border="0"></a></td>
</tr>
<tr>

<td onMouseOver="pviiW3Cbg(this, '#99CCFF');P7_autoLayers('InfoMenu')" bgcolor="#FFFFFF" onMouseOut="pviiW3Cbg(this, '#FFFFFF')"><a href="../history/history.pl"><img src="../../images/historybutton.gif" width="125" height="20" alt="Coming Soon!" border="0"></a></td>
</tr>
<tr>
<td onMouseOver="pviiW3Cbg(this, '#99CCFF');P7_autoLayers('InfoMenu')" bgcolor="#FFFFFF" onMouseOut="pviiW3Cbg(this, '#FFFFFF')"><a href="../../newsletters/53newsletter.htm"><img src="../../images/newsletters.gif" width="125" height="20" border="0"></a></td>
</tr>
<tr>
<td onMouseOver="pviiW3Cbg(this, '#99CCFF');P7_autoLayers('InfoMenu')" bgcolor="#FFFFFF" onMouseOut="pviiW3Cbg(this, '#FFFFFF')"><a href="../../links.htm"><img src="../../images/linksbutton.gif" width="125" height="20" alt="Coming Soon!" border="0"></a></td>
</tr>
<tr>
<td onMouseOver="pviiW3Cbg(this, '#99CCFF');P7_autoLayers('Apps','InfoMenu')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')" bgcolor="#FFFFFF"><img src="../../images/applications.gif" width="125" height="20"></td>
</tr>
</table>
</div>
<div id="PicsMenu" style="position:absolute; width:125px; z-index:22; left: 392px; top: 197px; visibility: hidden; height: 32px">
<table width="125" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<table width="125" border="0" cellspacing="0" cellpadding="0" onMouseOver="P7_autoLayers('PicsMenu')">
<tr>
<td onMouseOver="pviiW3Cbg(this, '#99CCFF')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')" bgcolor="#FFFFFF">&nbsp;</td>
</tr>
<tr>
<td onMouseOver="pviiW3Cbg(this, '#99CCFF')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')" bgcolor="#FFFFFF"><a href="../../photos/TEC54/tec54pics.htm"><img src="../../images/tec54picsbutton.gif" width="125" height="20" border="0"></a></td>
</tr>
<tr>
<td onMouseOver="pviiW3Cbg(this, '#99CCFF')" onMouseOut="pviiW3Cbg(this, '#FFFFFF')" bgcolor="#FFFFFF"><a href="../../photos/TEC55/tec55pics.htm"><img src="../../images/tec55picsbutton.gif" width="125" height="20" border="0"></a></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<p>&nbsp;</p>
<div id="MastRight" style="position:absolute; width:546px; height:160px; z-index:6; left: 175px; top: 12px; visibility: visible" onClick="P7_autoLayers()"><img src="../../images/masthead2004_03.jpg" width="591" height="160"></div>
</div>
</td>
</tr>
</table>
<div align="left">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="756" height="623" valign="top" onMouseOver="P7_autoLayers()">&nbsp;
<br><br><table width=700><tr><td align=center><br><font size=+2 font face=arial><b>TEC 60 Team Member Email List By Team</b></font></td></tr></table><form name=form1 method=post action=emaillist.pl>
<form name=form1 method=post action=>
<table width=800>
<tr>
<td valign=top> Leadership (3/20)<br>
<textarea name=textfield cols=40 rows=10 wrap=OFF>email6
email10
email9
</textarea>
</td>
<td> Entire Team (22/77)<br>
<textarea name=textarea2 cols=40 rows=10 wrap=OFF>email1
email2
email3
email4
email5
email6
email10
email9
email8
email7
email25
email24
email23
email12
email22
email20
email15
email17
email40
email35
email33
email31
</textarea>
</td>
</tr>
<tr>
<td valign=top>Support (8/18)<br>
<textarea name=textarea3 cols=40 rows=10 wrap=OFF>email4
email5
email6
email8
email7
email12
email22
email17
</textarea>
</td>
<td> Wheat (7/18)<br>
<textarea name=textarea4 cols=40 rows=10 wrap=OFF>email2
email3
email9
email25
email23
email15
email40
</textarea>
</td>
</tr>
<tr>
<td valign=top>Kitchen (3/15)<br>
<textarea name=textarea5 cols=40 rows=10 wrap=OFF>email1
email20
email31
</textarea>
</td>
<td> Music (1/6)<br>
<textarea name=textarea6 cols=40 rows=10 wrap=OFF>email10
</textarea>
</td>
</tr>
<tr>
<td valign=top> ATLs (0/6)<br>
<textarea name=textarea7 cols=40 rows=10 wrap=OFF></textarea>
</td>
<td> YTLs (3/8)<br>
<textarea name=textarea8 cols=40 rows=10 wrap=OFF>email24
email35
email33
</textarea>
</td>
</tr>
<tr>
<td valign=top> Spiritual Directors (0/2)<br>
<textarea name=textarea9 cols=40 rows=10 wrap=OFF></textarea>
</td>
</tr>
</table>email4<br>
email5<br>
email6<br>
email8<br>
email7<br>
email12<br>
email22<br>
email17<br>
<p>
</p>
</form>
</body>

flukshun
06-22-2005, 07:56 PM
i think the problem is in the output routine, the sorted emails are gonna be stored in %hash_of _sort_emails, but focusing on your code to print out the support emails you try to access @support_emails, which should contain the original unsorted emails. the sorted emails are gonna be stored in an anonymous array inside of %hash_of_sorted_emails

#output contents of %hash_of_sorted_emails
foreach $support_team_email (@support_emails) {
print "$support_team_email<br>\n";
}

should be

#output contents of %hash_of_sorted_emails
foreach $support_team_email ( @{$hash_of_sorted_emails{1}} ) {
print "$support_team_email<br>\n";
}

arrays of support, leadership, etc emails are keyed numerical in the %hash_of_sorted_emails structure. i havent checked but it looks like the sorted copy of @support_emails will get keyed to $hash_of_sorted_emails{1}, which you dereference as a list to obtain the sorted emails. you might wanna tweak the sort routine to key the arrays as "support", "leadership", etc for clarity later.

gschimek
06-22-2005, 08:58 PM
I made the change you noted and now it doesn't output any addresses--sorted or unsorted.

Would it help if I removed all the references to the files that get opened so that you could test it?

flukshun
06-22-2005, 09:46 PM
i really dont know what's goin on on your end there. one mistake in my last reply was that the hash key for the support emails would be '2', not '1'. i forgot i started at 1, but still...it should've printed at least the leadership emails or whatever. cutting out the other stuff this is the test script i put together:


#!/usr/bin/perl

@leadership_emails = ('me@leadership.com', 'me2@leadership.com');
@support_emails = ('me4@support.com', 'me3@support.com', 'me9@here.com');
@kitchen_emails = ('me5@here.com', 'me6@here.com');


my @array_of_unsorted_emails = (\@leadership_emails, \@support_emails, \@kitchen_emails);
my %hash_of_sorted_emails;
my $team_number = 1;


#sort emails and store each as an anonymous array in %hash_of_sorted_emails
foreach my $team_emails (@array_of_unsorted_emails) {
$hash_of_sorted_emails{$team_number++} = [sort {$a cmp $b} @$team_emails];
}

#output contents of %hash_of_sorted_emails
foreach $support_team_email ( @{$hash_of_sorted_emails{2}} ) {
print "$support_team_email<br>\n";
}


here's the output:
fluxion@purity:~/scripts$ ./email.pl
me3@support.com<br>
me4@support.com<br>
me9@support.com<br>
fluxion@purity:~/scripts$

so go ahead and change the hash key on the output routine to '2' and give it another shot. otherwise i dont see why it wouldn't work on my end, assuming @support_emails is just a list of emails, since i took the code straight out of your latest script and simply loaded the arrays manually and changed the hash key on the output routine.

gschimek
06-22-2005, 11:01 PM
I figured it out. In the code you suggested, you were using (I forget the actualy term) non-global arrays and hashes with "my @array_of_unsorted_emails" and "my %hash_of_sorted_emails"

I was calling them from a different subroutine, and since they weren't global, I think they were empty as far as the other subroutine was concerned.

I removed the "my's" and it's working fine.

Thanks for the help.