RE: Basic PERL Script
by Brian Raven other posts by this author
May 6 2008 9:29AM messages near this date
RE: Basic PERL Script
|
Re: Basic PERL Script
From: activeperl-bounces@[...].com
[mailto:activeperl-bounces@[...].com] On Behalf Of
Bernard Hill
Sent: 06 May 2008 15:08
To: activeperl@[...].com
Subject: Basic PERL Script
> Good morning, All.
Good afternoon :-) (this is an international forum).
>
> Not sure if this list supports basic questions, but I'll pose the
query to find out.
Shouldn't be a problem.
>
> 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 = '';
>
> chomp $_[0];
> $delim = $_[1];
> @input_fields = split /$delim/, $_[0];
>
> # input the values into the array
> for($i=0; $i<$#input_fields; $i++) {
> if i$ == 2
> {
> # perform the calculation
> $input_fields[$i] = $input_fields[$i-1] * $input_fields[$i-2];
> }
> output = $output . $input_fields[$i] . $delim;
> }
>
> $output = $output . $input_fields[$#input_fields] . "\n";
> return($output);
> }
>
> Any help is grealy appreciated!
You seem to defining an anonymous subroutine that is not assigned to
anything. It is hard to see how that could ever be called.
Your code would be easier to understand if you indented it
appropriately, and posted in plain text rather than html. It is also
better to cut & paste code, rather than typing it by hand, which I am
guessing you did. Also, a short, self contained script, that we can
simply copy and run, is better that posting a code extract.
If I understand your intention correctly, you seem to be going to a lot
of trouble for something that is relatively simple in Perl (note not
PERL, 'perldoc -q "perl.*Perl"').
For example:
------------------------------------------
use strict;
use warnings;
sub do_stuff {
my $data = shift;
my $delim = shift;
chomp $data;
my @input_fields = split /$delim/, $data;
$input_fields[2] = $input_fields[1] * $input_fields[0];
return join($delim, @input_fields);
}
my $result = do_stuff("2,3", ",");
print "Result: '$result'\n";
------------------------------------------
HTH
--
Brian Raven
=========================================
Atos Euronext Market Solutions Disclaimer
=========================================
The information contained in this e-mail is confidential and solely for the intended address
ee(s). Unauthorised reproduction, disclosure, modification, and/or distribution of this emai
l may be unlawful.
If you have received this email in error, please notify the sender immediately and delete it
from your system. The views expressed in this message do not necessarily reflect those of A
tos Euronext Market Solutions.
Atos Euronext Market Solutions Limited - Registered in England & Wales with registration no.
3962327. Registered office address at 25 Bank Street London E14 5NQ United Kingdom.
Atos Euronext Market Solutions SAS - Registered in France with registration no. 425 100 294.
Registered office address at 6/8 Boulevard Haussmann 75009 Paris France.
L'information contenue dans cet e-mail est confidentielle et uniquement destinee a la (aux)
personnes a laquelle (auxquelle(s)) elle est adressee. Toute copie, publication ou diffusion
de cet email est interdite. Si cet e-mail vous parvient par erreur, nous vous prions de bie
n vouloir prevenir l'expediteur immediatement et d'effacer le e-mail et annexes jointes de v
otre systeme. Le contenu de ce message electronique ne represente pas necessairement la posi
tion ou le point de vue d'Atos Euronext Market Solutions.
Atos Euronext Market Solutions Limited Société de droit anglais, enregistrée au Royaume U
ni sous le numéro 3962327, dont le siège social se situe 25 Bank Street E14 5NQ Londres Ro
yaume Uni.
Atos Euronext Market Solutions SAS, société par actions simplifiée, enregistré au regist
re dui commerce et des sociétés sous le numéro 425 100 294 RCS Paris et dont le siège so
cial se situe 6/8 Boulevard Haussmann 75009 Paris France.
=========================================
_______________________________________________
ActivePerl mailing list
ActivePerl@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Bernard Hill
Andy Bach
Frederick Washburn
Brian Raven
Bill Luebkert
|