one token per line

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chungku
    New Member
    • Jan 2010
    • 4

    one token per line

    hi sir,
    this is my input

    i am very happy

    i want this output

    i
    am
    very
    happy

    this is the program i wrote
    Code:
    open(FH, "worldaff_join.txt") or die("error opening");
    @file=<FH>;
    foreach $line (@file)
    {
     @sentence=split(/ /,  $line);
    print"@sentence";
    }
    close(FH);
    but the output is not what i wanted
    Last edited by numberwhun; Feb 1 '10, 04:46 PM. Reason: Please use code tags!
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    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){pri nt "$_\n";}

    Comment

    • chaarmann
      Recognized Expert Contributor
      • Nov 2007
      • 785

      #3
      I found another way without loop:

      print join("\n",@sent ence);

      Comment

      Working...