---------- Forwarded message ----------
From: David le Blanc <[EMAIL PROTECTED]>
Date: Thu, 9 Sep 2004 16:54:56 +1000
Subject: Re: how to skip new line character
To: "Anish Kumar K." <[EMAIL PROTECTED]>

Is the problem either
1)  Remove the end of line character from all lines
2) Remove the end of line character from some lines

or

3) remove the end of line character from all lines AND leave out blank lines.

The easiest solution for (3) is

open INPUT,"a.txt" or die $!;
> my @file = <INPUT>;

my @file=grep !/^$/,<INPUT>;   <-- grep out all the empty lines
chomp(@file);                          <-- remove all newlines.

this can be abbreviated to
chomp( @file=grep !/^$/,<INPUT> );

BUT NOT,  @file=chomp(<INPUT>); since chomp does for return the
chomp'ed data as a result.




On Thu, 9 Sep 2004 12:11:52 +0530, Anish Kumar K.
<[EMAIL PROTECTED]> wrote:
> Hi All
> As a beginner in PERL, I wrote a small program which reads data from the file and 
> stores in an array. In that process i wanted to skip the new line character...
>
> for ex: In my program
>
> say "a.txt" contains
>
> man
> pan
>
> tan
>
> In the program
>
> open INPUT,"a.txt" or die $!;
> my @file = <INPUT>;
>
> when I print the file, I could see $file[2] and $file[4] has only new line 
> character...
>
> So while I store in the array I should skip this character..I tried chop and 
> chomp..Not effective....
>
> Thanks
> Anish
>
>

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to