P
petersson
Hi,
I'm only familiar with two programming environments. That's Perl and
SPSS (Statistical Package for the Social Science, www.spss.com). This
is actually an SPSS question, but I got no answer from
comp.soft-sys.stat.spss so I turn to this ng since it's the other
environment that I understand (at least roughly). And I can pretty
much translate my SPSS code to Perl.
I have tree lists:
@rows=('q2','q8','q10','q11','q19','q20','q22','q29');
@m_vars=('q10','q19','q20');
@m_labs=('Filter A','Filter B','Filter C');
and I want this print:
q2
q8
Filter A
q11
Filter B
Filter C
q22
q29
I want to loop through @rows, and whenever I encounter a match between
an item in @rows and an item in @m_vars, I want to print the
corresponding item in @m_labs.
Here's the catch: In SPSS I only have access to a foreach-like loop. I
can use a if-structure with "next" ("last", "redo" and "goto" are not
available). The "elsif" is not available in SPSS if-structure, only
"else".
I have a work-around for an auto increment like thingy (++).
With all the tools available in Perl, this is probably a no-brainer,
but the constraints replicated from SPSS suggests a robust solution...
Anyone?
This the translated SPSS code I have so far:
$match=0;
@rows=('q1','q2','q3','q4','q5','q6','q7','q8');
@m_vars=('q3','q5','q6');
@m_labs=('Filter A','Filter B','Filter C');
foreach $i (@rows) {
$i_count=1;
$j_count=1;
foreach $j (@m_vars) {
$k_count=1;
foreach $k (@m_labs){
# Set a flag to use in the
# last condition below...
if($i eq $j && $k_count == 1){
$match++;
}
# Print the main list
if ($i ne $j && $i_count == 1) {
print "$i\n";
}
# Print the "Filters"...
if ($i eq $j && $match == $k_count) {
print "$k\n";
}
$i_count++;
$k_count++;
}
$j_count++;
}
}
I'm only familiar with two programming environments. That's Perl and
SPSS (Statistical Package for the Social Science, www.spss.com). This
is actually an SPSS question, but I got no answer from
comp.soft-sys.stat.spss so I turn to this ng since it's the other
environment that I understand (at least roughly). And I can pretty
much translate my SPSS code to Perl.
I have tree lists:
@rows=('q2','q8','q10','q11','q19','q20','q22','q29');
@m_vars=('q10','q19','q20');
@m_labs=('Filter A','Filter B','Filter C');
and I want this print:
q2
q8
Filter A
q11
Filter B
Filter C
q22
q29
I want to loop through @rows, and whenever I encounter a match between
an item in @rows and an item in @m_vars, I want to print the
corresponding item in @m_labs.
Here's the catch: In SPSS I only have access to a foreach-like loop. I
can use a if-structure with "next" ("last", "redo" and "goto" are not
available). The "elsif" is not available in SPSS if-structure, only
"else".
I have a work-around for an auto increment like thingy (++).
With all the tools available in Perl, this is probably a no-brainer,
but the constraints replicated from SPSS suggests a robust solution...
Anyone?
This the translated SPSS code I have so far:
$match=0;
@rows=('q1','q2','q3','q4','q5','q6','q7','q8');
@m_vars=('q3','q5','q6');
@m_labs=('Filter A','Filter B','Filter C');
foreach $i (@rows) {
$i_count=1;
$j_count=1;
foreach $j (@m_vars) {
$k_count=1;
foreach $k (@m_labs){
# Set a flag to use in the
# last condition below...
if($i eq $j && $k_count == 1){
$match++;
}
# Print the main list
if ($i ne $j && $i_count == 1) {
print "$i\n";
}
# Print the "Filters"...
if ($i eq $j && $match == $k_count) {
print "$k\n";
}
$i_count++;
$k_count++;
}
$j_count++;
}
}