#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    Split function in perl


    Hi,

    could you please help me on the below code.

    i am reading a file and using split funtion for comma and tab delimiter.

    if input file contains a comma or tab delimiter it should process the file and if a input file contains a pipe delimiter it should die.

    can you please help me on this?


    open FH, "$INPUT_DIR/$input_file" or die "Couldn't Open File: $!";

    while ( <FH> ) {

    chomp;

    my ($s, $a, $c, $r) = (split / [, \t]/, $_);

    the split fucntion process the comma and tab delimited now.

    Input file:

    process:


    regards,
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2012
    Posts
    832
    Rep Power
    496
    So what is your problem?

    Perhaps you want to do this:

    Perl Code:
    open my $FH, "<", "$INPUT_DIR/$input_file" or die "Couldn't Open File $input_file: $!";
    while ( <FH> ) {
         chomp;
         last if /\|/; # last to exit the while loop, or die to exit the program
         my ($s, $a, $c, $r) = (split / [, \t]/, $_);
    }

IMN logo majestic logo threadwatch logo seochat tools logo