Re: Unintended behavior: Range operator inside a while loop continues to pattern match on the subsequent file

2011-04-21 Thread Marc Perry
Thanks, Paul. A very thoughtful response--I will try this out (I don't recall every encountering the ?? operator, but if it works as advertised I will likely use it a lot). --Marc On Thu, Apr 21, 2011 at 3:29 PM, Paul Johnson wrote: > On Thu, Apr 21, 2011 at 01:42:42PM -0400, Marc Perry wrote:

Re: Unintended behavior: Range operator inside a while loop continues to pattern match on the subsequent file

2011-04-21 Thread Marc Perry
Beautiful; I should've known that brian d foy would have come up with a solution--I even have a copy of that book! Thanks, --Marc On Thu, Apr 21, 2011 at 3:10 PM, Brian Fraser wrote: > http://www.effectiveperlprogramming.com/blog/314 > > Brian. > > On Thu, Apr 21, 2011 at 2:42 PM, Marc Perry w

Re: Unintended behavior: Range operator inside a while loop continues to pattern match on the subsequent file

2011-04-21 Thread Paul Johnson
On Thu, Apr 21, 2011 at 01:42:42PM -0400, Marc Perry wrote: > Hi, > > I was parsing a collection of HTML files where I wanted to extract a certain > block from each file, like this: This is where everyone will tell you to use some dedicated HTML parsing module. > > ./script.pl *.html > > my $ac

Re: Unintended behavior: Range operator inside a while loop continues to pattern match on the subsequent file

2011-04-21 Thread Brian Fraser
http://www.effectiveperlprogramming.com/blog/314 Brian. On Thu, Apr 21, 2011 at 2:42 PM, Marc Perry wrote: > Hi, > > I was parsing a collection of HTML files where I wanted to extract a > certain > block from each file, like this: > > > ./script.pl *.html > > my $accumulator; > my $capture_coun

Unintended behavior: Range operator inside a while loop continues to pattern match on the subsequent file

2011-04-21 Thread Marc Perry
Hi, I was parsing a collection of HTML files where I wanted to extract a certain block from each file, like this: > ./script.pl *.html my $accumulator; my $capture_counter; while ( <> ) { if ( //.../labelsub/ ) { $accumulator .= $_ unless /labelsub/; if ( /labelsub/ && !$cap

Re: why while loop 6 times when @data have only 3 elements

2009-02-20 Thread John W. Krahn
itshardtogetone wrote: Hi, Hello, Looking at the script below, why does the while function loop 6 times instead of 3 times when @data have only 3 elements and I thought the output should be:- 1 $_ = aaa1 2 $_ = bbb2 3 $_ = ccc3 Thanks # #!/usr/bi

Re: why while loop 6 times when @data have only 3 elements

2009-02-20 Thread Chas. Owens
On Fri, Feb 20, 2009 at 23:22, Chas. Owens wrote: > On Fri, Feb 20, 2009 at 22:56, itshardtogetone > wrote: >> Hi, >> Looking at the script below, why does the while function loop 6 times >> instead of 3 times when @data have only 3 elements and >> I thought the output should be:- >> 1 $_ = aaa

Re: why while loop 6 times when @data have only 3 elements

2009-02-20 Thread Chas. Owens
On Fri, Feb 20, 2009 at 22:56, itshardtogetone wrote: > Hi, > Looking at the script below, why does the while function loop 6 times instead > of 3 times when @data have only 3 elements and > I thought the output should be:- > 1 $_ = aaa1 > 2 $_ = bbb2 > 3 $_ = ccc3 > > Thanks > >

why while loop 6 times when @data have only 3 elements

2009-02-20 Thread itshardtogetone
Hi, Looking at the script below, why does the while function loop 6 times instead of 3 times when @data have only 3 elements and I thought the output should be:- 1 $_ = aaa1 2 $_ = bbb2 3 $_ = ccc3 Thanks # #!/usr/bin/perl use strict; use warnings; my

Re: converting while loop to a for loop

2008-12-01 Thread John W. Krahn
dippa wrote: basic perl problem which is annoying me, the code is: --- #!/usr/bin/perl -w use strict; my $string; my $subString; my @indexes; print "Enter a string:\n"; chomp($string = ); print "\nEnter substring to search for:\n"; chomp($subString = ); ## This whil

Re: converting while loop to a for loop

2008-12-01 Thread Rob Dixon
dippa wrote: > > Trying to work out why: > 1. the for loop does not work, want the same logic as the while loop > 2. for(my $pos = -1; $pos == -1; $pos++) only iterates through once > 3. for(my $pos = 0; $pos == -1; $pos++) does not enter loop at all Because in both cases your

converting while loop to a for loop

2008-12-01 Thread dippa
basic perl problem which is annoying me, the code is: --- #!/usr/bin/perl -w use strict; my $string; my $subString; my @indexes; print "Enter a string:\n"; chomp($string = ); print "\nEnter substring to search for:\n"; chomp($subString = ); ## This while loop does what i&#

Re: Assign regex match to variable in while loop

2008-09-23 Thread Clemens Bieg
Thanks. Both solutions work. On Tue, Sep 23, 2008 at 9:19 PM, Clemens Bieg <[EMAIL PROTECTED]> wrote: > Thanks. > > On Tue, Sep 23, 2008 at 8:25 PM, John W. Krahn <[EMAIL PROTECTED]> wrote: > >> Clemens Bieg wrote: >> >>> Hello, >>> >>> I am trying to iterate over all the lines of a file, each o

Re: Assign regex match to variable in while loop

2008-09-23 Thread Clemens Bieg
Thanks. On Tue, Sep 23, 2008 at 8:25 PM, John W. Krahn <[EMAIL PROTECTED]> wrote: > Clemens Bieg wrote: > >> Hello, >> >> I am trying to iterate over all the lines of a file, each of which starts >> with a line number, and isolate the line number and the corresponding >> string >> into one varia

Re: Assign regex match to variable in while loop

2008-09-23 Thread John W. Krahn
Clemens Bieg wrote: Hello, I am trying to iterate over all the lines of a file, each of which starts with a line number, and isolate the line number and the corresponding string into one variable each, then have them printed into a separate file. Could someone give me a clue on how to assign the

Re: Assign regex match to variable in while loop

2008-09-23 Thread Mr. Shawn H. Corey
On Tue, 2008-09-23 at 20:05 +0200, Clemens Bieg wrote: > while (<$fh_in_extract>) { > >if ($id = m/^\d+/) { if( ( $id ) = m/^(\d+)/ ){ >print $fh_out_final $id; >} > } -- Just my 0.0002 million dollars worth, Shawn Linux is obsolete. -- Andrew Tanenbaum -- To unsubscribe,

Assign regex match to variable in while loop

2008-09-23 Thread Clemens Bieg
Hello, I am trying to iterate over all the lines of a file, each of which starts with a line number, and isolate the line number and the corresponding string into one variable each, then have them printed into a separate file. Could someone give me a clue on how to assign the line number match to

Re: Wrong while{} loop, maybe!? I need help, please.

2008-08-14 Thread Nayab
On Aug 14, 2:15 pm, [EMAIL PROTECTED] wrote: > #!/usr/bin/perl -w > use strict; > use Authen::Simple::POP3; > > print "Enter POP3 server hostname: "; > chomp( my $host = ); > > my $pop3 = Authen::Simple::POP3->new( >     host => $host > ); > > my $pwdlst = "pass.txt"; > open( INPASS, $pwdlst ) ||

Re: Wrong while{} loop, maybe!? I need help, please.

2008-08-14 Thread Nayab
On Aug 14, 2:15 pm, [EMAIL PROTECTED] wrote: > #!/usr/bin/perl -w > use strict; > use Authen::Simple::POP3; > > print "Enter POP3 server hostname: "; > chomp( my $host = ); > > my $pop3 = Authen::Simple::POP3->new( >     host => $host > ); > > my $pwdlst = "pass.txt"; > open( INPASS, $pwdlst ) ||

Re: Wrong while{} loop, maybe!? I need help, please.

2008-08-14 Thread Dr.Ruud
Rob Dixon schreef: > [EMAIL PROTECTED] wrote: >> close(INUSER); >> close(INPASS); > > There is no need to close open file handles at the end of the > program. If your program is written well there is never a need to > close them. While that is generally true for file handles that you only read fr

Re: Wrong while{} loop, maybe!? I need help, please.

2008-08-14 Thread Rob Dixon
) { > printf "\nPassword is \'%s\' .\n", $pass; > } else { > printf "\nTrying %s - %s\n", $user, $pass; > } > } Here is the source of your problem. When you have come to the end of pass.txt, attempting to read

Re: Wrong while{} loop, maybe!? I need help, please.

2008-08-14 Thread Mr. Shawn H. Corey
On Thu, 2008-08-14 at 02:15 -0700, [EMAIL PROTECTED] wrote: > # It's supposed to read first username from user.txt > # and try it against all the passwords from pass.txt, > # and then to move to the next username and run that > # against all the passwords, too, and so on...but it > # does not work

Wrong while{} loop, maybe!? I need help, please.

2008-08-14 Thread shoneris
#!/usr/bin/perl -w use strict; use Authen::Simple::POP3; print "Enter POP3 server hostname: "; chomp( my $host = ); my $pop3 = Authen::Simple::POP3->new( host => $host ); my $pwdlst = "pass.txt"; open( INPASS, $pwdlst ) || die "\nERROR: Cannot open file \'$pwdlst\'! \n"; my $usrlst = "user

RE: help in while loop

2008-03-17 Thread Thomas Bätzler
[EMAIL PROTECTED] asked: > I have certain doubts. > > What's the meaning of " if > mysubroutine was defined with prototypes and you were trying > to disable that" sentence. > > Could you please elaborate that what's the meaning of this??? When declaring a subroutine, you can optionally also d

Re: help in while loop

2008-03-17 Thread telemachus07
On Mar 17, 7:40 am, [EMAIL PROTECTED] (Irfan Sayed) wrote: > Hi All, > > Can somebody please let me know the meaning of this line. > > while (<$in>) > > { > > if(/,/) {print "before match: $`\t and after match: $'\n\n";}; $x=$'; > $y=$`; &

Re: help in while loop

2008-03-17 Thread Telemachus
On Mar 17, 7:40 am, [EMAIL PROTECTED] (Irfan Sayed) wrote: > Hi All, > > Can somebody please let me know the meaning of this line. > > while (<$in>) > > { > > if(/,/) {print "before match: $`\t and after match: $'\n\n";}; $x=$'; > $y=$`; &

RE: help in while loop

2008-03-17 Thread Thomas Bätzler
[EMAIL PROTECTED] asked > Can somebody please let me know the meaning of this line. > > > > while (<$in>) > > { > if(/,/) {print "before match: $`\t and after match: > $'\n\n";}; $x=$'; $y=$`; &mysubroutine($x,$y); > } The loop iterates over a filehandle, setting $_ to each line in turn. If

help in while loop

2008-03-17 Thread Irfan.Sayed
Hi All, Can somebody please let me know the meaning of this line. while (<$in>) { if(/,/) {print "before match: $`\t and after match: $'\n\n";}; $x=$'; $y=$`; &mysubroutine($x,$y); } I know it is a while loop for the file handle ($in) and it will be

Re: problem with regex in a while loop.

2007-08-24 Thread Tom Phoenix
ady at end-of-file. So it won't find anything. If you want to re-read the file, you could re-open it first, since that resets the read position to the start of the file. Or you could move the position directly by using seek(). But you probably don't need to re-read the file, since

problem with regex in a while loop.

2007-08-24 Thread Pat Rice
roblem is, as I connot get in to the while loop while ($line = ) I think the syntax is ok, could some one confirm this Code below. Thanks in Advance Pat #!/usr/bin/perl use strict; use warnings; my $data_file = 'df.'; print "$data_file \n"; # Open the file for reading. open

Re: Text munging problem: question on while loop differences

2007-04-06 Thread Chas Owens
On 4/6/07, Jeff Pang <[EMAIL PROTECTED]> wrote: > >So, if I put a filehandle in the diamond, instead of empty diamond, >does that mean that the first would operate line by line and the >second would pull the whole file into memory? > When the diamond(<>) is appeared with while(),it means you re

Re: Text munging problem: question on while loop differences

2007-04-06 Thread Chas Owens
On 4/6/07, Jeni Zundel <[EMAIL PROTECTED]> wrote: So, if I put a filehandle in the diamond, instead of empty diamond, does that mean that the first would operate line by line and the second would pull the whole file into memory? No, both while loops read line by line. The difference is where t

Re: Text munging problem: question on while loop differences

2007-04-06 Thread Jeff Pang
> >So, if I put a filehandle in the diamond, instead of empty diamond, >does that mean that the first would operate line by line and the >second would pull the whole file into memory? > When the diamond(<>) is appeared with while(),it means you read the file line by line. ig,while(){ .. } an

Re: Text munging problem: question on while loop differences

2007-04-06 Thread Chas Owens
On 4/6/07, Jeni Zundel <[EMAIL PROTECTED]> wrote: What is the difference between: a. while(defined(my $line = <>)) ... and b. while(<>) snip while (<>) {} is shorthand for while (defined ($_ = <>)) {} The biggest diff

Re: Text munging problem: question on while loop differences

2007-04-06 Thread Jeni Zundel
So, if I put a filehandle in the diamond, instead of empty diamond, does that mean that the first would operate line by line and the second would pull the whole file into memory? Thanks much, Jen On Apr 6, 2007, at 9:31 AM, Jeff Pang wrote: : Re: Text munging problem: question on while

Re: Text munging problem: question on while loop differences

2007-04-06 Thread Jeff Pang
: Re: Text munging problem: question on while loop differences > >What is the difference between: > >a. while(defined(my $line = <>)) ... > >and > >b. while(<>) Hello, When you say "

Re: Text munging problem: question on while loop differences

2007-04-06 Thread Jeni Zundel
What is the difference between: a. while(defined(my $line = <>)) ... and b. while(<>) On Apr 6, 2007, at 7:52 AM, Rob Dixon wrote: Why shift and unshift? Just use a for loop: #!/usr

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
o$end"; $fileno++; open NEW ,"> $newfile"; while ($lineno < 71){ $lineno++; print NEW $_; }} Either your inner while loop needs to read from the input file or it should be an 'if' instead of a while. See if you like the solution below. HTH, Rob use strict; use warn

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

while loop problem

2007-01-31 Thread Brad Cahoon
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{while{}} loops Help ple

Re: maximum file size for while() loop?

2007-01-21 Thread D. Bolliger
David Moreno Garza am Sonntag, 21. Januar 2007 07:50: > On Sat, 2007-01-20 at 09:31 +1100, Ken Foskey wrote: > > > What's exactly the difference between: > > > ++$lines and $lines++; ? > > > > Nothing in this context. > > What about other contexts? Hi David #!/usr/bin/perl use strict; use warni

Re: maximum file size for while() loop?

2007-01-21 Thread David Moreno Garza
On Sat, 2007-01-20 at 09:31 +1100, Ken Foskey wrote: > > What's exactly the difference between: > > > > ++$lines; > > > > and > > > > $lines++; ? > > > Nothing in this context. What about other contexts? David. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail:

Re: maximum file size for while() loop? -> maybe HASH problem?

2007-01-20 Thread Tom Phoenix
On 1/19/07, Bertrand Baesjou <[EMAIL PROTECTED]> wrote: While running my script it seems to use around a gigabyte of memory (there is 1GB of RAM and 1GB of swap in the system), might this be the problem? If you're running low on memory, unless you're working on an inherintly large problem, you

Re: Cannot modify read-only value in while loop?

2007-01-19 Thread Richard Jones
Xavier Noria wrote: On Jan 19, 2007, at 12:55 PM, Richard Jones wrote: while ( my $ref = $sth->fetchrow_arrayref() ) { # $ref is arrayref push @$ref, 1; # line xx } dies with 'Modification of read-only value attempted at .. line xx' Yes, that reference has a flag READONLY turned on, this i

Re: maximum file size for while() loop?

2007-01-19 Thread John W. Krahn
David Moreno Garza wrote: > On Fri, 2007-01-19 at 13:24 +, Rob Dixon wrote: >> ++$lines; > > What's exactly the difference between: > > ++$lines; > > and > > $lines++; ? In void context they are both the same because perl optimizes $lines++ to ++$lines. John -- Perl isn't a toolbox,

Re: maximum file size for while() loop?

2007-01-19 Thread Ken Foskey
On Fri, 2007-01-19 at 16:21 -0600, David Moreno Garza wrote: > On Fri, 2007-01-19 at 13:24 +, Rob Dixon wrote: > >++$lines; > > What's exactly the difference between: > > ++$lines; > > and > > $lines++; ? Nothing in this context. It does make a difference if you are 'using' the value

Re: maximum file size for while() loop?

2007-01-19 Thread David Moreno Garza
On Fri, 2007-01-19 at 13:24 +, Rob Dixon wrote: >++$lines; What's exactly the difference between: ++$lines; and $lines++; ? David. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: Cannot modify read-only value in while loop?

2007-01-19 Thread Xavier Noria
On Jan 19, 2007, at 12:55 PM, Richard Jones wrote: while ( my $ref = $sth->fetchrow_arrayref() ) { # $ref is arrayref push @$ref, 1; # line xx } dies with 'Modification of read-only value attempted at .. line xx' I can't see the difference here between the two $ref arrayrefs, but Perl obvi

Re: maximum file size for while() loop? -> maybe HASH problem?

2007-01-19 Thread Paul Johnson
On Fri, Jan 19, 2007 at 03:17:19PM +0100, Bertrand Baesjou wrote: > foreach $line () { See, this isn't a while loop, as you have in the subject. That is the cause of your problems. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTEC

Re: maximum file size for while() loop? -> maybe HASH problem?

2007-01-19 Thread Bertrand Baesjou
Ken Foskey wrote: On Fri, 2007-01-19 at 13:16 +0100, Bertrand Baesjou wrote: Hi, I am trying to read data from a file, I do this by using the "while (){ $line}" construction. However with files with a size of roughly bigger than 430MB it seems to crash the script :S Syntax seems all fi

Re: maximum file size for while() loop?

2007-01-19 Thread Rob Dixon
Bertrand Baesjou wrote: Hi, I am trying to read data from a file, I do this by using the "while (){ $line}" construction. > However with files with a size of roughly bigger than 430MB it seems to crash the script :S Syntax seems all fine (perl -wc -> syntax OK). How does your script cra

Re: maximum file size for while() loop?

2007-01-19 Thread Ken Foskey
On Fri, 2007-01-19 at 13:16 +0100, Bertrand Baesjou wrote: > Hi, > > I am trying to read data from a file, I do this by using the "while > (){ $line}" construction. > However with files with a size of roughly bigger than 430MB it seems to > crash the script :S Syntax seems all fine (perl -wc

maximum file size for while() loop?

2007-01-19 Thread Bertrand Baesjou
Hi, I am trying to read data from a file, I do this by using the "while (){ $line}" construction. However with files with a size of roughly bigger than 430MB it seems to crash the script :S Syntax seems all fine (perl -wc -> syntax OK). I was thinking that maybe it was running to the end

Cannot modify read-only value in while loop?

2007-01-19 Thread Richard Jones
Help. I've just stumbled upon a new one to me: my $ref = [ 1..3 ]; push @$ref, 4; print Dumper $ref as expected gives: $VAR1 = [ 1, 2, 3, 4 ]; But in a DBI context: while ( my $ref = $sth->fetchrow_arrayref() ) { # $ref is arrayref push @$ref, 1; # line xx } dies with 'Modificati

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
:11 > > Is there an equivalent way to do the same using map instead of an > explicit while loop? I'm guessing not, since map is expecting a list > and not a scalar, which $foo is. > This is Perl, these is always another way :) my $foo = "fee fie foe foo"; my $su

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
' > 2:3:7:11 > > Is there an equivalent way to do the same using map instead of an > explicit while loop? I'm guessing not, I guess the same (did nevertheless some tests without luck) > since map is expecting a list and not a scalar, which $foo is. but have a slightly

Re: while loop -> map

2005-05-24 Thread Xavier Noria
the same using map instead of an explicit while loop? I'm guessing not, since map is expecting a list and not a scalar, which $foo is. The difficulty comes from the need to figure out the indices, a possible approach would be: my $i = 0; my @bar = map $_->

while loop -> map

2005-05-24 Thread 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 the same using map instead of an explicit

Re: Understanding split in a while loop

2005-02-28 Thread Gavin Henry
On Monday 28 Feb 2005 18:34, John W. Krahn wrote: > Gavin Henry wrote: > > Hi all, > > Hello, > > > Just a quickie. I think the answer is that th while loop is going through > > the file twice? > > > > -- > > Codes that does what I e

Re: Understanding split in a while loop

2005-02-28 Thread John W. Krahn
Gavin Henry wrote: Hi all, Hello, Just a quickie. I think the answer is that th while loop is going through the file twice? -- Codes that does what I expect, i.e. prints out the 42 lines of my passwd file, with the array spaces, due to the array in "", swapped for a

Re: Understanding split in a while loop

2005-02-28 Thread Jenda Krynicky
From: "Gavin Henry" <[EMAIL PROTECTED]> > Just a quickie. I think the answer is that th while loop is going > through the file twice? Nope > -- > Codes that does what I expect, i.e. prints out the 42 lines of my > passwd file, with the array spaces,

Re: Understanding split in a while loop

2005-02-28 Thread Gavin Henry
-- Just getting into the best language ever... Fancy a [EMAIL PROTECTED] Just ask!!! >> >> >>I am not sure why? It misses the odd ones. >> >>while () { >>my @passwds = split /:/, ; >> > You are reading the file twice in each while loop. Whenever

Re: Understanding split in a while loop

2005-02-28 Thread Ankur Gupta
I am not sure why? It misses the odd ones. while () { my @passwds = split /:/, ; You are reading the file twice in each while loop. Whenever you access , it returns a line and moves to the next line of the file. So in "while () {" it returns one line of the passwd file . As you are r

Understanding split in a while loop

2005-02-28 Thread Gavin Henry
Hi all, Just a quickie. I think the answer is that th while loop is going through the file twice? -- Codes that does what I expect, i.e. prints out the 42 lines of my passwd file, with the array spaces, due to the array in "", swapped for and runs on $_: #!/usr/bin/perl

Re: AW: Reading from a filehandle in while-loop

2004-10-27 Thread Chasecreek Systemhouse
On Wed, 27 Oct 2004 10:43:46 +0200, Bastian Angerstein <[EMAIL PROTECTED]> wrote: > Yes it should, but not on my system. > > Thanks for your comments. > So, you are saying this doesnt work? #!/usr/bin/perl -w use strict; use warnings; use diagnostics; open (TEST,"STDIN") or die "cannot read i

AW: Reading from a filehandle in while-loop

2004-10-27 Thread Bastian Angerstein
Yes it should, but not on my system. Thanks for your comments. -Ursprüngliche Nachricht- Von: Bob Showalter [mailto:[EMAIL PROTECTED] Gesendet: Dienstag, 26. Oktober 2004 16:00 An: 'David le Blanc' Cc: [EMAIL PROTECTED] Betreff: RE: Reading from a filehandle in while-loop

Re: Reading from a filehandle in while-loop

2004-10-26 Thread Randal L. Schwartz
> "David" == David le Blanc <[EMAIL PROTECTED]> writes: David> You are making the assumption that '' sets '$_' which is not David> true. Oddly, perl makes '<>' set $_, but not ... dunno why No, that's completely wrong. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503

RE: Reading from a filehandle in while-loop

2004-10-26 Thread Bob Showalter
David le Blanc wrote: ... > You are making the assumption that '' sets '$_' which is not > true. Oddly, perl makes '<>' set $_, but not ... dunno why Sorry, but that's just not correct. while () DOES set $_, as documented in perldoc perlop under the secion "I/O Operators" The OP has some o

Re: Reading from a filehandle in while-loop

2004-10-26 Thread David le Blanc
On Tue, 26 Oct 2004 11:33:24 +0200, Bastian Angerstein <[EMAIL PROTECTED]> wrote: > > Why does this don´t work in my Script? > > open (TEST, " while () { > print $_; > # or just > print; > } You are making the assumption that '' sets '$_' which is not true. Oddly, perl makes '<>' set $_, bu

Re: Reading from a filehandle in while-loop

2004-10-26 Thread Flemming Greve Skovengaard
Bastian Angerstein wrote: I noticed that while ($test=) works on my system perfectly but while () donÂt ... donÂt know why... should reinstall perl. Thanks for your help Bastian They should both work, why they don't is beyond me. Please post on the list, I am *not* a all-seeing, all-knowing Perl g

Re: Reading from a filehandle in while-loop

2004-10-26 Thread Flemming Greve Skovengaard
c: Bastian Angerstein Betreff: Re: Reading from a filehandle in while-loop Bastian Angerstein wrote: Why does this donÂt work in my Script? open (TEST, ") { print $_; # or just print; } Does the file exists and can you read it? Bottompost, please. Your script works on my machine. Is this you w

AW: Reading from a filehandle in while-loop

2004-10-26 Thread Bastian Angerstein
etreff: Re: Reading from a filehandle in while-loop Bastian Angerstein wrote: > Why does this donÂt work in my Script? > > open (TEST, " while () { > print $_; > # or just > print; > } > > Does the file exists and can you read it? -- Flemming Greve Skoven

Re: Reading from a filehandle in while-loop

2004-10-26 Thread Flemming Greve Skovengaard
Bastian Angerstein wrote: Why does this donÂt work in my Script? open (TEST, ") { print $_; # or just print; } Does the file exists and can you read it? -- Flemming Greve SkovengaardThe killer's breed or the Demon's seed, a.k.a Greven, TuxPowerThe glamour, the for

Reading from a filehandle in while-loop

2004-10-26 Thread Bastian Angerstein
Why does this don´t work in my Script? open (TEST, ") { print $_; # or just print; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: Can do in 1 while loop?

2004-10-11 Thread Mark Goland
- Original Message - From: "loan tran" <[EMAIL PROTECTED]> To: "perl beginners" <[EMAIL PROTECTED]> Sent: Monday, October 11, 2004 3:36 PM Subject: Re: Can do in 1 while loop? > > --- Ramprasad A Padmanabhan > <[EMAIL PROTECTED]> wrot

Re: Can do in 1 while loop?

2004-10-11 Thread loan tran
nd either of them. My codes below work but > it's > > not efficent. As you can see I open the file and > go to > > while loop twice. Can someone suggest a better > way? > > Thanks. > > (attached is the text file i open to search.) > > Below is my codes: >

Re: Can do in 1 while loop?

2004-10-11 Thread Ramprasad A Padmanabhan
rint "$log_suspend \n"; > if ($log_suspend eq 'LOG SUSPEND'){ > print 'Alert! LOG SUSPEND processes'; > system("/usr/bin/mailx -s 'Alert LOG SUSPEND > Process' $receipients < $whodo_out"); > } > >

Can do in 1 while loop?

2004-10-10 Thread loan tran
Hello Perl Gurus, I wrote a script to search for log suspends and bloking processes in a text file and send me email if it find either of them. My codes below work but it's not efficent. As you can see I open the file and go to while loop twice. Can someone suggest a better way? Thanks. (att

while loop

2003-08-28 Thread Ronen Kfir
Hi, Newbie question... This script delete logs on remote machine mapped to drive "z:", based on "disk is above %x of capacity. use strict; use warnings; use Win32::AdminMisc; my $drive="z:"; my ($Total, $Free) = Win32::AdminMisc::GetDriveSpace ( $drive ); my @Out = `dir $drive`; (my

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-a

RE: While loop on a file handle

2003-08-14 Thread Morrison, Trevor (Trevor)
man though!). What I was checking was to see if the code ever made it inside of the while loop. That is why I have two different HI on either side of the while loop. 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 u

FW: While loop on a file handle

2003-08-14 Thread Morrison, Trevor (Trevor)
man though!). What I was checking was to see if the code ever made it inside of the while loop. That is why I have two different HI on either side of the while loop. 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 u

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
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 the fields populated and I have reached a certain line at the end of each order write the data to the database. Then have it all reset, and process the next order; and do this until the EOF. T

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

While loop on a file handle

2003-08-06 Thread Trevor Morrison
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"; while (defined($_ = )) { print "Hi there \n"; I am trying to test

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
type = "Linux"; } if (($type eq "WINDOWS") || ($type eq "W")) { $type = "Windows"; } } until (($type eq "Windows") || ($type eq "Linux")); Rob "Bill Akins" <[EMAIL PROTECTED]> wrote in message news:[EMA

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 ((

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.

  1   2   >