Re: golf

2006-04-25 Thread Dr.Ruud
"M. Kristall" schreef: > Ruud: >> [ while(local $_ = ) ] >> With while(), the $_ is already local. >> Wouldn't using that 'local' explicitly, add another local-layer? > > my $i = 5; > $_ = 'Hi there!!!'; > while ($_ = $i--) { print } > print > 543210 > > my $i = 5; > $_ = 'Hi there!!!'; > while (

Re: golf

2006-04-23 Thread M. Kristall
With while(), the $_ is already local. Wouldn't using that 'local' explicitly, add another local-layer? my $i = 5; $_ = 'Hi there!!!'; while ($_ = $i--) { print } print 543210 my $i = 5; $_ = 'Hi there!!!'; while (local $_ = $i--) { print } print 54321Hi there!!! for (<>) is the same as for (r

Re: golf

2006-04-23 Thread Mr. Shawn H. Corey
On Sun, 2006-23-04 at 13:23 -0700, John W. Krahn wrote: > "array context"?? There is no "array context". See `perldoc perlsyn` and search 'Foreach Loops'. All foreach loops iterate over a list. So you are right, it's not "array context", it's list context. For details, see `perldoc -q 'What is th

Re: golf

2006-04-23 Thread Dr.Ruud
"Mr. Shawn H. Corey" schreef: > The expression 'while(<>)' is in scalar context. > It reads the file one line at a time. Rather one piece (or record) at a time, which by default is a line. The value of "$/" is the record separator; see `perldoc perlvar` for more information, such as special v

Re: golf

2006-04-23 Thread John W. Krahn
M. Kristall wrote: > John W. Krahn wrote: >> Chad Perrin wrote: >>> On Fri, Apr 21, 2006 at 12:48:51PM -0700, John W. Krahn wrote: print/.*/g,$"while<> > Yeah, that's it. >>> Woah, that's pretty short. >> >> You can make it even shorter: >> >> print/.*/g,$"for<> > They aren't quite the same th

Re: golf

2006-04-23 Thread Chad Perrin
On Sun, Apr 23, 2006 at 12:30:40PM -0400, Smith, Derek wrote: > > What is perl golf? It's like normal golf, only with Perl. You try to finish the program (or the 18-hole golf course) in as few (key)strokes as possible. In other words, Perl golf is the game of shortening a program without losing

RE: golf

2006-04-23 Thread Smith, Derek
-Original Message- From: John W. Krahn [mailto:[EMAIL PROTECTED] Sent: Friday, April 21, 2006 7:04 PM To: Perl Beginners Subject: Re: golf Chad Perrin wrote: > On Fri, Apr 21, 2006 at 12:48:51PM -0700, John W. Krahn wrote: >>print/.*/g,$"while<> > > Woah, tha

Re: golf

2006-04-23 Thread Mr. Shawn H. Corey
On Sun, 2006-23-04 at 05:03 -0400, M. Kristall wrote: > John W. Krahn wrote: > > You can make it even shorter: > > > > print/.*/g,$"for<> > They aren't quite the same though. 'while' loops if the condition is > still true (scalar context). 'for' loops if there are more items in the > array (arra

Re: golf

2006-04-23 Thread Dr.Ruud
"M. Kristall" schreef: > John W. Krahn: >> Chad Perrin: >>> John W. Krahn: print/.*/g,$"while<> > > Yeah, that's it. >>> Woah, that's pretty short. >> >> You can make it even shorter: >> >> print/.*/g,$"for<> > > They aren't quite the same though. 'while' loops if the condition is > still tr

Re: golf

2006-04-23 Thread M. Kristall
John W. Krahn wrote: Chad Perrin wrote: On Fri, Apr 21, 2006 at 12:48:51PM -0700, John W. Krahn wrote: print/.*/g,$"while<> Yeah, that's it. Woah, that's pretty short. You can make it even shorter: print/.*/g,$"for<> They aren't quite the same though. 'while' loops if the condition is sti

Re: golf

2006-04-21 Thread Chad Perrin
On Fri, Apr 21, 2006 at 04:03:49PM -0700, John W. Krahn wrote: > Chad Perrin wrote: > > On Fri, Apr 21, 2006 at 12:48:51PM -0700, John W. Krahn wrote: > >>print/.*/g,$"while<> > > > > Woah, that's pretty short. > > You can make it even shorter: > > print/.*/g,$"for<> True, that. I'm used to us

Re: golf

2006-04-21 Thread John W. Krahn
Chad Perrin wrote: > On Fri, Apr 21, 2006 at 12:48:51PM -0700, John W. Krahn wrote: >>print/.*/g,$"while<> > > Woah, that's pretty short. You can make it even shorter: print/.*/g,$"for<> > Thanks. Now I just need to go read a bit > and figure out how exactly it works. > > . . . unless you wan

Re: golf

2006-04-21 Thread Chad Perrin
On Fri, Apr 21, 2006 at 12:48:51PM -0700, John W. Krahn wrote: > > print/.*/g,$"while<> Woah, that's pretty short. Thanks. Now I just need to go read a bit and figure out how exactly it works. . . . unless you want to explain it. -- Chad Perrin [ CCD CopyWrite | http://ccd.apotheon.org ] "Th

Re: golf

2006-04-21 Thread John W. Krahn
M. Kristall wrote: > Chad Perrin wrote: >> This is kind of a frivolous question, but . . . is there some way to >> golf this? >> >> while (<>) { >> s/\n/ /; >> print; >> } > > How about > print/(.*)\n/while<> You probably meant: print/.*/g,$"while<> :-) John -- use Perl; program fulfi

Re: golf

2006-04-21 Thread M. Kristall
Chad Perrin wrote: This is kind of a frivolous question, but . . . is there some way to golf this? while (<>) { s/\n/ /; print; } Oops, I misread that as s/\n//; Sorry :'( -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: golf

2006-04-21 Thread M. Kristall
Chad Perrin wrote: This is kind of a frivolous question, but . . . is there some way to golf this? while (<>) { s/\n/ /; print; } How about print/(.*)\n/while<> ? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: golf

2006-04-20 Thread Chad Perrin
On Thu, Apr 20, 2006 at 09:15:12AM +0200, Dr.Ruud wrote: > Chad Perrin schreef: > > > This is kind of a frivolous question, but . . . is there some way to > > golf this? > > > > while (<>) { > > s/\n/ /; > > print; > > } > > Create a file called (for example) "-p" with somewhat like this

Re: golf

2006-04-20 Thread Dr.Ruud
Chad Perrin schreef: > This is kind of a frivolous question, but . . . is there some way to > golf this? > > while (<>) { > s/\n/ /; > print; > } Create a file called (for example) "-p" with somewhat like this: #!/usr/bin/perl -p y/\n/ / It can run on itself: -p -p -- Affijn, Ruud

Re: golf

2006-04-19 Thread Chad Perrin
On Thu, Apr 20, 2006 at 07:35:16AM +0530, Ankur Gupta wrote: > > { > local $/ = undef; > while (<>) { > s/\n/ /sg; > print; > } > } The goal in golf is to get the ball in the hole with less strokes, not more. -- Chad Perrin [ CCD CopyWrite | http://ccd.apotheon.org ]

RE: golf

2006-04-19 Thread Ankur Gupta
Chad Perrin scribbled on Wednesday, April 19, 2006 6:59 PM: > On Wed, Apr 19, 2006 at 06:51:21PM -0700, Timothy Johnson wrote: >> >> You mean like this? >> >> perl -p -e "s/\n/ /" > > Thanks. I looked -p up in perlrun and learned something new. It's > not quite what

Re: golf

2006-04-19 Thread Chad Perrin
On Wed, Apr 19, 2006 at 07:58:59PM -0600, Chad Perrin wrote: > On Wed, Apr 19, 2006 at 06:51:21PM -0700, Timothy Johnson wrote: > > > > You mean like this? > > > > perl -p -e "s/\n/ /" > > Thanks. I looked -p up in perlrun and learned something new. It's not > quite what I set out to learn, bu

Re: golf

2006-04-19 Thread Chad Perrin
On Wed, Apr 19, 2006 at 06:51:21PM -0700, Timothy Johnson wrote: > > You mean like this? > > perl -p -e "s/\n/ /" Thanks. I looked -p up in perlrun and learned something new. It's not quite what I set out to learn, but learning new things is good anyway. I was actually looking for something d

Re: golf

2006-04-19 Thread Randy W. Sims
Chad Perrin wrote: This is kind of a frivolous question, but . . . is there some way to golf this? while (<>) { s/\n/ /; print; } perl -pl40 -e1 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: golf

2006-04-19 Thread Randy W. Sims
Chad Perrin wrote: This is kind of a frivolous question, but . . . is there some way to golf this? while (<>) { s/\n/ /; print; } perl -pl04 -e1 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: golf

2006-04-19 Thread John W. Krahn
Chad Perrin wrote: > This is kind of a frivolous question, but . . . is there some way to > golf this? > > while (<>) { > s/\n/ /; > print; > } perl -012l040pe1 yourfile John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail

Re: golf

2006-04-19 Thread Mr. Shawn H. Corey
On Wed, 2006-19-04 at 19:36 -0600, Chad Perrin wrote: > This is kind of a frivolous question, but . . . is there some way to > golf this? > > while (<>) { > s/\n/ /; > print; > } perl -pe 's/\n/ /' See `perldoc perlrun` and search for 'Command Switches'. -- __END__ Just my 0.0002

RE: golf

2006-04-19 Thread Timothy Johnson
You mean like this? perl -p -e "s/\n/ /" (Some tweaking may be necessary for non-Win32 OS) -Original Message- From: Chad Perrin [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 19, 2006 6:36 PM To: beginners@perl.org Subject: golf This is kind of a frivolous question, but . . . is th