Foo bar in reverse for 10 times _ Perl program

3 views
Skip to first unread message

R A J Rajkishore

unread,
Sep 10, 2014, 2:47:33 AM9/10/14
to unix-and-perl-...@googlegroups.com
I have to open a text file in which "foo bar" is written in 10 times.
Example:
foo bar
foo bar
foo bar
.
.
.
.
.foo bar


I have to get the output in perl window as 
 bar foo
 bar foo
 bar foo
 bar foo
 bar foo
 .
 .
 .
 ..
 bar foo


10times as reversed of "foo bar" 

Please help in perl

Claudius Kerth

unread,
Sep 10, 2014, 3:35:07 AM9/10/14
to unix-and-perl-...@googlegroups.com
A perl version to switch the two columns in the file could look like this: 

perl -ane 'print $F[1], " ", $F[0], "\n"' foobar

see 'man perlrun' for documentation of command line perl

However, for these simple tasks, awk is still better because easier and less error prone:

awk '{print $2, $1}' foobar

claudius


--
You received this message because you are subscribed to the Google Groups "Unix and Perl for Biologists" group.
To unsubscribe from this group and stop receiving emails from it, send an email to unix-and-perl-for-bi...@googlegroups.com.
To post to this group, send email to unix-and-perl-...@googlegroups.com.
Visit this group at http://groups.google.com/group/unix-and-perl-for-biologists.
For more options, visit https://groups.google.com/d/optout.

R A J Rajkishore

unread,
Sep 10, 2014, 3:37:47 AM9/10/14
to unix-and-perl-...@googlegroups.com

Cant we do this using split operator and array

You received this message because you are subscribed to a topic in the Google Groups "Unix and Perl for Biologists" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/unix-and-perl-for-biologists/P0wgjgLE5DU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to unix-and-perl-for-bi...@googlegroups.com.

Keith Bradnam

unread,
Sep 22, 2014, 5:30:48 PM9/22/14
to unix-and-perl-...@googlegroups.com


On Wednesday, September 10, 2014 12:37:47 AM UTC-7, R A J Rajkishore wrote:

Cant we do this using split operator and array


Yes you can. But the other solutions are easier, unless you are thinking that will become a bigger, and more complex, script. 
Reply all
Reply to author
Forward
0 new messages