Re: `$#array` vs `scalar @array`

2018-01-29 Thread Chas. Owens
Luckily in these cases, the faster answer is also the clearest answer in either case. On Mon, Jan 29, 2018 at 5:32 PM Paul Johnson wrote: > On Sun, Jan 28, 2018 at 10:57:25PM +, Chas. Owens wrote: > > $#array is the index of the last element of @array, so it will be one >

Re: `$#array` vs `scalar @array`

2018-01-29 Thread Paul Johnson
On Sun, Jan 28, 2018 at 10:57:25PM +, Chas. Owens wrote: > $#array is the index of the last element of @array, so it will be one less > than scalar @array which is the number of elements in @array (since Perl > arrays start with index 0). Therefore, to get the number of elements, you > would

Re: `$#array` vs `scalar @array`

2018-01-28 Thread Chas. Owens
$#array is the index of the last element of @array, so it will be one less than scalar @array which is the number of elements in @array (since Perl arrays start with index 0). Therefore, to get the number of elements, you would need to add one to $#array, which makes scalar @array faster. To get

Re: Array iterator count

2013-08-16 Thread Wbiker
Hi, since Perl 5.12 you can use Each to give back the index as well: Code: use v5.12; my @ar = ('mais', 'kirschen', 'bohnen', 'gurken'); while(my ($index, $value) = each(@ar)) { say Index: $index - Value: $value; } Outcome: Index: 0 - Value: mais Index: 1 - Value:

Re: Array iterator count

2013-08-10 Thread Michael Rasmussen
On Thu, Aug 08, 2013 at 12:30:10PM -0500, Andy Bach wrote: On Thu, Aug 8, 2013 at 12:05 PM, Unknown User knowsuperunkn...@gmail.comwrote: at any point is it possible to say which element i am handling without using a counter? Er, well, if it were an array rather than a list my

Re: Array iterator count

2013-08-10 Thread Michael Rasmussen
On Thu, Aug 08, 2013 at 11:30:29PM -0500, Andy Bach wrote: And buggy, consider: my @timings = ( 11, 22, 3, 14, 18, 45, 18, ... 86 ); Yeah, it's a constraint without a cause. Do you want to treat every 18 in the if or only the first? Why not use a counter? Is the data from a list, a

Re: Array iterator count

2013-08-09 Thread Dermot
my $counter = 0; foreach my $e ( a .. z ) { $counter++; if ( $counter == 5 ) { } } I know this is a perl idiom but I, and I suspect others, would find a perl variable useful for the keeping the count when iterating. The draw back with the above is that $counter

Re: Array iterator count

