Hi Kaushal,

Yes you are right if you have a hardcoded line of text in your script you
know if there is a "\n" or not at the end.

Now imagine you are reading a bunch of data from a text file created from
user input or some unknown script... who knows how much weird things are
there at the end of those lines.
So in order to save you a huge headache perl offers you the chomp operator
to at least get rid of the line feeds.

Regards,

Rob


On 10/30/07, Kaushal Shriyan <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I have the below lines of code.
>
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my $text =" a line of text\n" ;
> chomp($text); #the chomp operator gets rid of the newline character
> print "$text";
>
> My question is if i remove the new line character "\n" in the above code
> then i dont need the chomp operator if my understanding is correct.
>
> so where does the chomp operator plays its role, can some one explain me
> here with a sample of code.
>
> Thanks and Regards
>
> Kaushal
>

Reply via email to