Wednesday 16 July 2014

perl split function example

#!/usr/bin/perl
use strict;
use warnings;

#open (fh2, "file1") || die "Error opening file1: $!";
open (fh2, "/etc/passwd") || die "Error opening file1: $!";

my @array1;

while (<fh2>){
    #push  @array1, [ split ]; # push function to push the data in array1 from $_
    push  @array1, [ split/:/];
}

foreach ( @array1){

   
    print "@$_[0],";
    print "@$_[5]\n";
    print "@$_\n";        # for printing all the field.
}

No comments:

Post a Comment