in reply to Chomp is removing the whole word instead of the newline

... my @row = split (/,/,$_); # I believe this is what you trying to do chomp( my $var = $row[1]); # Or maybe a little bit more understandable $var = $row[1]; chomp $var; # Return the total number of characters removed in $row[1] to $chomp_r +esult # (in your case every 1 stands for a character chomp found in $row[1] +could # be a line break or something like that ) my $chomp_result = chomp( $row[1]); print "$var || $chomp_result\n"; ...
I hope you get what i'm trying to say ...

Replies are listed 'Best First'.
Re^2: Chomp is removing the whole word instead of the newline
by slayedbylucifer (Scribe) on Jul 26, 2012 at 03:49 UTC

    So, I was quite frustrated with this easy looking task bugging me for the whole day long. I really appreciate everyone who responded.

    Finaly I ended up using Text::CSV perl module and then calling each of the CSV field as array reference. There was no need left to run the chomp after using Text::CSV.

    Here is the code:

    #!/usr/bin/perl use warnings; use strict; use Text::CSV; my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary attr +ibute. or die "Cannot use CSV: ".Text::CSV->error_diag (); open my $fh, "<:encoding(utf8)", "vm.csv" or die "vm.csv: $!"; <$fh>; ## this is to remove the column headers. while ( my $row = $csv->getline ($fh) ) { print $row->[1]; }

    and here is hte output:

    fd1fd2fd3fd4

    Later i was pulled these individual values and inserted into the DB.

    Thanks everyone.

Re^2: Chomp is removing the whole word instead of the newline
by slayedbylucifer (Scribe) on Jul 26, 2012 at 03:47 UTC
    Agree. Thanks for your time.