Re: lambda array

2024-01-13 Thread Ken Slater
On Sat, Jan 13, 2024 at 12:41 PM Andrew Solomon wrote: > > when is an array in perl declared with [] instead of ()? > > Using the [ ] delimiters you are creating a *reference* to an array. > (Think of a reference as the memory address where the array is stored). So > > my $

Re: lambda array

2024-01-13 Thread Andrew Solomon
> when is an array in perl declared with [] instead of ()? Using the [ ] delimiters you are creating a *reference* to an array. (Think of a reference as the memory address where the array is stored). So my $foo = [1,2,3]; is equivalent to the following, because given an array the \ gets

Re: lambda array

2024-01-13 Thread hw
romJID], "blah" ); > > because > > \('foo', 'bar') > > evaluates to > > (\'foo', \'bar') > > Does that clarify this for you? Not really ... I vaguely thought that [] might do the trick, but since when is an ar

Re: lambda array

2024-01-13 Thread Andrew Solomon
x27;foo', \'bar') Does that clarify this for you? Andrew On Sat, Jan 13, 2024 at 2:51 PM hw wrote: > Hi, > > how do I pass an array that is created on the fly as one parameter of > a function? > > Example: > > > use feature 'signat

lambda array

2024-01-13 Thread hw
Hi, how do I pass an array that is created on the fly as one parameter of a function? Example: use feature 'signatures'; no warnings 'experimental::signatures'; sub reply_multi ( $xmpp_o, $rcpts, $msg ) { foreach my $rcpt (@$rcpts) { $$xmpp_o->MessageS

Re: Can't use 'defined(@array)'

2018-02-23 Thread David Precious
t; elsif (defined (@$glob)) { > $localconfig{$var} = \@$glob; > } > elsif (defined (%$glob)) { > $localconfig{$var} = \%$glob; > } > > when I run it, the interpreter errors out with: > > Can&#

Can't use 'defined(@array)'

2018-02-23 Thread jose cabrera
(defined (%$glob)) { $localconfig{$var} = \%$glob; } when I run it, the interpreter errors out with: Can't use 'defined(@array)' (Maybe you should just omit the defined()?) at Bugzilla/Install/Localconfig.pm line 239, line 755. Any thoughts? Thanks.

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 > l

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, yo

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

`$#array` vs `scalar @array`

2018-01-28 Thread Peng Yu
Hi, For the following two expressions, are they of the same speed or one of them is faster? `$#array` vs `scalar @array` -- Regards, Peng -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: How to delete multiple indices from array

2017-04-12 Thread Илья Рассадин
en we start to splice elements from array indices will be change. If we delete first element, third element became second, fourth became third and so on. 12.04.17 23:19, Uri Guttman пишет: On 04/12/2017 04:08 PM, Илья Рассадин wrote: Hi! You can use splice to delete elements from array. To d

Re: How to delete multiple indices from array

2017-04-12 Thread Shawn H Corey
On Wed, 12 Apr 2017 19:34:22 -0400 Uri Guttman wrote: > it is so odd to be filtering an array by the indexes. i smell an XY > problem here. i wonder what the real goal is vs how to solve it this > way. > > thanx, > > uri I was thinking that too. -- Don'

Re: How to delete multiple indices from array

2017-04-12 Thread Uri Guttman
sing descending indexing do you get the correct deletions. i get that now. this is because of the need to filter based on indexes rather than values. the hash slice ideas should still work but even then ordering may be off due to the lack of sorting of the values (which are the indexes of the or

Re: How to delete multiple indices from array

2017-04-12 Thread Shawn H Corey
On Wed, 12 Apr 2017 18:16:56 -0400 Uri Guttman wrote: > On 04/12/2017 05:42 PM, Shawn H Corey wrote: > > On Wed, 12 Apr 2017 16:19:32 -0400 > > Uri Guttman wrote: > > > > > > my @array; > > > > for my $index (reverse sort @indices) { > >> so

Re: How to delete multiple indices from array

2017-04-12 Thread Uri Guttman
On 04/12/2017 05:42 PM, Shawn H Corey wrote: On Wed, 12 Apr 2017 16:19:32 -0400 Uri Guttman wrote: my @array; for my $index (reverse sort @indices) { sort defaults to a lexical sort which won't work well on integers with more than 2 digits. and why are you sorting and reversing the in

Re: How to delete multiple indices from array

2017-04-12 Thread X Dungeness
Quite! Even the slowest may find redemption in clarity :) my @arr = qw( zero one two three ... ); my @del = qw( 2,4,... ); my( %del, @new ); @del{ @del } = (); for (0..$#arr) { push @new, $arr[$_] unless exists $del{$_}} On Wed, Apr 12, 2017 at 2:18 PM, Paul Johnson wrote: > On Wed, Apr 12, 20

Re: How to delete multiple indices from array

2017-04-12 Thread Shawn H Corey
On Wed, 12 Apr 2017 16:19:32 -0400 Uri Guttman wrote: > On 04/12/2017 04:08 PM, Илья Рассадин wrote: > > Hi! > > > > You can use splice to delete elements from array. > > > > To delete multiple elements you need to do splice in a loop > > > > my @ind

Re: How to delete multiple indices from array

2017-04-12 Thread Paul Johnson
On Wed, Apr 12, 2017 at 11:12:45PM +0200, David Emanuel da Costa Santiago wrote: > Thank you all for your replies. > > I tested the 5 solutions with the benchmark module, and the splice one > is the fastest: > The hash one, which was my first solution is the slowest one. :-( But they're all fas

Re: How to delete multiple indices from array

2017-04-12 Thread David Emanuel da Costa Santiago
; > Hi Uri! > > > > Some notes. > > > > On Wed, 12 Apr 2017 15:19:33 -0400 > > Uri Guttman wrote: > > > >> On 04/12/2017 03:00 PM, David Emanuel da Costa Santiago wrote: > >>> Hello! > >>> > >&g

Re: How to delete multiple indices from array

2017-04-12 Thread Uri Guttman
On 04/12/2017 04:38 PM, Shlomi Fish wrote: Hi Uri! Some notes. On Wed, 12 Apr 2017 15:19:33 -0400 Uri Guttman wrote: On 04/12/2017 03:00 PM, David Emanuel da Costa Santiago wrote: Hello! What's the best way to delete multiple indices from an array? i'm doing: ---

Re: How to delete multiple indices from array

2017-04-12 Thread Shlomi Fish
Hi Uri! Some notes. On Wed, 12 Apr 2017 15:19:33 -0400 Uri Guttman wrote: > On 04/12/2017 03:00 PM, David Emanuel da Costa Santiago wrote: > > Hello! > > > > What's the best way to delete multiple indices from an array? > > > > i'm doing: > >

Re: How to delete multiple indices from array

2017-04-12 Thread Uri Guttman
On 04/12/2017 04:08 PM, Илья Рассадин wrote: Hi! You can use splice to delete elements from array. To delete multiple elements you need to do splice in a loop my @indices = qw/2 4 5 7/; why are you using qw which makes strings and not a list of integers? my @array; for my $index

Re: How to delete multiple indices from array

2017-04-12 Thread Илья Рассадин
Hi! You can use splice to delete elements from array. To delete multiple elements you need to do splice in a loop my @indices = qw/2 4 5 7/; my @array; for my $index (reverse sort @indices) { splice @array, $index, 0; } 12.04.17 22:19, Uri Guttman пишет: On 04/12/2017 03:00 PM

Re: How to delete multiple indices from array

2017-04-12 Thread Uri Guttman
On 04/12/2017 04:01 PM, David Emanuel da Costa Santiago wrote: Thanks for your reply. I didn't think about that! :-) While i was reading your email, i remembered about splice, so i guess i'm going to end up with: -- my @array=qw/zero one two three four five six seven eigh

Re: How to delete multiple indices from array

2017-04-12 Thread David Emanuel da Costa Santiago
Thanks for your reply. I didn't think about that! :-) While i was reading your email, i remembered about splice, so i guess i'm going to end up with: -- my @array=qw/zero one two three four five six seven eight nine ten/; my @indicesToDelete = (2,4,6,7); my $deviation =

Re: How to delete multiple indices from array

2017-04-12 Thread Uri Guttman
On 04/12/2017 03:00 PM, David Emanuel da Costa Santiago wrote: Hello! What's the best way to delete multiple indices from an array? i'm doing: --- my @array=qw/zero one two three four five six seven eight nine ten/; my @indicesToDelete = (2,4,6,7); if you have the

How to delete multiple indices from array

2017-04-12 Thread David Emanuel da Costa Santiago
Hello! What's the best way to delete multiple indices from an array? i'm doing: --- my @array=qw/zero one two three four five six seven eight nine ten/; my @indicesToDelete = (2,4,6,7); my %hash; @hash{(0..scalar(@array)-1)} = @array; delete $hash{$_} for @indic

Re: if element exists in an array

2016-08-19 Thread Chas. Owens
On Fri, Aug 19, 2016 at 2:22 PM Chas. Owens wrote: > Truth. If you are checking in lots of things exist a hashset might be a > better way to go: > > my %hashset = map { ($_ => undef) } (3,1,4,2,9,0); > > my $found = exists $hashset{4} || 0; > my $not_found = exists $hashset{10} || 0; > > By sett

Re: if element exists in an array

2016-08-19 Thread Chas. Owens
han setting it any other value. On Fri, Aug 19, 2016 at 2:15 PM wrote: > But does it need to be an array. Rethink into hash and life could be a > little bit easier... > > Wags ;) > WagsWorld > Hebrews 4:15 > Ph: 408-914-1341 > > On Aug 18, 2016, 19:41 -0700, kp...@fre

Re: if element exists in an array

2016-08-19 Thread wagsworld48 via beginners
But does it need to be an array. Rethink into hash and life could be a little bit easier... Wags ;) WagsWorld Hebrews 4:15 Ph: 408-914-1341 On Aug 18, 2016, 19:41 -0700, kp...@freenet.de, wrote: > Thanks for all the replies. > Yes I found List::Util is a useful toolset. > > > On

Re: if element exists in an array

2016-08-18 Thread kpeng
Thanks for all the replies. Yes I found List::Util is a useful toolset. On 2016/8/19 10:00, Chas. Owens wrote: The any function from List::Util will also do what you want. perldoc List::Util http://perldoc.perl.org/List/Util.html#any my $found = any { $_ == 4 } (3, 1, 4, 2, 9, 0); # true my

Re: if element exists in an array

2016-08-18 Thread Chas. Owens
On Thu, Aug 18, 2016 at 9:39 PM wrote: > Hello, > > What's the better way to decide if an element exists in an array? > Something like what ruby does, > > irb(main):001:0> x=[3,1,4,2,9,0] > => [3, 1, 4, 2, 9, 0] > irb(main):002:0> x.include? 4 >

Re: if element exists in an array

2016-08-18 Thread Chris Fedde
llo, > > What's the better way to decide if an element exists in an array? > Something like what ruby does, > > irb(main):001:0> x=[3,1,4,2,9,0] > => [3, 1, 4, 2, 9, 0] > irb(main):002:0> x.include? 4 > => true > irb(main):003:0> x.include? 10 > => fa

Re: if element exists in an array

2016-08-18 Thread Kent Fredric
On 19 August 2016 at 13:45, Kent Fredric wrote: >if ( first { $item == 4 } @items ) { >say "Yes"; >} > Ugh, my bad. if ( first { $_ == 4 } @items ) { say "Yes"; } -- Kent KENTNL - https://metacpan.org/author/KENTNL -- To unsubscribe, e-mail: beginners-unsub

Re: if element exists in an array

2016-08-18 Thread Kent Fredric
On 19 August 2016 at 13:35, wrote: > > What's the better way to decide if an element exists in an array? > Something like what ruby does, > > irb(main):001:0> x=[3,1,4,2,9,0] > => [3, 1, 4, 2, 9, 0] > irb(main):002:0> x.include? 4 > => true > irb(main

if element exists in an array

2016-08-18 Thread kpeng
Hello, What's the better way to decide if an element exists in an array? Something like what ruby does, irb(main):001:0> x=[3,1,4,2,9,0] => [3, 1, 4, 2, 9, 0] irb(main):002:0> x.include? 4 => true irb(main):003:0> x.include? 10 => false irb(main):004:0> quit I

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
it $way3 = $confused->[0]{Id}[1]; print $_, "\n" for $way1, $way2, $way3; # okay, let’s pretend you want all the ids @ids = @{ $confused->[0]{Id} }; print $_, “\n” for @ids; The first thing to realize is that data structure (hash/array) references, or any kind of reference for th

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

2016-04-14 Thread Raj Barath
it $way3 = $confused->[0]{Id}[1]; print $_, "\n" for $way1, $way2, $way3; # okay, let’s pretend you want all the ids @ids = @{ $confused->[0]{Id} }; print $_, “\n” for @ids; The first thing to realize is that data structure (hash/array) references, or any kind of reference for th

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

2016-04-14 Thread Aaron Wells
way to do it $way2 = $confused->[0]->{Id}->[0]; # an even cleaner way to do it $way3 = $confused->[0]{Id}[1]; print $_, "\n" for $way1, $way2, $way3; # okay, let’s pretend you want all the ids @ids = @{ $confused->[0]{Id} }; print $_, “\n” for @ids; The first thing to

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

2016-04-14 Thread Shlomi Fish
AR1}[0]}{'Id'}}[0]; > say @{ %{ @{$VAR1}[0]}{'Id'}}[1]; > say ${ @{$VAR1}[0]}{'type'}; > What the hell is this code doing? It looks absolutely horrifying. See for example: http://perl-begin.org/tutorials/bad-elements/#at-array-for-subscripting Please do

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

2016-04-14 Thread Raj Barath
}, 'sObject' ) >> ]; >> >> So if the data structure is contained in a Perl variable called >> $data, then I think that this is a reference to a hash. >> >> So I need to do something like "@{$data}" to get to the hash. >

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

