Chris Stinemetz wrote:
Hello Shanmugam,

Please start a new thread when you post a new topic.


On Wed, Mar 7, 2012 at 5:14 PM, shanmugam m<bluepulse5...@gmail.com>  wrote:
Hi,
  This is my first perl program..I'm getting wired errors.Please take a
look.


#!persist/pkg/bin/perl
use diagnostics;
use warnings;

always use the strict pragma especially when you are learning Perl.
This will help you understand what is going on and also enforce you to
use better programming practices such as lexical scope.
use strict;


open(MYINPUTFILE ,"/net/fallsroot/export/d100/m4/input_file");
open(MYOUTFILE, ">  output_file");

it is recommended to use a three argument filehandle

"three argument filehandle"?


open my $INPUTFILE, '<',$input_file or die "ERROR opening $input_file: $!";
open my $OUTFILE, '>',$output_file or die "ERROR opening $output_file: $!";


foreach $line (<MYINPUTFILE>){

use a while loop to read one line at a time
while ( my $line = $INPUTFILE ) {
     chomp $line;


    chomp($line);                    # remove the newline from $line.
                                     # do line-by-line processing.
    my @column1 = split("/\\/",$line);
I'm not sure what you are trying to do here. Split will split on white
space by default

    print MYOUTFILE $column1[5] ,"\t" ;
you are trying to print the fifth element in the array @column1

Array indexes start at 0 so that is the sixth element.


    my @column2 = split("=",$line);
now it looks like you are wanting to split $line again based on "="
this would require you to reread the input file or create a better

Why would you need to reread the input file?


regex to capture everything you want in the first read

    print MYOUTFILE $column2[1]  ,"\n" ;

    }

close(MYOUTFILE);



John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to