By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,660 Members | 1,267 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,660 IT Pros & Developers. It's quick & easy.

one token per line

P: 4
hi sir,
this is my input

i am very happy

i want this output

i
am
very
happy

this is the program i wrote
Expand|Select|Wrap|Line Numbers
  1. open(FH, "worldaff_join.txt") or die("error opening");
  2. @file=<FH>;
  3. foreach $line (@file)
  4. {
  5.  @sentence=split(/ /,  $line);
  6. print"@sentence";
  7. }
  8. close(FH);
  9.  
but the output is not what i wanted
Feb 1 '10 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 785
your words are in an array now:

@sentence=("i", "am", "very", "happy");

You must loop through the array and print each array element:

foreach (@sentence){print "$_\n";}
Feb 1 '10 #2

Expert 100+
P: 785
I found another way without loop:

print join("\n",@sentence);
Feb 1 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.