Hi
I am new to perl, i need to write a program to convert horizontal words to vertical
eg: cat, dog, cow,.....(text file)
this should be written as
1.cat
2.dog
like this. can u pls help me to work out..
Is this homework?
no if i get idea i can do main prog that y..
Please use complete English words, not "chat" abbreviations. Typing "why" instead of "y" only takes 2 keystrokes more, and makes the text much more readable.
It's pretty simple actually:
echo 'cat, dog, cow, fish' | perl -ne 'print join("\n",split(/,\s*/,$_));'
split will separate the input line (saved in this case in $_ (see perlvar for more information)), returning an array, which then is concatenated by join, using a newline ( \n ) between elements, to a string.
Thanks..