2013-08-09 Thread Jing Yu
You probably can use 'state' instead of 'my' to keep $counter in scope. foreach my $e ( 'a'..'z' ) { state $counter++; if ( $counter == 5 ) { say $e; } } Cheers, Jing On 9 Aug 2013, at 16:24, Dermot paik...@gmail.com wrote: my $counter = 0; foreach my $e ( a .. z ) {

Re: Array iterator count

2013-08-09 Thread Uri Guttman
On 08/09/2013 04:24 AM, Dermot wrote: my $counter = 0; foreach my $e ( a .. z ) { $counter++; if ( $counter == 5 ) { } } I know this is a perl idiom but I, and I suspect others, would find a perl variable useful for the keeping the count when iterating. The

Re: Array iterator count

2013-08-09 Thread Uri Guttman
On 08/09/2013 04:34 AM, Jing Yu wrote: You probably can use 'state' instead of 'my' to keep $counter in scope. foreach my $e ( 'a'..'z' ) { state $counter++; if ( $counter == 5 ) { say $e; } } and what if that code is run again in the same program? it will keep the

Re: Array iterator count

2013-08-09 Thread Jing Yu
That is true.. Perhaps it's better to introduce a bare block enclosing the loop, and declare $count as 'my' just before 'foreach'. Cheers, Jing On 9 Aug 2013, at 16:39, Uri Guttman u...@stemsystems.com wrote: On 08/09/2013 04:34 AM, Jing Yu wrote: You probably can use 'state' instead of

Re: Array iterator count

2013-08-08 Thread jbiskofski
my $counter = 0; foreach my $e ( a .. z ) { $counter++; On Thu, Aug 8, 2013 at 12:05 PM, Unknown User knowsuperunkn...@gmail.comwrote: Hello, If i am iterating through the elements in an array, at any point is it possible to say which element i am handling without using a counter?

Re: Array iterator count

2013-08-08 Thread jbiskofski
my $counter = 0; foreach my $e ( a .. z ) { $counter++; if ( $counter == 5 ) { } } On Thu, Aug 8, 2013 at 12:11 PM, jbiskofski jbiskof...@gmail.com wrote: my $counter = 0; foreach my $e ( a .. z ) { $counter++; On Thu, Aug 8, 2013 at 12:05 PM,

Re: Array iterator count

2013-08-08 Thread Andy Bach
On Thu, Aug 8, 2013 at 12:05 PM, Unknown User knowsuperunkn...@gmail.comwrote: at any point is it possible to say which element i am handling without using a counter? Er, well, if it were an array rather than a list my @letters = (a .. z); foreach my $letter ( a .. z ) { if ( $letter eq

Re: Array iterator count

2013-08-08 Thread Brian Fraser
On Thu, Aug 8, 2013 at 2:05 PM, Unknown User knowsuperunkn...@gmail.comwrote: Hello, If i am iterating through the elements in an array, at any point is it possible to say which element i am handling without using a counter? Are there any builtins that i can use for it? ie foreach my

Re: Array iterator count

2013-08-08 Thread Jing Yu
Or maybe you can convert your list into a file, and use the line number variable to do what you want. Cheers, Jing On 9 Aug 2013, at 01:05, Unknown User knowsuperunkn...@gmail.com wrote: Hello, If i am iterating through the elements in an array, at any point is it possible to say

Re: Array iterator count

2013-08-08 Thread Jing Yu
Something like this: while(DATA){ if(/d/){ print; say $.; } } __DATA__ a b c d e f g h i j k l m n o p q r s t u v w x y z Cheers, Jing On 9 Aug 2013, at 01:05, Unknown User knowsuperunkn...@gmail.com wrote: Hello, If i am iterating through the elements in an

Re: Array iterator count

2013-08-08 Thread Andy Bach
And buggy, consider: my @timings = ( 11, 22, 3, 14, 18, 45, 18, ... 86 ); Yeah, it's a constraint without a cause. Do you want to treat every 18 in the if or only the first? Why not use a counter? Is the data from a list, a file or … ? Do we know it's the 5th element ahead of time? But

Re: Array vs List output

2013-01-02 Thread David Precious
On Wed, 2 Jan 2013 16:05:25 +0530 Neeraj neeraj.seh...@gmail.com wrote: Why do i have white-space between words when printing array while not getting white-space when printing individual element. perlfaq explains this - from perlfaq5: Why do I get weird spaces when I print an array of

Re: Array vs List output

2013-01-02 Thread *Shaji Kalidasan*
Neeraj, If you print an array inside double quotes, each item of the array is separated by the value specified in Perl special variable $ which is the Output list separator. (interpolated lists) By default the value of $ is space So you can rewrite your code modifying the Output list

Re: Array vs List output

2013-01-02 Thread John W. Krahn
Neeraj wrote: Hi, I am new to Perl and perplexed with output of printing entire Array vs printing each element +4 ## check Array vis-a-vis List +5 +6 @arr = qwhello happy new year 2013; +7 print my array is : @arr \n; +8 +9 ## lets print in a loop +10 my

Re: Array vs List output

2013-01-02 Thread John W. Krahn
*Shaji Kalidasan* wrote: Neeraj, If you print an array inside double quotes, each item of the array is separated by the value specified in Perl special variable $ which is the Output list separator. (interpolated lists) It is just the _List Separator_ , it has nothing to do with output.

Re: Array vs List output

2013-01-02 Thread *Shaji Kalidasan*
. --- From: John W. Krahn jwkr...@shaw.ca To: Perl Beginners beginners@perl.org Sent: Wednesday, 2 January 2013 6:11 PM Subject: Re: Array vs List output *Shaji Kalidasan* wrote: Neeraj

Re: Array elements in Hash

2012-10-05 Thread Shekar
Would this help. @match = (6c7b00, 6d7b00, 6d9d8f, 6c6863, 6e6632); %abc = ('6c' ='device1', '6d'= 'device5', '6e'= 'device3', '6g'='device9'); foreach my $element(@match) { print $element.=.$abc{substr($element, 0, 2)}.\n; } -- Shekar On Thu, Oct 4, 2012 at 10:14 PM, Lawrence

Re: Array elements in Hash

2012-10-05 Thread jet speed
Hi Shekar, Appreciate your help, you saved me a lot of time ! I applied your loop and it works fine. Apologies i couldn't post my final program due to our internal system restriction.hence i have used test data here. @match = (6c7b00, 6d7b00, 6d9d8f, 6c6863, 6e6632); %abc = ('6c' ='device1',

Re: Array elements in Hash

2012-10-05 Thread Shekar
Yes. Loop through the array, for each element get the first 2 characters using substr, then pass it to hash as key to get the corresponding value. -- Shekar On Fri, Oct 5, 2012 at 4:51 PM, jet speed speedj...@googlemail.com wrote: Hi Shekar, Appreciate your help, you saved me a lot of

Re: Array elements in Hash

2012-10-05 Thread jet speed
Great. Thanks Shekar ! On Fri, Oct 5, 2012 at 12:37 PM, Shekar c.shekar1...@gmail.com wrote: Yes. Loop through the array, for each element get the first 2 characters using substr, then pass it to hash as key to get the corresponding value. -- Shekar On Fri, Oct 5, 2012 at 4:51 PM,

Re: Array elements in Hash

2012-10-04 Thread David Precious
On Thu, 4 Oct 2012 17:26:23 +0100 jet speed speedj...@googlemail.com wrote: I am trying to find the array elements in hash, if it matches then print the hash value. Please help me to achieve this. Note: array elements matches the first 2 characters of the hash keys. @match = (6c7b00,

Re: Array elements in Hash

2012-10-04 Thread Lawrence Statton
On 10/04/2012 11:26 AM, jet speed wrote: Hi All, I am trying to find the array elements in hash, if it matches then print the hash value. Please help me to achieve this. Note: array elements matches the first 2 characters of the hash keys. @match = (6c7b00, 6d7b00, 6d9d8f, 6c6863, 6e6632);

Re: array element access

2012-08-27 Thread Shawn H Corey
On Mon, 27 Aug 2012 18:57:08 -0500 Chris Stinemetz chrisstinem...@gmail.com wrote: I am trying to incorporate sprintf to access an element in an array. Not needed. Do this instead: $cp_cell = $data[$cp_cell_index]; -- Just my 0.0002 million dollars worth, Shawn Programming is as

Re: array question

2012-08-19 Thread Shlomi Fish
Hi Chris, On Sun, 19 Aug 2012 08:49:25 -0500 Chris Stinemetz perlqu...@gmail.com wrote: Hello List, I have input data such as far below: I would like to read the data into an array and modify the 2nd index if the 0th and first indices are identical. I would like the updated 2nd index to

Re: array question

2012-08-19 Thread Chris Charley
Chris Stinemetz wrote in message news Hello List, I have input data such as far below: I would like to read the data into an array and modify the 2nd index if the 0th and first indices are identical. I would like the updated 2nd index to be an average of the 2nd index where both occurences of

Re: array question

2012-08-19 Thread Chris Charley
Chris Charley wrote in message Chris Stinemetz wrote in message news Hello List, I have input data such as far below: I would like to read the data into an array and modify the 2nd index if the 0th and first indices are identical. I would like the updated 2nd index to be an average of

Re: array match- help !

2012-08-17 Thread jet speed
Hi Shomi, Appreciate your comments.Thanks I find it difficult to understand, if i convert into has. i.e keys and corresponding values. if my keys are from @actzone and values are from @all. How can i do this, becuase there are 2 keys and values are multiple ex. alias: wwn: etc. how can i

Re: array match- help !

2012-08-17 Thread Shlomi Fish
Hi jet speed, I apologise for sending my reply to you in private instead of to the list. It was an accident. On Fri, 17 Aug 2012 15:10:03 +0100 jet speed speedj...@googlemail.com wrote: Hi Shomi, It's Shlomi. Appreciate your comments.Thanks You're welcome. I find it difficult to

Re: array match- help !

2012-08-17 Thread Paul Anderson
Isn't this basically the format of YAML? Couldn't a YAML CPAN module handle this data? On 2012-08-17, at 10:10 AM, jet speed speedj...@googlemail.com wrote: Hi Shomi, Appreciate your comments.Thanks I find it difficult to understand, if i convert into has. i.e keys and corresponding

Re: array match- help !

2012-08-17 Thread Shawn H Corey
On Fri, 17 Aug 2012 15:10:03 +0100 jet speed speedj...@googlemail.com wrote: Your code is lacking indentation. Perhaps you should consider using Perl::Tidy to automatically format your code. http://search.cpan.org/~shancock/Perl-Tidy-20120714/lib/Perl/Tidy.pm -- Just my 0.0002 million

Re: array match- help !

2012-08-17 Thread jet speed
Chaps, Thanks for all your comments, I am strill trying to resolve my inital query. Any help would be much appreciated. I have the below program. i can match the entries in actzone.txt file in bluealias.txt and print it. what i would like to achive is to print the alias name and the reated wwn

Re: array match- help !

2012-08-17 Thread Bill Stephenson
On Aug 17, 2012, at 10:07 AM, jet speed wrote: Chaps, Thanks for all your comments, I am strill trying to resolve my inital query. Any help would be much appreciated. I have the below program. i can match the entries in actzone.txt file in bluealias.txt and print it. what i would

Re: array ref as subroutine parameter

2012-07-13 Thread timothy adigun
Hi Chris, On Fri, Jul 13, 2012 at 3:28 AM, Shawn H Corey shawnhco...@gmail.comwrote: On 12-07-12 10:25 PM, Chris Stinemetz wrote: I have an anonymous array below and would like to know how to pass the first element to a subroutine as a parameter. push @data,

Re: array ref as subroutine parameter

2012-07-12 Thread Shawn H Corey
On 12-07-12 10:25 PM, Chris Stinemetz wrote: I have an anonymous array below and would like to know how to pass the first element to a subroutine as a parameter. push @data, [$srt,$srfc,$cfc,$cfcq,$cell,$icell,$isector,$sector]; call to subroutine: session_attempts($srt); Thank you in

Re: Array elements

2012-07-02 Thread Shlomi Fish
Hi Yuma, a few comments on your code. On Mon, 2 Jul 2012 23:10:36 +1000 Yuma More yuma...@gmail.com wrote: Hi there: I am very new in Perl and I am trying to write a script to search for similar text in two different files, If it founds a match, it should out put the whole line from the

Re: Array elements

2012-07-02 Thread Chris Charley
Hi there: I am very new in Perl and I am trying to write a script to search for similar text in two different files, If it founds a match, it should out put the whole line from the second file in a third file. Let say that my first file (F1) has a list of some samples like

Re: Array elements

2012-07-02 Thread Yuma More
Than you Chris, your scrip is very helpful and know about BioPerl Module also. I appreciated it . On Mon, Jul 2, 2012 at 11:55 PM, Chris Charley char...@pulsenet.com wrote: Hi there: I am very new in Perl and I am trying to write a script to search for similar text in two different files,

Re: array sorting

2012-05-18 Thread Rob Dixon
On 17/05/2012 23:19, Shawn H Corey wrote: On 12-05-17 05:24 PM, Chris Stinemetz wrote: push(@fields, $Icell,$Isect,$Ichan,$cfc,$cfcq,$rtd); # push an anonymous array for each record push @fields, [ $Icell,$Isect,$Ichan,$cfc,$cfcq,$rtd ]; } } my @sorted_fields = sort { $a-[0]= $b-[0]

Re: array sorting

2012-05-17 Thread Shawn H Corey
On 12-05-17 03:36 PM, Chris Stinemetz wrote: I would like to sort the array by $fields[0],$fields[1],$fields[2],$fields[3],$fields[4],$fields[5] in ascending order starting witht he first element before I print the array. Do you want the fields sorted or do you want records sorted? If you want

Re: array sorting

2012-05-17 Thread Uri Guttman
On 05/17/2012 04:52 PM, Shawn H Corey wrote: On 12-05-17 03:36 PM, Chris Stinemetz wrote: I would like to sort the array by $fields[0],$fields[1],$fields[2],$fields[3],$fields[4],$fields[5] in ascending order starting witht he first element before I print the array. Do you want the fields

Re: array sorting

2012-05-17 Thread Chris Stinemetz
Thank you Uri and Shawn. I am getting the following error and not sure how to resolve: I will also checkout the great suggestions Uri made. Can't use string (3) as an ARRAY ref while strict refs in use at ./DBSRtest.pl line 51, line 999. #!/usr/bin/perl use warnings; use strict; use POSIX;

Re: array sorting

2012-05-17 Thread Shawn H Corey
On 12-05-17 05:24 PM, Chris Stinemetz wrote: Thank you Uri and Shawn. I am getting the following error and not sure how to resolve: I will also checkout the great suggestions Uri made. Can't use string (3) as an ARRAY ref while strict refs in use at ./DBSRtest.pl line 51, line 999.

Re: Array of Hashes

2012-04-13 Thread Paul.G
Thanks for your help, I will look carefully at both of your comments. cheers From: John W. Krahn jwkr...@shaw.ca To: Perl Beginners beginners@perl.org Sent: Friday, 13 April 2012 6:08 AM Subject: Re: Array of Hashes Rob Dixon wrote: Hi Paul and welcome

Re: Array of Hashes - problem solved

2012-04-12 Thread Paul.G
Hi All I have solved the problem, I would be interested in any comments however on this script. Positive and negative comments are welcome. #!/usr/bin/perl use strict; use warnings; my @vggroup; my @PV; my $PV=0; my $Extents; my $AllocatedPE; my $rec = {}; my $href; my $extent;

Re: Array of Hashes

2012-04-12 Thread Rob Dixon
On 12/04/2012 12:48, Paul.G wrote: Hi All New to this group, so hello to everybody. I am currently working on creating a Array of Hashes, note it is a work in progress. I appear to be getting some corruption when inputting data with the pvdisplay, I can't see why this is the case. I have put

Re: Array of Hashes

2012-04-12 Thread John W. Krahn
Rob Dixon wrote: Hi Paul and welcome to the list. I can see a few things wrong with your code, but I have only a Windows machine so cannot test any changes I am suggestion so please beware. The reason you get the marked line in your output is because that is what you have written. This loop

Re: array uniq elements

2012-01-09 Thread Chris Stinemetz
Thank you Jim. Your advice worked perfectly. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: array uniq elements

2012-01-08 Thread Robert Wohlfarth
On Sun, Jan 8, 2012 at 11:15 PM, Chris Stinemetz chrisstinem...@gmail.comwrote: How do I extract uniq elements from an array? Basically I want to preserve the order of the elements as they are first seen, but I would like to remove any duplicates. You may want to check out List::MoreUtils on

Re: array uniq elements

2012-01-08 Thread Jim Gibson
At 11:15 PM -0600 1/8/12, Chris Stinemetz wrote: How do I extract uniq elements from an array? Basically I want to preserve the order of the elements as they are first seen, but I would like to remove any duplicates. Use a hash to keep track of elements. Create an entry in the hash with the

Re: array like split of string

2011-01-26 Thread Peter K. Michie
On Jan 23, 2:55 am, jwkr...@shaw.ca (John W. Krahn) wrote: Peter K. Michie wrote: I have this regex expression in a script that appears to do an array like split of a string but I cannot figure out how it does so. Any help appreciated $fname = ($0 =~ m[(.*/)?([^/]+)$])[1] ; print 7

Re: array like split of string

2011-01-23 Thread John W. Krahn
Peter K. Michie wrote: I have this regex expression in a script that appears to do an array like split of a string but I cannot figure out how it does so. Any help appreciated $fname = ($0 =~ m[(.*/)?([^/]+)$])[1] ; print 7 $errlog\n; $fpath = ($0 =~ m[(.*/)?([^/]+)$])[0] ; print 8 $errlog\n;

Re: Array Question

2010-12-15 Thread Jeff Peng
于 2010-12-15 1:38, Jim Gibson 写道: or the File::Find module to find files without resorting to the use of separate processes and shell commands. Me second. File::Find is your friend. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail:

Re: Array Question

2010-12-15 Thread shawn wilson
or the File::Find module to find files without resorting to the use of separate processes and shell commands. Me second. File::Find is your friend. Also, since you seem to be familiar with find use find2perl and you barely have to lift a finger. Its like training wheels for File::Find -

Re: Array Question

2010-12-14 Thread Jim Gibson
On 12/14/10 Tue Dec 14, 2010 9:18 AM, Matt lm7...@gmail.com scribbled: I am assigning a number of elements to an array like so: my @new = `find /home/*/new -cmin 1 -type f`; That works fine. I would also like to append more lines to that array from here: find /home/*/filed -cmin 1

Re: Array Question

2010-12-14 Thread John W. Krahn
Matt wrote: I am assigning a number of elements to an array like so: my @new = `find /home/*/new -cmin 1 -type f`; That works fine. I would also like to append more lines to that array from here: find /home/*/filed -cmin 1 -type f How do I do that without losing whats in the array already?

Re: array problem

2010-11-15 Thread shawn wilson
too much freaking data. i increased my scroll buffer and found that i do get data, just not the last 1k lines err On Mon, Nov 15, 2010 at 12:33 PM, shawn wilson ag4ve...@gmail.com wrote: so, i'm thinking i'm not understanding references here again, but here's what i have. i fill in

Re: array problem

2010-11-15 Thread Uri Guttman
sw == shawn wilson ag4ve...@gmail.com writes: swmy $worksheetout = $workbookout-add_worksheet( '$year' ); why are you quoting $year? that doesn't do what you think it does. in fact it is a bug. you aren't checking if you get results out of that call which is another problem. uri -- Uri

Re: array problem

2010-11-15 Thread shawn wilson
On Mon, Nov 15, 2010 at 1:54 PM, Uri Guttman u...@stemsystems.com wrote: sw == shawn wilson ag4ve...@gmail.com writes: swmy $worksheetout = $workbookout-add_worksheet( '$year' ); why are you quoting $year? that doesn't do what you think it does. in fact it is a bug. you aren't

Re: array to hash array

2010-07-27 Thread C.DeRykus
On Jul 26, 3:22 am, sharan.basa...@gmail.com (Sharan Basappa) wrote: Hi, Can someone tell me how to convert an array to hash. Each array entry has a row of values e.g. a(0) = ab cd ef; a(1) = mn de fg The hash array needs to be constructed with one of the element in the array row as the

Re: array to hash array

2010-07-26 Thread Teo
Dear Sharan, Can someone tell me how to convert an array to hash. Each array entry has a row of values e.g. a(0) = ab cd ef; a(1) = mn de fg The hash array needs to be constructed with one of the element in the array row as the key. e.g. hash{ab} = cd ef      - ab is a string in the array

Re: Array, foreach problem

2010-05-05 Thread Shlomi Fish
Hi Paul, a few comments on your code - so you'll know how to write Perl better. On Wednesday 05 May 2010 02:52:03 Paul Fontenot wrote: Hi, I'm stuck on using an array to determine the out come of a foreach loop. The script is below.

Re: Array, foreach problem

2010-05-05 Thread Brian
foreach $line (LOGFILE) { while (my $line = $logfile) would be a better idea than foreach $line. Just curious for an explanation to this. I tend to use foreach too. Don't they both accomplish the same thing? :) -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For

Re: Array, foreach problem

2010-05-05 Thread Shawn H Corey
Brian wrote: foreach $line (LOGFILE) { while (my $line = $logfile) would be a better idea than foreach $line. Just curious for an explanation to this. I tend to use foreach too. Don't they both accomplish the same thing? :) Yes, but they go about it in different ways. The

Re: Array, foreach problem

2010-05-05 Thread Akhthar Parvez K
On Wednesday 05 May 2010, Shlomi Fish wrote: 2. Don't use bareword filehandles - use lexical ones: open(my $output, , $output) or die Could not append to output - $!; Wouldn't there be any issues if we use same name for lexical filehandle and the scalar variable. Is Perl too intelligent to

Re: Array, foreach problem

2010-05-05 Thread Shlomi Fish
On Wednesday 05 May 2010 17:20:25 Akhthar Parvez K wrote: On Wednesday 05 May 2010, Shlomi Fish wrote: 2. Don't use bareword filehandles - use lexical ones: open(my $output, , $output) or die Could not append to output - $!; Wouldn't there be any issues if we use same name for lexical

Re: Array, foreach problem

2010-05-05 Thread Akhthar Parvez K
On Wednesday 05 May 2010, Shlomi Fish wrote: Wouldn't there be any issues if we use same name for lexical filehandle and the scalar variable. Is Perl too intelligent to recognize both of them? There certainly would be, and I don't think Perl is that intelligent to multiplex between the

Re: Array, foreach problem

2010-05-05 Thread Akhthar Parvez K
On Wednesday 05 May 2010, Shawn H Corey wrote: Brian wrote: foreach $line (LOGFILE) { while (my $line = $logfile) would be a better idea than foreach $line. Just curious for an explanation to this. I tend to use foreach too. Don't they both accomplish the same thing? :)

Re: Array, foreach problem

2010-05-05 Thread Rob Coops
On Wed, May 5, 2010 at 10:18 AM, Shlomi Fish shlo...@iglu.org.il wrote: Hi Paul, a few comments on your code - so you'll know how to write Perl better. On Wednesday 05 May 2010 02:52:03 Paul Fontenot wrote: Hi, I'm stuck on using an array to determine the out come of a foreach loop.

Re: Array, foreach problem

2010-05-05 Thread John W. Krahn
Akhthar Parvez K wrote: On Wednesday 05 May 2010, Shawn H Corey wrote: Brian wrote: foreach $line (LOGFILE) { while (my $line = $logfile) would be a better idea than foreach $line. Just curious for an explanation to this. I tend to use foreach too. Don't they both accomplish the

Re: Array, foreach problem

2010-05-05 Thread Akhthar Parvez K
On Wednesday 05 May 2010, Rob Coops wrote: Would it not be more efficient to reset the file handle to the star of the file? use strict; use warnings; use Fcntl qw(:seek); ... foreach my $condition (@conditions) {  seek ( $fh, 0, 0 ) or die ERROR: Could not reset file handle\n;  while

Re: Array, foreach problem

2010-05-05 Thread Rob Coops
On Wed, May 5, 2010 at 7:21 PM, Akhthar Parvez K akht...@sysadminguide.comwrote: On Wednesday 05 May 2010, Rob Coops wrote: Would it not be more efficient to reset the file handle to the star of the file? use strict; use warnings; use Fcntl qw(:seek); ... foreach my $condition

Re: Array, foreach problem

2010-05-05 Thread Akhthar Parvez K
On Wednesday 05 May 2010, Rob Coops wrote: A file never starts life being huge but certainly logs tend to grow, and they are not always kept in check properly so assume they will be massive (I've seen flat text logs that grew by as much as +1GB per day) assuming that the file will always be

Re: Array, foreach problem

2010-05-05 Thread Rob Coops
On Wed, May 5, 2010 at 8:50 PM, Akhthar Parvez K akht...@sysadminguide.comwrote: On Wednesday 05 May 2010, Rob Coops wrote: A file never starts life being huge but certainly logs tend to grow, and they are not always kept in check properly so assume they will be massive (I've seen flat

Re: Array, foreach problem

2010-05-05 Thread Akhthar Parvez K
On Wednesday 05 May 2010, John W. Krahn wrote: If I could explain this further for Perl beginners: With that foreach statement, it reads the file first and creates an array with each line as elements and that array is being looped so the overhead is higher, whereas with that while

Re: Array, foreach problem

2010-05-05 Thread Uri Guttman
APK == Akhthar Parvez K akht...@sysadminguide.com writes: APK Thanks for the explanation John. Could you give one or two real APK time examples where you used a list (instead of an array) except APK in loops such as: for ('a', 'b', 'c', 'd')? I wonder if I'm APK underusing lists in my

Re: Array, foreach problem

2010-05-05 Thread Akhthar Parvez K
On Thursday 06 May 2010, Rob Coops wrote: Of course and a system like nagios does exactly that, it reports errors and positives, mail is of course not the way right to deal with monitoring certainly in large environments it is simply not done via mail. Currently looking at the monitoring

Re: Array, foreach problem

2010-05-04 Thread Jim Gibson
On 5/4/10 Tue May 4, 2010 4:52 PM, Paul Fontenot wpfonte...@cox.net scribbled: Hi, I'm stuck on using an array to determine the out come of a foreach loop. The script is below. -- --

Re: Array, foreach problem

2010-05-04 Thread Shawn H Corey
Jim Gibson wrote: You need to reset LOGFILE to the beginning for subsequent iterations over the @conditions array. As written, the nested foreach will never be executed except for the first condition. Add the indicated seek call. The actual command is seek. See `perldoc -f seek` or

Re: Array, foreach problem

2010-05-04 Thread Paul Fontenot
Thank you very much On 5/4/2010 6:12 PM, Shawn H Corey wrote: Jim Gibson wrote: You need to reset LOGFILE to the beginning for subsequent iterations over the @conditions array. As written, the nested foreach will never be executed except for the first condition. Add the indicated seek call.

Re: Array, foreach problem

2010-05-04 Thread Uri Guttman
JG == Jim Gibson jimsgib...@gmail.com writes: JG On 5/4/10 Tue May 4, 2010 4:52 PM, Paul Fontenot wpfonte...@cox.net JG scribbled: JG You need to reset LOGFILE to the beginning for subsequent JG iterations over the @conditions array. As written, the nested JG foreach will never be

Re: array of anonymous hash?

2010-02-25 Thread Shlomi Fish
Hi Raphael! Welcome to Perl. On Thursday 25 Feb 2010 12:41:30 raphael() wrote: use strict; use warnings; It's good that you're using strict and warnings; use Data::Dumper; my @links = ({ name1 = 'http://www.abc.com/data/a/000/name1.txt', name2 =

Re: array of anonymous hash?

2010-02-25 Thread Shlomi Fish
Hi Raphael! On Thursday 25 Feb 2010 12:59:33 raphael() wrote: My BAD :( THERE IS NO FIRST ELEMENT IN A HASH!! PLEASE FORGIVE ME. I AM IN A THICK OF EVERYTHING TODAY. LET ME REPHRASE -- HOW DO I LOOP OVER THE ANONYMOUS HASH WHICH IS INSIDE AN ARRAY? OK, no need to use all-caps (it's

Re: array of anonymous hash?

2010-02-25 Thread Rob Dixon
raphael() wrote: use strict; use warnings; use Data::Dumper; my @links = ({ name1 = 'http://www.abc.com/data/a/000/name1.txt', name2 = 'http://www.abc.com/data/a/000/name2.txt', }); for my $element ( @links ) { for my $name ( sort keys %$element ) { print $name --

Re: array of anonymous hash?

2010-02-25 Thread Rob Dixon
raphael() wrote: My BAD :( THERE IS NO FIRST ELEMENT IN A HASH!! PLEASE FORGIVE ME. I AM IN A THICK OF EVERYTHING TODAY. LET ME REPHRASE -- HOW DO I LOOP OVER THE ANONYMOUS HASH WHICH IS INSIDE AN ARRAY? use strict; use warnings; my @links = ({ name1 =

Re: array of anonymous hash?

2010-02-25 Thread Shlomi Fish
Hi raphael! I believe you meant to CC this to the list, so I'm CCing it (I don't see anything in your reply that needs to be in private). On Thursday 25 Feb 2010 13:42:07 raphael() wrote: On Thu, Feb 25, 2010 at 4:50 PM, Shlomi Fish shlo...@iglu.org.il wrote: Hi Raphael! On Thursday 25

Re: array of anonymous hash?

2010-02-25 Thread Rob Dixon
Shlomi Fish wrote: ... WxWidgets has wxGlade ... Does it? Thanks Shlomi I am very fond of Wx and didn't know about this. Rob -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: array of anonymous hash?

2010-02-25 Thread Shlomi Fish
On Thursday 25 Feb 2010 17:09:02 Rob Dixon wrote: Shlomi Fish wrote: ... WxWidgets has wxGlade ... Does it? Thanks Shlomi I am very fond of Wx and didn't know about this. You're welcome. I think I've tried it and wasn't really impressed and returned to a standard writing-GUI-code-in-Perl

Re: Array Initialization

2009-05-13 Thread Chas. Owens
On Wed, May 13, 2009 at 01:59, John W. Krahn jwkr...@shaw.ca wrote: snip What's your point? I am trying to understand what point you are trying to make. snip I believe the point is that declaration is only one of the things my does, so saying that my() happens when the code is compiled so it

Re: Array Initialization

2009-05-13 Thread Gunnar Hjalmarsson
Chas. Owens wrote: On Wed, May 13, 2009 at 01:59, John W. Krahn jwkr...@shaw.ca wrote: snip What's your point? I am trying to understand what point you are trying to make. snip I believe the point is that declaration is only one of the things my does, so saying that my() happens when the

Re: Array Initialization

2009-05-12 Thread Chas. Owens
On Tue, May 12, 2009 at 14:30, AndrewMcHorney andrewmchor...@cox.net wrote: Hello I put the strict and warning statements in my perl code. I now need to initialize arrays. What is the best way to initialize an array before the loop where I will basically recreating the array size in the loop?

Re: Array Initialization

2009-05-12 Thread John W. Krahn
AndrewMcHorney wrote: Hello Hello, I put the strict and warning statements in my perl code. I now need to initialize arrays. What is the best way to initialize an array before the loop where I will basically recreating the array size in the loop? my @array = ? while (more work to do) {

Re: Array Initialization

2009-05-12 Thread Bryan Harris
[stuff cut out] It is usually best to declare variables in the smallest scope possible so: while (more work to do) { my @array = split $string; # do work on array } Doesn't that try to re-localize (?) the @array variable every time through the loop? i.e. doesn't it re-run the my()

Re: Array Initialization

2009-05-12 Thread John W. Krahn
Bryan Harris wrote: [stuff cut out] It is usually best to declare variables in the smallest scope possible so: while (more work to do) { my @array = split $string; # do work on array } Doesn't that try to re-localize (?) the @array variable every time through the loop? i.e.

  1   2   3   4   5   6   7   >