associative arrays in Switch
Posted: Tue Apr 16, 2013 9:39 am
Good morning fellas,
imagine being faced with the following XML:
<order number="15006888">
<products>
<product type="AH_FOLDEDCARD_4P_A6_POR_4_1">
<orderitem id="3" crc="8f64fc6f" name="15006888-AH_FOLDEDCARD_4P_A6_POR_4_1-3.pdf"/>
</product>
</products>
</order>
i'm calling an external process to check the crc value of ordernumber*.pdf files and getting this back on stdout:
; Generated on 04/15/13 at 14:44:31
;
8f64fc6f ?CRC32*15006888-AH_FOLDEDCARD_4P_A6_POR_4_1-3.pdf
now i want to go through the resulting lines and push them in a multidimensional associative array:
var crcCheck = new Process( args );
// start crc32 check
crcCheck.start();
crcCheck.waitForFinished();
var crc = new Array;
// push results into array
// example output on stdout:
// -------
// ; Generated on 04/15/13 at 14:44:31
// ;
// 8f64fc6f ?CRC32*15006888-AH_FOLDEDCARD_4P_A6_POR_4_1-3.pdf
// -------
// example resulting array:
// crc[15006888-AH_FOLDEDCARD_4P_A6_POR_4_1][3] == 8f64fc6f
var stdOut = crcCheck.readStdout().split("n");
var product;
var id;
for ( i = 0; i < stdOut.length; i++ )
{
var crcLine = stdOut;
// skip clutter lines without CRC values
if ( crcLine.match(/?CRC32*/) )
{
product = crcLine.substring(16).split("-")[1];
id = crcLine.substring(16).split("-")[2].split(".")[0];
if ( !crc[product] )
crc[product] = new Array;
crc[product][id] = crcLine.substring(0, 8);
s.log(1, crcLine.substring(16) + " " + crc[product][id]);
}
}
well guess... it doesn't work... the last s.log line already fails.
Can someone please push me in the right direction on what i'm doing wrong? I can't seem to be able to fill an associative array with strings as keys.
Any hints?
imagine being faced with the following XML:
<order number="15006888">
<products>
<product type="AH_FOLDEDCARD_4P_A6_POR_4_1">
<orderitem id="3" crc="8f64fc6f" name="15006888-AH_FOLDEDCARD_4P_A6_POR_4_1-3.pdf"/>
</product>
</products>
</order>
i'm calling an external process to check the crc value of ordernumber*.pdf files and getting this back on stdout:
; Generated on 04/15/13 at 14:44:31
;
8f64fc6f ?CRC32*15006888-AH_FOLDEDCARD_4P_A6_POR_4_1-3.pdf
now i want to go through the resulting lines and push them in a multidimensional associative array:
var crcCheck = new Process( args );
// start crc32 check
crcCheck.start();
crcCheck.waitForFinished();
var crc = new Array;
// push results into array
// example output on stdout:
// -------
// ; Generated on 04/15/13 at 14:44:31
// ;
// 8f64fc6f ?CRC32*15006888-AH_FOLDEDCARD_4P_A6_POR_4_1-3.pdf
// -------
// example resulting array:
// crc[15006888-AH_FOLDEDCARD_4P_A6_POR_4_1][3] == 8f64fc6f
var stdOut = crcCheck.readStdout().split("n");
var product;
var id;
for ( i = 0; i < stdOut.length; i++ )
{
var crcLine = stdOut;
// skip clutter lines without CRC values
if ( crcLine.match(/?CRC32*/) )
{
product = crcLine.substring(16).split("-")[1];
id = crcLine.substring(16).split("-")[2].split(".")[0];
if ( !crc[product] )
crc[product] = new Array;
crc[product][id] = crcLine.substring(0, 8);
s.log(1, crcLine.substring(16) + " " + crc[product][id]);
}
}
well guess... it doesn't work... the last s.log line already fails.
Can someone please push me in the right direction on what i'm doing wrong? I can't seem to be able to fill an associative array with strings as keys.
Any hints?