Re: Array Initialization

2009-05-12 Thread John W. Krahn
Bryan Harris wrote: Doesn't that try to re-localize (?) the @array variable every time through the loop? i.e. doesn't it re-run the my() function every time through the loop? For some reason I thought that was a no-no. my() happens when the code is compiled so it is *not* re-run every time

Re: Array Initialization

2009-05-12 Thread Gunnar Hjalmarsson
John W. Krahn wrote: my() happens when the code is compiled so it is *not* re-run every time through the loop. The assignment happens when the code is run so it is re-run every time. $ perl -e ' for (1..5) { my $count; $count += 1; print $count; last if $count == 3; } print

Re: Array Initialization

2009-05-12 Thread Jenda Krynicky
From: John W. Krahn jwkr...@shaw.ca 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 (?)

Re: Array Initialization

2009-05-12 Thread John W. Krahn
Gunnar Hjalmarsson wrote: John W. Krahn wrote: my() happens when the code is compiled so it is *not* re-run every time through the loop. The assignment happens when the code is run so it is re-run every time. $ perl -e ' for (1..5) { my $count; $count += 1; print $count;

Re: Array Initialization

2009-05-12 Thread Gunnar Hjalmarsson
John W. Krahn wrote: Gunnar Hjalmarsson wrote: John W. Krahn wrote: my() happens when the code is compiled so it is *not* re-run every time through the loop. The assignment happens when the code is run so it is re-run every time. $ perl -e ' for (1..5) { my $count; $count += 1;

Re: Array Initialization

2009-05-12 Thread John W. Krahn
Gunnar Hjalmarsson wrote: John W. Krahn wrote: Gunnar Hjalmarsson wrote: John W. Krahn wrote: my() happens when the code is compiled so it is *not* re-run every time through the loop. The assignment happens when the code is run so it is re-run every time. $ perl -e ' for (1..5) { my

Re: Array Initialization

2009-05-12 Thread Chas. Owens
On Tue, May 12, 2009 at 18:11, John W. Krahn jwkr...@shaw.ca wrote: 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: Array Initialization

2009-05-12 Thread Gunnar Hjalmarsson
John W. Krahn wrote: Gunnar Hjalmarsson wrote: John W. Krahn wrote: Gunnar Hjalmarsson wrote: John W. Krahn wrote: my() happens when the code is compiled so it is *not* re-run every time through the loop. The assignment happens when the code is run so it is re-run every time. $ perl -e '

Re: Array Initialization

2009-05-12 Thread John W. Krahn
Gunnar Hjalmarsson wrote: John W. Krahn wrote: Gunnar Hjalmarsson wrote: John W. Krahn wrote: Gunnar Hjalmarsson wrote: John W. Krahn wrote: my() happens when the code is compiled so it is *not* re-run every time through the loop. The assignment happens when the code is run so it is

Re: @array a copy of @names???

2009-04-02 Thread Joseph Mwesigwa Bbaale
Hello, I am a complete beginner - no programming background. I want to begin with Perl and I decided to by Randal's book *Learning Perl*. I seem to have been progressing smoothly till when I arrived at the code below on page 65. my @names = qw/ tom fred dan betty roy /; my $result =

Re: @array a copy of @names???

2009-04-02 Thread í Kadaník jirikada...@gmail.com
That does the first line in function: my($what, @array) = @_; That puts to $what the first parameter passed to function and to @array the rest of parametres..in this case @names. So you have a copy of @names in @array. But I am begginer too, so maybe i undersand it wrong;-) And for

Re: @array a copy of @names???

2009-04-02 Thread Chas. Owens
On Thu, Apr 2, 2009 at 07:06, Joseph Mwesigwa Bbaale joemwesi...@gmail.com wrote: Hello, I am a complete beginner - no programming background. I want to begin with Perl and I decided to by Randal's book *Learning Perl*. I seem to have been progressing smoothly till when I arrived at the code

Re: @array a copy of @names???

