This is a multi-part message in MIME format.
--===============0776205055==
Content-class: urn:content-classes:message
Content-Type: multipart/alternative;
boundary="----_=_NextPart_001_01C8AF90.DD7A4488"
This is a multi-part message in MIME format.
------_=_NextPart_001_01C8AF90.DD7A4488
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Hi Bernard,
=20
You really should consider indenting your code to show proper scope.
It's not clear what you are trying to do here, but it appears you either
have a extra "}" or are missing an "} else {" after the "perform the
calculation" If the 2 lines are supposed to go together in the "if"
statement, just remove the lone "}" between them, otherwise make it an
"} else {".
=20
Also you probably really want to do a modulus '%' 2 in the if statement
as what you have here will only execute one time during the loop, you
may also want to increment your loop by 2 instead of 1 since you are
processing 2 array elements per pass.
=20
Your statements of the form "$output =3D $output . stuff" can be written
"$output .=3D stuff"
=20
Rick
=20
________________________________
From: activeperl-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@listserv.ActiveState.com] On Behalf Of
Bernard Hill
Sent: Tuesday, May 06, 2008 7:08 AM
To: activeperl@listserv.ActiveState.com
Subject: Basic PERL Script
=20
Good morning, All.=20
Not sure if this list supports basic questions, but I'll pose the query
to find out.=20
I am new to PERL and working on an basic PERL script. The script will
import values into an array. when complete, I want to do a calculation
based on two feilds and drop the answer into the third field. Basically
I have the following script, but keep getting a syntax error and can't
figure out where I've gone wrong:=20
sub {=20
$output =3D '';=20
chomp $_[0];=20
$delim =3D $_[1];=20
@input_fields =3D split /$delim/, $_[0];=20
# input the values into the array=20
for($i=3D0; $i
<$#input_fields; $i++) { >if i$ == 2=20
{=20
# perform the calculation=20
$input_fields[$i] =3D $input_fields[$i-1] * $input_fields[$i-2];=20
}=20
output =3D $output . $input_fields[$i] . $delim;=20
}=20
$output =3D $output . $input_fields[$#input_fields] . "\n";=20
return($output);=20
}=20
Any help is grealy appreciated!=20
Barney=20
------_=_NextPart_001_01C8AF90.DD7A4488
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Hi Bernard,
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>You really should consider =
indenting your
code to show proper scope. It’s not clear what you are trying to =
do here,
but it appears you either have a extra “}” or are missing an =
“}
else {“ after the “perform the calculation” If the 2 =
lines are
supposed to go together in the “if” statement, just remove =
the lone
“}” between them, otherwise make it an “} else =
{“.
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Also you probably really want to do =
a modulus
‘%’ 2 in the if statement as what you have here will only =
execute one
time during the loop, you may also want to increment your loop by 2 =
instead of 1
since you are processing 2 array elements per pass.
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Your statements of the form =
“$output
=3D $output . stuff” can be written “$output .=3D =
stuff”
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>Rick
style=3D'font-size:
10.0pt;font-family:Arial;color:navy'>
size=3D3
face=3D"Times New Roman">
style=3D'font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:
size=3D2
face=3DTahoma>
activeperl-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@listserv.ActiveState.com]
style=3D'font-weight:
bold'>On Behalf Of Bernard Hill
Sent: Tuesday, May 06, =
2008 7:08
AM
To:
activeperl@listserv.ActiveState.com
Subject: Basic PERL =
Script
style=3D'font-size:
12.0pt'>
style=3D'font-size:
12.0pt'>Good morning, All.
Not sure if this list supports basic questions, but I'll pose the query =
to find
out.
I am new to PERL and working on an basic PERL script. The script will =
import
values into an array. when complete, I want to do a calculation based on =
two
feilds and drop the answer into the third field. Basically I have the =
following
script, but keep getting a syntax error and can't figure out where I've =
gone
wrong:
sub {
$output =3D '';
chomp $_[0];
$delim =3D $_[1];
@input_fields =3D split /$delim/, $_[0];
# input the values into the array
for($i=3D0; $i
<$#input_fields; $i++) { >if i$ == 2
{
# perform the calculation
$input_fields[$i] =3D $input_fields[$i-1] * $input_fields[$i-2];
}
output =3D $output . $input_fields[$i] . $delim;
}
$output =3D $output . $input_fields[$#input_fields] . "\n"; =
return($output);
}
Any help is grealy appreciated!
Barney