loop break condition

2011-08-21 Thread anant mittal
hello! i want to input some numbers via in while loop.And loop should be broken if any nonnumeric character is entered.So how it can be checked. . my @ln; my $i=0; print"Give line numbers you want to put into array.\n"; while(1){ $ln[$i]=; chomp

Re: loop break condition

2011-08-22 Thread Alan Haggai Alavi
Hello Anant, > i want to input some numbers via in while loop.And loop should be > broken if any nonnumeric character is entered.So how it can be checked. > > > . > my @ln; > my $i=0; > print"Give line numbers you want to put into array.\n"; > whi

Re: loop break condition

2011-08-22 Thread timothy adigun
Hi Anant, One more query:- > HOW TO REMOVE ANY ELEMENT FROM AN ARRAY. > I mean if i have allocated till arr[5]. Now I want to remove the value > arr[4] and arr[5]. So how it can be done so that $#arr would tell 3. > #!/usr/bin/perl -l use strict; use warnings; my @arr=qw( home father son sun mot

Re: loop break condition

2011-08-22 Thread Shlomi Fish
Hi Alan, On Mon, 22 Aug 2011 13:10:05 +0530 Alan Haggai Alavi wrote: > Hello Anant, > > > i want to input some numbers via in while loop.And loop should be > > broken if any nonnumeric character is entered.So how it can be checked. > > > > > >

Re: loop break condition

2011-08-22 Thread Alan Haggai Alavi
Hello Shlomi, > It's a good idea to always use "last LABEL;" instead of "last;" (as well as > "next LABEL;" etc. in case more loops are added in between. > ⋮ > http://perl-begin.org/tutorials/bad-elements/#flow-stmts-without-labels Now I understand why it is always good to label loops that use `l

Re: loop break condition

2011-08-22 Thread Shlomi Fish
Hi Alan, On Mon, 22 Aug 2011 14:43:48 +0530 Alan Haggai Alavi wrote: > Hello Shlomi, > > > It's a good idea to always use "last LABEL;" instead of "last;" (as well as > > "next LABEL;" etc. in case more loops are added in between. > > ⋮ > > http://perl-begin.org/tutorials/bad-elements/#flow-stm

Re: loop break condition

2011-08-22 Thread Shawn H Corey
On 11-08-22 05:03 AM, Shlomi Fish wrote: It's a good idea to always use "last LABEL;" instead of "last;" (as well as "next LABEL;" etc. in case more loops are added in between. Good idea but try to choose meaningful names. Also, the else clause is not needed. [CODE] use strict; use warnings

Re: loop break condition

2011-08-22 Thread Randal L. Schwartz
> "anant" == anant mittal writes: anant> $ln[$i]=; I'd swear that lowercase "stdin" was deprecated already, but I can't find any record of it in the deltas, and it still works in 5.12 (I don't have 5.14 compiled here). In any case, you should shift to the proper STDIN, as everyone else's a

Re: loop break condition

2011-08-22 Thread Shawn H Corey
On 11-08-22 07:37 PM, Randal L. Schwartz wrote: "anant" == anant mittal writes: anant> $ln[$i]=; I'd swear that lowercase "stdin" was deprecated already, but I can't find any record of it in the deltas, and it still works in 5.12 (I don't have 5.14 compiled here). In any case, you should s

Re: loop break condition

2011-08-24 Thread Emeka
Do we really need "goto" here? Emeka On Mon, Aug 22, 2011 at 10:03 AM, Shlomi Fish wrote: > Hi Alan, > > On Mon, 22 Aug 2011 13:10:05 +0530 > Alan Haggai Alavi wrote: > > > Hello Anant, > > > > > i want to input some numbers via in while loop.And loop should > be > > > broken if any nonnumeric

Re: loop break condition

2011-08-24 Thread Shlomi Fish
On Wed, 24 Aug 2011 16:32:30 +0100 Emeka wrote: > Do we really need "goto" here? > Where do you see a "goto"? Perl 5 has a goto statement (see http://perldoc.perl.org/functions/goto.html ) and it's pretty flexible, but we did not use it here, and instead used "last LABEL" or "next LABEL" which

Re: loop break condition

2011-08-24 Thread Jim Gibson
On 8/24/11 Wed Aug 24, 2011 8:32 AM, "Emeka" scribbled: > Do we really need "goto" here? > > Emeka No, we don't need a goto here. The statement 'last' is effectively a 'goto' but with the restriction that it will only work inside a loop and only transfer control out of the loop. This avoids m

Re: loop break condition

2011-08-24 Thread Rob Dixon
On 22/08/2011 10:29, Shlomi Fish wrote: Hi Alan, On Mon, 22 Aug 2011 14:43:48 +0530 Alan Haggai Alavi wrote: Hello Shlomi, It's a good idea to always use "last LABEL;" instead of "last;" (as well as "next LABEL;" etc. in case more loops are added in between. ⋮ http://perl-begin.org/tutorial

Re: loop break condition

2011-08-25 Thread Shlomi Fish
Hi Rob, On Wed, 24 Aug 2011 23:07:13 +0100 Rob Dixon wrote: > On 22/08/2011 10:29, Shlomi Fish wrote: > > Hi Alan, > > > > On Mon, 22 Aug 2011 14:43:48 +0530 > > Alan Haggai Alavi wrote: > > > >> Hello Shlomi, > >> > >>> It's a good idea to always use "last LABEL;" instead of "last;" (as well >

Re: loop break condition

2011-08-25 Thread Randal L. Schwartz
> "Shlomi" == Shlomi Fish writes: Shlomi> I also tend to avoid using "$_" (except for map/grep/etc. where Shlomi> it is required), because it can be clobbered and devastated too Shlomi> easily, which also makes depending on it error prone. Well, that's interesting. I've *never* accidentally

Re: loop break condition

2011-08-25 Thread Shlomi Fish
On Thu, 25 Aug 2011 10:08:55 -0700 mer...@stonehenge.com (Randal L. Schwartz) wrote: > > "Shlomi" == Shlomi Fish writes: > > Shlomi> I also tend to avoid using "$_" (except for map/grep/etc. where > Shlomi> it is required), because it can be clobbered and devastated too > Shlomi> easily, whi

Re: loop break condition

2011-08-25 Thread Randal L. Schwartz
> "Shlomi" == Shlomi Fish writes: Shlomi> Well, I believe I've always avoided using an implicit $_ as preventative Shlomi> measure (out of thinking I know better) and so cannot present such a case Shlomi> first-hand. However, see: Shlomi> http://www.forum2.org/gaal/perl/Pitfall/slide001.htm

Re: loop break condition

2011-08-25 Thread Shlomi Fish
Hi Randal, On Thu, 25 Aug 2011 11:41:34 -0700 mer...@stonehenge.com (Randal L. Schwartz) wrote: > > "Shlomi" == Shlomi Fish writes: > > Shlomi> Well, I believe I've always avoided using an implicit $_ as > Shlomi> preventative measure (out of thinking I know better) and so cannot > Shlomi>

Re: loop break condition

2011-08-25 Thread Rob Dixon
On 25/08/2011 20:36, Shlomi Fish wrote: If you want to use $_ so be it, but it can easily introduce subtle errors into your code, because $_ is so easy to modify and clobber. So I would recommend against these, and still think it's a good idea. Please substantiate this assertion. I believe you

Re: loop break condition

2011-08-26 Thread Jim Gibson
On 8/25/11 Thu Aug 25, 2011 5:20 PM, "Rob Dixon" scribbled: > On 25/08/2011 20:36, Shlomi Fish wrote: >> >> If you want to use $_ so be it, but it can easily introduce subtle errors >> into >> your code, because $_ is so easy to modify and clobber. So I would recommend >> against these, and st

Re: loop break condition

2011-08-26 Thread Brandon McCaig
On Wed, Aug 24, 2011 at 6:07 PM, Rob Dixon wrote: > On 22/08/2011 10:29, Shlomi Fish wrote: > Just as with pronouns in natural language, implicit operands in Perl > allow the meaning of a program to be more lucid. Yes, if we are not > careful we can sometimes write confusing English where it is un

Re: loop break condition

2011-08-26 Thread Rob Dixon
On 26/08/2011 18:12, Jim Gibson wrote: On 8/25/11 Thu Aug 25, 2011 5:20 PM, "Rob Dixon" On 25/08/2011 20:36, Shlomi Fish wrote: If you want to use $_ so be it, but it can easily introduce subtle errors into your code, because $_ is so easy to modify and clobber. So I would recommend against t

Re: loop break condition

2011-08-26 Thread Shawn H Corey
On 11-08-26 03:08 PM, Rob Dixon wrote: As an aside, the same applies to the common warning against using the global values $a and $b 'because they are used by sort'. Once again, sort localizes these variables within the comparison code so there is very little chance of inadvertently modifying the

Re: loop break condition

2011-08-26 Thread Shlomi Fish
On Fri, 26 Aug 2011 20:08:31 +0100 Rob Dixon wrote: > On 26/08/2011 18:12, Jim Gibson wrote: > > On 8/25/11 Thu Aug 25, 2011 5:20 PM, "Rob Dixon" > scribbled: > >> On 25/08/2011 20:36, Shlomi Fish wrote: > >>> > >>> If you want to use $_ so be it, but it can easily introduce > >>> subtle errors

Re: loop break condition

2011-08-27 Thread Rob Dixon
On 26/08/2011 18:12, Jim Gibson wrote: On 8/25/11 Thu Aug 25, 2011 5:20 PM, "Rob Dixon" scribbled: On 25/08/2011 20:36, Shlomi Fish wrote: If you want to use $_ so be it, but it can easily introduce subtle errors into your code, because $_ is so easy to modify and clobber. So I would recomm

Re: loop break condition

2011-08-27 Thread C.DeRykus
On Aug 26, 12:25 pm, shlo...@shlomifish.org (Shlomi Fish) wrote: > On Fri, 26 Aug 2011 20:08:31 +0100 > > ... > > The problem starts to happen when you try to declare $a and $b using my. This > program: > > [CODE] > #!/usr/bin/perl > > use strict; > use warnings; > > my $a = 5; > my $b = 6; > > pri

Re: loop break condition

2011-08-27 Thread C.DeRykus
On Aug 26, 12:25 pm, shlo...@shlomifish.org (Shlomi Fish) wrote: > ... > The problem starts to happen when you try to declare $a and $b using my. This > program: > > [CODE] > #!/usr/bin/perl > > use strict; > use warnings; > > my $a = 5; > my $b = 6; > > print map { "$_\n" } sort { $a <=> $b } (9,1

Re: loop break condition

2011-08-27 Thread Dr.Ruud
On 2011-08-26 21:08, Rob Dixon wrote: But I would be sad to rule against niceties like not /^#/ and print for <$fh>; Which can also be written as /^#/ or print for <$fh>; I would like 'lazy' syntax like: <$fh> x {/^#/ or print}; to process a list. -- Ruud -- To unsubscribe, e-mail:

Re: loop break condition

2011-08-28 Thread Dr.Ruud
On 2011-08-26 19:23, Brandon McCaig wrote: Personally I think that it's easier to read without the labels. I think that any programmer that added an inner loop and didn't refactor the corresponding 'next', 'last', or 'redo' statement should be given up on. :P Whenever you modify code you can

Re: loop break condition

2011-08-28 Thread Mike McClain
On Sat, Aug 27, 2011 at 08:16:50PM +0200, Dr.Ruud wrote: > I would like 'lazy' syntax like: > > <$fh> x {/^#/ or print}; > > to process a list. When I tried your code like so: open my $fh, '<', $file or die qq(Unable to open $file: $! ); <$fh> x {/^\s*#/ or print}; close $fh

Re: loop break condition

2011-08-29 Thread Rob Dixon
On 28/08/2011 19:48, Mike McClain wrote: On Sat, Aug 27, 2011 at 08:16:50PM +0200, Dr.Ruud wrote: I would like 'lazy' syntax like: <$fh> x {/^#/ or print}; to process a list. When I tried your code like so: open my $fh, '<', $file or die qq(Unable to open $file: $! ); <$fh>

Re: loop break condition

2011-08-30 Thread Mike McClain
On Mon, Aug 29, 2011 at 03:27:52PM +0100, Rob Dixon wrote: > > Hey Mike. Ruud was just proposing a "wouldn't it be nice if" syntax. It > isn't valid Perl! > > Rob Well that explains the errors. I've gotten so many good ideas from his posts it didn't dawn on me to doubt the validity of this one.