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
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

>    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
regex to capture everything you want in the first read

>    print MYOUTFILE $column2[1]  ,"\n" ;
>
>    }
>
> close(MYOUTFILE);
> Regards,
> Shanmugam
>

--
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