Necesito crear un archivo de texto (aptest.s) que puedo usar para leer en otro programa. Estoy usando Perl porque tengo una gran lista para trabajar. Mi código es el siguiente (que no da la salida deseada, se muestra después del código y la salida real). Cualquier ayuda sería apreciada.¿Cómo puedo iterar sobre varias listas al mismo tiempo en Perl?
#!/usr/bin/perl -w
chdir("D://projects//SW Model ODME");
@link = ("319-116264||319-118664","320-116380||320-116846","321-119118||321-119119","322-115298||322-119087");
@link1 = ("116264-319||118664-319","116380-320||116846-320","119118-321||119119-321","115298-322||119087-322");
open (FSAS, ">>aptest.s");
foreach $link (@link) {
foreach $link1 (@link1){
print FSAS "other code \n";
print FSAS "PATHLOAD SELECTLINK=(Link=".$link."), VOL[2]=MW[1] \n";
print FSAS "PATHLOAD SELECTLINK=(Link=".$link1."), VOL[3]=MW[2] \n";
print FSAS "other code \n";
}
}
Salida Real:
other output
PATHLOAD SELECTLINK=(Link=319-116264||319-118664), VOL[2]=MW[1]
PATHLOAD SELECTLINK=(Link=116264-319||118664-319), VOL[3]=MW[2]
other output
other output
PATHLOAD SELECTLINK=(Link=**319-116264||319-118664**), VOL[2]=MW[1]
PATHLOAD SELECTLINK=(Link=**116380-320||116846-320**), VOL[3]=MW[2]
other output
salida deseada
other output
PATHLOAD SELECTLINK=(Link=319-116264||319-118664), VOL[2]=MW[1]
PATHLOAD SELECTLINK=(Link=116264-319||118664-319), VOL[3]=MW[2]
other output
other output
PATHLOAD SELECTLINK=(Link=**320-116380||320-116846**), VOL[2]=MW[1]
PATHLOAD SELECTLINK=(Link=**116380-320||116846-320**), VOL[3]=MW[2]
other output
Gracias a todos por sus comentarios y sugerencias. He hecho que mi código sea más legible y agradezco su opinión. – Krishnan