Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SHIFT @ARRAY

Status
Not open for further replies.

lanny93

MIS
May 8, 2003
3
US
I have this statement($prm = shift @parms) What happens is the shift stops when it gets to a null, blank value or a zero .... It does not shift all the parameters. Why? they values in the array may be ALUMNI 1999 BLANK TCU_REC_DUESMAG Y Y. It will only read up to the blank. What can I pass to recognize the this as a blank, zero or null?
 
i think you will have to post more of the code, but it sounds like the statement is in a boolean test (either a while() or an if()). If that is the case then you should evaluate whether the expression is defined, as in:
Code:
while ( defined($prm = shift @parms) ) {
Another alternative is to use a for loop
Code:
for $prm (@params) {
jaa
 
This is the exact code...
It stops at blanks, nulls, or zero

while ($prm = shift @parms) {
$SqlStatement = "INSERT INTO GJBPRUN (GJBPRUN_JOB, GJBPRUN_ONE_UP_NO, GJBPRUN_NUMBER, GJBPRUN_ACTIVITY_DATE, GJBPRUN_VALUE, GJBPRUN_LABEL)";
$SqlStatement = $SqlStatement . "VALUES ('${uproc}',${sctban_oneup_number},'${pnum}',sysdate,'${prm}',$prun_label)";
if ($db->Sql($SqlStatement)){
print "SQL failed.\n";
print "Error: " . $db->Error() . "\n";
$db->Close();
exit;
}
 
It does not process the loop after the blank, zero, or null value
 
Try:

while (@parms) {
$prm = shift @parms;

As previously pointed by justice41, your test is failing because Perl sees the result of the shift as a false value when it encounters blank, null or undef. When in actual fact you only want to stop when the number of items in the array returns a false value, ie there are no items in the array.

Barbie
Leader of Birmingham Perl Mongers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top