Re: Iterating over Arrays

2022-09-26 Thread William Torrez Corea
On Sun, Sep 25, 2022 at 12:02 PM Mike wrote: > > Your version produces this output in Perl 5.30.0: > > this > that > Use of uninitialized value $element in concatenation (.) or string at > trash.pl line 14. > > Use of uninitialized value $element in concatenation (.) or string at > trash.pl line

Re: Iterating over Arrays

2022-09-25 Thread Mike
Your version produces this output in Perl 5.30.0: this that Use of uninitialized value $element in concatenation (.) or string at trash.pl line 14. Use of uninitialized value $element in concatenation (.) or string at trash.pl line 14. Use of uninitialized value $element in concatenation (

Re: Iterating over Arrays

2022-09-24 Thread Ken Peng
Hello Try with this code: use strict; use warnings; use Data::Dumper; my @words = ("this","that"); # With this code $words[5] = "bad idea"; print Dumper \@words; And it outputs: $VAR1 = [ 'this', 'that', undef, undef, undef, 'bad i

Iterating over Arrays

2022-09-24 Thread William Torrez Corea
What happen with my code? use strict; use warnings; use diagnostics; my @words = ("this","that"); # With this code $words[5] = "bad idea"; for my $element (@words){ print "$element\n"; } ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ "words.pl" 13L, 167B 1,1

Re: How to navigate through a hash of hashes of arrays (?) to get to the first array entry

2016-04-15 Thread Shlomi Fish
Hi Raj, On Thu, 14 Apr 2016 16:15:08 + Raj Barath wrote: > I was wrong. Please don't use my example. > Aaron wells explanation is perfect. > Thanks for admitting you were wrong - many people fail to do so. I agree that Aaron Wells's explanation appears to be very good, and one can find mor

Re: How to navigate through a hash of hashes of arrays (?) to get to the first array entry

2016-04-14 Thread Raj Barath
rayref[0], or $arrayref->[0] @one_val_slice = @{ $arrayref }[0]; # or @$arrayref[0], or ( $arrayref->[0] ) @three_val_slice = @{ $arrayref }[0..2]; # or @$arrayref[0..2] Fundamentally, arrays and hashes can only hold scalar values. All a hash ref or array ref is, is a scalar value that act

Re: How to navigate through a hash of hashes of arrays (?) to get to the first array entry

2016-04-14 Thread Raj Barath
rayref[0], or $arrayref->[0] @one_val_slice = @{ $arrayref }[0]; # or @$arrayref[0], or ( $arrayref->[0] ) @three_val_slice = @{ $arrayref }[0..2]; # or @$arrayref[0..2] Fundamentally, arrays and hashes can only hold scalar values. All a hash ref or array ref is, is a scalar value that act

Re: How to navigate through a hash of hashes of arrays (?) to get to the first array entry

2016-04-14 Thread Aaron Wells
ef $count = @{ $arrayref }; # or, @$arrayref $single_val = ${ $arrayref }[0]; # or $$arrayref[0], or $arrayref->[0] @one_val_slice = @{ $arrayref }[0]; # or @$arrayref[0], or ( $arrayref->[0] ) @three_val_slice = @{ $arrayref }[0..2]; # or @$arrayref[0..2] Fundamentally, arrays and hashes ca

Re: How to navigate through a hash of hashes of arrays (?) to get to the first array entry

2016-04-14 Thread Shlomi Fish
Hello Raj, On Thu, 14 Apr 2016 03:52:56 + Raj Barath wrote: > Hello Kenneth, > > Check this out: > > use v5.22; > use Data::Dumper; > > my $VAR1; > > $VAR1 = [ > bless( { >'Id' => [ >'01tC003udXAIAY', >

Re: How to navigate through a hash of hashes of arrays (?) to get to the first array entry

2016-04-14 Thread Raj Barath
Hello Kenneth, Check this out: use v5.22; use Data::Dumper; my $VAR1; $VAR1 = [ bless( { 'Id' => [ '01tC003udXAIAY', '01tC003udXAIAY' ], 'type' => 'Product2'

Re: How to navigate through a hash of hashes of arrays (?) to get to the first array entry

2016-04-14 Thread Raj Barath
Hello Kenneth, Check this out: use v5.22; use Data::Dumper; my $VAR1; $VAR1 = [ bless( { 'Id' => [ '01tC003udXAIAY', '01tC003udXAIAY' ], 'type' => 'Product2'

Re: How to navigate through a hash of hashes of arrays (?) to get to the first array entry

2016-04-13 Thread Kenneth Wolcott
On Wed, Apr 13, 2016 at 7:13 PM, Ken Slater wrote: > > On Wed, Apr 13, 2016 at 9:29 PM, Kenneth Wolcott > wrote: >> >> Hi; >> >> I have the following output from Data::Dumper and I want to extract >> the first string that the "Id" name points to. >> >> $VAR1 = [ >> bless( { >>

Re: How to navigate through a hash of hashes of arrays (?) to get to the first array entry

2016-04-13 Thread Lawrence Statton
On 04/13/2016 08:29 PM, Kenneth Wolcott wrote: Hi; I have the following output from Data::Dumper and I want to extract the first string that the "Id" name points to. $VAR1 = [ bless( { 'Id' => [ '01tC003udXAIAY',

Re: How to navigate through a hash of hashes of arrays (?) to get to the first array entry

2016-04-13 Thread Ken Slater
On Wed, Apr 13, 2016 at 9:29 PM, Kenneth Wolcott wrote: > Hi; > > I have the following output from Data::Dumper and I want to extract > the first string that the "Id" name points to. > > $VAR1 = [ > bless( { >'Id' => [ >'01tC003udXAI

How to navigate through a hash of hashes of arrays (?) to get to the first array entry

2016-04-13 Thread Kenneth Wolcott
Hi; I have the following output from Data::Dumper and I want to extract the first string that the "Id" name points to. $VAR1 = [ bless( { 'Id' => [ '01tC003udXAIAY', '01tC003udXAIAY'

Re: returning arrays

2016-02-21 Thread lee
return ($a, $b); >>>> } >>>> >>>> >>>> anymore because you could, by mistake (or intentionally), write >>>> >>>> >>>> my $x = s; >>>> >>>> >>>> . So let me re-phrase my

Re: returning arrays

2016-02-21 Thread lee
Kent Fredric writes: > On 26 January 2016 at 12:02, Nathan Hilterbrand wrote: >> return wantarray() ? ($a, $b) : [$a, $b]; >> >> In a list context, you get back a list.. otherwise you get back a reference >> to a list. Might not be what you want, though. &

Re: returning arrays

2016-01-25 Thread Kent Fredric
On 26 January 2016 at 12:02, Nathan Hilterbrand wrote: > return wantarray() ? ($a, $b) : [$a, $b]; > > In a list context, you get back a list.. otherwise you get back a reference > to a list. Might not be what you want, though. > > Works with arrays, too.. > > my @a

Re: returning arrays

2016-01-25 Thread Nathan Hilterbrand
like sub s { my $a = 1; my $b = 3; return ($a, $b); } anymore because you could, by mistake (or intentionally), write my $x = s; . So let me re-phrase my original question to: How do you /safely/ return arrays? That means I need an error message for '$x = s;' because

Re: returning arrays

2016-01-25 Thread lee
Shlomi Fish writes: > Hi lee, > > I should note that it is my impression that you are far too needy in your > enquiring, and I'm starting to lose patience. > > On Mon, 25 Jan 2016 00:11:43 +0100 > lee wrote: > >> Shlomi Fish writes: >> >> >> > >> >> > In scalar context the comma operator evalu

Re: returning arrays

2016-01-25 Thread lee
s like >> >> >> sub s { >> my $a = 1; >> my $b = 3; >> >>return ($a, $b); >> } >> >> >> anymore because you could, by mistake (or intentionally), write >> >> >> my $x = s; >> >> >

Re: returning arrays

2016-01-25 Thread Paul Johnson
use it to create convoluted code, which is usually not my intention. > > Consider with these examples that an expression like (1, 3) might > unexpectedly evaluate to 3, and you start to think that you don't like > things like > > > sub s { > my $a = 1; > my $

Re: returning arrays

2016-01-25 Thread Shlomi Fish
Hi lee, I should note that it is my impression that you are far too needy in your enquiring, and I'm starting to lose patience. On Mon, 25 Jan 2016 00:11:43 +0100 lee wrote: > Shlomi Fish writes: > > >> > > >> > In scalar context the comma operator evaluates its left-hand side, > >> > throws

Re: returning arrays

2016-01-24 Thread lee
create convoluted code, which is usually not my intention. Consider with these examples that an expression like (1, 3) might unexpectedly evaluate to 3, and you start to think that you don't like things like sub s { my $a = 1; my $b = 3; return ($a, $b); } anymore becau

Re: returning arrays

2016-01-24 Thread lee
Shlomi Fish writes: >> > >> > In scalar context the comma operator evaluates its left-hand side, >> > throws it away and returns the right-hand side. >> >> What is the useful use for this operator? >> > > Well, I believe its use was originally inherited from > https://en.wikipedia.org/wiki/C_

Re: returning arrays

2016-01-24 Thread Shlomi Fish
On Sun, 24 Jan 2016 20:03:29 +0100 Paul Johnson wrote: > On Sun, Jan 24, 2016 at 05:44:14PM +0200, Shlomi Fish wrote: > > Hi lee, > > > > On Sun, 24 Jan 2016 13:11:37 +0100 > > lee wrote: > > > > > Paul Johnson writes: > > > > > > > > In scalar context the comma operator evaluates its lef

Re: returning arrays

2016-01-24 Thread Paul Johnson
On Sun, Jan 24, 2016 at 05:44:14PM +0200, Shlomi Fish wrote: > Hi lee, > > On Sun, 24 Jan 2016 13:11:37 +0100 > lee wrote: > > > Paul Johnson writes: > > > > > > In scalar context the comma operator evaluates its left-hand side, > > > throws it away and returns the right-hand side. > > > > W

Re: returning arrays

2016-01-24 Thread Shlomi Fish
Hi lee, On Sun, 24 Jan 2016 13:11:37 +0100 lee wrote: > Paul Johnson writes: > > > On Tue, Sep 09, 2014 at 03:12:00PM -0700, Jim Gibson wrote: > >> > >> On Sep 9, 2014, at 2:57 PM, Shawn H Corey wrote: > >> > >> > On Tue, 09 Sep 2014 23:09:52 +0200 > >> > lee wrote: > >> > > >> >> my

Re: returning arrays

2016-01-24 Thread lee
Paul Johnson writes: > On Tue, Sep 09, 2014 at 03:12:00PM -0700, Jim Gibson wrote: >> >> On Sep 9, 2014, at 2:57 PM, Shawn H Corey wrote: >> >> > On Tue, 09 Sep 2014 23:09:52 +0200 >> > lee wrote: >> > >> >> my $i = 1; >> >> my $f = 2.5; >> >> my $s = 'string'; >> >> my $list = (1, 2, 3); >>

Re: help with Hash of arrays of arrays

2015-07-02 Thread Илья Рассадин
seful from your problem domain). Final code https://gist.github.com/elcamlost/54f32cd48ae1106052e0 чт, 2 июля 2015 г. в 13:03, Nathalie Conte : > HI Shlomi, > Thanks for your comments about best practise which I have implemented, Any > ideas on why my hash of arrays of arrays is misbehavin

Re: help with Hash of arrays of arrays

2015-07-02 Thread Nathalie Conte
HI Shlomi, Thanks for your comments about best practise which I have implemented, Any ideas on why my hash of arrays of arrays is misbehaving? Thanks Nat On 1 Jul 2015, at 15:42, Shlomi Fish wrote: > Hi Nat, > > some comments about your code. > > On Wed, 1 Jul 2015 13:00

Re: help with Hash of arrays of arrays

2015-07-01 Thread Shlomi Fish
data10 > gene bal3 data5 data6 data12 > gene bal4 data7 data8 data12 > > I take each data variable, see above, from a sql query and parse the data > to build a new data structure: a hash of arrays of arrays. > In the input data presented here, the fi

help with Hash of arrays of arrays

2015-07-01 Thread nconte
and parse the data to build a new data structure: a hash of arrays of arrays. In the input data presented here, the first column will be the key of the hash and the other 4 columns should compose 4 arrays. example :Each gene (gene a gene b ..) should be the keys, the al column should be the first

RE: reading a hash of arrays

2014-11-19 Thread Frank K.
Subject: Re: reading a hash of arrays On Wed, 19 Nov 2014 17:03:40 -0600 "Frank K." wrote: > I can't do @array1 = @hash{one}; @array1 = @{ $hash{one} }; $hash{one} contains a reference to an array. By dereferencing it with @{ ... }, you get the array. -- Don't

Re: reading a hash of arrays

2014-11-19 Thread Shawn H Corey
On Wed, 19 Nov 2014 17:03:40 -0600 "Frank K." wrote: > I can't do @array1 = @hash{one}; @array1 = @{ $hash{one} }; $hash{one} contains a reference to an array. By dereferencing it with @{ ... }, you get the array. -- Don't stop where the ink does. Shawn -- To unsubscribe, e-mail: b

reading a hash of arrays

2014-11-19 Thread Frank K.
Have a hash of arrays.. i.e. $hash{one}[0] = "value 10"; $hash{one}[1] = "value 11"; $hash{one}[2] = "value 11"; $hash{one}[3] = "value 13"; $hash{one}[0] = "value 20"; $hash{one}[1] = "value 21"; $hash{one}[2] = "value 22&

Re: Difference between list and arrays.

2014-09-16 Thread Paul Johnson
On Tue, Sep 16, 2014 at 02:43:28PM -0500, Andy Bach wrote: > On Tue, Sep 16, 2014 at 1:45 PM, Paul Johnson wrote: > > > The comma operator evaluates its LHS, throws it away, evaluates its RHS > > and returns that. The comma operator is left associative (see perlop). > > > > So the result of eval

Re: Difference between list and arrays.

2014-09-16 Thread Andy Bach
On Tue, Sep 16, 2014 at 1:45 PM, Paul Johnson wrote: > The comma operator evaluates its LHS, throws it away, evaluates its RHS > and returns that. The comma operator is left associative (see perlop). > > So the result of evaluating the RHS (1, 2, 3) is: > > (1, 2, 3) -> ((1, 2), 3) -> (2, 3) -

Re: Difference between list and arrays.

2014-09-16 Thread Paul Johnson
On Tue, Sep 16, 2014 at 12:12:05PM -0500, Andy Bach wrote: >The other thing to think > about is "context" - the LHS of the assigning "=" determines how the RHS > list is treated. So far, so good. Well, almost ... > In scalar c

Re: Difference between list and arrays.

2014-09-16 Thread Andy Bach
On Tue, Sep 16, 2014 at 4:22 AM, Uday Vernekar wrote: > Confusion on array and list. can anybody explain me the difference between > list and arrays. > > my @xyz = ( 4, 5, 6 ); > > The right-hand side of the equals sign is a list.here I assign that list > to the variable

Difference between list and arrays.

2014-09-16 Thread Uday Vernekar
Confusion on array and list. can anybody explain me the difference between list and arrays. my @xyz = ( 4, 5, 6 ); The right-hand side of the equals sign is a list.here I assign that list to the variable @xyz. its an array,list can be assigned to an array. on similiar lines we can assign Lists

Re: returning arrays

2014-09-09 Thread Paul Johnson
On Tue, Sep 09, 2014 at 03:12:00PM -0700, Jim Gibson wrote: > > On Sep 9, 2014, at 2:57 PM, Shawn H Corey wrote: > > > On Tue, 09 Sep 2014 23:09:52 +0200 > > lee wrote: > > > >> my $i = 1; > >> my $f = 2.5; > >> my $s = 'string'; > >> my $list = (1, 2, 3); > > > > No, the count of items in the

Re: returning arrays

2014-09-09 Thread Shawn H Corey
man wrote: > to be a little more exact, lists live only in expressions and are on > the stack. arrays can live between statements and are allocated from > the heap. That isn't much help since the Perl documentation does not mention the calling stack or the heap (except `perldoc pe

Re: returning arrays

2014-09-09 Thread Uri Guttman
On 09/09/2014 06:01 PM, John SJ Anderson wrote: On Tue, Sep 9, 2014 at 2:57 PM, Shawn H Corey wrote: Lists are sequences used by Perl. They are very short lived, seldom longer than one statement. The way I've always liked to explain this is that arrays are the containers you use to st

Re: returning arrays

2014-09-09 Thread Jim Gibson
On Sep 9, 2014, at 2:57 PM, Shawn H Corey wrote: > On Tue, 09 Sep 2014 23:09:52 +0200 > lee wrote: > >> my $i = 1; >> my $f = 2.5; >> my $s = 'string'; >> my $list = (1, 2, 3); > > No, the count of items in the list gets stored in $list: $list == 3 Unless the thing on the right-hand-side of t

Re: returning arrays

2014-09-09 Thread Jim Gibson
t;> elements. References are scalars. >> >> The second example returns ( 1, 2, 3 ), which is a list with 3 elements. >> >> So, yes, there is a difference. > > Hm, so what way of thinking is behind this, and how do you declare an > array? Perls 1-4 (I believ

Re: returning arrays

2014-09-09 Thread John SJ Anderson
On Tue, Sep 9, 2014 at 2:57 PM, Shawn H Corey wrote: > Lists are sequences used by Perl. They are very short lived, seldom > longer than one statement. The way I've always liked to explain this is that arrays are the containers you use to store a list. As Shawn says, a list is usu

Re: returning arrays

2014-09-09 Thread Shawn H Corey
ence; my @dereferenced_list = @$list_reference > my @artificial_array = $@list_reference; my @artificial_array = @$list_reference; > my @true_array = ? > > > I'm finding this very confusing. What's the benefit of using extra > designators for some types of variables (ar

Re: returning arrays

2014-09-09 Thread lee
reference; my @true_array = ? I'm finding this very confusing. What's the benefit of using extra designators for some types of variables (arrays) while not even having any at all for some others (lists)? >> ? And my understanding was/is that in >> >> sub myfunc { >

Re: returning arrays (was: Re: return the list content)

2014-09-08 Thread Shawn H Corey
On Tue, 09 Sep 2014 00:13:13 +0200 lee wrote: > Shawn H Corey writes: > > > On Mon, 18 Aug 2014 16:17:53 +0800 > > Ken Peng wrote: > > > >> sub myfunc { > >> my @x=(1,2,3); > >> return \@x; > >> } > >> > >> # or, > >> > >> sub myfunc { > >> my @x=(1,2,3); > >> return [@x]; > >> } > >

Re: returning arrays (was: Re: return the list content)

2014-09-08 Thread Jim Gibson
On Sep 8, 2014, at 3:13 PM, lee wrote: > Shawn H Corey writes: > >> On Mon, 18 Aug 2014 16:17:53 +0800 >> Ken Peng wrote: >> >>> sub myfunc { >>> my @x=(1,2,3); >>> return \@x; >>> } >>> >>> # or, >>> >>> sub myfunc { >>> my @x=(1,2,3); >>> return [@x]; >>> } >> >> # or >> >> sub myfu

returning arrays (was: Re: return the list content)

2014-09-08 Thread lee
Shawn H Corey writes: > On Mon, 18 Aug 2014 16:17:53 +0800 > Ken Peng wrote: > >> sub myfunc { >> my @x=(1,2,3); >> return \@x; >> } >> >> # or, >> >> sub myfunc { >> my @x=(1,2,3); >> return [@x]; >> } > > # or > > sub myfunc { > return [ 1, 2, 3 ]; > } Is there a difference to su

Re: List::MoreUtils with array of arrays not working

2014-07-10 Thread Jim Gibson
On Jul 10, 2014, at 11:50 AM, Natxo Asenjo wrote: > On Thu, Jul 10, 2014 at 1:00 AM, Jim Gibson wrote: > > On Jul 9, 2014, at 2:58 PM, Natxo Asenjo wrote: > > On Wed, Jul 9, 2014 at 10:35 PM, Jim Gibson wrote: > > On Jul 9, 2014, at 1:20 PM, Natxo Asenjo wrote: > > In order to use the hash m

Re: List::MoreUtils with array of arrays not working

2014-07-10 Thread Natxo Asenjo
On Thu, Jul 10, 2014 at 1:00 AM, Jim Gibson wrote: > > On Jul 9, 2014, at 2:58 PM, Natxo Asenjo wrote: > > On Wed, Jul 9, 2014 at 10:35 PM, Jim Gibson > wrote: > > On Jul 9, 2014, at 1:20 PM, Natxo Asenjo wrote: > > In order to use the hash method of determining uniqueness, you must > convert

RE: Creating a hash of arrays from

2014-07-10 Thread Sunita Pradhan
}; I guess you want output something like this . > From: p...@surfshopcart.com > Subject: Creating a hash of arrays from > Date: Wed, 9 Jul 2014 18:59:58 -0700 > To: beginners@perl.org > > I'm having a problem creating a hash of arrays. The while loop below > works,

Re: Creating a hash of arrays from

2014-07-10 Thread SSC_perl
On Jul 10, 2014, at 9:00 AM, Ron Bergin wrote: > my($state, @zipcodes) = split /[=,]/, $line; Interesting concept, the multiple split. I'd be interested in knowing how Perl knows to give the singular value on the left of the "=" to $state and all other values split on the "," to @zipcod

Re: Creating a hash of arrays from

2014-07-10 Thread Ron Bergin
Ron Bergin wrote: > Others have already pointed what you were doing wrong, so I'll point out > something else. > > Instead of using 2 separate split statements, I'd use a single split > statement to assign $state and a @zipcodes array. > > use 5.010; > use strict; > use warnings; > use Data::Dumpe

Re: Creating a hash of arrays from

2014-07-10 Thread Ron Bergin
SSC_perl wrote: > If someone could explain what I'm doing wrong, I'd appreciate it. I > just > can't see it. > > Thanks, > Frank > > -- > > use strict; > use warnings; > use 5.010; > > use Data::Dumper; > > my %entries; > > while (my $line = ) { > chomp $line;

Re: Creating a hash of arrays from

2014-07-10 Thread Nathan Hilterbrand
Hi Frank On 07/10/2014 11:02 AM, SSC_perl wrote: On Jul 10, 2014, at 7:14 AM, Nathan Hilterbrand wrote: $entries{$state} = [ (split /,/ => $zipcodes) ]; Thanks, Nathan. The line above caught my eye. It's interesting to see that you don't need both 'push' and 'split' to populate th

Re: Creating a hash of arrays from

2014-07-10 Thread SSC_perl
On Jul 10, 2014, at 7:14 AM, Nathan Hilterbrand wrote: > $entries{$state} = [ (split /,/ => $zipcodes) ]; Thanks, Nathan. The line above caught my eye. It's interesting to see that you don't need both 'push' and 'split' to populate the hash. Could you explain a little about wh

Re: Creating a hash of arrays from

2014-07-09 Thread SSC_perl
On Jul 9, 2014, at 7:56 PM, John SJ Anderson wrote: > This foreach loop is looping over the five zip codes in the array... > >> print Dumper (@{$entries{$state}}); > > And printing out the same array each time. Thanks, John. I wasn't even looking at the printout loop. :\ For so

Re: Creating a hash of arrays from

2014-07-09 Thread John SJ Anderson
On Wed, Jul 9, 2014 at 6:59 PM, SSC_perl wrote: > If someone could explain what I'm doing wrong, I'd appreciate it. I > just can't see it. You're looping over the entries in the array, not the entries in the hash. > foreach my $state (sort keys %entries) { > say "The Zip Codes of $

Creating a hash of arrays from

2014-07-09 Thread SSC_perl
I'm having a problem creating a hash of arrays. The while loop below works, but it's working too well. ;) Instead of giving me 5 values (from the example data below), it's giving me 25. I don't understand why it seems to be "looping" through the push

Re: List::MoreUtils with array of arrays not working

2014-07-09 Thread Jim Gibson
On Jul 9, 2014, at 2:58 PM, Natxo Asenjo wrote: > > > > On Wed, Jul 9, 2014 at 10:35 PM, Jim Gibson wrote: > > On Jul 9, 2014, at 1:20 PM, Natxo Asenjo wrote: > > > hi, > > > > i have an array of arrays which contains equal elements. I would like to

Re: List::MoreUtils with array of arrays not working

2014-07-09 Thread Natxo Asenjo
On Wed, Jul 9, 2014 at 10:35 PM, Jim Gibson wrote: > > On Jul 9, 2014, at 1:20 PM, Natxo Asenjo wrote: > > > hi, > > > > i have an array of arrays which contains equal elements. I would like to > isolate the unique values. > > Do you mean that the subarra

Re: List::MoreUtils with array of arrays not working

2014-07-09 Thread Jim Gibson
On Jul 9, 2014, at 1:20 PM, Natxo Asenjo wrote: > hi, > > i have an array of arrays which contains equal elements. I would like to > isolate the unique values. Do you mean that the subarrays contain equal NUMBERS of elements? > > I have tried using the uniq method of List

List::MoreUtils with array of arrays not working

2014-07-09 Thread Natxo Asenjo
hi, i have an array of arrays which contains equal elements. I would like to isolate the unique values. I have tried using the uniq method of List::MoreUtils but it apparently does not work with an AoA. This is what I tried: for my $i ( @$data_ref ) { push $seen_ref, [ $i->{'valu

Re: How do I pass arrays into a subroutine

2013-09-07 Thread Karol Bujaček
my @animals = @$animals; # dereference my @digits = @$digits; # dereference The comment is inaccurate. Why would you want to copy the arrays? Because I don't want to change an array by my subroutine, as Shawn H Corey answered already. Well, this may or may not be eventual's intentio

Re: How do I pass arrays into a subroutine

2013-09-07 Thread Shawn H Corey
> >my @animals = @$animals; # dereference > >my @digits = @$digits; # dereference > > The comment is inaccurate. > > Why would you want to copy the arrays? So you could can their contents without the contents of the arrays in the caller being changed. > >

Re: How do I pass arrays into a subroutine

2013-09-07 Thread Dr.Ruud
you want to copy the arrays? print Dumper(@animals, @digits); # just look ... Consider: print Dumper( $animals, $digits ); -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: How do I pass arrays into a subroutine

2013-09-07 Thread Karol Bujaček
On 09/07/2013 01:11 PM, eventual wrote: Hi, In the example below, how do I pass @pets and @numbers into the subroutine so that @animals = @pets and @digits = @numbers. Thanks my @pets = ('dogs' , 'cats' , 'horses'); my @numbers = (1..10); &study (@pets , @numbers); sub study { my (@animals

Re: How do I pass arrays into a subroutine

2013-09-07 Thread *Shaji Kalidasan*
Greetings, You cannot pass two arrays as the previous array will slurp (consume) all the elements. You need to go for references. Here is one way to do it [code] use strict; use warnings; my @pets = ('dogs' , 'cats' , 'horses'); my @numbers = (1..10);   &

Re: How do I pass arrays into a subroutine

2013-09-07 Thread Shlomi Fish
Hi Eventual, On Sat, 7 Sep 2013 04:11:06 -0700 (PDT) eventual wrote: > Hi, >   > In the example below, how do I pass @pets and @numbers into the subroutine so > that @animals = @pets  and > @digits = @numbers. Please look into references and pass the arrays as references. Se

How do I pass arrays into a subroutine

2013-09-07 Thread eventual
Hi,   In the example below, how do I pass @pets and @numbers into the subroutine so that @animals = @pets  and @digits = @numbers. Thanks   my @pets = ('dogs' , 'cats' , 'horses'); my @numbers = (1..10);   &study (@pets , @numbers);   sub study {   my (@animals, @digits) = (@_[0] , @_[1]);  

Re: grep array of arrays

2012-08-24 Thread Brandon McCaig
On Thu, Aug 23, 2012 at 05:19:34PM -0400, Shawn H Corey wrote: > You're trying to do too much in one statement. > > for my $coord ( @coords ){ > if( $coords->[0] >= 0 ){ > print join( q{, }, @{ $coords } ), "\n"; > } > } Looks like you're trying to do too much too. ;) You are test

Re: grep array of arrays

2012-08-23 Thread Shawn H Corey
On Thu, 23 Aug 2012 14:17:26 -0700 Jim Gibson wrote: > You could also combine print, grep, and map to accomplish the same > thing. Please don't. If you're having this much trouble getting it right, the person stuck with maintaining it will also have trouble understanding what you coded. Break it

Re: grep array of arrays

2012-08-23 Thread Shawn H Corey
On Thu, 23 Aug 2012 15:58:43 -0500 Chris Stinemetz wrote: > print grep { $_->[0] >= 0 } @coords; You're trying to do too much in one statement. for my $coord ( @coords ){ if( $coords->[0] >= 0 ){ print join( q{, }, @{ $coords } ), "\n"; } } -- Just my 0.0002 million dolla

Re: grep array of arrays

2012-08-23 Thread Jim Gibson
On Aug 23, 2012, at 1:58 PM, Chris Stinemetz wrote: >> >> >> If @coords is just an Array of Arrays then that should be: >> >> print grep { $_->[0] >= 0 } @coords; >> >> >> Your example thinks @coords is an Array of Arrays of Arrays. &g

Re: grep array of arrays

2012-08-23 Thread Chris Stinemetz
> > > If @coords is just an Array of Arrays then that should be: > > print grep { $_->[0] >= 0 } @coords; > > > Your example thinks @coords is an Array of Arrays of Arrays. > > > John > -- > print grep { $_->[0] >= 0 } @coords; Just prints the m

Re: grep array of arrays

2012-08-23 Thread Jim Gibson
On Aug 23, 2012, at 12:57 PM, Chris Stinemetz wrote: > Hello List, > I'm trying to grep an array of arrays, but I am getting the following error: > > Can't use string ("1") as an ARRAY ref while "strict refs" in use at > form.pl line 121, <

Re: grep array of arrays

2012-08-23 Thread John W. Krahn
Chris Stinemetz wrote: Hello List, Hello, I'm trying to grep an array of arrays, but I am getting the following error: Can't use string ("1") as an ARRAY ref while "strict refs" in use at form.pl line 121,<$COORDS> line 1281. Press any key to continue

grep array of arrays

2012-08-23 Thread Chris Stinemetz
Hello List, I'm trying to grep an array of arrays, but I am getting the following error: Can't use string ("1") as an ARRAY ref while "strict refs" in use at form.pl line 121, <$COORDS> line 1281. Press any key to continue . . . Below is the grep stat

Re: hash of arrays sorting

2012-08-23 Thread Salvador Fandino
$type, ref(code): " . ref($code); +next TEST; +} +} +} +my $sub = eval "sub { $init (" . join(", ", @code) . ") }"; +my $sorter = Sort::Key::multi

Re: hash of arrays sorting

2012-08-23 Thread Salvador Fandino
On 08/23/2012 09:10 AM, Uri Guttman wrote: > On 08/23/2012 02:54 AM, Salvador Fandino wrote: > >>> >>> It's a pity Sort::Maker not in Debian >> >> There is also Sort::Key, available in Debian testing and unstable, and >> which is usually faster than Sort::Maker and also Sort::Key::Radix, even >> f

Re: hash of arrays sorting

2012-08-23 Thread Rob Coops
On Thu, Aug 23, 2012 at 9:10 AM, Uri Guttman wrote: > On 08/23/2012 02:54 AM, Salvador Fandino wrote: > > >>> It's a pity Sort::Maker not in Debian >>> >> >> There is also Sort::Key, available in Debian testing and unstable, and >> which is usually faster than Sort::Maker and also Sort::Key::Radi

Re: hash of arrays sorting

2012-08-23 Thread Uri Guttman
On 08/23/2012 02:54 AM, Salvador Fandino wrote: It's a pity Sort::Maker not in Debian There is also Sort::Key, available in Debian testing and unstable, and which is usually faster than Sort::Maker and also Sort::Key::Radix, even faster when sorting by numeric keys but not available in Debian

Re: hash of arrays sorting

2012-08-22 Thread Salvador Fandino
On 08/22/2012 10:34 PM, Eduardo wrote: > On 22/08/12 03:49, Uri Guttman wrote: >> On 08/21/2012 08:29 PM, Eduardo wrote: >>> how would you do with Sort::Maker? >> i don't have time to show an example now but it is much cleaner >> looking. all you need to do is code up how you extract each key from

Re: hash of arrays sorting

2012-08-22 Thread Eduardo
On 22/08/12 03:49, Uri Guttman wrote: > On 08/21/2012 08:29 PM, Eduardo wrote: >> how would you do with Sort::Maker? > i don't have time to show an example now but it is much cleaner > looking. all you need to do is code up how you extract each key from > the data set and how it gets sorted (number

Re: hash of arrays sorting

2012-08-21 Thread Uri Guttman
On 08/21/2012 08:29 PM, Eduardo wrote: On 22/08/12 00:35, Uri Guttman wrote: my %cache = (); foreach ( keys %$hash ) { my ( $naa, $nab ) = $_ =~ m|^(\d+)-(\d+)|; $cache{ ($naa * 100 + $nab ) } = $_; } that is a variant of the orcish manoever which is supported by sort::maker. fore

Re: hash of arrays sorting

2012-08-21 Thread Eduardo
On 22/08/12 00:35, Uri Guttman wrote: > On 08/21/2012 05:33 PM, Eduardo wrote: >> On 21/08/12 22:05, Chris Stinemetz wrote: >>> Hello List, >>> >>> I am trying to sort a hash of arrays ( example below: ) >>> >>> I would the sort to so

Re: hash of arrays sorting

2012-08-21 Thread Uri Guttman
On 08/21/2012 05:33 PM, Eduardo wrote: On 21/08/12 22:05, Chris Stinemetz wrote: Hello List, I am trying to sort a hash of arrays ( example below: ) I would the sort to sort in ascending order the first index of the array then the second index of the array. So in this example the arrays

Re: hash of arrays sorting

2012-08-21 Thread Eduardo
On 21/08/12 22:05, Chris Stinemetz wrote: > Hello List, > > I am trying to sort a hash of arrays ( example below: ) > > I would the sort to sort in ascending order the first index of the array > then the second index of the array. > > So in this example the arrays would

Re: hash of arrays sorting

2012-08-21 Thread Chris Stinemetz
I will leave it to you to write an actual program incorporating these > ideas. > > Thank you Jim for the excelent explanation. This seems to do the trick. foreach my $cellNo ( sort { $hash{$a}->[0] <=> $hash{$b}->[0] || $hash{$a}->[1] <=> $hash{$b}->[1] } keys %hash ) { print join( "\0", @{

Re: hash of arrays sorting

2012-08-21 Thread Jim Gibson
On Aug 21, 2012, at 1:23 PM, Jim Gibson wrote: > > On Aug 21, 2012, at 1:05 PM, Chris Stinemetz wrote: > >> Hello List, >> >> I am trying to sort a hash of arrays ( example below: ) >> >> I would the sort to sort in ascending order the first index of th

Re: hash of arrays sorting

2012-08-21 Thread Jim Gibson
On Aug 21, 2012, at 1:05 PM, Chris Stinemetz wrote: > Hello List, > > I am trying to sort a hash of arrays ( example below: ) > > I would the sort to sort in ascending order the first index of the array > then the second index of the array. I believe you mean "fir

Re: hash of arrays sorting

2012-08-21 Thread Chris Stinemetz
On Tue, Aug 21, 2012 at 3:11 PM, Shawn H Corey wrote: > On Tue, 21 Aug 2012 15:05:33 -0500 > Chris Stinemetz wrote: > > > I am trying to sort a hash of arrays ( example below: ) > > > > I would the sort to sort in ascending order the first index of the > > a

Re: hash of arrays sorting

2012-08-21 Thread Shawn H Corey
On Tue, 21 Aug 2012 15:05:33 -0500 Chris Stinemetz wrote: > I am trying to sort a hash of arrays ( example below: ) > > I would the sort to sort in ascending order the first index of the > array then the second index of the array. What have you tried so far? Can we see the code?

hash of arrays sorting

2012-08-21 Thread Chris Stinemetz
Hello List, I am trying to sort a hash of arrays ( example below: ) I would the sort to sort in ascending order the first index of the array then the second index of the array. So in this example the arrays would sort to: 97,2,120,65 219,1,30,33 280,3,230,90 462,2,270,65 $VAR1

Re: Comparing two arrays

2012-06-06 Thread Brock
On 2012.06.06.04.06, Uri Guttman wrote: > On 06/06/2012 03:58 AM, Wernher Eksteen wrote: > >I have two arrays that I need to compare, and then print the differences: > > this is answered in the perl FAQ. please check that before you ask > ... Specifically, you can use &quo

Re: Comparing two arrays

2012-06-06 Thread Uri Guttman
On 06/06/2012 03:58 AM, Wernher Eksteen wrote: Hi, I have two arrays that I need to compare, and then print the differences: this is answered in the perl FAQ. please check that before you ask what could be a frequently asked question. in fact, i teach perl newbies to read/skim the entire

  1   2   3   4   5   6   7   8   9   10   >