Yes, and I think that gives us *two* reasons to always explicitly close
filehandles. :-)
David
On Sun, Jul 16, 2017 at 8:00 AM, Shawn H Corey
wrote:
> On Sun, 16 Jul 2017 07:36:39 -0400
> David Mertens wrote:
>
> > Also note that lexical
On Sun, 16 Jul 2017 07:36:39 -0400
David Mertens wrote:
> Also note that lexical filehandles close when they go out of scope
True but you should always explicitly close your files. This gives you
a chance to report any errors it had, have rather than silently
ignoring
last such
expression won't close until the end of the program.
David
On Wed, Jul 12, 2017 at 5:28 PM, Jim Gibson <jimsgib...@gmail.com> wrote:
> If you wish to terminate execution of a foreach loop without iterating
> over all of the elements (@files, in this case) use the “last” statement:
&
On Thu, 13 Jul 2017 00:50:42 +0530
perl kamal wrote:
> open (my $FH, $file) or die "could not open file\n";
A quick note: output the file name and error message to have a better
idea of what went wrong.
open (my $FH, $file) or die "could not open file $file: $!\n";
If you wish to terminate execution of a foreach loop without iterating over all
of the elements (@files, in this case) use the “last” statement:
foreach my $file ( @files ) {
# process file
open( my $fh, ‘<‘, $file ) or die(…);
while( my $line = <$fh> ) {
# process line
}
c
That code will read each line from each file. The problem is likely in the
part that says:
#[process the lines & hash construction.]
What are you doing there?
On Wed, Jul 12, 2017 at 3:23 PM perl kamal wrote:
> Hello All,
>
> I would like to read multiple files and
Hello All,
I would like to read multiple files and process them.But we could read the
first file alone and the rest are skipped from the while loop. Please
correct me where am i missing the logic.Thanks.
use strict;
use warnings;
my @files=qw(Alpha.txt Beta.txt Gama.txt);
foreach my $file
On 07/02/2012 01:39, sono...@fannullone.us wrote:
On Feb 6, 2012, at 1:42 PM, Steve Bertrand wrote:
This may be easier. It uses the hash elements directly as an
array, then uses grep to see if the zip code is within the specific
state. It returns true if the state owns that zip code, and false
On 12-02-07 06:26 AM, Rob Dixon wrote:
in fact, if the objective is to reduce the code to something as brief as
possible then this will do the trick
my $match = (grep $_ eq $customers_zip, @{$states{$customers_state}})
? 'yes' : 'no';
You can use first from List::Util for more efficient
I have a web form where people enter their address info and I want to
make sure that the first three digits of their Zip Code correspond to their
State.
So I'm creating a hash of arrays that contains a list of Zip Codes for
the United States. I've also written a foreach loop
for
the United States. I've also written a foreach loop to access this hash but
I'd like to see if it could be written better. For example, do I really need
three foreach loops?
Also, the first line that's printed contains 499 and I can't figure
out where that's coming from.
I'd
On Mon, Feb 6, 2012 at 1:14 PM, sono...@fannullone.us wrote:
For example, do I really need three foreach loops?
You can get rid of third ForLoop for sure.
use strict;
use warnings;
my %states = (
AL = [ '350','351', ],
AK = [ '995','996', ],
AZ = [ '850','851', ],
On 06/02/2012 21:14, sono...@fannullone.us wrote:
use strict;
use warnings;
my %states = (
AL = [ '350','351', ],
AK = [ '995','996', ],
AZ = [ '850','851', ],
AR = [ '716','717', ],
);
my $customers_state = 'AZ';
my $customers_zip = '850';
my $match = 'no'
On 02/06/2012 04:58 PM, Parag Kalra wrote:
On Mon, Feb 6, 2012 at 1:14 PM,sono...@fannullone.us wrote:
For example, do I really need three foreach loops?
You can get rid of third ForLoop for sure.
you don't actually lose the third loop. grep is an implied loop.
STATE: foreach
On Mon, Feb 6, 2012 at 3:14 PM, sono...@fannullone.us wrote:
So I'm creating a hash of arrays that contains a list of Zip Codes
for the United States. I've also written a foreach loop to access this
hash but I'd like to see if it could be written better. For example, do I
really need
On Feb 6, 2012, at 1:42 PM, Steve Bertrand wrote:
This may be easier. It uses the hash elements directly as an array, then uses
grep to see if the zip code is within the specific state. It returns true if
the state owns that zip code, and false if it doesn't.
if ( grep(
Gents,
Sorry for my delayed response. Thank you for your suggestions. Based on your
feedback, I made the following changes, and the hook is now working as expected.
Thanks a million!
my $taskstate = $taskEntity-GetFieldValue(state)-GetValue();
$session-OutputDebugString (Task's state is
Maybe it's too early in the morning here, but I can't seem to remember
how to use a lexical $variable that is defined inside a foreach loop, outside
of that loop.=:\
Here's the loop:
foreach my $name (split (/, */, $names)) {
next
Hello,
foreach my $name (split (/, */, $names)) {
Here, the scope of $name is limited to the foreach loop and not outside it.
So, you will have to declare the variable again for use outside the loop.
Regards,
Alan Haggai Alavi.
--
The difference makes the difference
On Jun 3, 2011, at 8:45 AM, Alan Haggai Alavi wrote:
Here, the scope of $name is limited to the foreach loop and not outside it.
So, you will have to declare the variable again for use outside the loop.
But wouldn't that make the second $name a different variable? I'm
not at my
At 8:37 AM -0700 6/3/11, sono...@fannullone.us wrote:
Maybe it's too early in the morning here, but I can't seem to
remember how to use a lexical $variable that is defined inside a
foreach loop, outside of that loop.=:\
Here's the loop:
foreach my $name (split
On Jun 3, 8:37 am, sono...@fannullone.us wrote:
...
I want to use $name in another loop just after this one, but when I
do, I get Global symbol $name requires explicit package.
One option is an outer enclosing block that'll
extend the scope of $name to that entire block:
{
C.DeRykus wrote:
One option is an outer enclosing block that'll extend the scope of $name to
that entire block:
Jim Gibson wrote:
Declare the variable just before the loop, and remove the 'my' from the
foreach statement:
Thanks for the responses. I was able to get it to work.
On 11-06-03 11:37 AM, sono...@fannullone.us wrote:
I want to use $name in another loop just after this one, but when I do, I get
Global symbol $name requires explicit package.
Could someone please point me in the right direction?
Certainly. The variable used in a foreach loop
s == sono-io sono...@fannullone.us writes:
sMaybe it's too early in the morning here, but I can't seem to remember
how to use a lexical $variable that is defined inside a foreach loop, outside
of that loop.=:\
sHere's the loop:
sforeach my $name (split
On Fri, Jun 3, 2011 at 1:23 PM, Jim Gibson jimsgib...@gmail.com wrote:
Declare the variable just before the loop, and remove the 'my' from the
foreach statement:
my $name;
foreach $name ( ... ) {
...
}
That won't do. What that code actually translated to is
my $name;
for my $name ( ...
in a for(each) is probably introducing
BF subtle bugs into your program.
why search PBP when the perldocs are very clear about it and easily
searched?
from perldoc perlsyn:
The foreach loop iterates over a normal list value and sets
the variable VAR to be each element of the list
in a foreach loop is independent of anything outside the
loop.
I actually had to use another variable in the second loop to grab the
name.
Thanks to everyone who responded. I got it to work now.
Marc
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e
On 11-06-03 03:58 PM, sono...@fannullone.us wrote:
I wasn't very clear in what I wanted. Sorry. I wanted to use the value of
$name in another loop but after testing
That implies something is wrong with your logic. The question is: what
value of $name do you want? The first? The last?
On Jun 3, 2011, at 1:38 PM, Shawn H Corey wrote:
That implies something is wrong with your logic.
Yep. I came to the same conclusion. =:)
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/
On 2011-06-03 17:37, sono...@fannullone.us wrote:
Maybe it's too early in the morning here, but I can't seem to remember
how to use a lexical $variable that is defined inside a foreach loop, outside
of that loop.=:\
Here's the loop:
foreach my $name
R == Ruud rvtol+use...@isolution.nl writes:
R On 2011-06-03 17:37, sono...@fannullone.us wrote:
Maybe it's too early in the morning here, but I can't seem to remember how
to use a lexical $variable that is defined inside a foreach loop, outside of
that loop.=:\
Here's the loop
On Jun 3, 2011 3:17 PM, Uri Guttman u...@stemsystems.com wrote:
perl -le 'my $x = zzz ; for $x ( qw( foo bar ) ) { print L: $x } print
E: $x'
L: foo
L: bar
E: zzz
That's odd, I would have thought that would have given 'foo bar bar'. So,
how would you keep data from a loop once you're
sw == shawn wilson ag4ve...@gmail.com writes:
sw On Jun 3, 2011 3:17 PM, Uri Guttman u...@stemsystems.com wrote:
perl -le 'my $x = zzz ; for $x ( qw( foo bar ) ) { print L: $x } print
sw E: $x'
L: foo
L: bar
E: zzz
sw That's odd, I would have thought that would have
Hi,
In this code, the intent is to iterate through the tasks and modify the ID
field. The Task record (entity) should not be modified if it's state equals
Completed.
When I run this routine, there are two problems:
Problem 1) The if statement is not being evaluated. The record (even if it's
On 5/18/11 Wed May 18, 2011 5:06 PM, CM Analyst cmanal...@yahoo.com
scribbled:
Hi,
In this code, the intent is to iterate through the tasks and modify the ID
field. The Task record (entity) should not be modified if it's state equals
Completed.
When I run this routine, there are two
CA == CM Analyst cmanal...@yahoo.com writes:
CA my $taskEntity = $session-GetEntity ('almtask', $_);
that gets a perl object in $taskEntity.
CA $taskEntity-GetFieldValue(state)-GetValue();
where is the value being assigned to? $taskEntity is not being modified
or set in that line of code.
Thanks Rob. That seems to have done the trick. I understand this is a
for loop, but do you mind breaking it down line by line so I fully
understand what it is doing?
Thank you,
Chris
for my $i (44..47) {
my $rlp = $data[$i];
$sum{$cell}{$sect}{$carr}{$dist} += $rlp if $rlp;
}
--
On 3/25/11 Fri Mar 25, 2011 9:11 AM, Chris Stinemetz
chrisstinem...@gmail.com scribbled:
Thanks Rob. That seems to have done the trick. I understand this is a
for loop, but do you mind breaking it down line by line so I fully
understand what it is doing?
My name isn't Rob, but I can give
Thanks again Jim!
I have one more question..lol
I appreciate all your help!
I would like $dist be part of the print statement, but I am not sure how to
code it correctly.
I am getting the following error:
Global symbol @dist requires explicit package name at ./jim.pl line 38.
Execution of
On 3/24/11 Thu Mar 24, 2011 9:04 AM, Chris Stinemetz
cstinem...@cricketcommunications.com scribbled:
I would like $dist be part of the print statement, but I am not sure how to
code it correctly.
The value of $dist will vary for each row. If you want to print out the
correct value of $dist
Jim Gibson wrote:
On 3/24/11 Thu Mar 24, 2011 9:04 AM, Chris Stinemetz
cstinem...@cricketcommunications.com scribbled:
$sum{$cell}{$sect}{$carr} += $rlp1 += $rlp2 += $rlp3 += $rlp4 || 0 ; }
I see you are changing your program requirements. You are now accumulating
multiple rlp values
Jim,
I am getting really close to finishing up this program. perl is lot's
of fun and I appreciate all your help!
The output is giving me the data I am looking for except for the
following issues:
How would I add the correct code to make sure the array has a numeric
value before the loop
On 25/03/2011 02:36, Chris Stinemetz wrote:
Jim,
I am getting really close to finishing up this program. perl is lot's
of fun and I appreciate all your help!
The output is giving me the data I am looking for except for the
following issues:
How would I add the correct code to make sure
Thanks Jim,
I am still unable to sum up the field $rlptxat.
The error I am getting is below:
Scalar found where operator expected at ./jim.pl line 52, near $sum
(Missing semicolon on previous line?)
my variable %sum masks earlier declaration in same scope at ./jim.pl line 54.
my
On 3/23/11 Wed Mar 23, 2011 10:02 AM, Chris Stinemetz
cstinem...@cricketcommunications.com scribbled:
Thanks Jim,
I am still unable to sum up the field $rlptxat.
The error I am getting is below:
Scalar found where operator expected at ./jim.pl line 52, near $sum
(Missing
On Mon, Mar 21, 2011 at 01:46, Mike McClain m.d.mccl...@cox.net wrote:
snip
my @report = map
$_-{cell}\t$_-{sect}\t$_-{carr}\t$_-{chan}\t$_-{dist}\n , @sorted;
print @report ;
This map will consume a lot of memory, better do it using a foreach loop.
In what way will the use of map here
On 3/23/11 Wed Mar 23, 2011 10:02 AM, Chris Stinemetz
cstinem...@cricketcommunications.com scribbled:
In addition to the missing semicolon, the declaration of %sum must appear
before it is used, i.e. before the while(DATA) loop. The line adding
values of $rlptxat1 to the sum must appear inside
That worked! Thanks Jim.
Chris
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/
Jim,
I have another question.
How do I sort the results so it is from smallest to largest starting with
$cell,$sect,$carr?
Thanks again for all you help. I am gaining a much better understanding.
This is what I got:
#!/usr/bin/perl
use warnings;
use strict;
#my $filepath = 'C:/temp/PCMD';
On 3/23/11 Wed Mar 23, 2011 12:49 PM, Chris Stinemetz
cstinem...@cricketcommunications.com scribbled:
Jim,
I have another question.
How do I sort the results so it is from smallest to largest starting with
$cell,$sect,$carr?
It is difficult to sort a multi-level, nested hash. I would
No, it doesn't. What is a rlptxat element? Where do they come from.
rlptxat is just an element indexed at 44 that has a value, in which I would
like to sum up, when it has the same elements cell sect and carr in the
record.
I hope this helps
Thank you,
Chris
At 8:03 PM -0600 3/20/11, Chris
On 3/22/11 Tue Mar 22, 2011 2:24 PM, Chris Stinemetz
cstinem...@cricketcommunications.com scribbled:
No, it doesn't. What is a rlptxat element? Where do they come from.
rlptxat is just an element indexed at 44 that has a value, in which I would
like to sum up, when it has the same elements
Jim,
You hit it right on. This is exactly what I am trying to do.
OK. With this information and that from previous posts, your requirements may
be summaryized as follows:
You have a file with one record per line, each line consisting of a number of
fields. Within each record may be found
At 9:58 PM -0600 3/22/11, Chris Stinemetz wrote:
Jim,
You hit it right on. This is exactly what I am trying to do.
OK. With this information and that from previous posts, your
requirements may be summaryized as follows:
You have a file with one record per line, each line consisting of
a
On Sun, Mar 20, 2011 at 10:06:25AM +0200, Shlomi Fish wrote:
On Sunday 20 Mar 2011 05:43:38 Chris Stinemetz wrote:
I am trying to code a foreach loop, that will add all occurrences of the
element rlptxat that have the same elements cell, sect and chan.
snip
$record{dist}/6.6/8/2*10/10
Hi Chris,
On Sunday 20 Mar 2011 05:43:38 Chris Stinemetz wrote:
I am trying to code a foreach loop, that will add all occurrences of the
element rlptxat that have the same elements cell, sect and chan.
My failed attempt can be located in between the ### lines.
If I understand your code
. slurping is faster and generally cleaner than line by
line. considering he was doing a poor version of slurping before, this
is much better.
print @report ;
SF This map will consume a lot of memory, better do it using a foreach loop.
again, not. his file isn't that large. given he wants to print
So back to the question. How can I nest this foreach loop correctly to add all
occurrences of the element rlptxat that have the same elements cell, sect and
chan in the array?
$record{rlptxat} = ( length($record{rlptxat}) 1 ) ? $record{rlptxat}{cell,
sect, chan, dist}++ : '' ;
Thank you very
At 8:31 AM -0600 3/20/11, Chris Stinemetz wrote:
So back to the question. How can I nest this foreach loop correctly
to add all occurrences of the element rlptxat that have the same
elements cell, sect and chan in the array?
$record{rlptxat} = ( length($record{rlptxat}) 1 ) ?
$record{rlptxat
:58 PM
To: beginners@perl.org
Subject: RE: foreach loop
At 8:31 AM -0600 3/20/11, Chris Stinemetz wrote:
So back to the question. How can I nest this foreach loop correctly
to add all occurrences of the element rlptxat that have the same
elements cell, sect and chan in the array?
$record{rlptxat
At 8:03 PM -0600 3/20/11, Chris Stinemetz wrote:
Jim,
Thanks for your feedback. I am actually trying to sum up all rlptxat
elements that have the same cell, sect, and chan elements in the
array. I hope this clarifies.
No, it doesn't. What is a rlptxat element? Where do they come from.
You
于 2011-3-21 13:33, Jim Gibson 写道:
Iterate over the result:
for my $cell ( sort keys %sum ) {
for my $sect ( sort keys %{$sum{$cell}} ) {
for my $chan ( sort keys %{$sum{$cell}{$sect}} ) {
print Value of sum($cell,$sect,$chan) is
$sum{$cell}{$sect}{$chan}\n;
}
I am trying to code a foreach loop, that will add all occurrences of the
element rlptxat that have the same elements cell, sect and chan.
My failed attempt can be located in between the ### lines.
Below is what I have so far.
Thank you in advance,
Chris
#!/usr/bin/perl
use warnings;
use
Hello list,
Could someone please explain why this test script:
my @arr1 = qw(one two three);
my @arr2 = qw(1 2 3);
foreach my $arr1 ( @arr1 ) {
print Arr1: $arr1\n;
foreach my $arr2 ( @arr2 ) {
print Arr2: $arr2\n;
if ( $arr2 eq '2' ) {
. September 2010 09:20
An: beginners@perl.org
Betreff: Problem with foreach loop
Hello list,
Could someone please explain why this test script:
my @arr1 = qw(one two three);
my @arr2 = qw(1 2 3);
foreach my $arr1 ( @arr1 ) {
print Arr1: $arr1\n;
foreach my $arr2 ( @arr2
Hi Nora,
On Monday 27 September 2010 09:19:46 HACKER Nora wrote:
Hello list,
Could someone please explain why this test script:
my @arr1 = qw(one two three);
my @arr2 = qw(1 2 3);
foreach my $arr1 ( @arr1 ) {
print Arr1: $arr1\n;
foreach my $arr2 ( @arr2 ) {
2010 09:34
An: HACKER Nora
Betreff: Re: Problem with foreach loop
When $arr2 eq '2', you shift 'one' off @arr1, but you're still working
with$ arr[0], which is now 'two'. When the second foreach ends, it
moves onto $arr1[1], which is 'three'.
Also, if you want it to stop at '2', put a last
On Mon, Sep 27, 2010 at 9:19 AM, HACKER Nora nora.hac...@stgkk.at wrote:
Hello list,
Could someone please explain why this test script:
my @arr1 = qw(one two three);
my @arr2 = qw(1 2 3);
foreach my $arr1 ( @arr1 ) {
print Arr1: $arr1\n;
foreach my $arr2 ( @arr2 ) {
On Monday 27 September 2010 09:40:43 HACKER Nora wrote:
Hi Michael,
Thanks for your fast reply. I didn't realize that the shift is of
immediate effect not only to the array but also to the current element
of iteration in the loop itself.
It may be. However, that is besides the point
something with $arr1_elem
}
[/code]
Is the principle you are trying to explain that the foreach loop should
be changed to a while or that it is advisable to make a copy of the
original array? (Or just both? :-) ) I suppose it's all about the
'while' because even if I made a copy of the array
HACKER Nora wrote:
Hello list,
Hello,
Could someone please explain why this test script:
my @arr1 = qw(one two three);
my @arr2 = qw(1 2 3);
foreach my $arr1 ( @arr1 ) {
print Arr1: $arr1\n;
foreach my $arr2 ( @arr2 ) {
print Arr2: $arr2\n;
;
while (defined (my $arr1_elem = shift(@arr1_copy))) {
# Do something with $arr1_elem
}
[/code]
Is the principle you are trying to explain that the foreach loop should
be changed to a while or that it is advisable to make a copy of the
original array? (Or just both? :-) )
Well
Hi,
Complete newbie.
Is there any way to use next from within a foreach loop?
All the examples I have seen/read use a while loop to demo.
Thanks,
Stuart
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/
2010/8/13 Kryten kryte...@googlemail.com:
Hi,
Complete newbie.
Is there any way to use next from within a foreach loop?
Sure.
$ perl -le '
for (1..10) {
next if $_ == 5;
print;
} '
1
2
3
4
6
7
8
9
10
--
Jeff Pang
http://home.arcor.de/pangj/
--
To unsubscribe, e-mail
On Aug 12, 2010, at 19:08, Kryten kryte...@googlemail.com wrote:
Hi,
Complete newbie.
Is there any way to use next from within a foreach loop?
All the examples I have seen/read use a while loop to demo.
Yes, next will work on for/foreach, while, and until loops. So you can say
for my
for the lexical scope. While Perl by itself will
happily let variables spring into existence whenever you first refer to them,
the accepted best practice is to run perl with the -w switch or the use
warnings; pragma which requires variables to be declared before their first
use.
The foreach loop iterates
TB == Thomas Bätzler t.baetz...@bringe.com writes:
TB Jon Forsyth jon4s...@gmail.com asked:
I am truly a beginner. Could someone help me understand this syntax
out of a code example from Learning Perl? On line 5 I'm confused
as to why my $number is between foreach and the ()? is my
Uri Guttman u...@stemsystems.com wrote:
TB == Thomas Bätzler t.baetz...@bringe.com writes:
TB with the -w switch or the use warnings; pragma which requires
TB variables to be declared before their first use.
that is the use strict pragma, not the warnings one.
Of course. I knew I
On Tue, 30 Mar 2010 23:05:00 -0600
Jon Forsyth jon4s...@gmail.com wrote:
I am truly a beginner. Could someone help me understand this syntax
out of a code example from Learning Perl? On line 5 I'm confused
as to why my $number is between foreach and the ()? is my
$number part of the loop?
I am truly a beginner. Could someone help me understand this syntax out of
a code example from Learning Perl? On line 5 I'm confused as to why my
$number is between foreach and the ()? is my $number part of the loop?
sub running_sum {
state $sum = 0;
state @numbers;
foreach my $number
I have been trying to make this thing work ..
this is not a actual code
@s = { some elemnts};
foreach my $s(@s){
# i made that $s into array something like @data1
foreach my$data(@data1)
if( $data =~ some text){
#here i will get my data for sure
On Sunday 21 Mar 2010 17:44:49 perl wrote:
I have been trying to make this thing work ..
this is not a actual code
@s = { some elemnts};
foreach my $s(@s){
# i made that $s into array something like @data1
foreach my$data(@data1)
if( $data =~ some text){
On Fri, Nov 6, 2009 at 6:48 PM, John W. Krahn jwkr...@shaw.ca wrote:
tom smith wrote:
On Mon, Nov 2, 2009 at 5:10 AM, John W. Krahn jwkr...@shaw.ca wrote:
Philip Potter wrote:
2009/11/2 Thomas Bätzler t.baetz...@bringe.com:
while( my $line = $file ){
snip
}
Won't this loop
2009/11/2 Anant Gupta anantgupta...@gmail.com:
Hello,
In the foreach loop, without going to the beginning of the loop, i want to
get the next iteration of data. How do i get it.
eg
You can always use a for loop and refer to the next item:
for (my $i= 0; $i @lines; $i++) {
if ($lines[$i + 1
Anant Gupta mailto:anantgupta...@gmail.com asked:
In the foreach loop, without going to the beginning of the loop, i want
to get the next iteration of data. How do i get it.
You should probably not slurp (read in all at once) the file unless you need
to.
In your particular case reading
Anant Gupta wrote:
Hello,
Hello,
In the foreach loop, without going to the beginning of the loop, i want to
get the next iteration of data. How do i get it.
eg
use strict;
open(FILE,abc.txt) or die CAnnot open;
my @lines=FILE;
foreach my $line(@lines)
{
if($lin =~ m/something
Ohh,
Thanks for the help
On Mon, Nov 2, 2009 at 1:40 PM, John W. Krahn jwkr...@shaw.ca wrote:
Anant Gupta wrote:
Hello,
Hello,
In the foreach loop, without going to the beginning of the loop, i want to
get the next iteration of data. How do i get it.
eg
use strict;
open(FILE
2009/11/2 Thomas Bätzler t.baetz...@bringe.com:
while( my $line = $file ){
snip
}
Won't this loop terminate early if there is a blank line or a line
containing only '0'? If I do a readline loop I always do:
while (defined ($line = $file))
Is there something magical happening here I don't know
Philip Potter philip.g.pot...@gmail.com asked:
Won't this loop terminate early if there is a blank line or a line
containing only '0'? If I do a readline loop I always do:
while (defined ($line = $file))
Is there something magical happening here I don't know about? I know
about the magical:
Philip Potter wrote:
2009/11/2 Thomas Bätzler t.baetz...@bringe.com:
while( my $line = $file ){
snip
}
Won't this loop terminate early if there is a blank line or a line
containing only '0'? If I do a readline loop I always do:
while (defined ($line = $file))
Is there something magical
On Mon, 02 Nov 2009 13:06:27 +0530, Anant Gupta wrote:
Hello,
In the foreach loop, without going to the beginning of the loop, i want
to get the next iteration of data. How do i get it. eg
use strict;
open(FILE,abc.txt) or die CAnnot open; my @lines=FILE;
foreach my $line(@lines
Hello,
In the foreach loop, without going to the beginning of the loop, i want to
get the next iteration of data. How do i get it.
eg
use strict;
open(FILE,abc.txt) or die CAnnot open;
my @lines=FILE;
foreach my $line(@lines)
{
if($lin =~ m/something/)
{
#some code
Hi all,
What is the difference between the 'for' 'foreach' loops? I know that they
can be used interchangeably then what is the purpose of keeping them
separate? Can anyone suggest me a good url which can tell the difference
between two?
Thanks Regards,
Sanket Vaidya
2009/5/25 sanket vaidya sanket.vai...@patni.com:
What is the difference between the 'for' 'foreach' loops?
There is none.
http://perldoc.perl.org/perlsyn.html#Foreach-Loops :
The foreach keyword is actually a synonym for the for keyword, so you
can use foreach for readability or for for
sanket vaidya wrote:
What is the difference between the 'for' 'foreach' loops? I know that they
can be used interchangeably then what is the purpose of keeping them
separate?
The _words_ 'for' and 'foreach' can be used interchangeably in foreach
loops, but a true for loop is something else.
there is no foreach loop. And the c-style loop is
named loop.
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/
sanket between two?
Back in the early days of Perl, Larry Wall decided to borrow from both C (the
for loop) and Csh (the foreach loop) to provide a means of a computed
iterator or a simple list enumeration.
Apparently, he noticed that Perl could always distinguish (by the contents
-Original Message-
From: Randal L. Schwartz [mailto:mer...@stonehenge.com]
Sent: Monday, May 25, 2009 10:10 PM
To: beginners@perl.org
Subject: Re: Difference between for foreach loop
sanket == sanket vaidya sanket.vai...@patni.com writes:
sanket What is the difference between
On Mon, May 25, 2009 at 23:50, sanket vaidya sanket.vai...@patni.com wrote:
snip
So to conclude
'for' 'foreach' are the two different ways to write same thing there is
no particular advantage of using one over other.
Group, correct me if I am wrong.
snip
I wouldn't say there is no
1 - 100 of 208 matches
Mail list logo