2009-04-02 Thread Gunnar Hjalmarsson
Joseph Mwesigwa Bbaale wrote: my @names = qw/ tom fred dan betty roy /; my $result = which_element_is(dan @names); sub which_element_is { my($what, @array) = @_; foreach (0..$#array) { if ($what eq $array[$_]) { return $_; } } -1; } snip Please,

Re: @array a copy of @names???

2009-04-02 Thread Chas. Owens
On Thu, Apr 2, 2009 at 13:18, Gunnar Hjalmarsson nore...@gunnar.cc wrote: snip Another thing is that I was a little surprised to see that a book written by Randal contains an example where a function is called with before the name. It's not just a matter of taste, but the character changes

Re: Array question

2009-03-30 Thread Rodrick Brown
On Mon, Mar 30, 2009 at 2:20 PM, ANJAN PURKAYASTHA anjan.purkayas...@gmail.com wrote: Hi, Here is my problem; I have a series of arrays with 0s and 1s. here is an example: (1, 0, 1, 1). I need to parse through this series of arrays and extract the index of the 0s in the array. Is there any

Re: Array question

2009-03-30 Thread Chas. Owens
On Mon, Mar 30, 2009 at 14:20, ANJAN PURKAYASTHA anjan.purkayas...@gmail.com wrote: Hi, Here is my problem; I have a series of arrays with 0s and 1s. here is an example: (1, 0, 1, 1). I need to parse through this series of arrays and extract the index of the 0s in the array. Is there any

Re: Array question

2009-03-30 Thread Chas. Owens
On Mon, Mar 30, 2009 at 14:28, Rodrick Brown rodrick.br...@gmail.com wrote: snip Millions of ways here is one: snip my $pos = 0; for my $index (@arr) {  if ( $index == 0 ) {     printf (%d , $pos );  }  $pos++; } snip If you are going to go with a full bore for loop, you might as well

Re: Array question

2009-03-30 Thread John W. Krahn
ANJAN PURKAYASTHA wrote: Hi, Hello, Here is my problem; I have a series of arrays with 0s and 1s. here is an example: (1, 0, 1, 1). I need to parse through this series of arrays and extract the index of the 0s in the array. Is there any quick way of doing this? $ perl -le' my @array = ( 1,

Re: Array question

2009-03-30 Thread Dave Tang
On Tue, 31 Mar 2009 04:49:17 +1000, John W. Krahn jwkr...@shaw.ca wrote: Or instead of using arrays you could store the 1s and 0s in strings: $ perl -le' my $string = 10110111001; print $-[0] while $string =~ /0/g; ' 1 4 8 9 Hi John, Could you explain how the above code works please? I

Re: Array question

2009-03-30 Thread John W. Krahn
Dave Tang wrote: On Tue, 31 Mar 2009 04:49:17 +1000, John W. Krahn jwkr...@shaw.ca wrote: Or instead of using arrays you could store the 1s and 0s in strings: $ perl -le' my $string = 10110111001; print $-[0] while $string =~ /0/g; ' 1 4 8 9 Could you explain how the above code works

Re: Array manipulation

2008-11-16 Thread Mr. Shawn H. Corey
On Sun, 2008-11-16 at 08:35 -0800, hotkitty wrote: How do I combine the arrays so that the the newstuff in array1 gets appended only to an item in array2 if the dates match? Create a hash of lists with the dates as its keys. Go through Array2 and push each oldstuff on the list stored in the

Re: Array manipulation

2008-11-16 Thread John W. Krahn
hotkitty wrote: Hi, Hello, I have two arrays, as follows: Array1=( date 11/01/2008 newstuff1, date 10/27/2008 newstuff2, date 10/24/2008 newstuff3 ) Array2=( date 11/01/2008 oldstuff1, date 10/31/2008 oldstuff2, date 10/30/2008 oldstuff3, date 10/29/2008 oldstuff4, date 10/28/2008

Re: array serach for partial value

2008-10-14 Thread John W. Krahn
Richard wrote: Hello, Hello, I have small Perl project and got stuck on following problem : There is a zip file with bunch of files in it. I need to search through it and find if every xxx.txt file has xxx.log pair and list all of those .txt without pairs. Use File::Basename to separate

Re: Array always compares equal

2008-08-04 Thread John W. Krahn
Mr. Shawn H. Corey wrote: On Sat, 2008-08-02 at 06:31 -0700, hsfrey wrote: I'm trying to set up a list of words to ignore in a text. I tried it like this: my @ignore = (U.S.C, Corp, Miss, Conf, Cong); and later in a loop if ( $exists $ignore [$lastWord] ) { next;} But that tested positive

Re: Array always compares equal

2008-08-03 Thread Mr. Shawn H. Corey
On Sat, 2008-08-02 at 06:31 -0700, hsfrey wrote: I'm trying to set up a list of words to ignore in a text. I tried it like this: my @ignore = (U.S.C, Corp, Miss, Conf, Cong); and later in a loop if ( $exists $ignore [$lastWord] ) { next;} But that tested positive for EVERY $lastWord

Re: Array indexing question

2008-07-10 Thread Stephen Kratzer
On Thursday 10 July 2008 05:59:36 Anirban Adhikary wrote: Dear list I want to capture the output of w and then I want to do some job as per the o/p of w command in my linux system. So i have written the code as follows use strict; use warnings; open (LS, w|) or die can't open w: $!; my

Re: Array indexing question

2008-07-10 Thread Jay Savage
On Thu, Jul 10, 2008 at 5:59 AM, Anirban Adhikary [EMAIL PROTECTED] wrote: Dear list I want to capture the output of w and then I want to do some job as per the o/p of w command in my linux system. So i have written the code as follows open (LS, w|) or die can't open w: $!; my @arr = LS;

Re: Array indexing question

2008-07-10 Thread Jay Savage
On Thu, Jul 10, 2008 at 8:48 AM, Stephen Kratzer [EMAIL PROTECTED] wrote: Anirban, The output of 'w' is delimited by whitespace, not necessarily a single space. Try passing the pattern '\w+' to split. Something like this: I think you meant the '\s+' pattern. -- j

Re: Array indexing question

2008-07-10 Thread Rob Dixon
Stephen Kratzer wrote: On Thursday 10 July 2008 05:59:36 Anirban Adhikary wrote: Dear list I want to capture the output of w and then I want to do some job as per the o/p of w command in my linux system. So i have written the code as follows use strict; use warnings; open (LS, w|) or die

Re: Array indexing question

2008-07-10 Thread Stephen Kratzer
On Thursday 10 July 2008 10:33:31 Jay Savage wrote: On Thu, Jul 10, 2008 at 8:48 AM, Stephen Kratzer [EMAIL PROTECTED] wrote: Anirban, The output of 'w' is delimited by whitespace, not necessarily a single space. Try passing the pattern '\w+' to split. Something like this: I think you

Re: Array indexing question

2008-07-10 Thread Brad Baxter
On Jul 10, 5:59 am, [EMAIL PROTECTED] (Anirban Adhikary) wrote: Dear list I want to capture the output of w and then I want to do some job as per the o/p of w command in my linux system. So i have written the code as follows use strict; use warnings; open (LS, w|) or die can't open w: $!;

Re: Array problem

2008-07-02 Thread Beyza
Thanks for the answers. I have tried to use quotemeta but it did not work as expected, DBI's quote function was exactly what I want. Thanks again, On Jul 1, 6:35 pm, [EMAIL PROTECTED] (Amit Saxena) wrote: use $*dbh*-*quote*($str) On Tue, Jul 1, 2008 at 4:59 AM, Gunnar Hjalmarsson [EMAIL

Re: Array problem

2008-07-01 Thread Amit Saxena
use $*dbh*-*quote*($str) On Tue, Jul 1, 2008 at 4:59 AM, Gunnar Hjalmarsson [EMAIL PROTECTED] wrote: Beyza wrote: I have an array which has strings like; John's House Bla bla; etc, When I use them in an SQL query, perl gives an error. So, I need to put escape character for every

Re: Array problem

2008-06-30 Thread Aruna Goke
Beyza wrote: Hi, I would like to know how to insert escape character in front of special characters in an array. I have an array which has strings like; John's House Bla bla; etc, When I use them in an SQL query, perl gives an error. So, I need to put escape character for every special

Re: Array problem

2008-06-30 Thread Rob Dixon
Beyza wrote: Hi, I would like to know how to insert escape character in front of special characters in an array. I have an array which has strings like; John's House Bla bla; etc, When I use them in an SQL query, perl gives an error. So, I need to put escape character for every

Re: Array problem

2008-06-30 Thread Gunnar Hjalmarsson
Beyza wrote: I have an array which has strings like; John's House Bla bla; etc, When I use them in an SQL query, perl gives an error. So, I need to put escape character for every special character. Is there any quick way to do it? perldoc -f quotemeta -- Gunnar Hjalmarsson Email:

Re: Array element split, with grep

2008-04-30 Thread Steve Bertrand
Steve Bertrand wrote: Hi all, Can someone explain to me how I can fix this up to achieve my desired results? my $time = (split (/:/, (grep (/^info/, @contents[0]; I figured it out :) my $time = (split (/:/, (grep (/^info/, @contents))[0]))[0]; I neglected to realize that the result

Re: Array element split, with grep

2008-04-30 Thread Rob Dixon
Steve Bertrand wrote: Can someone explain to me how I can fix this up to achieve my desired results? my $time = (split (/:/, (grep (/^info/, @contents[0]; A sample snip of data: this382:3828 info447:4729 that274:9294 ...and I just want the $time to become info447. The way

Re: Array element split, with grep

2008-04-30 Thread John W. Krahn
Steve Bertrand wrote: Hi all, Hello, Can someone explain to me how I can fix this up to achieve my desired results? my $time = (split (/:/, (grep (/^info/, @contents[0]; A sample snip of data: this382:3828 info447:4729 that274:9294 ...and I just want the $time to become info447.

Re: Array element split, with grep

2008-04-30 Thread John W. Krahn
Rob Dixon wrote: Steve Bertrand wrote: Can someone explain to me how I can fix this up to achieve my desired results? my $time = (split (/:/, (grep (/^info/, @contents[0]; A sample snip of data: this382:3828 info447:4729 that274:9294 ...and I just want the $time to become info447. The

Re: Array element split, with grep

2008-04-30 Thread Gunnar Hjalmarsson
Steve Bertrand wrote: Can someone explain to me how I can fix this up to achieve my desired results? my $time = (split (/:/, (grep (/^info/, @contents[0]; A sample snip of data: this382:3828 info447:4729 that274:9294 ...and I just want the $time to become info447. my $time;

Re: array question

2008-02-27 Thread Rob Dixon
Paul Lalli wrote: On Feb 26, 11:07 am, [EMAIL PROTECTED] (Irfan Sayed) wrote: Hello All, I have two arrays contains exact no. of elements. Now what I need to do is , I want to execute certain commands to each elements of the array at a time. It means that I want take first element of first

Re: array question

2008-02-26 Thread Troy Bull
On Tue, Feb 26, 2008 at 10:07 AM, [EMAIL PROTECTED] wrote: Hello All, I have two arrays contains exact no. of elements. Now what I need to do is , I want to execute certain commands to each elements of the array at a time. @array1 = (1,2,3); @array2 = (4,5,6); for (my $i=0; $i

Re: array question

2008-02-26 Thread Kashif Salman
On Tue, Feb 26, 2008 at 8:07 AM, [EMAIL PROTECTED] wrote: Hello All, I have two arrays contains exact no. of elements. Now what I need to do is , I want to execute certain commands to each elements of the array at a time. It means that I want take first element of first array and

Re: array question

2008-02-26 Thread Paul Lalli
On Feb 26, 11:07 am, [EMAIL PROTECTED] (Irfan Sayed) wrote: Hello All, I have two arrays contains exact no.  of elements. Now what I need to do is , I want to execute certain commands to each elements of the array at a time. It means that I want take first element of first array and first

Re: array modification

2007-12-13 Thread Jenda Krynicky
From: John W.Krahn [EMAIL PROTECTED] On Wednesday 12 December 2007 07:15, Jenda Krynicky wrote: From: jeff pang [EMAIL PROTECTED] --- Sayed, Irfan (Irfan) [EMAIL PROTECTED] wrote: My query is that can i store the output of this for loop in variable or list. so that if i print

Re: array modification

2007-12-13 Thread John W . Krahn
On Thursday 13 December 2007 03:52, Jenda Krynicky wrote: From: John W.Krahn [EMAIL PROTECTED] On Wednesday 12 December 2007 07:15, Jenda Krynicky wrote: From: jeff pang [EMAIL PROTECTED] You can add a \n (or \r\n on windows,etc) at the end of each element in the array,like,

Re: array modification

2007-12-13 Thread Jenda Krynicky
From: Chas. Owens [EMAIL PROTECTED] Yes, but I am the one making pronouncements about how people should code. Rob was just calling me on being a little pompous. I still think that use of $_ in places other than the start of a loop (with a function that uses the default variable like split,

Re: array modification

2007-12-12 Thread protoplasm
Irfan, this will work: #!/opt/local/bin/perl use warnings; use strict; my @output = (dadsad, assasd); foreach (@output) { print $_\n; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: array modification

2007-12-12 Thread Chas. Owens
On Dec 12, 2007 1:00 AM, jeff pang [EMAIL PROTECTED] wrote: snip You can add a \n (or \r\n on windows,etc) at the end of each element in the array,like, snip In Perl, \n is not linefeed, it is the newline character. It translates to the proper sequence of characters on each operating system,

Re: array modification

2007-12-12 Thread Chas. Owens
On Dec 12, 2007 12:04 AM, Sayed, Irfan (Irfan) [EMAIL PROTECTED] wrote: Hi All, I have some string stored in array as follows. @array=(dadsad,assasd) Now if i print this array then it is printing as dadsad,assasd I certainly hope you are not using barewords like this. This will work (for

Re: array modification

2007-12-12 Thread Jenda Krynicky
From: jeff pang [EMAIL PROTECTED] --- Sayed, Irfan (Irfan) [EMAIL PROTECTED] wrote: My query is that can i store the output of this for loop in variable or list. so that if i print the content of that variable or array then it should print as dadsad assasd You can add

Re: array modification

2007-12-12 Thread John W . Krahn
On Wednesday 12 December 2007 07:15, Jenda Krynicky wrote: From: jeff pang [EMAIL PROTECTED] --- Sayed, Irfan (Irfan) [EMAIL PROTECTED] wrote: My query is that can i store the output of this for loop in variable or list. so that if i print the content of that variable or array then

Re: array modification

2007-12-12 Thread Rob Dixon
Chas. Owens wrote: On Dec 12, 2007 1:00 AM, jeff pang [EMAIL PROTECTED] wrote: snip You can add a \n (or \r\n on windows,etc) at the end of each element in the array,like, snip In Perl, \n is not linefeed, it is the newline character. It translates to the proper sequence of characters on

Re: array modification

2007-12-12 Thread Rob Dixon
Chas. Owens wrote: Only use the default variable with functions and operators that use it by default like chomp and regexes. What's this? The Gospel according to Chas?! Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: array modification

2007-12-12 Thread Steve Bertrand
Rob Dixon wrote: Chas. Owens wrote: Only use the default variable with functions and operators that use it by default like chomp and regexes. What's this? The Gospel according to Chas?! Hey now... Take into consideration that this is not everyone's point of view. Just because you (and I,

Re: array modification

2007-12-12 Thread Chas. Owens
On Dec 13, 2007 1:02 AM, Steve Bertrand [EMAIL PROTECTED] wrote: Rob Dixon wrote: Chas. Owens wrote: Only use the default variable with functions and operators that use it by default like chomp and regexes. What's this? The Gospel according to Chas?! Hey now... Take into

Re: array modification

2007-12-11 Thread yitzle
The built in join() function sounds like what you want. Read up on it here: http://perldoc.perl.org/functions/join.html $output = join(\n, @array); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: array modification

2007-12-11 Thread jeff pang
--- Sayed, Irfan (Irfan) [EMAIL PROTECTED] wrote: My query is that can i store the output of this for loop in variable or list. so that if i print the content of that variable or array then it should print as dadsad assasd You can add a \n (or \r\n on windows,etc) at the end of

Re: array within array

2007-10-30 Thread Ron Bergin
On Oct 29, 11:09 am, [EMAIL PROTECTED] (John W . Krahn) wrote: On Monday 29 October 2007 06:42, Mike Tran wrote: Hey all, Hello, I'm new with Perl and need help with this simple script. I'm still playing around with the script below to get a feel for Perl. My script below is

Re: Array Manipulation newbie

2007-10-29 Thread Greg
Thank you, Tom, that is exactly what I was looking for!! Thanks again! -Greg -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: array within array

2007-10-29 Thread Beginner
On 29 Oct 2007 at 8:42, Mike Tran wrote: Hey all, I'm new with Perl and need help with this simple script. I'm still playing around with the script below to get a feel for Perl. My script below is incomplete and I'm doing an array within an array which is incorrect. Please help.

RE: array within array

2007-10-29 Thread Andrew Curry
PROTECTED] Sent: 29 October 2007 15:30 To: beginners @ perl. org Subject: Re: array within array On 29 Oct 2007 at 8:42, Mike Tran wrote: Hey all, I'm new with Perl and need help with this simple script. I'm still playing around with the script below to get a feel for Perl. My script

Re: array within array

2007-10-29 Thread John W . Krahn
On Monday 29 October 2007 07:29, Beginner wrote: while (EXCLUDE) { chomp; my @fields = split(/|/,$_); ^^^ $exclude_bases{$F[0]} = 0; # $f[0] contains base_no } close(EXCLUDE); open(BASE,base.txt)|| die(Could not open file!); while (BASE) {

Re: array within array

2007-10-29 Thread Dr.Ruud
Andrew Curry schreef: be very careful with exists, it auto creates the structure use Data::Dumper; my %hash; if (exists $hash{a}{b}) {} print Dumper(\%hash) then the next time you use exists it is there. defined is much safer as it doesnt do this. No, the difference here

Re: array within array

2007-10-29 Thread John W . Krahn
On Monday 29 October 2007 06:42, Mike Tran wrote: Hey all, Hello, I'm new with Perl and need help with this simple script. I'm still playing around with the script below to get a feel for Perl. My script below is incomplete and I'm doing an array within an array which is incorrect. Please

Re: array within array

2007-10-29 Thread Ron Bergin
On Oct 29, 6:42 am, [EMAIL PROTECTED] (Mike Tran) wrote: Hey all, I'm new with Perl and need help with this simple script. I'm still playing around with the script below to get a feel for Perl. My script below is incomplete and I'm doing an array within an array which is incorrect. Please

RE: array within array

2007-10-29 Thread Mike Tran
beginners Subject: Re: array within array On Monday 29 October 2007 06:42, Mike Tran wrote: Hey all, Hello, I'm new with Perl and need help with this simple script. I'm still playing around with the script below to get a feel for Perl. My script below is incomplete and I'm doing an array within

Re: Array Manipulation

2007-10-27 Thread John W . Krahn
On Thursday 25 October 2007 11:03, [EMAIL PROTECTED] wrote: Hi Hello, Please do not top-post, TIA. This will do what you want:- perl -le '@test=(1,2,3,4,5);print join \n,@test;' The -l option ensures a final newline after the last element of the array is printed. The order of the

Re: Array Manipulation

2007-10-25 Thread Dyana Wu
On 25 Oct 2007, at 4:59 PM, Sayed, Irfan (Irfan) wrote: Hi All, I have one array say my @test=(1,2,3,4,5); if I print this array it will print like this print @test\n; and the output is 1 2 3 4 5 so I mean to say that if I type print @test1\n; then output should come as 1 2 3 4 5 Try map:

Re: Array Manipulation

2007-10-25 Thread Gunnar Hjalmarsson
Sayed, Irfan (Irfan) wrote: I have one array say my @test=(1,2,3,4,5); if I print this array it will print like this print @test\n; and the output is 1 2 3 4 5 now my req. is that I want to store these array values in another array in such a fashion where I can print like 1 2 3 4 5 so I

RE: Array Manipulation

2007-10-25 Thread Sayed, Irfan (Irfan)
guide. Thanks in Advance. Regards Irfan. -Original Message- From: Gunnar Hjalmarsson [mailto:[EMAIL PROTECTED] Sent: Thursday, October 25, 2007 5:06 PM To: beginners@perl.org Subject: Re: Array Manipulation Sayed, Irfan (Irfan) wrote: I have one array say my @test=(1,2,3,4,5); if I print

Re: Array Manipulation

2007-10-25 Thread Ron Bergin
On Oct 25, 1:59 am, [EMAIL PROTECTED] (Irfan Sayed) wrote: Hi All, I have one array say my @test=(1,2,3,4,5); if I print this array it will print like this print @test\n; and the output is 1 2 3 4 5 now my req. is that I want to store these array values in another array in such a fashion

Re: Array Manipulation

2007-10-25 Thread [EMAIL PROTECTED]
On Oct 25, 4:21 pm, [EMAIL PROTECTED] (Ron Bergin) wrote: print $_,$/ for @test; Nothing wrong with that, but I usually write: print $_\n for @test; TMTOWTDI! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/

Re: Array Manipulation

2007-10-25 Thread asmith9983
Hi This will do what you want:- perl -le '@test=(1,2,3,4,5);print join \n,@test;' The -l option ensures a final newline after the last element of the array is printed. The order of the options is important as changing it to el wouldn't work. -- Andrew Edinburgh,Scotland On Thu, 25 Oct

Re: Array Manipulation

2007-10-25 Thread Greg
Similar issue here, but with a twist. I have an input file that I'm reading in that is pipe delimited. (HL7 actually) So far I have my @record = split (/\|/,$_); I want to take $record[16] and replace it with $record[16] / $record[7] ONLY if $record[7] is not empty. I have this accomplished by

Re: Array Manipulation newbie

2007-10-25 Thread Tom Phoenix
On 10/25/07, Greg [EMAIL PROTECTED] wrote: my @record = split (/\|/,$_); #split on '|' characters My question comes in, how do I put the |'s back in the line in memory so that I can continue with my working script? I think you're looking for join(), maybe something like this: my $line =

Re: array index

2007-09-12 Thread Pavanvithal Torvi
Hi All, Thanks a lot for the advice/help. I think it would be better to avoid using this feature :) Regards, Pavan On 9/11/07, Jeff Pang [EMAIL PROTECTED] wrote: 2007/9/11, Pavanvithal Torvi [EMAIL PROTECTED]: I wanted to ask others if this is expected behaviour. Yes. If I make use

Re: array index

2007-09-12 Thread Chas Owens
On 9/11/07, Pavanvithal Torvi [EMAIL PROTECTED] wrote: Hi All, Thanks a lot for the advice/help. I think it would be better to avoid using this feature :) snip It is perfectly safe to use negative indexes. Perl 6 won't be out for a while and this feature change is one of the smaller

RE: array index

2007-09-11 Thread Thomas Bätzler
Pavanvithal Torvi [EMAIL PROTECTED] asked: While debugging a script I came across a scenario where array access was happening with a negative index. (because of a corner case that was not properly handled). This resulted in accessing the array in a reverse order. [...] I wanted to ask

Re: array index

2007-09-11 Thread Jeff Pang
2007/9/11, Pavanvithal Torvi [EMAIL PROTECTED]: I wanted to ask others if this is expected behaviour. Yes. If I make use of this feature will it cause compatibility issues with the later versions of perl. Please don't use $a and $b as variable names,they are built-in variables used by

Re: array index

2007-09-11 Thread Chas Owens
On 9/10/07, Pavanvithal Torvi [EMAIL PROTECTED] wrote: snip If I make use of this feature will it cause compatibility issues with the later versions of perl. snip Negative indexing has been around at least since Perl 5 (and I think it goes back much farther than that). As for compatibility

Re: array index

2007-09-11 Thread Jenda Krynicky
On 11 Sep 2007 at 13:04, Chas Owens wrote: Negative indexing has been around at least since Perl 5 (and I think it goes back much farther than that). As for compatibility with future versions of Perl, you should have no problem with the Perl 5 line (e.g. 5.10, the next and possibly last Perl

Re: array index

2007-09-11 Thread Chas Owens
On 9/11/07, Jenda Krynicky [EMAIL PROTECTED] wrote: snip OH MY ! Yet another reason to stay away from Perl6. After reading that part of S09 I can't keep from thinking that Perl6 was designed specifically for golf and obfu. Well *. snip Heh. Perl 6 is going to meet a lot of resistance, but

Re: Array modification

2007-08-16 Thread Xavier Noria
On Aug 16, 2007, at 11:47 AM, Sayed, Irfan (Irfan) wrote: I have one array which stores some data after executing specific command. Depends on situation , command has different output at different time. sometime array may store 4 values or it may store 5 values. Now my req. is that I need to

Re: Array modification

2007-08-16 Thread Chas Owens
On 8/16/07, Sayed, Irfan (Irfan) [EMAIL PROTECTED] wrote: Hi All, I have one array which stores some data after executing specific command. Depends on situation , command has different output at different time. sometime array may store 4 values or it may store 5 values. Now my req. is that

RE: Array modification

2007-08-16 Thread Sayed, Irfan (Irfan)
programme should pick up the third element of the array Please help Regards Irfan. -Original Message- From: Chas Owens [mailto:[EMAIL PROTECTED] Sent: Thursday, August 16, 2007 4:16 PM To: Sayed, Irfan (Irfan) Cc: beginners@perl.org Subject: Re: Array modification On 8/16/07, Sayed

Re: Array modification

2007-08-16 Thread Chas Owens
On 8/16/07, Sayed, Irfan (Irfan) [EMAIL PROTECTED] wrote: Thanks Chas but my req. is little bit different. As I said the data in the array will not be fixed so I don't know how many elements are present in the array. I don't want to just print the contents of the array but to use the contents

Re: Array to Hash

2007-08-13 Thread Ken Foskey
On Sun, 2007-08-12 at 22:55 -0400, yitzle wrote: I got an array of values where the order is relevent, eg the ages of Alice, Bob and Charles, and I want to make a hash out of it. I got this code that does it: my %ages = (alice = $r[0], bob = $r[1], charles = $r[2]); Is there a more elegent

Re: Array to Hash

2007-08-13 Thread Mr. Shawn H. Corey
Ken Foskey wrote: On Sun, 2007-08-12 at 22:55 -0400, yitzle wrote: I got an array of values where the order is relevent, eg the ages of Alice, Bob and Charles, and I want to make a hash out of it. I got this code that does it: my %ages = (alice = $r[0], bob = $r[1], charles = $r[2]); Is there

Re: Array to Hash

2007-08-13 Thread Paul Lalli
On Aug 13, 9:40 am, [EMAIL PROTECTED] (Ken Foskey) wrote: On Sun, 2007-08-12 at 22:55 -0400, yitzle wrote: I got an array of values where the order is relevent, eg the ages of Alice, Bob and Charles, and I want to make a hash out of it. I got this code that does it: my %ages = (alice =

Re: Array to Hash

2007-08-13 Thread Ken Foskey
On Mon, 2007-08-13 at 07:47 -0700, Paul Lalli wrote: On Aug 13, 9:40 am, [EMAIL PROTECTED] (Ken Foskey) wrote: On Sun, 2007-08-12 at 22:55 -0400, yitzle wrote: I got an array of values where the order is relevent, eg the ages of Alice, Bob and Charles, and I want to make a hash out of it.

Re: Array to Hash

2007-08-12 Thread Jeff Pang
-Original Message- From: yitzle [EMAIL PROTECTED] Sent: Aug 12, 2007 10:55 PM To: beginners@perl.org beginners@perl.org Subject: Array to Hash I got an array of values where the order is relevent, eg the ages of Alice, Bob and Charles, and I want to make a hash out of it. I got this

Re: Array reformatting problem

2007-08-09 Thread Mr. Shawn H. Corey
minky arora wrote: Hello Team, I have a problem and I need some ideas to put me on the right track to form an algo: I have four 8x12 arrays (Arr1,Arr2, Arr3,Arr4) and ONE 16x24 (ARR5) array. Now these four arrays are formatted in a particular way by a robot( these are actually plates with

Re: Array reformatting problem

2007-08-09 Thread [EMAIL PROTECTED]
On Aug 9, 5:38 pm, [EMAIL PROTECTED] (Mr. Shawn H. Corey) wrote: minky arora wrote: Hello Team, I have a problem and I need some ideas to put me on the right track to form an algo: I have four 8x12 arrays (Arr1,Arr2, Arr3,Arr4) and ONE 16x24 (ARR5) array. Now these four arrays are

Re: Array reformatting problem

2007-08-09 Thread [EMAIL PROTECTED]
On Aug 9, 5:13 pm, [EMAIL PROTECTED] (Minky Arora) wrote: Hello Team, I have a problem and I need some ideas to put me on the right track to form an algo: I have four 8x12 arrays (Arr1,Arr2, Arr3,Arr4) and ONE 16x24 (ARR5) array. Please define I have. You are not talking about arrays in

Re: array assignement

2007-07-24 Thread Paul Lalli
On Jul 23, 4:35 am, [EMAIL PROTECTED] (Jeevs) wrote: I just wanted to know what does the following line do @{$args{owner}} = qw(hero wierd); lets assume $args{owner} = 'sachin'; Then it would mean @{sachin} = qw(hero wierd); what would {sachin} stand for does it mean an hash refernce or

Re: array assignement

2007-07-24 Thread Paul Lalli
On Jul 23, 1:51 pm, [EMAIL PROTECTED] (John W. Krahn) wrote: John W. Krahn wrote: jeevs wrote: I just wanted to know what does the following line do @{$args{owner}} = qw(hero wierd); You are assigning a list to the anonymous array in $args{owner}. lets assume $args{owner} =

Re: array assignement

2007-07-23 Thread John W. Krahn
jeevs wrote: Hi forum! Hello, I just wanted to know what does the following line do @{$args{owner}} = qw(hero wierd); You are assigning a list to the anonymous array in $args{owner}. lets assume $args{owner} = 'sachin'; 'sachin' is a scalar value. Then it would mean @{sachin} =

Re: array assignement

2007-07-23 Thread John W. Krahn
John W. Krahn wrote: jeevs wrote: I just wanted to know what does the following line do @{$args{owner}} = qw(hero wierd); You are assigning a list to the anonymous array in $args{owner}. lets assume $args{owner} = 'sachin'; 'sachin' is a scalar value. Then it would mean @{sachin}

<    1   2   3   4   5   6   7   >