ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> activeperl
activeperl
Basic PERL Script
by Bernard Hill other posts by this author
May 6 2008 8:23AM messages near this date
Re: Finding a printer; need help | Re: Basic PERL Script
Good morning, All.
<br> 
<br> Not sure if this list supports basic questions, but I'll pose the query to find out.
<br> 
<br> 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 erro
r and can't figure out where I've gone wrong:
<br> 
<br> sub { 
<br>   $output = ''; 
<br>  	
<br>   chomp $_[0]; 
<br>   $delim = $_[1]; 
<br>   @input_fields = split /$delim/, $_[0]; 
<br>  	
<br>   # input the values into the array
<br>   for($i=0; $i<$#input_fields; $i++) { 
<br>      if i$ == 2 
<br>         {
<br>          # perform the calculation
<br>          $input_fields[$i]  = $input_fields[$i-1] * $input_fields[$i-2];
<br>         }
<br>      output = $output . $input_fields[$i] . $delim; 
<br>   } 
<br>  	
<br>   $output = $output . $input_fields[$#input_fields] . "\n"; 
<br>   return($output); 
<br> }	
<br> 
<br> Any help is grealy appreciated!
<br> 
<br> Barney
<br> 
Thread:
Bernard Hill
Andy Bach
Frederick Washburn
Brian Raven
Bill Luebkert

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved