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 filehandles close when they go out of scope
>
> True but
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 them.
--
Don't stop wher
ch
expression won't close until the end of the program.
David
On Wed, Jul 12, 2017 at 5:28 PM, Jim Gibson 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:
>
> foreach my $file
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";
--
Don't stop where th
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
}
close
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 process them.But we could r
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 (@file
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 cod
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 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( /^$customers_z
On Mon, Feb 6, 2012 at 3:14 PM, 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
>
On 02/06/2012 04:58 PM, Parag Kalra wrote:
On Mon, Feb 6, 2012 at 1:14 PM, 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 my $state (keys %states
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 = 'n
On Mon, Feb 6, 2012 at 1:14 PM, 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', ],
AR => [ '
s 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 whe
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 fo
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
> "sw" == shawn wilson writes:
sw> On Jun 3, 2011 3:17 PM, "Uri Guttman" 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 given 'foo
On Jun 3, 2011 3:17 PM, "Uri Guttman" 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 outside of
>>>>> "R" == Ruud 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
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:
f
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 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? E
orry. I wanted to use the
value of $name in another loop but after testing, it looks like Shawn was
correct when he wrote:
> The variable used 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
nam
, if you want to use the variable outside of the for,
BF> don't name the two variables the same. The rough rule of thumb is
BF> that leaving off the my in a for(each) is probably introducing
BF> subtle bugs into your program.
why search PBP when the perldocs are very clear a
On Fri, Jun 3, 2011 at 1:23 PM, Jim Gibson 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 ( ... ) { ... }
Wi
>>>>> "s" == sono-io writes:
s>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.=:\
s>Here's the loop:
s>
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
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 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:
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
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 vari
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.
--
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)) {
> "CA" == CM Analyst 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. it is j
On 5/18/11 Wed May 18, 2011 5:06 PM, "CM Analyst"
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 problems:
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
On 3/25/11 Fri Mar 25, 2011 9:11 AM, "Chris Stinemetz"
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 you a line-by-line des
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 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 m
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 iterati
Jim Gibson wrote:
On 3/24/11 Thu Mar 24, 2011 9:04 AM, "Chris Stinemetz"
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 instead of one.
This line has two pro
On 3/24/11 Thu Mar 24, 2011 9:04 AM, "Chris Stinemetz"
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 that corresponds to the value of t
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/23/11 Wed Mar 23, 2011 12:49 PM, "Chris Stinemetz"
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 transfer the
values to an arra
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';
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/
On 3/23/11 Wed Mar 23, 2011 10:02 AM, "Chris Stinemetz"
scribbled:
In addition to the missing semicolon, the declaration of %sum must appear
before it is used, i.e. before the while() loop. The line adding
values of $rlptxat1 to the sum must appear inside the while loop, not after
it.
Run this
On Mon, Mar 21, 2011 at 01:46, Mike McClain 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
On 3/23/11 Wed Mar 23, 2011 10:02 AM, "Chris Stinemetz"
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 semicolon on previous line?)
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" va
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 n
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 fou
On 3/22/11 Tue Mar 22, 2011 2:24 PM, "Chris Stinemetz"
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 "cell" "sect" and "carr"
>>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/2
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.
> > $recor
于 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";
}
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
: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?
&
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 ) ?
$rec
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}++ : '' ;
T
it.
there is no reason to read it line by line. it is small enough to
slurp. 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
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
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
do:
> >
> > [code]
> > my @arr1_copy = @arr1;
> >
> > while (defined (my $arr1_elem = shift(@arr1_copy))) {
> >
> > # Do something with $arr1_elem
> >
> > }
> > [/code]
>
> Is the principle you are trying to explain that
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";
(@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? :-) ) I suppose it's all about the
'w
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
On Mon, Sep 27, 2010 at 9:19 AM, 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 ) {
>
ember 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'
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 )
ndet: Montag, 27. 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 ) {
>
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' ) {
On Aug 12, 2010, at 19:08, Kryten 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 yo
2010/8/13 Kryten :
> 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.arco
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/
On Tue, 30 Mar 2010 23:05:00 -0600
Jon Forsyth 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?
Yes, it
Uri Guttman wrote:
> > "TB" == Thomas Bätzler 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 shouldn't have posted befor
> "TB" == Thomas Bätzler writes:
TB> Jon Forsyth 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
>> $number part
the loop?
"my" declares a variable 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 variab
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 $
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){
>
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 Fri, Nov 6, 2009 at 6:48 PM, John W. Krahn wrote:
> tom smith wrote:
>
>> On Mon, Nov 2, 2009 at 5:10 AM, John W. Krahn wrote:
>>
>> Philip Potter wrote:
>>>
>>> 2009/11/2 Thomas Bätzler :
while( my $line = <$file> ){
>
> }
>
> Won't this loop terminate early if
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,";
> foreach my $line(@lines)
>
Philip Potter wrote:
2009/11/2 Thomas Bätzler :
while( my $line = <$file> ){
}
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 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:
>
> while (<$fil
2009/11/2 Thomas Bätzler :
> while( my $line = <$file> ){
>
> }
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
abou
Ohh,
Thanks for the help
On Mon, Nov 2, 2009 at 1:40 PM, John W. Krahn 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.
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,";
foreach my $line(@lines)
{
if($lin =~ m/something/)
{
#some code
# get
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 p
2009/11/2 Anant Gupta :
> 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
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,";
foreach my $line(@lines)
{
if($lin =~ m/something/)
{
#some code
# get next data
# Without goi
On Mon, May 25, 2009 at 23:50, sanket vaidya 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 advantage; for is four ch
-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" writes:
&quo
uot;sanket> separate? Can anyone suggest me a good url which can tell the
difference
"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
itera
t as well get used to using for as an iterator loop now,
because in Perl 6 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 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.
2009/5/25 sanket vaidya :
> 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 brevity. (Or because the
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
_
1 - 100 of 215 matches
Mail list logo