2016-04-14 Thread Raj Barath
}, 'sObject' ) >> ]; >> >> So if the data structure is contained in a Perl variable called >> $data, then I think that this is a reference to a hash. >> >> So I need to do something like "@{$data}" to get to the hash. >

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

2016-04-13 Thread Kenneth Wolcott
'type' => 'Product2' >> }, 'sObject' ) >> ]; >> >> So if the data structure is contained in a Perl variable called >> $data, then I think that this is a reference to a hash. >> >> So

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

2016-04-13 Thread Lawrence Statton
$data, then I think that this is a reference to a hash. So I need to do something like "@{$data}" to get to the hash. But I want the "Id" element of the hash so I want something like @{$data}->{'Id'} But that's the array, so what about ${@{$data}->{&#x

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

2016-04-13 Thread Ken Slater
; > So if the data structure is contained in a Perl variable called > $data, then I think that this is a reference to a hash. > > So I need to do something like "@{$data}" to get to the hash. > > But I want the "Id" element of the hash so I want something li

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

2016-04-13 Thread Kenneth Wolcott
ed to do something like "@{$data}" to get to the hash. But I want the "Id" element of the hash so I want something like @{$data}->{'Id'} But that's the array, so what about ${@{$data}->{'Id'}}[0] But that isn't right either. I'

