how to skip new line character

------=_NextPart_000_0015_01C49666.30D23690
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

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 =3D ;

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


------=_NextPart_000_0015_01C49666.30D23690--

0 anish 9/9/2004 6:41:52 AM
---------- Forwarded message ----------
From: David le Blanc 
Date: Thu, 9 Sep 2004 16:54:56 +1000
Subject: Re: how to skip new line character
To: "Anish Kumar K." 

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 = ;

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

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

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




On Thu, 9 Sep 2004 12:11:52 +0530, Anish Kumar K.
 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 = ;
>
> 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
>
>
0 dmleblanc 9/9/2004 6:55:17 AM
open F, "file.txt";
my @file = ;
chomp @file;

print "@file";
Is that what you want ?

----- Original Message ----- 
From: "Anish Kumar K." 
To: 
Sent: Thursday, September 09, 2004 2:41 PM
Subject: how to skip new line character


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 = ;

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



0 perl 9/9/2004 8:17:49 AM
Reply:

(Thread closed)