Thanks Philip for the wonderful explanation. And thanks John, your code worked like a breeze both on Windoze & *Nix :) And good thing is it provided the solution to insert a new-line character which was not present in my Windoze code.
One question though in following code - >>perl -le "/^s/i && print q/I am only addicted to - 'Shekels'/ for qw/Sugar Sex Simplicity Sleep Success Smoking/" How is it going to new line without a new line character - '\n'. If I am not wrong - 'q/ /' signifies quoted context thus - a replacement for double quotes but still you should need a new line character to go to next line. Kindly correct me if I am wrong. Cheers, Parag On Sat, Dec 12, 2009 at 1:55 AM, John W. Krahn <[email protected]> wrote: > Parag Kalra wrote: > >> Hello All, >> > > Hello, > > > This works on Linux - >> perl -e 'foreach (Sugar,Sex,Simplicity,Sleep,Success,Smoking) { print "I >> am >> only addicted to - 'Shekels' \n" if ($_ =~ /^s.*/i) }' >> >> This works on Windoze - >> perl -e "foreach (Sugar,Sex,Simplicity,Sleep,Success,Smoking) { print 'I >> am >> only addicted to - Shekels' if ($_ =~ /^s.*/i) }" >> >> How can I have 1 code that will run both on Nix & Windoze. >> > > I don't have Windows to test this on, but try: > > perl -le "/^s/i && print q/I am only addicted to - 'Shekels'/ for qw/Sugar > Sex Simplicity Sleep Success Smoking/" > > > > John > -- > The programmer is fighting against the two most > destructive forces in the universe: entropy and > human stupidity. -- Damian Conway > > -- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > http://learn.perl.org/ > > >
