Re: while: both syntaxes cant solve my problem

2012-03-13 Thread Shawn H Corey
On 12-03-13 12:11 PM, oxy wrote: I have a problem with the following structure: while(){$thevariable=$1 if (/variable1=(.*)/)}; Now I wanna be sure that variable1 was really set in the above statement (it could have an old value from a previous embracing loop). Then I tried: while(){if (/varia

Re: while: both syntaxes cant solve my problem

2012-03-13 Thread Jim Gibson
On 3/13/12 Tue Mar 13, 2012 9:11 AM, "oxy" scribbled: > hi all, > > I have a problem with the following structure: > > while(){$thevariable=$1 if (/variable1=(.*)/)}; > > Now I wanna be sure that variable1 was really set in the above > statement (it could have an old value from a previous em

Re: while: one supresses the other?

2012-03-12 Thread timothy adigun
Hi Oxy, In addition, On Mon, Mar 12, 2012 at 6:34 PM, Jim Gibson wrote: > On 3/12/12 Mon Mar 12, 2012 10:17 AM, "oxy" > scribbled: > > > Hi, > > > > i have the following file content: numbers = one two three four > > > > I run the code: > > = begin code == > > #

Re: while: one supresses the other?

2012-03-12 Thread Jim Gibson
On 3/12/12 Mon Mar 12, 2012 10:17 AM, "oxy" scribbled: > Hi, > > i have the following file content: numbers = one two three four > > I run the code: > = begin code == > #!/usr/bin/perl -w > $AG2 = non; > $AG3 = non; > open (file , " > while(){if (/(.*)\s*=\s*.

Re: while(@data) works but why

2011-08-12 Thread Tony Esposito
rl.org Sent: Fri, 12 August, 2011 14:13:26 Subject: Re: while(@data) works but why On 8/12/11 Fri Aug 12, 2011 12:02 PM, "Tony Esposito" scribbled: > . > . > . > while(@dat = $sth->fetchrow) { > print "@dat\n"; > . > . > . > > This cod

Re: while(@data) works but why

2011-08-12 Thread Tony Esposito
got it ... thank you. cheers! From: Brandon McCaig To: Tony Esposito Cc: beginners@perl.org Sent: Fri, 12 August, 2011 14:08:52 Subject: Re: while(@data) works but why On Fri, Aug 12, 2011 at 3:02 PM, Tony Esposito wrote: > . > . > . > while

Re: while(@data) works but why

2011-08-12 Thread Jim Gibson
On 8/12/11 Fri Aug 12, 2011 12:02 PM, "Tony Esposito" scribbled: > . > . > . > while(@dat = $sth->fetchrow) { > print "@dat\n"; > . > . > . > > This code works yet there is no 'my @dat' defined anywhere in the code. > Using Perl 5.8.x - 5.14.x > > Q: Why does the variable @dat not nee

Re: while(@data) works but why

2011-08-12 Thread Brandon McCaig
On Fri, Aug 12, 2011 at 3:02 PM, Tony Esposito wrote: > . > . > . > while(@dat = $sth->fetchrow) { >        print "@dat\n"; > . > . > . > > This code works yet there is no 'my @dat' defined anywhere in the code. > Using Perl 5.8.x - 5.14.x > > Q: Why does the variable @dat not need a 'my' in front

Re: while and eval

2010-04-21 Thread Shawn H Corey
Uri Guttman wrote: "JWK" == John W Krahn writes: >> Also, how does 'eval' work and when is it useful? What is the difference if >> we put a block inside eval like: eval ( }; JWK> eval interprets a string as Perl code and compiles and runs it. If JWK> you are using a block eval then

Re: while and eval

2010-04-21 Thread Uri Guttman
> "JWK" == John W Krahn writes: >> Also, how does 'eval' work and when is it useful? What is the difference if >> we put a block inside eval like: eval ( }; JWK> eval interprets a string as Perl code and compiles and runs it. If JWK> you are using a block eval then the block must b

Re: while and eval

2010-04-21 Thread John W. Krahn
Arun P Menon wrote: Hello All, Hello, Could you tell me what does the following do? 1 while (<>); That reads through all the files listed on the command line, or if there are no files listed on the command line then it reads through STDIN, and does nothing with the lines read, but does se

Re: while (<>) and wildcards on DOS/Windows

2009-08-10 Thread Peter Daum
John W. Krahn wrote: Peter Daum wrote: Unfortunately, this leads right to the next problem: I also need "binmode" to turn off cr/lf conversion on DOS; with "while (<>)" I don't know where to do this anymore, because AFAIK, this has to be done after open, but before the 1st I/O; now before the "

Re: while (<>) and wildcards on DOS/Windows

2009-08-03 Thread Jenda Krynicky
From: Peter Daum > I occasionally have to write Perl scripts that should behave the same on > Unix- and DOS-like Systems. One little problem I encounter there is: > > For quick hacks, the "while(<>)" mechanism is very handy, because it > saves a lot of typing. On Unix, I can call a script as a fi

Re: while (<>) and wildcards on DOS/Windows

2009-08-03 Thread John W. Krahn
Peter Daum wrote: Shawn H. Corey wrote: I've always used: beg...@argv=glob(@ARGV)} ... I still need at least: BEGIN{ @ARGV=map { glob($_) } @ARGV } but that's already much shorter - thanks :-) Unfortunately, this leads right to the next problem: I also need "binmode" to turn off cr/lf con

Re: while (<>) and wildcards on DOS/Windows

2009-08-03 Thread Peter Daum
Shawn H. Corey wrote: Peter Daum wrote: Unfortunately, this leads right to the next problem: I also need "binmode" to turn off cr/lf conversion on DOS; with "while (<>)" I don't know where to do this anymore, because AFAIK, this has to be done after open, but before the 1st I/O; now before th

RE: while (<>) and wildcards on DOS/Windows

2009-08-03 Thread Bob McConnell
From: Peter Daum > > I occasionally have to write Perl scripts that should behave the same on > Unix- and DOS-like Systems. One little problem I encounter there is: I am using Camelbox Perl on WinXP. This is my command line for unit tests: perl -MTest::Harness -e "@ARGV= map glob, @ARGV if $^O =

Re: while (<>) and wildcards on DOS/Windows

2009-08-03 Thread Shawn H. Corey
Peter Daum wrote: Shawn H. Corey wrote: I've always used: beg...@argv=glob(@ARGV)} ... I still need at least: BEGIN{ @ARGV=map { glob($_) } @ARGV } but that's already much shorter - thanks :-) Unfortunately, this leads right to the next problem: I also need "binmode" to turn off cr/lf con

Re: while (<>) and wildcards on DOS/Windows

2009-08-03 Thread Peter Daum
Ed Avis wrote: Peter Daum yahoo.de> writes: With more recent Perl versions, when a script is called with '*.xyz' it will just try to open '*.xyz' and fail. What version of Perl do you have? (perl -V) ... when I 1st encountered this problem, it was with ActivePerl 5.8 generally, I try t

Re: while (<>) and wildcards on DOS/Windows

2009-08-03 Thread Peter Daum
Shawn H. Corey wrote: I've always used: beg...@argv=glob(@ARGV)} ... I still need at least: BEGIN{ @ARGV=map { glob($_) } @ARGV } but that's already much shorter - thanks :-) Unfortunately, this leads right to the next problem: I also need "binmode" to turn off cr/lf conversion on DOS; wit

Re: while (<>) and wildcards on DOS/Windows

2009-08-03 Thread Ed Avis
Peter Daum yahoo.de> writes: >With more recent Perl versions, when >a script is called with '*.xyz' it will just try to open '*.xyz' and >fail. What version of Perl do you have? (perl -V) -- Ed Avis -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail:

Re: while (<>) and wildcards on DOS/Windows

2009-08-03 Thread Shawn H. Corey
Peter Daum wrote: Is all this really necessary, or is there a better / more elegant way? I've always used: beg...@argv=glob(@ARGV)} -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. My favourite four-lett

Re: while() I have a simple question

2009-07-23 Thread Chas. Owens
On Thu, Jul 23, 2009 at 21:29, Steve Bertrand wrote: > I just ran into an issue where I was loosing literally half of some > expected data, which for a theoretical accounting system, would make for > some interesting audit trails (I already shave a fraction for myself, > but 50% will be noticeable

Re: While issues

2009-07-16 Thread John W. Krahn
Jo for lists and groups wrote: Are you supposed to be printing something here? Somewhat newb, but this doesn't look right to me: print (FO); That is short for: print( FO $_ ); The $_ variable is the default in a lot of places in Perl code. I'm guessing you want to remove commas an

RE: While issues

2009-07-16 Thread Jo for lists and groups
Are you supposed to be printing something here? Somewhat newb, but this doesn't look right to me: print (FO); I'm guessing you want to remove commas and so are rewriting the line into a new file after subst. I'd probably do print FO "$_"; I suspect your way may just be leaving the server

RE: While issues

2009-07-16 Thread Patrick K Christopher TANAGER
- CFS [mailto:david.wag...@fedex.com] Sent: Thursday, July 16, 2009 1:46 PM To: Patrick K Christopher TANAGER; beginners@perl.org Subject: RE: While issues > -Original Message- > From: Patrick K Christopher TANAGER > [mailto:pchristop...@tanagerinc.com] > Sent: Thursday, July 16

RE: While issues

2009-07-16 Thread Wagner, David --- Senior Programmer Analyst --- CFS
> -Original Message- > From: Patrick K Christopher TANAGER > [mailto:pchristop...@tanagerinc.com] > Sent: Thursday, July 16, 2009 11:39 > To: beginners@perl.org > Subject: While issues > > I can't seem to find this oddness in this script. > #! /usr/bin/perl You should use strict

Re: While issues

2009-07-16 Thread Shawn H. Corey
Patrick K Christopher TANAGER wrote: I can't seem to find this oddness in this script. #! /usr/bin/perl open(FH,"<$ARGV[0]") || die ("File failed to open!\n"); open(FO,">$ARGV[1]") || die ("Output failed to open!\n"); while (){ s/,//g s/,//g; # Watch your semi-colons :) print (FO); } clo

Re: while loops and the bedlam of the hash key

2008-09-06 Thread frazzmata
On Sep 5, 5:32 am, [EMAIL PROTECTED] (Hridyesh Pant) wrote: > in my case this works > while (<>) { >       chomp; >       my ($id, $record) = split(/\t+/,$_); >       push @{$table{$id}}, $record; >     } > >     foreach $id (sort keys %table) { >       print "$id "; >       my @records = @{$table{

Re: while loops and the bedlam of the hash key

2008-09-05 Thread Mr. Shawn H. Corey
On Fri, 2008-09-05 at 15:27 +0200, Dr.Ruud wrote: > Why use $1 if you can get the match by putting the regex in a list > context? > > while ( <$in> ) { > if( my ($id) = m/^\s*(\d+)/ ) { > $longz{$id} = $_; > } > else { > die "no ID in line $.: $_"; > }

Re: while loops and the bedlam of the hash key

2008-09-05 Thread Dr.Ruud
"Mr. Shawn H. Corey" schreef: > while( ){ > if( /^\s*(\d+)/ ){ > my $id = $1; > $longz{$id} = $_; > }else{ > die "no ID in line $.: $_"; > } > } Why use $1 if you can get the match by putting the regex in a list context? while ( <$in> ) { if( my ($id) = m/^\s*(\d+)/ )

Re: while loops and the bedlam of the hash key

2008-09-05 Thread Mr. Shawn H. Corey
On Fri, 2008-09-05 at 20:35 +0800, Jeff Pang wrote: > 2008/9/5 Mr. Shawn H. Corey <[EMAIL PROTECTED]>: > > > if( /^\s*(\d+)/ ){ > >my $id = $1; > >$longz{$id} = $_; > > I prefer the shorter one: > > $longz{$1} = $_; I prefer defencive programming techniques. After every match, assign

Re: while loops and the bedlam of the hash key

2008-09-05 Thread Jeff Pang
2008/9/5 Mr. Shawn H. Corey <[EMAIL PROTECTED]>: > if( /^\s*(\d+)/ ){ >my $id = $1; >$longz{$id} = $_; I prefer the shorter one: $longz{$1} = $_; -- Regards, Jeff. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: while loops and the bedlam of the hash key

2008-09-05 Thread Hridyesh Pant
in my case this works while (<>) { chomp; my ($id, $record) = split(/\t+/,$_); push @{$table{$id}}, $record; } foreach $id (sort keys %table) { print "$id "; my @records = @{$table{$id}}; print join ', ', sort @records; print "\n"; } --Hridyesh fraz

Re: while loops and the bedlam of the hash key

2008-09-05 Thread Mr. Shawn H. Corey
On Thu, 2008-09-04 at 14:03 -0700, frazzmata wrote: > I have a problem > I am trying to take lines in a text file that look like this. although > there are 500 more or so (and they have more realistic names) > > 25727 dude, some M MEX.AMER. DORM1 > 25797 dude, other M BLACK DORM2 >

Re: while loops and the bedlam of the hash key

2008-09-05 Thread John W. Krahn
frazzmata wrote: I have a problem I am trying to take lines in a text file that look like this. although there are 500 more or so (and they have more realistic names) 25727 dude, some M MEX.AMER. DORM1 25797 dude, other M BLACK DORM2 29291 guy, randomM BLACK DORM3 3024

RE: while trying to learn pack

2008-07-28 Thread Bob McConnell
From: Richard Lee >John W. Krahn wrote: >> Richard Lee wrote: >>> I am begining to read bit of low level(assembly) book to just gain >>> some knoweldge on inner workings of memory. >>> >>> My quesiton is, if machine is 32 bit, even if it's accessing string >>> 'A', it will have to fetch 32 bit (i

Re: while trying to learn pack

2008-07-26 Thread John W. Krahn
Richard Lee wrote: Just one more question on the topic, I am trying to understand how it works in binary world. So, If let's say I take a pcap file. I am assuming here that ethereal/wireshark will take binaries on the wire and then decoding it based on pcap standard(? hex? ) and then present t

Re: while trying to learn pack

2008-07-26 Thread Richard Lee
John W. Krahn wrote: Richard Lee wrote: I am begining to read bit of low level(assembly) book to just gain some knoweldge on inner workings of memory. My quesiton is, if machine is 32 bit, even if it's accessing string 'A', it will have to fetch 32 bit (instead of 8 bit that requires to make

Re: while trying to learn pack

2008-07-26 Thread Richard Lee
John W. Krahn wrote: Richard Lee wrote: I am begining to read bit of low level(assembly) book to just gain some knoweldge on inner workings of memory. My quesiton is, if machine is 32 bit, even if it's accessing string 'A', it will have to fetch 32 bit (instead of 8 bit that requires to make

Re: while trying to learn pack

2008-07-25 Thread John W. Krahn
Richard Lee wrote: I am begining to read bit of low level(assembly) book to just gain some knoweldge on inner workings of memory. My quesiton is, if machine is 32 bit, even if it's accessing string 'A', it will have to fetch 32 bit (instead of 8 bit that requires to make that letter A ) ? I

Re: while trying to learn pack

2008-07-25 Thread Rob Dixon
Richard Lee wrote: > > I am begining to read bit of low level(assembly) book to just gain some > knoweldge on inner workings of memory. > > My quesiton is, if machine is 32 bit, even if it's accessing string 'A', > it will have to fetch 32 bit (instead of 8 bit that requires to make > that lett

Re: while reading 'mastering perl' @+ and @-, not too clear on this

2008-03-23 Thread brian d foy
In article <[EMAIL PROTECTED]>, Richard Lee <[EMAIL PROTECTED]> wrote: > While reading 'mastering perl', I run into @- and @+ for the first time. > Trying to understand what's going on, I ran the code from the book, but > > $-[1] and $+[1] shoudln't match only the first match? (in this case, > sh

Re: while reading 'mastering perl' @+ and @-, not too clear on this

2008-03-19 Thread Richard Lee
John W. Krahn wrote: Richard Lee wrote: Thanks John for detailed explanation!! I just dont' understand why \ (also didn't know that within [ ], \ has to be escaped.) needs to be watch out for within " " .. \ use can be tricky, for example: $ perl -le"print 'hello'" hello $ perl -le"print '

Re: while reading 'mastering perl' @+ and @-, not too clear on this

2008-03-18 Thread John W. Krahn
Richard Lee wrote: Thanks John for detailed explanation!! I just dont' understand why \ (also didn't know that within [ ], \ has to be escaped.) needs to be watch out for within " " .. \ use can be tricky, for example: $ perl -le"print 'hello'" hello $ perl -le"print 'he\llo'" he\llo $ perl

Re: while reading 'mastering perl' @+ and @-, not too clear on this

2008-03-18 Thread Richard Lee
John W. Krahn wrote: Richard Lee wrote: Took your advice and start to read 'Mastering regular expression' by Jeffrey E.F.Friedl, Can you explain below further? on page, 205 push(@fields, $+) while $text =~ m{ "([^\"\\]*(?:\\.[^\"\\]*)*)",? #standard quoted string(with possible co

Re: while reading 'mastering perl' @+ and @-, not too clear on this

2008-03-18 Thread John W. Krahn
Richard Lee wrote: Took your advice and start to read 'Mastering regular expression' by Jeffrey E.F.Friedl, Can you explain below further? on page, 205 push(@fields, $+) while $text =~ m{ "([^\"\\]*(?:\\.[^\"\\]*)*)",? #standard quoted string(with possible comma) | ([^,]+),?

Re: while reading 'mastering perl' @+ and @-, not too clear on this

2008-03-17 Thread Richard Lee
Say you have the string "abcdefghi". The positions in the string are: a b c d e f g h i ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ 0 1 2 3 4 5 6 7 8 9 If you have the regular expression: /(de)/ Then the match starts at position 3, moves forward two characters, and ends at position 5, where the next match, i

Re: while reading 'mastering perl' @+ and @-, not too clear on this

2008-03-16 Thread Richard Lee
Rob Dixon wrote: Richard Lee wrote: Rob Dixon wrote: Perhaps it would help to think of the offset as being the index of the points between the characters, so the start of the string is at offset zero, after 'a' (and before 'b') is at offset one and so on. Then can you see how offset 7 is befor

Re: while reading 'mastering perl' @+ and @-, not too clear on this

2008-03-16 Thread Rob Dixon
Richard Lee wrote: Rob Dixon wrote: Perhaps it would help to think of the offset as being the index of the points between the characters, so the start of the string is at offset zero, after 'a' (and before 'b') is at offset one and so on. Then can you see how offset 7 is before 'hi' and offset

Re: while reading 'mastering perl' @+ and @-, not too clear on this

2008-03-16 Thread John W. Krahn
Richard Lee wrote: John W. Krahn wrote: Richard Lee wrote: While reading 'mastering perl', I run into @- and @+ for the first time. perldoc perlvar Trying to understand what's going on, I ran the code from the book, but $-[1] and $+[1] shoudln't match only the first match? (in this case,

Re: while reading 'mastering perl' @+ and @-, not too clear on this

2008-03-16 Thread Richard Lee
Rob Dixon wrote: Richard Lee wrote: John W. Krahn wrote: Richard Lee wrote: While reading 'mastering perl', I run into @- and @+ for the first time. perldoc perlvar Trying to understand what's going on, I ran the code from the book, but $-[1] and $+[1] shoudln't match only the first mat

Re: while reading 'mastering perl' @+ and @-, not too clear on this

2008-03-16 Thread Rob Dixon
Richard Lee wrote: John W. Krahn wrote: Richard Lee wrote: While reading 'mastering perl', I run into @- and @+ for the first time. perldoc perlvar Trying to understand what's going on, I ran the code from the book, but $-[1] and $+[1] shoudln't match only the first match? (in this case,

Re: while reading 'mastering perl' @+ and @-, not too clear on this

2008-03-16 Thread Richard Lee
John W. Krahn wrote: Richard Lee wrote: While reading 'mastering perl', I run into @- and @+ for the first time. perldoc perlvar Trying to understand what's going on, I ran the code from the book, but $-[1] and $+[1] shoudln't match only the first match? (in this case, shoudln't it be, 7 t

Re: while reading 'mastering perl' @+ and @-, not too clear on this

2008-03-16 Thread John W. Krahn
Richard Lee wrote: While reading 'mastering perl', I run into @- and @+ for the first time. perldoc perlvar Trying to understand what's going on, I ran the code from the book, but $-[1] and $+[1] shoudln't match only the first match? (in this case, shoudln't it be, 7 to 8 ?, instead of 7 to

RE: while and last

2008-01-15 Thread Kevin Viel
> -Original Message- > From: John W. Krahn [mailto:[EMAIL PROTECTED] > Sent: Tuesday, January 15, 2008 1:39 PM > To: Perl Beginners > Subject: Re: while and last > my $data = ; # Grap one line from file Doh! Thanks :) Kevin Viel, PhD Post-doctoral fellow Depa

Re: while and last

2008-01-15 Thread John W. Krahn
Kevin Viel wrote: Hello, Hello, If I only want the data on the first line of a file, can I use "last" to exit the loop or should I consider another tool? Don't use a loop at all: my $data = ; # Grap one line from file John -- Perl isn't a toolbox, but a small machine shop where you ca

Re: while(1) or redo [was: Re: IPC problem]

2007-02-07 Thread Adriano Ferreira
On 2/7/07, Rob Dixon <[EMAIL PROTECTED]> wrote: Igor Sutton wrote: > Hi fellows, > >> Dave, you wanted to use >> >> while (1) { >> ... >> the code to be repeated >> .. >> } >> > > The above code could be written like this: > > { >... ># the code to be repeated >... >redo; >

Re: while(1) or redo [was: Re: IPC problem]

2007-02-07 Thread Rob Dixon
Igor Sutton wrote: Hi fellows, Dave, you wanted to use while (1) { ... the code to be repeated .. } The above code could be written like this: { ... # the code to be repeated ... redo; } Do you think this is better or worse than the other idiom? I like the last more.

Re: while loop problem

2007-02-01 Thread Brad Cahoon
Done it, thank you all for your help. My next problem is regexp, you my be hearing from me :) Regards Brad -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: while loop problem

2007-01-31 Thread John W. Krahn
Brad Cahoon wrote: > Hi Perl Masters Hello, > I have a problem with a script which is suposed to open a huge text > file and take 70 lines, create a file, then take the next 70 lines > create a file and so on until it has parsed the whole file. My code > just doesn't work and my brain cannot figu

Re: while loop problem

2007-01-31 Thread Rob Dixon
Brad Cahoon wrote: Hi Perl Masters I have a problem with a script which is suposed to open a huge text file and take 70 lines, create a file, then take the next 70 lines create a file and so on until it has parsed the whole file. My code just doesn't work and my brain cannot figure out while{whi

RE: while loop problem

2007-01-31 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Brad Cahoon wrote: > Hi Perl Masters > > I have a problem with a script which is suposed to open a huge text > file and take 70 lines, create a file, then take the next 70 lines > create a file and so on until it has parsed the whole file. My code > just doesn't work and my brain cannot figure out

Re: while loop -> map

2005-05-25 Thread Jeff 'japhy' Pinyan
On May 25, Jay Savage said: On 5/25/05, Jeff 'japhy' Pinyan <[EMAIL PROTECTED]> wrote: On May 25, Jay Savage said: /e(?{push @bar, pos})/g; should work, but seems to ignore the /g. Because as you wrote it, the regex is in void context, which means it'll only match once. Put it in list co

Re: while loop -> map

2005-05-25 Thread Jay Savage
On 5/25/05, Jay Savage <[EMAIL PROTECTED]> wrote: [snip] >/p(?:{push @bar, pos})attern(?!)/g oops! make that: /p(?{push @bar, pos})attern(?!)/g -- daggerquill [at] gmail [dot] com http://www.engatiki.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional c

Re: while loop -> map

2005-05-25 Thread Jay Savage
On 5/25/05, Jeff 'japhy' Pinyan <[EMAIL PROTECTED]> wrote: > On May 25, Jay Savage said: > > > /e(?{push @bar, pos})/g; > > > > should work, but seems to ignore the /g. > > Because as you wrote it, the regex is in void context, which means it'll > only match once. Put it in list context: > >

Re: while loop -> map

2005-05-25 Thread Jeff 'japhy' Pinyan
On May 25, Jay Savage said: /e(?{push @bar, pos})/g; should work, but seems to ignore the /g. Because as you wrote it, the regex is in void context, which means it'll only match once. Put it in list context: () = /e(?{ push @bar, pos })/g; But this looks weird to almost anyone. I'd d

Re: while loop -> map

2005-05-25 Thread Jay Savage
On 5/25/05, Jay Savage <[EMAIL PROTECTED]> wrote: > On 5/24/05, Robert Citek <[EMAIL PROTECTED]> wrote: > > I like your idea. Unfortunately, the above works only in the special > > case where the regular expression match is actually a single- > > character, exact match. > > > > Regards, > > - Robe

Re: while loop -> map

2005-05-25 Thread Jay Savage
On 5/24/05, Robert Citek <[EMAIL PROTECTED]> wrote: > > On May 24, 2005, at 3:14 PM, Jay Savage wrote: > > One thing that springs to mind is: > > > >perl -le ' > >$foo = "fee fie foe foo"; > >map {$i++; push @bar, $i if $_ eq "e"} split //, $foo; > >print join(":",@bar)' > > > > I'

Re: while loop -> map

2005-05-24 Thread Offer Kaye
On 5/24/05, Robert Citek wrote: > > I found a variation of this in the Perl Nutshell book: > > $ perl -le ' > $foo="fee fie foe foo" ; > while ($foo =~ m/e/g ) { > push @bar, pos $foo ; > } > print join(":", @bar); ' > 2:3:7:11 > > Is there an equivalent way to do the same using map

Re: while loop -> map

2005-05-24 Thread Ing. Branislav Gerzo
Xavier Noria [XN], on Tuesday, May 24, 2005 at 22:12 (+0200) typed the following: XN> my $i = 0; XN> my @bar = map $_->[1], # take second component XN>grep $_->[0] eq 'e', # let 'e's pass XN>map [$_, ++$i],# arrayref [char, index of cha

Re: while loop -> map

2005-05-24 Thread John Doe
Am Dienstag, 24. Mai 2005 19.22 schrieb Robert Citek: > I found a variation of this in the Perl Nutshell book: > > $ perl -le ' > $foo="fee fie foe foo" ; > while ($foo =~ m/e/g ) { > push @bar, pos $foo ; > } > print join(":", @bar); ' > 2:3:7:11 > > Is there an equivalent way to do th

Re: while loop -> map

2005-05-24 Thread Xavier Noria
On May 24, 2005, at 19:22, Robert Citek wrote: I found a variation of this in the Perl Nutshell book: $ perl -le ' $foo="fee fie foe foo" ; while ($foo =~ m/e/g ) { push @bar, pos $foo ; } print join(":", @bar); ' 2:3:7:11 Is there an equivalent way to do the same using map instead of a

Re: while(1){print "a"; sleep 1;}

2005-02-09 Thread mgoland
- Original Message - From: TapasranjanMohapatra <[EMAIL PROTECTED]> Date: Wednesday, February 9, 2005 9:17 am Subject: while(1){print "a"; sleep 1;} > Hi All, Hello, > > Why I dont get a's printed with the code below? Works well on my system, are you sure you are not redirecting the out

Re: while(1){print "a"; sleep 1;}

2005-02-09 Thread Marcello
TapasranjanMohapatra ha scritto: Hi All, Why I dont get a's printed with the code below? +++ while(1) { print "a"; sleep 1; } +++ It works well if I print a newline with a, i.e while(1) { print "a\n"; # newline with a sleep 1; } Please hel

RE: while(1){print "a"; sleep 1;} -my thanks

2005-02-09 Thread TapasranjanMohapatra
-Original Message- From: Chris Devers [mailto:[EMAIL PROTECTED] Sent: Wed 2/9/2005 8:01 PM To: TapasranjanMohapatra Cc: Perl Beginners List Subject:Re: while(1){print "a"; sleep 1;} On Wed, 9 Feb 2005, TapasranjanMohapatra wrote: > Why I dont get a&#

Re: while(1){print "a"; sleep 1;}

2005-02-09 Thread Chris Devers
On Wed, 9 Feb 2005, TapasranjanMohapatra wrote: > Why I dont get a's printed with the code below? Apparently it's an output buffering issue. If you flush output, it works: $ perl -e 'while(1){print"a";sleep 1}' ^C $ perl -e '$|=1;while(1){print"a";sleep 1}' aaa^C $ So, setting $|

Re: while(1){print "a"; sleep 1;}

2005-02-09 Thread Ing. Branislav Gerzo
TapasranjanMohapatra [T], on Wednesday, February 9, 2005 at 19:47 (+0530) typed the following: T> It works well if I print a newline with a, i.e I hope it works without sleep 1, try that, and you will see the answer. -- ...m8s, cu l8r, Brano. ["You should never go in there without a mongoos

Re: While or For

2003-11-17 Thread drieux
On Monday, Nov 17, 2003, at 09:04 US/Pacific, Jeff 'japhy' Pinyan wrote: [..] which only reads ONE line at a time, whereas for () { ... } reads ALL the lines of the file at once, into a list. really good point there. but wouldn't the position been just a tad stronger had you noted that the abo

Re: While or For

2003-11-17 Thread Jeff 'japhy' Pinyan
On Nov 17, angie ahl said: >I keep getting hung up on deciding whether to use for or while for >loops. Well, it usually depends on how the code "reads". I use 'while' for loops based on a condition that will change in some execution of the block. while () { # eventually, will return unde

Re: While loop on a file handle

2003-08-14 Thread Rob Dixon
Sorry guys. There's a keyboard shortcut set up on my PC that sends my current mail that I often hit accidentally. It means I occasionally post half-finished mails. I'll knuckle-down and fix it. This is the post as it should have been: Hi Trevor. Trevor Morrison wrote: > > I am trying to step th

RE: While loop on a file handle

2003-08-14 Thread Jenda Krynicky
From: "Morrison, Trevor (Trevor)" <[EMAIL PROTECTED]> > What I am trying to do is to process a file that has say 1000 orders > in it all pretty much of the same format. I want to open up the file, > and then using a while loop go down through all of the order > one-at-a-time and once I have all th

RE: While loop on a file handle

2003-08-14 Thread Morrison, Trevor (Trevor)
al Message- From: Rob Dixon [mailto:[EMAIL PROTECTED] Sent: Tuesday, August 05, 2003 3:01 PM To: [EMAIL PROTECTED] Subject: Re: While loop on a file handle Sorry guys. There's a keyboard shortcut set up on my PC that sends my current mail that I often hit accidentally. It means I occasionally pos

Re: While loop on a file handle

2003-08-07 Thread Rob Dixon
"Trevor Morrison" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > > I am trying to step through each line of a file that contains orders that > were place through a internet shopping cart. I have this code: > > open(ORDER,$order) or die "Error opening \"$order\": $OS_ERROR\n"

RE: While loop on a file handle

2003-08-06 Thread David Wall
--On Wednesday, August 06, 2003 2:50 PM +0200 Jenda Krynicky <[EMAIL PROTECTED]> wrote: From: "Morrison, Trevor (Trevor)" <[EMAIL PROTECTED]> What I am trying to do is to process a file that has say 1000 orders in it all pretty much of the same format. I want to open up the file, and then usin

RE: While loop on a file handle

2003-08-06 Thread Perry, Alan
On Tuesday, August 05, 2003 12:13, Trevor Morrison wrote: > >Hi, > >I am trying to step through each line of a file that contains orders that >were place through a internet shopping cart. I have this code: > > open(ORDER,$order) or die "Error opening \"$order\": $OS_ERROR\n"; > >print "HI\n"; > wh

Re: While loop, confused... - Thanks!

2003-07-03 Thread Bill Akins
Thank you all for your responses!! I finally have a handle on it and used a little of everyones suggestions. This list rocks because of people like you. Thanks again!

Re: While loop, confused...

2003-07-03 Thread Rob Anderson
Hi Bill, I know you've had lots of comments on this, but I thought I'd throw my own style in. Why not do your check at the bottom with a "do until"? First time round the check is useless anyway, and will give you 'undef' type warnings with perl -w. It also allows you to be more positive in your co

RE: While loop, confused...

2003-07-02 Thread Shishir K. Singh
>Hi all! >I have this while loop in my script: >while (($type ne "Windows") || ($type ne "Linux")) { >print "Enter TYPE of server to build. Linux or Windoze [linux, windows]:\n"; >$type = ; >chomp $type; >$type =~ tr/a-z/A-Z/; >if (($type eq "LINUX") || ($type eq "L")) { >$type = "Linux"; } >i

RE: While loop, confused...

2003-07-02 Thread Charles K. Clarkson
Bill Akins <[EMAIL PROTECTED]> wrote: : : while (($type ne "Windows") || ($type ne "Linux")) { This will always be true. Try: while ( $type ne 'Windows' && $type ne 'Linux' ) { ^^ HTH, Charles K. Clarkson -- Head Bottle Washer, Clarkson Energy Homes, Inc.

Re: While loop, confused...

2003-07-02 Thread Kevin Pfeiffer
Sorry... In article <[EMAIL PROTECTED]>, Kevin Pfeiffer wrote: > In article <[EMAIL PROTECTED]>, Kevin Pfeiffer wrote: > > >> Here's an 'or' version: >> my $type1 = ''; >> while ( $type1 !~ /wisteria|lime/i ) { >>print "Enter COLOR of server. Lime or Wisteria [lime, wisteria]: "; >>chom

Re: While loop, confused...

2003-07-02 Thread Kevin Pfeiffer
In article <[EMAIL PROTECTED]>, Kevin Pfeiffer wrote: > Here's an 'or' version: > my $type1 = ''; > while ( $type1 !~ /wisteria|lime/i ) { >print "Enter COLOR of server. Lime or Wisteria [lime, wisteria]: "; >chomp( $type1 = ucfirst lc ); >$type1 = 'Wisteria' if $type1 eq 'W'; >$

Re: While loop, confused...

2003-07-02 Thread Kevin Pfeiffer
In article <[EMAIL PROTECTED]>, John W. Krahn wrote: > Bill Akins wrote: >> >> Hi all! > > Hello, > >> I have this while loop in my script: >> >> while (($type ne "Windows") || ($type ne "Linux")) { > > Your problem is that you are using or when you should be using and. > > >> print "Enter

RE: While loop, confused...

2003-07-02 Thread Bill Akins
> > while (($type ne "Windows") || ($type ne "Linux")) { > Right here, you must have the full string "Windows" or "Linux" Yes, correct. > > print "Enter TYPE of server to build. Linux or Windoze > > [linux, windows]: > > \n"; > > $type = ; > > chomp $type; > > $type =~ tr/a-z/A-Z/; > > Here yo

Re: While loop, confused...

2003-07-02 Thread John W. Krahn
Bill Akins wrote: > > Hi all! Hello, > I have this while loop in my script: > > while (($type ne "Windows") || ($type ne "Linux")) { Your problem is that you are using or when you should be using and. > print "Enter TYPE of server to build. Linux or Windoze [linux, windows]: > \n"; > $type =

RE: While loop, confused...

2003-07-02 Thread LoBue, Mark
> -Original Message- > From: Bill Akins [mailto:[EMAIL PROTECTED] > Sent: Wednesday, July 02, 2003 3:48 PM > To: [EMAIL PROTECTED] > Subject: While loop, confused... > > > Hi all! > > I have this while loop in my script: > > while (($type ne "Windows") || ($type ne "Linux")) { Right

Re: while (<>)

2003-06-17 Thread Bryan Harris
> Finally occurred to me to try using ARGV in slurp mode, which does > indeed do the Right Thing: > >> #!/usr/bin/perl -l >> use strict; >> use warnings; >> >> die usage() if (@ARGV == 0) >> or (@ARGV == 1 and -t STDIN); >> >> my $pattern = shift; >> l

Re: while (<>)

2003-06-17 Thread Steve Grazzini
On Tue, Jun 17, 2003 at 04:34:04AM -0400, Steve Grazzini wrote: > On Mon, Jun 16, 2003 at 10:33:28PM -0700, Bryan Harris wrote: > > Pretty neat, Steve, thanks. Well don't thank me too soon! Finally occurred to me to try using ARGV in slurp mode, which does indeed do the Right Thing: > #!/usr

Re: while (<>)

2003-06-17 Thread Steve Grazzini
On Mon, Jun 16, 2003 at 10:33:28PM -0700, Bryan Harris wrote: > Pretty neat, Steve, thanks. The only thing that'd be nice to > fix is making it so it gives the usage line if you enter: > > % showme 'ah\d' > > instead of waiting for STDIN. Aside from that it works perfectly. > And I learned a

Re: while (<>)

2003-06-16 Thread Mark G
- Original Message - From: "Bryan Harris" <[EMAIL PROTECTED]> To: "Beginners Perl" <[EMAIL PROTECTED]> Sent: Tuesday, June 17, 2003 1:33 AM Subject: Re: while (<>) > > > #!/usr/bin/perl > > > > my $showme = shift > &g

Re: while (<>)

2003-06-16 Thread Bryan Harris
> #!/usr/bin/perl > > my $showme = shift > or die "Usage: $0 [FILES]\n"; > > while (defined(my $line = <>)) { > $_ .= $line; > next unless eof; # [1] > > my $prefix = ($ARGV eq '-')? '' : "$ARGV: "; # [2] > > print "${prefix}$1\n" while /(

  1   2   >