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


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

0
anish
9/9/2004 6:41:52 AM
perl.beginners 29356 articles. 3 followers. Follow

2 Replies
426 Views

Similar Articles

[PageSpeed] 26

---------- Forwarded message ----------
From: David le Blanc <dmleblanc@gmail.com>
Date: Thu, 9 Sep 2004 16:54:56 +1000
Subject: Re: how to skip new line character
To: "Anish Kumar K." <anish@vitalect-india.com>

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.
<anish@vitalect-india.com> 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
>
>
0
dmleblanc
9/9/2004 6:55:17 AM
open F, "file.txt";
my @file = <F>;
chomp @file;

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

----- Original Message ----- 
From: "Anish Kumar K." <anish@vitalect-india.com>
To: <beginners@perl.org>
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 = <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



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

Similar Artilces:

How to force a new line to keep one line only have 10 characters?
For example, user may input text as below: AAAAAAAAAABBBBBBBBBBCCCCCCCCCC But to make it as: AAAAAAAAAA BBBBBBBBBB CCCCCCCCCC string wholeLine = "AAAAAAAAAABBBBBBBBBBCCCCCCCCCC";List<string> lines = new List<string>();while ( wholeline.Length > 0){    if (wholeline.length >= 10)    {        lines.Add( wholeline.Substring(0, 10);        wholeline = wholeline.Substring (10);    }    else    {       &nb...

New line character
I am writing code (VS2008/C#) that reads text file and passes the file data to SQL Server Procedure. I am reading data of file in StreamReader and passing as Input Parameter to procedure. I need to pass the New Line character also to the procedure. 1. The New Line character can be chr(13) & chr(10) or only chr(10). How to check this in C#?2. How to pass New Line character to SQL Procedure? Thanks    Try using Environment.NewLine Hanan Schwartzberg--------------------http://www.lionsden.co.il Environment.NewLine returns the new line defined in the environment. I nee...

New Line Character
i using mysql connect to database and found data like "abcde fgh" how to convert this string from two line into one line? and result become "abcdefgh"  hello friend, suppose your string is called myString= "abcde fgh" and then use myString.Replace(System.Enviornment.NewLine,"") hope it helps, Jessica  Jessica CaoSincerely,Microsoft Online Community Support“Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other comm...

new line character
Is there a way to insert a "new line/carriage control" in a varchar column? <Ctrl><Enter> keys work with a text column but just tabs to next control on a varchar column. Tried ~r~n but that just stores/prints the text ~r~n. Seems that <ctrl><enter> used to work in the app. PB 7.02 9028 You can use char(10) + char(13) to get the cr/lf -- Terry Dykstra (TeamSybase) Please state PB / OS / DB versions in your post. MySybase http://my.sybase.com/mysybase Search Deja: http://www.pfcguide.com/_newsgroups/search.asp <Mike> wrote in message...

new line character in the validation
Hi, I have a radiobuttonlist repeatdirection horizontally, and I have a requirefieldvalitor against this field with *. However, when the user miss the field and a red * is outputed, but it goes to the next line. I want them to be on the same line. How can I do that? Thanks. post some code? There may not be enough space on the line for it to go there so it automatically goes to the next line Actually there are still a lot of space on the line. here's the code.  <asp:RadioButtonList ID="GenderSelect" runat="server" RepeatDirection="Horizontal" ...

New line character in XML
HI Friends, I am in a deep trouble. If u help me in this issue, it will be greatful. Requirement is as below. I am having a grid which will be bind to a datatable. i will have to show tooltips on the column headers of this gridview. I have an XML file which contains the content for these tooltips. i have written a method which takes a string as a parameter, which is the column name of the gridview. Based on this string that we have passed, the method will pick the content for the tooltip from the XML file and display. But i have a problem here. Here the content of the tooltip can ...

New Line Character(s)
Greetings. I've got some Perl code that's inserting data into a MySQL, which is later being read & displayed by MS Access. I'm constructing a note, and I'm using: \n for new lines - to break up paragraphs. However, in Access, these \n characters appear as little boxes instead of new lines. What should I use to get Access to display a new line? -- Daniel Kasak IT Developer NUS Consulting Group Level 5, 77 Pacific Highway North Sydney, NSW, Australia 2060 T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989 email: dkasak@nusconsulting.com.au website: http:...

Crossplatform new line character
I need to split a caption of a TCheckBox in two lines at a specific place. So, I set CheckBox1.WordWrap to True, adjust its height and sofar OK, if the text is long enough, it wraps to a second line. Q1: I can't figure out how to enter a carriage return, line feed or both in the object inspector. Is it possible? A workaround is to define a string const: const CR = #$0D; cbCaption = 'The text that needs to' + CR + 'wrap around'; and then in the forms OnCreate assign it to CheckBox1.Caption I also tested with LF = #$0A and CRLF = CR + LF, and on Windows al...

New Line character in a String
I want to create a string which contains a new line character. In Powerbuilder, I would use '~n' but what do I use within a stored procedure in ASE 12.0? I'm trying to create a mulit-line error message that is passed back from the stored procedure to the Powerbuilder front-end. select @message = 'Line1~n Line 2 ~n Line 3" should display like this: Line 1 Line 2 Line 3 Thanks! select @message = "Line 1" + char(10) + "Line 2" + char(10) + "Line 3" select @message RM wrote: > I want to create a string which co...

ASCII import
I am importing ascii text files to tables in an whatcom 4 db. For some big text fields i need to put a "newline" character in order to get a new line in i.e varchar fileds. I have tried � ~n with no success. any postings will be appreciated. Per H. Kleppe Try using \n. Watcom/SQL Anywhere reads the C special print characters, sometimes when you don't want it to. -- Jim Egan [TeamPS] Dealer Solutions, LLC Houston, TX This is a multi-part message in MIME format. ------=_NextPart_000_0005_01BCD822.8928C750 Content-Type: text/plain; charset="iso...

add a new line character in label
How do i add a new line character in a label content? I tried system.environment.newline and it doesn't work. "<br/>"LolliDon't forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped. Hi, try this  lbl1.Text = lbl1.Text+ "<br />" Public Shared Function BrakeRow(ByVal _count As Integer) As LiteralControl Dim tmp As String = "" Dim i As Integer For i = 0 To _count ...

new line is changed in space character
Hallo, when I submit the data of a multiline textarea the new line is changed into a space character. If the user write: A B C The text will be displayed as: A B C I am using a datalist with parameter stored procedure, Access 2003 DB. Do you have a solution? Thanks   before you send in the data you can do something like : txtstmtbdy1.text.replace(environment.newline,"<br>")  to preserve the newline's.***********************Dinakar NethiLife is short. Enjoy it.***********************...

New line character in email notifications
Quick question...... How do you insert a new line in an email sent by Identity Manager? I am sending an email with user information and would like to have the info on separate lines, instead of separated by comas. I think I have seen this answer before somewhere on the Novell site, but I cant find it now. Anyone know? Thanks for any response, Jordan http://tinyurl.com/s3oey -- Father Ramon jcocke1@dot.state.tx.us wrote: > Quick question...... How do you insert a new line in an email sent by > Identity Manager? I am sending an email with user information and...

new line character in a result set
Hi I try this select 'First line:\nSecond line:';output to d:\temp\test.txt and the result is'First line:\x0ASecond line:'Tried with char(10)+char(13).How can I make the result set that:First lineSecond LimeTIARegardsVesselin First Line Second Line .... .... TIA "Veselin Ivanov" <vs@sonita.com> wrote in message news:42d6ab50@forums-1-dub... > Hi > I try this > select 'First line:\nSecond line:';output to d:\temp\test.txt and the > result is'First line:\x0ASecond line:'Tried with char(10)+char(13).How can...

Web resources about - how to skip new line character - perl.beginners

Dilbert (character) - Wikipedia, the free encyclopedia
Dilbert is a fictional character and the main character and protagonist of the Dilbert comic strip . He is a white collar office worker who has ...

Jack & Coke renamed "The Lemmy" by Food & Beverage magazine; Lemmy now a GTA V character
by Rob Sperry-Fromm In the wake of Lemmy's passing, tributes to the Motorhead frontman have come from all over the place, including a petition ...

A deleted scene from 'Star Wars: The Force Awakens' reveals a new character's awesome power
Maz Kanata's castle plays a larger part in "The Force Awakens" than the character herself, but she's more powerful than you realized watching ...

Nintendo promises to bring characters you love to mobile
... company promises it has greater things up its sleeve for 2016. Nintendo president Tatsumi Kimishima has confirmed plans to bring the characters ...

‘Jessica Jones’ Showrunner On Season 2: “I Just Want It To Be About Her Character” – TCA
Given that Daredevil was renewed two weeks after the show’s April premiere, you’d be forgiven for thinking that its successor, the hugely acclaimed ...

'Walking Dead' Star Lauren Cohan Says Fans Should Be 'Concerned' for Her Character
'Walking Dead' Star Lauren Cohan Says Fans Should Be 'Concerned' for Her Character

Netflix open to more Marvel shows: Any character could get spin-off - EW.com
Skip to main content X TV TV Recaps Movies Music Books Gaming Video Recaps The Royals Angie Tribeca Billions Downton Abbey Galavant The Good ...

'Plants vs. Zombies Garden Warfare 2' Beta Shows Off New Modes, Characters And Weapons
Plants vs. Zombies Garden Warfare 2 beta proves popular as sequel impresses with its new modes, characters, weapons and locations.

How Marceline Became One of Adventure Time’s Most Fascinating Characters
Marceline the Vampire Queen was a lot of fun in her first appearances on Adventure Time , but nobody could have predicted how much she’s evolved, ...

Maddow Accuses Clinton Of 'Casting Aspersions' On Bernie Sanders' Character
Clinton insisted she and Sanders "engage on substantive differences."

Resources last updated: 1/18/2016 9:40:23 AM