Re: uniq array creation

2015-11-29 Thread Paul Johnson
On Sun, Nov 29, 2015 at 03:30:53PM +0530, Pritish Pattanaik wrote: > *Remove duplicate elelments from an array, It will maintain the original > order* > > __CODE__ > @array = qw(11 2 3 4 55 4 3 2); > %hash = (); > for(my $i=0;$i<=$#array;$i++){ > # store the pos

Re: uniq array creation

2015-11-29 Thread Shlomi Fish
Hi Jitendra, some comments on your code: On Sun, 29 Nov 2015 13:09:42 +0530 Jitendra Barik wrote: > Hi Sunita, > > Please find the code snippet here: > > @array = qw(1 2 3 4 5 4 3 2); You are missing "use strict;", "use warnings;" and "my" declar

Re: uniq array creation

2015-11-29 Thread Pritish Pattanaik
Hi, *Remove duplicate from an array using hash, It will disorder the original position of an array * __CODE__ my @array = qw(11 2 3 4 55 4 3 2); my %hash; map { $hash{$_}++ } @array; @array = keys %hash; print "Array:@array\n"; __END__ *Remove duplicate elelments from an arra

Re: uniq array creation

2015-11-28 Thread Jitendra Barik
Hi Sunita, Please find the code snippet here: @array = qw(1 2 3 4 5 4 3 2); foreach (@array){ $myhash{$_} = $myhash{$_} + 1; } while(($s,$k) = each(%myhash)){ push @res,$k; } print "Array in unique is : @res\n"; Regards, Jitendra On Thu, No

Re: uniq array creation

2015-11-26 Thread Mike Flannigan
See if this meets your needs: http://www.arl.wustl.edu/projects/fpx/references/perl/cookbook/ch04_07.htm Mike On 11/25/2015 1:53 AM, beginners-digest-h...@perl.org wrote: Hi I want to create a unique array . I have the code below. It is creating a array which will have duplicate data

Re: uniq array creation

2015-11-25 Thread Shlomi Fish
Hi Sunita, On Wed, 25 Nov 2015 13:23:24 +0530 Sunita Pradhan wrote: > Hi > I want to create a unique array . You probably mean an "array with unique elements". To do so, you should use a hash. See: http://perl-begin.org/topics/hashes/ > I have the code below. It is cre

uniq array creation

2015-11-24 Thread Sunita Pradhan
Hi I want to create a unique array . I have the code below. It is creating a array which will have duplicate data . How can I filter duplicate data ? #!/usr/bin/perl use Data::Dumper; #my $cnt = scalar @$net_int_parsed_output; $net_int_parsed_output = [lif_1 ,lif_2,lif_3,lif_4,lif_1,lif_2

Re: convert linear array to nested structure

2015-08-07 Thread Simon Reinhardt
Am 04.08.2015 um 23:06 schrieb Brandon McCaig: > Generally I meant that your solution was short and simple enough that > it probably wasn't worth the extra effort of trying to improve it > [unless the code was going to be maintained for a long time]. This is > what I came up with in a few minutes.

Re: convert linear array to nested structure

2015-08-04 Thread Brandon McCaig
On Tue, Aug 4, 2015 at 5:06 PM, Brandon McCaig wrote: > my %prev = (1 => { kids => \@output }); Perhaps a more adequate identifier for this hash would have been %parents. *shrugs* Regards, -- Brandon McCaig Castopulence Software Blog

Re: convert linear array to nested structure

2015-08-04 Thread Brandon McCaig
On Sat, Aug 1, 2015 at 12:39 PM, Simon Reinhardt wrote: > Am 30.07.2015 um 20:42 schrieb Brandon McCaig: >> I'll give you my 2 cents for whatever that's worth. >:) > > Thanks for your many comments. > > The updated full project code is below. Feedback is appreciated. (you > also find this at git

Re: convert linear array to nested structure

2015-08-01 Thread Simon Reinhardt
eturn $outline_items; } sub dump_to_simple_format { my $out_handle = shift; my $outline_items = shift; binmode $out_handle, ':encoding(UTF-8)'; for my $outline (@$outline_items) { print {$out_handle} ""x($outline->{level}), prepare_title ($outli

Re: convert linear array to nested structure

2015-07-30 Thread Brandon McCaig
k: Again, you mean "file handle" here. > # returns: arrayref of hashrefs, each describing level, title and page of an > # outline item. > sub parse_djvused_output { > my $djvused_fd = shift; > my $level = 0; > my $line = <$djvused_fd>; >

Re: convert linear array to nested structure

2015-07-24 Thread Simon Reinhardt
(?(\s*\))*)\s*$/ or die "line '$line' in djvused output does not match."; push @$outline_items, {level => $level, title => $title, page => $+{page}}; $level -= ($+{close} =~ tr/\)//) - 1; } return $out

Re: convert linear array to nested structure

2015-07-21 Thread Shawn H Corey
uses nested arrays instead of hashes: > > [ > [0, “string1"], > [1, “string2"], > [2, “string3"], > [2, “string4"] > ] my @data = ( [ "string1" ], [ "string2" ], [ "string3", "string4" ],

Re: convert linear array to nested structure

2015-07-21 Thread Jim Gibson
> On Jul 21, 2015, at 12:40 PM, Simon Reinhardt wrote: > > Hi Team, > > is there a ready solution to convert an linear array of hashrefs > like this > > [ {level => 0, value => "string1"}, > {level => 1, value => "string2"},

convert linear array to nested structure

2015-07-21 Thread Simon Reinhardt
Hi Team, is there a ready solution to convert an linear array of hashrefs like this [ {level => 0, value => "string1"}, {level => 1, value => "string2"}, {level => 2, value => "string3"}, {level => 2, value => "string4"} ]

Re: Display a hash in the order of an array

2015-07-21 Thread Vincent Lequertier
Le 2015-07-20 16:49, Charles DeRykus a écrit : On Mon, Jul 20, 2015 at 6:19 AM, Vincent Lequertier wrote: Thank you for the help, Charles! Unfortunately, I'm not able to figure out how to access the element of %ordered, despite some diggings in the perldoc (http://perldoc.perl.org/perldsc.htm

Re: Display a hash in the order of an array

2015-07-20 Thread Charles DeRykus
On Mon, Jul 20, 2015 at 6:19 AM, Vincent Lequertier wrote: > Thank you for the help, Charles! Unfortunately, I'm not able to figure out > how to access the element of %ordered, despite some diggings in the perldoc > (http://perldoc.perl.org/perldsc.html). > I can print a single element with print

Re: Display a hash in the order of an array

2015-07-20 Thread Vincent Lequertier
re : $hash{$date} = { 'ip' => $ip, 'action' => $action, }; witch produce data like : $VAR1 = '[15/Jul/2015:10:30:03 +0200]'; $VAR2 = { 'ip' => 'xxx.xxx.xxx.xxx', 'ac

Re: Display a hash in the order of an array

2015-07-20 Thread nosettle
= '[15/Jul/2015:10:30:03 +0200]'; > $VAR2 = { >'ip' => 'xxx.xxx.xxx.xxx', >'action' => 'GET xxx' > }; > > and an array of ip addresses, say @ip > > My question is how can I display the content of %hash in

Re: Display a hash in the order of an array

2015-07-20 Thread Vincent Lequertier
#x27;[15/Jul/2015:10:30:03 +0200]'; $VAR2 = { 'ip' => 'xxx.xxx.xxx.xxx', 'action' => 'GET xxx' }; and an array of ip addresses, say @ip My question is how can I display the content of %hash in the order of @ip, assuming

Re: Display a hash in the order of an array

2015-07-20 Thread Shlomi Fish
:03 +0200]'; > $VAR2 = { > 'ip' => 'xxx.xxx.xxx.xxx', > 'action' => 'GET xxx' > }; > > The workaround I found is to loop over the hash, push an array with the > ip addresses, an

Re: Display a hash in the order of an array

2015-07-20 Thread Илья Рассадин
gt; > $VAR1 = '[15/Jul/2015:10:30:03 +0200]'; > $VAR2 = { > 'ip' => 'xxx.xxx.xxx.xxx', > 'action' => 'GET xxx' > }; > > The workaround I found is to loop over the hash, push an array wi

Re: Display a hash in the order of an array

2015-07-20 Thread Vincent Lequertier
, 'action' => 'GET xxx' }; The workaround I found is to loop over the hash, push an array with the ip addresses, and sort them, like this : sub sort_by_ip { my @ip; for my $key (keys %hash) { push @ip, $hash{$key}{ip}; } my @ip_sorted = map {

Re: Display a hash in the order of an array

2015-07-17 Thread Charles DeRykus
=> $ip, > 'action' => $action, > }; > > witch produce data like : > > $VAR1 = '[15/Jul/2015:10:30:03 +0200]'; > $VAR2 = { > 'ip' => 'xxx.xxx.xxx.xxx', > 'acti

Re: Display a hash in the order of an array

2015-07-17 Thread Brandon McCaig
On Fri, Jul 17, 2015 at 10:40 AM, Brandon McCaig wrote: > for my $i (0..4) { Errr, 0..3. >_> Regards, -- Brandon McCaig Castopulence Software Blog perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }. q{Vg qbrfa'\''g nyjnlf fbhaq gung

Re: Display a hash in the order of an array

2015-07-17 Thread Brandon McCaig
; > witch produce data like : > > $VAR1 = '[15/Jul/2015:10:30:03 +0200]'; > $VAR2 = { > 'ip' => 'xxx.xxx.xxx.xxx', > 'action' => 'GET xxx' > }; > > and an array of ip addresse

Re: Display a hash in the order of an array

2015-07-17 Thread Shawn H Corey
witch produce data like : > > $VAR1 = '[15/Jul/2015:10:30:03 +0200]'; > $VAR2 = { >'ip' => 'xxx.xxx.xxx.xxx', >'action' => 'GET xxx' > }; > > and an array of ip addresses, say @ip &

Display a hash in the order of an array

2015-07-17 Thread Vincent Lequertier
7; => 'xxx.xxx.xxx.xxx', 'action' => 'GET xxx' }; and an array of ip addresses, say @ip My question is how can I display the content of %hash in the order of @ip, assuming %hash has the same length as @ip ? Thank you -- Vincent Lequertier v

Re: How to check the index positions of an array element in perl in case of multiple occurance

2015-06-16 Thread Shlomi Fish
Hi Anirban, On Tue, 16 Jun 2015 21:35:13 +0530 Anirban Adhikary wrote: > Hi List > > I need to find the index positions of many elements. For a single > occurrence there are many ways to find it. But in my case the element which > I am searching for has multiple occurrence. > In addition to w

Re: How to check the index positions of an array element in perl in case of multiple occurance

2015-06-16 Thread Paul Johnson
On Wed, Jun 17, 2015 at 07:01:06AM +1200, Kent Fredric wrote: > On 17 June 2015 at 04:46, Vincent Lequertier wrote: > > > > #!/usr/bin/perl > > use strict; > > use warnings; > > open my $fh, '<', 'text'; > > my @words = split ' ', <$fh>; > > my @matchs; > > while (my ($index, $elem) = each @words)

Re: How to check the index positions of an array element in perl in case of multiple occurance

2015-06-16 Thread Kent Fredric
On 17 June 2015 at 04:46, Vincent Lequertier wrote: > > #!/usr/bin/perl > use strict; > use warnings; > open my $fh, '<', 'text'; > my @words = split ' ', <$fh>; > my @matchs; > while (my ($index, $elem) = each @words) { > if ($elem eq 'bspwrt') { > push @matchs, $index++; >

Re: How to check the index positions of an array element in perl in case of multiple occurance

2015-06-16 Thread Vincent Lequertier
many ways to find it. But in my case the element > which I am searching for has multiple occurrence. > > The following is the array from where I have to find the indexes of a > specific element say bspwrt. > > > NW MSC BSC CELL ch_group_0 chgr_tg chgr_state band bccd bspwrt c

How to check the index positions of an array element in perl in case of multiple occurance

2015-06-16 Thread Anirban Adhikary
Hi List I need to find the index positions of many elements. For a single occurrence there are many ways to find it. But in my case the element which I am searching for has multiple occurrence. The following is the array from where I have to find the indexes of a specific element say bspwrt

Re: Perl array question

2015-05-06 Thread Marius Gavrilescu
anirban.adhik...@gmail.com (Anirban Adhikary) writes: > Hi List > I have the following array --- > ('1900-0','1900-1','NULL','NULL','1900-2','1900-4','1902-5','1902-6','1902-7','1902-8');

Fwd: Fw: Perl array question

2015-05-06 Thread Shlomi Fish
-- Forwarded message -- From: Shlomi Fish Date: Wed, May 6, 2015 at 11:31 AM Subject: Fw: Perl array question To: shlo...@gmail.com Begin forwarded message: Date: Wed, 6 May 2015 11:04:30 +0300 From: Shlomi Fish To: beginners Subject: Re: Perl array question Hi Anirban

Re: Perl array question

2015-05-06 Thread Shawn H Corey
On Wed, 6 May 2015 12:49:53 +0530 Anirban Adhikary wrote: > Hi List > I have the following array --- > ('1900-0','1900-1','NULL','NULL','1900-2','1900-4','1902-5','1902-6','1902-7','1902-8

Re: Perl array question

2015-05-06 Thread Vincent Lequertier
s one way to do it : Your code encourages many bad practices. Some notes are: #!/usr/bin/perl no "use strict;"/"use warnings;": http://perl-begin.org/tutorials/bad-elements/#no-strict-and-warnings my @array = ('1900-0', '1900-1', 'NULL',

Re: Perl array question

2015-05-06 Thread Shlomi Fish
/tutorials/bad-elements/#no-strict-and-warnings > my @array = ('1900-0', '1900-1', 'NULL', 'NULL', '1900-2', '1900-4', > '1902-5', '1902-6', '1902-7', '1902-8'); > my $num1900 = 'EAR

Fwd: Fw: Perl array question

2015-05-06 Thread Shlomi Fish
-- Forwarded message -- From: Shlomi Fish Date: Wed, May 6, 2015 at 11:31 AM Subject: Fw: Perl array question To: shlo...@gmail.com Begin forwarded message: Date: Wed, 6 May 2015 11:04:30 +0300 From: Shlomi Fish To: beginners Subject: Re: Perl array question Hi Anirban

Re: Perl array question

2015-05-06 Thread Vincent Lequertier
It's a bit ugly, but here is one way to do it : #!/usr/bin/perl my @array = ('1900-0', '1900-1', 'NULL', 'NULL', '1900-2', '1900-4', '1902-5', '1902-6', '1902-7', '1902-8'); my

Perl array question

2015-05-06 Thread Anirban Adhikary
Hi List I have the following array --- ('1900-0','1900-1','NULL','NULL','1900-2','1900-4','1902-5','1902-6','1902-7','1902-8'); There are two part for each element separated by a dash. first one

Re: How to handle null elements inside an array

2015-04-02 Thread Andrew Solomon
Hi Anirban 'unless ($dev)' is just the same as 'if(not ($dev))' and it means 'if this string (from which I've removed all the spaces) is empty do ... ' Does that answer your question? Andrew On Thu, Apr 2, 2015 at 5:05 PM, Anirban Adhikary wrote: > Hi Andrew > > From your code I have comple

Re: How to handle null elements inside an array

2015-04-02 Thread Anirban Adhikary
Hi Andrew >From your code I have completed the code and it is working fine. I am pasting here the final code. #!/usr/bin/perl use strict; use warnings; 1 #!/usr/bin/perl 2 3 use strict; 4 use warnings; 5 6 my $Input_File_Name = "inputdir/MAT4BE_SC_STD_INFO"; 7 open my $RFH,'<',$Inpu

Re: How to handle null elements inside an array

2015-04-02 Thread Dejian Zhao
I think you should study your data first. For example, how are those fields separated? Usually fields are tab-delimited. If this is true with your data, you can split lines with split(/\t/,$line), then the fields will be correctly separated. On 4/2/15 10:43 AM, Anirban Adhikary wrote: Hi List

Re: How to handle null elements inside an array

2015-04-02 Thread Shawn H Corey
On Thu, 2 Apr 2015 08:34:37 -0700 SSC_perl wrote: > On Apr 2, 2015, at 7:43 AM, Anirban Adhikary wrote: > > When I am trying to split the line based on whitespace > > @elements = split(/\s+/,$line); > > It will be interesting if someone can come up with a solution > to this, but I don't se

Re: How to handle null elements inside an array

2015-04-02 Thread Andrew Solomon
Or more politely... :) https://gist.github.com/anonymous/2ebb0441bcdec4a94e48 On Thu, Apr 2, 2015 at 4:43 PM, Andrew Solomon wrote: > Hi Anirban > > I haven't completely solved the problem - only addressing the DEV field, > but I hope this points you in the right direction! > > cheers > > And

Re: How to handle null elements inside an array

2015-04-02 Thread Andrew Solomon
Hi Anirban I haven't completely solved the problem - only addressing the DEV field, but I hope this points you in the right direction! cheers Andrew #!/usr/bin/env perl use strict; use warnings; # NOTE This assumes the space aren't tabs and the columns are aligned my $input = ' SCGR SC

Re: How to handle null elements inside an array

2015-04-02 Thread SSC_perl
On Apr 2, 2015, at 7:43 AM, Anirban Adhikary wrote: > When I am trying to split the line based on whitespace > @elements = split(/\s+/,$line); It will be interesting if someone can come up with a solution to this, but I don't see one. If your separator is whitespace, then the split has

How to handle null elements inside an array

2015-04-02 Thread Anirban Adhikary
Hi List I would like to process a file which has the following structure. SCGR SC DEVDEV1 NUMDEV DCP STATE REASON 10 31 1 SCGR SC DEVDEV1 NUMDEV DCP STATE REASON 20

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

  1   2   3   4   5   6   7   8   9   10   >