the
args list to builtins. it eliminates funny arg parsing and also shows to
the reader there is a function call with no args. it would have caught
the error as:
gmtime()[1..5]
should be a syntax error (didn't check).
also a better way to slice out gmtime is to assign it to an list o
Uri Guttman writes:
> On 7/4/19 2:41 PM, Mike Small wrote:
>> A co-worker was trying to take some of the elements from gmtime's return
>> value. He did something like the following:
>>
>> $ perl -E'$,="\t";say gmtime[1..5]'
>
> that is calling gmtime with the argument of [1..5] which is an
>
On 7/4/19 2:41 PM, Mike Small wrote:
A co-worker was trying to take some of the elements from gmtime's return
value. He did something like the following:
$ perl -E'$,="\t";say gmtime[1..5]'
that is calling gmtime with the argument of [1..5] which is an arrayref.
so the arg to gmtime is some
A co-worker was trying to take some of the elements from gmtime's return
value. He did something like the following:
$ perl -E'$,="\t";say gmtime[1..5]'
8 32 12 31 7 2999416 1 243 0
I suggested he try something like this instead...
$ perl -E'$,="\t";say
many to many
problem i noted above). my issue is how to print out a slice of an arrayref
of a hashref?
my underlying problem (i think) is that there has got to be a better way?
i've got half a mind to create a temp table in the db to do this, but that
doesn't seem like my 'better way' either.
thanks
$template-param(
RESULTS = $self-dbh-selectall_arrayref('
SELECT age, day FROM table WHERE id = ?',
{ Slice = {} },
$self-session-param('cell')-{'sid'} )
);
I saw that code and while I do database stuff I was wondering what that
Slice = {} does?
Thanks,
Robert
On 3/16/09 Mon Mar 16, 2009 3:05 PM, R. Hicks sigz...@gmail.com
scribbled:
$template-param(
RESULTS = $self-dbh-selectall_arrayref('
SELECT age, day FROM table WHERE id = ?',
{ Slice = {} },
$self-session-param('cell')-{'sid'} )
);
I saw that code and while I do
On Sat, Mar 14, 2009 at 01:06, Chap Harrison c...@pobox.com wrote:
On Mar 13, 2009, at 7:52 AM, Jenda Krynicky wrote:
That's prettymuch it, except that it's not an array of aliases, but
LIST of aliases. The difference is subtle, but important.
See
From: Chap Harrison c...@pobox.com
Let me break this expression down according to my current understanding.
@{$hash{adams...@keys} = @values;
parses as follows:
adams : short for 'adams', a string literal, being used as a hash key
$hash{adams} : the value in the hash
On Mar 13, 2009, at 7:52 AM, Jenda Krynicky wrote:
That's prettymuch it, except that it's not an array of aliases, but
LIST of aliases. The difference is subtle, but important.
See http://perldoc.perl.org/perlfaq4.html#What-is-the-difference-
between-a-list-and-an-array%3f and
On Mar 12, 2009, at 12:52 AM, Chas. Owens wrote:
On Thu, Mar 12, 2009 at 01:27, Chap Harrison c...@pobox.com wrote:
It's still not intuitive to me why we FIRST convert the hash to
an array,
and THEN ask for keys - keys being hash-ish, rather than array-ish
sorts of
things. (I've said
', 'aw' );
my @values = ( 1, 19, 13, 11);
#
# The following is trying to assign an array to a hash slice.
# (courtesy http://www.perlmonks.org/?node_id=4402, who did a simpler
# version that did not involve references.)
#
@{{$hashref}-{...@keys}} = @values;# don't know if this is right
= $schoolprops{Adams}; # create a ref to a hash.
my @keys = ( 'a', 'ar', 'af', 'aw' );
my @values = ( 1, 19, 13, 11);
#
# The following is trying to assign an array to a hash slice.
# (courtesy http://www.perlmonks.org/?node_id=4402, who did a simpler
# version that did not involve references
On Mar 11, 2009, at 11:51 PM, Chas. Owens wrote:
Dereference the hashref as an arrayref then ask for the keys:
#!/usr/bin/perl
use strict;
use warnings;
my %hash = ( adams = {} );
my @keys = qw/a ar af aw/;
my @values = (1, 19, 13, 11);
@{$hash{adams...@keys} = @values;
use
to a reference
to an empty hash.
my $hashref = $schoolprops{Adams}; # create a ref to a hash.
It doesn't create it, it just copies it.
my @keys = ( 'a', 'ar', 'af', 'aw' );
my @values = ( 1, 19, 13, 11);
#
# The following is trying to assign an array to a hash slice.
# (courtesy http
that badly.) What exactly are
the elements of the array @{$hash{adams...@keys} ?
@{$hash{adams...@keys} is *not* an array, it is a hash slice.
John
--
Those people who think they know everything are a great
annoyance to those of us who do.-- Isaac Asimov
--
To unsubscribe, e-mail: beginners
On Thu, Mar 12, 2009 at 01:27, Chap Harrison c...@pobox.com wrote:
On Mar 11, 2009, at 11:51 PM, Chas. Owens wrote:
Dereference the hashref as an arrayref then ask for the keys:
#!/usr/bin/perl
use strict;
use warnings;
my %hash = ( adams = {} );
my @keys = qw/a ar af aw/;
my
Is there such a thing?
I'm trying to take a HoH and make a reference to a sub-part of the hash.
This doesn't work:
my %sub_hash = $main_hash{'sub_hash'};
I get the following error:
Reference found where even-sized list expected at ./my_buggy_program line 30.
Any quick tips on how to
,
six = 6
);
#get keys whose values are odd
my @keys = grep { $name_to_num{$_} % 2 } keys %name_to_num;
#make a hash of the odd keys and values with a hash slice
my %odd_name_to_num;
@[EMAIL PROTECTED] = @[EMAIL PROTECTED];
print Dumper \%name_to_num, \%odd_name_to_num;
--
Chas. Owens
On Mon, Nov 10, 2008 at 3:52 PM, Travis Thornhill [EMAIL PROTECTED]
wrote:
Is there such a thing?
I'm trying to take a HoH and make a reference to a sub-part of the hash.
This doesn't work:
my %sub_hash = $main_hash{'sub_hash'};
I get the following error:
Reference found where
Travis Thornhill wrote:
Is there such a thing?
Yes there is.
I'm trying to take a HoH and make a reference to a sub-part of the hash.
This doesn't work:
my %sub_hash = $main_hash{'sub_hash'};
I get the following error:
Reference found where even-sized list expected at ./my_buggy_program
30.
Any quick tips on how to reference and assign this sub-hash?
There is certainly such a thing as a hash slice, but I think it is probably not
what you want here. A slice will let you extract multiple values from the hash
simultaneously, something like
my @subhashes = @main_hash{'key1
Hello all,
Recently I faced one scenario with references and array slice in perl.
I used following program to retrieve the rows from a table in Oracle using
Perl DBI.
As shown in the program, I did following steps to retrieve the rows :-
- used fetchall_arrayref to get the array reference
of them were same.
When I did a through debugging on this, I found that @{$row}[0] or
@{$row}[1] etc is taken as array slice by perl with only one member so it
returns the value of the column in scalar and not in list context. With
${$row}[0] or ${$row}[1] etc, the column value is returned
to populate @l2r{a,b}, it
seems to me that it would go through this process:
- I have a slice here, so I'll loop over the slice elements
- The first is a, so I'll pull a scalar off the list and assign it to
$l2r{a}
- The second is b, so I'll pull another scalar off the list and assign
it
to $l2r
to me that it would go through this process:
- I have a slice here, so I'll loop over the slice elements
- The first is a, so I'll pull a scalar off the list and assign it to
$l2r{a}
- The second is b, so I'll pull another scalar off the list and assign
it
to $l2r{b}
- Remaining scalars
From:Bryan R Harris [EMAIL PROTECTED]
Jenda wrote:
From: Bryan R Harris [EMAIL PROTECTED]
It makes more sense to me that (FILE,FILE) is kind of the same thing as
saying (@a,@b). In list context @a returns the array as a list, but in
scalar context @a returns the number of elements.
}, it
seems to me that it would go through this process:
- I have a slice here, so I'll loop over the slice elements
- The first is a, so I'll pull a scalar off the list and assign it to
$l2r{a}
- The second is b, so I'll pull another scalar off the list and assign
it
to $l2r{b
{...} part?
The left hand side of the assignment determines context so the @l2r{...}
part.
That strikes me as odd... When perl goes to populate @l2r{a,b}, it
seems to me that it would go through this process:
- I have a slice here, so I'll loop over the slice elements
- The first is a, so I'll
:
- I have a slice here, so I'll loop over the slice elements
- The first is a, so I'll pull a scalar off the list and assign it to
$l2r{a}
- The second is b, so I'll pull another scalar off the list and assign it
to $l2r{b}
- Remaining scalars in the list are discarded
Correct, except for the loop
this process:
- I have a slice here, so I'll loop over the slice elements
- The first is a, so I'll pull a scalar off the list and assign it to
$l2r{a}
- The second is b, so I'll pull another scalar off the list and assign it
to $l2r{b}
- Remaining scalars in the list are discarded
Correct, except
From: Bryan R Harris [EMAIL PROTECTED]
Given an open filehandle, why don't these two things do the same thing?
**
@l2r{a,b} = (FILE, FILE);
$c = FILE;
**
$l2r{a} = FILE;
$l2r{b} = FILE;
$c = FILE;
Bryan R Harris wrote:
From: Bryan R Harris [EMAIL PROTECTED]
Given an open filehandle, why don't these two things do the same thing?
**
@l2r{a,b} = (FILE, FILE);
$c = FILE;
**
$l2r{a} = FILE;
$l2r{b} = FILE;
$c = FILE;
this process:
- I have a slice here, so I'll loop over the slice elements
- The first is a, so I'll pull a scalar off the list and assign it to
$l2r{a}
- The second is b, so I'll pull another scalar off the list and assign it
to $l2r{b}
- Remaining scalars in the list are discarded
Why would $l2r
side of the assignment determines context so the @l2r{...}
part.
That strikes me as odd... When perl goes to populate @l2r{a,b}, it
seems to me that it would go through this process:
- I have a slice here, so I'll loop over the slice elements
- The first is a, so I'll pull a scalar off the list
Given an open filehandle, why don't these two things do the same thing?
**
@l2r{a,b} = (FILE, FILE);
$c = FILE;
**
$l2r{a} = FILE;
$l2r{b} = FILE;
$c = FILE;
**
The first seems to be
On Thu, Jun 19, 2008 at 5:50 AM, Bryan R Harris
[EMAIL PROTECTED] wrote:
Given an open filehandle, why don't these two things do the same thing?
**
@l2r{a,b} = (FILE, FILE);
$c = FILE;
because @l2r{...} is a list, right?
so the statement above is in a
From: Bryan R Harris [EMAIL PROTECTED]
Given an open filehandle, why don't these two things do the same thing?
**
@l2r{a,b} = (FILE, FILE);
$c = FILE;
**
$l2r{a} = FILE;
$l2r{b} = FILE;
$c = FILE;
Richard Lee schreef:
I use this before (split slice ) but it's working bit funny now..
it looks like it's splitting on '' instead of /|/ as I have specified
below... ??
Look for quotemeta in perlre.
--
Affijn, Ruud
Gewoon is een tijger.
--
To unsubscribe, e-mail: [EMAIL PROTECTED
I use this before (split slice ) but it's working bit funny now..
can someone tell me why??
it looks like it's splitting on '' instead of /|/ as I have specified
below... ??
use strict;
use warnings;
my $array = q/hi|how|are|you|fine/;
my ($moe,$hae,$now) = (split(/|/,$array))[0,1,2
Richard Lee wrote:
my ($moe,$hae,$now) = (split(/|/,$array))[0,1,2];
'|' is special in a regular expression and needs to be escaped.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL
was trying to
achieve. I typed out the output from Dumper I was expecting because I
was/am not entirely sure what terms to use. The above operation looks
like a hash slice to me albeit with another operator (map) involved.
Thanx for the help.
Dp.
--
To unsubscribe, e-mail: [EMAIL PROTECTED
of confusion over what I was trying to
achieve. I typed out the output from Dumper I was expecting because I
was/am not entirely sure what terms to use. The above operation looks
like a hash slice to me albeit with another operator (map) involved.
Yep, the Dumper output was exactly the right thing
Hi all,
Is it possible to make a hash slice like so
my %hash;
@[EMAIL PROTECTED] = [EMAIL PROTECTED];
My efforts suggest not:
#!/bin/perl
use strict;
use warnings;
use Data::Dumper;
my @keys = qw(fe fi fo thumb);
my @vals = 1..4;
my %hash;
@[EMAIL PROTECTED] = [EMAIL PROTECTED];
print
Beginner wrote:
Hi all,
Is it possible to make a hash slice like so
my %hash;
@[EMAIL PROTECTED] = [EMAIL PROTECTED];
My efforts suggest not:
#!/bin/perl
use strict;
use warnings;
use Data::Dumper;
my @keys = qw(fe fi fo thumb);
my @vals = 1..4;
my %hash;
@[EMAIL PROTECTED] = [EMAIL
From: Beginner [EMAIL PROTECTED]
#!/bin/perl
use strict;
use warnings;
use Data::Dumper;
my @keys = qw(fe fi fo thumb);
my @valone = 1..4;
my @valtwo = 10..14;
my %hash;
@[EMAIL PROTECTED] = [EMAIL PROTECTED],@valtwo];
[...] creates an array reference. You want
@[EMAIL PROTECTED]
On 9 Nov 2007 at 14:59, Rob Dixon wrote:
Beginner wrote:
Hi all,
Is it possible to make a hash slice like so
Hey Dermot
Hi Rob,
It's certainly possible, but I'm not sure why you've taken a reference
to your key and value arrays. [EMAIL PROTECTED] is a single scalar value
On 9 Nov 2007 at 16:35, Jenda Krynicky wrote:
From: Beginner [EMAIL PROTECTED]
#!/bin/perl
use strict;
use warnings;
use Data::Dumper;
my @keys = qw(fe fi fo thumb);
my @valone = 1..4;
my @valtwo = 10..14;
my %hash;
@[EMAIL PROTECTED] = [EMAIL PROTECTED],@valtwo];
On Nov 9, 4:09 pm, [EMAIL PROTECTED] (Beginner) wrote:
On 9 Nov 2007 at 16:35, Jenda Krynicky wrote:
What I was attempting was to have each key to be assigned the
coresponding items from the array. So it might look like something
like:
Right, so your question has nothing to do with hash
On Nov 9, 3:35 pm, [EMAIL PROTECTED] (Jenda Krynicky) wrote:
@[EMAIL PROTECTED] = ( [EMAIL PROTECTED],[EMAIL PROTECTED]);
Note that _can_ also be written
@[EMAIL PROTECTED] = \( @valone, @valtwo);
But IMNSHO it this syntax should _only_ be used in code that is
intended as part of a
Beginner wrote:
On 9 Nov 2007 at 14:59, Rob Dixon wrote:
Beginner wrote:
Is it possible to make a hash slice like so
It's certainly possible, but I'm not sure why you've taken a reference
to your key and value arrays. [EMAIL PROTECTED] is a single scalar value, as is
[EMAIL PROTECTED
On Nov 9, 11:09 am, [EMAIL PROTECTED] (Beginner) wrote:
What I was attempting was to have each key to be assigned the
coresponding items from the array.
Why didn't you just say that in the first place, rather than letting
everyone guess as to what you wanted?
So it might look like something
From: Beginner [EMAIL PROTECTED]
On 9 Nov 2007 at 16:35, Jenda Krynicky wrote:
From: Beginner [EMAIL PROTECTED]
#!/bin/perl
use strict;
use warnings;
use Data::Dumper;
my @keys = qw(fe fi fo thumb);
my @valone = 1..4;
my @valtwo = 10..14;
my %hash;
@[EMAIL
Try this:
map {$_-{text}} @[EMAIL PROTECTED]
Ryan Perry wrote:
@[EMAIL PROTECTED]{text}
I want to get all the text values for a set of keys in a hashref,
but the above code always gives me only the first in @sortedkeys.
Thanks for any assistance!
Ryan
--To unsubscribe, e-mail: [EMAIL
And this will work also:
map {$tmp-{$_}-{text}} @sortedkeys
Karjala wrote:
Try this:
map {$_-{text}} @[EMAIL PROTECTED]
Ryan Perry wrote:
@[EMAIL PROTECTED]{text}
I want to get all the text values for a set of keys in a hashref,
but the above code always gives me only the first in
@[EMAIL PROTECTED]{text}
I want to get all the text values for a set of keys in a hashref,
but the above code always gives me only the first in @sortedkeys.
Thanks for any assistance!
Ryan
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
JupiterHost.Net ha scritto:
In benchmarking some code I've come across something I did not expect:
slice:
use strict;
use warnings;
my @k=qw(1 2 3 4 5 6);
my %n;@[EMAIL PROTECTED] = @k;
print hi if exists $n{1};
print hi if exists $n{3};
print hi if exists $n{5};
print hi if exists $n{7};
print hi
The slice version took about 10 seconds, the grep one took more than 1
minute.
Marcello
Thanks Marcello!
Your example, John's. and renards have been very helpful to help see the
point someone else was trying to make about watching what you include in
your benchmark.
I appreciate your time
renard wrote:
BE AWARE THAT THE BENCHMARK PROVIDES INCORRECT RESULTS.
Thnaks, I was aware of that, but still wanted a general idea :)
The tested code is within an anonymous subroutine while this does
executes, the results differ dramitcally from the results when the
tested code is enclosed
efficient to:
1) create a hash slice and use exists when checking for specific ones
or
2) grep a regex out of the array when checking for specific ones
slice:
use strict;
use warnings;
my @k=qw(1 2 3 4 5 6);
my %n;@[EMAIL PROTECTED] = @k;
print hi if exists $n{1};
print hi if exists $n{3};
print hi
- Original Message -
From: JupiterHost.Net [EMAIL PROTECTED]
Date: Tuesday, January 25, 2005 11:01 am
Subject: Re: hash slice/exists vs. grep benchmark weirdness...
You have to stop spending so much time playing with all this bogus
benchmarking :)
It not bogus :) Its an example
Just as an FYI, you don't need exists in your code at all. It is just a
waste of time in your example. Should be beter writen as:
print hi if $n{11};
What if it's value is 0, '', or undef? It would exist but your test
would miss it :)
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional
[EMAIL PROTECTED] suggested:
Just as an FYI, you don't need exists in your code at all.
It is just a waste of time in your example. Should be beter writen as:
print hi if $n{11};
Bad idea, if you consider this:
$n{'oops'} = 0;
print hi if $n{'oops'};
print ho if exists $n{'oops'};
HTH,
is it
quicker/more efficient to:
1) create a hash slice and use exists when checking for
specific ones
or
2) grep a regex out of the array when checking for specific ones
If you're going to be looking for something in an array over and over
again, perhaps you shouldn't be using an array
- Original Message -
From: JupiterHost.Net [EMAIL PROTECTED]
Date: Tuesday, January 25, 2005 11:37 am
Subject: Re: hash slice/exists vs. grep benchmark weirdness...
Just as an FYI, you don't need exists in your code at all. It
is just a waste of time in your example. Should
the question I was trying to answer with the
benchmark:
Assuming you have an array of 0-15 elements is it quicker/more efficient to:
1) create a hash slice and use exists when checking for specific ones
or
2) grep a regex out of the array when checking for specific ones
Both. Each
simply asked what if to illustrate why if $n{11} is not better
than exists $n{11} in this case.
So the original question remains:
Which is faster:
1) slice the array into a has and do exists $hsh{key}
or
2) just grep a regex on the array
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional
is it
quicker/more efficient to:
1) create a hash slice and use exists when checking for
specific ones
or
2) grep a regex out of the array when checking for specific ones
If you're going to be looking for something in an array over and over
again, perhaps you shouldn't be using an array
Thanks for your input :)
Finally, there were serious errors in your methodology in your
Serious? I thought in the Big Picture, it won't matter a gnats eyebrow. :)
original benchmark. It turns out the printing dominated the total
That is why I made both identical except for the difference I'm
Thanks for your input :)
No problem -- I really do enjoy this. However, I do have some actual
WORK that I need to do today :(
Finally, there were serious errors in your methodology in your
Serious? I thought in the Big Picture, it won't matter a gnats eyebrow. :)
And I stand by that
JupiterHost.Net wrote:
In benchmarking some code I've come across something I did not expect:
slice:
use strict;
use warnings;
my @k=qw(1 2 3 4 5 6);
my %n;@[EMAIL PROTECTED] = @k;
print hi if exists $n{1};
print hi if exists $n{3};
print hi if exists $n{5};
print hi if exists $n{7};
print hi
#!/usr/bin/perl
use warnings;
use strict;
use Benchmark 'cmpthese';
my @k = qw( 1 2 3 4 5 6 );
cmpthese( -10, {
exists = sub {
my $count = 0;
my %hash;
@hash{ @k } = ();
for my $num ( 1, 3, 5, 7, 9, 11 ) {
$count++ if exists $hash{ $num };
Lawrence Statton wrote:
[snip]
Gotcha, thx
So then can you suggest a method of benchmarking these 2 methods that
would be more accurate?
I believe John's solution was excellent at illustrating th deficiencies
in the way I was doing it and supplying a solution and answering my
question all at
In benchmarking some code I've come across something I did not expect:
slice:
use strict;
use warnings;
my @k=qw(1 2 3 4 5 6);
my %n;@[EMAIL PROTECTED] = @k;
print hi if exists $n{1};
print hi if exists $n{3};
print hi if exists $n{5};
print hi if exists $n{7};
print hi if exists $n{9};
print hi
In benchmarking some code I've come across something I did not expect:
You have to stop spending so much time playing with all this bogus
benchmarking :)
slice:
use strict;
use warnings;
my @k=qw(1 2 3 4 5 6);
my %n;@[EMAIL PROTECTED] = @k;
print hi if exists $n{1};
print hi if exists
This works and does what I want it to:
perl -e '@x = split(\\., a.b.c); print $x[0];'
Why does not this work?
perl -e 'print @{split(\\., a.b.c)}[0];'
Is there a compact way to take a slice of a split (or other function that
returns an array) without creating a temporary variable?
Thanks
, it returns a list.
print( (split(/\./, a.b.c))[0] );
Is there a compact way to take a slice of a split (or other function that
returns an array) without creating a temporary variable?
Thanks,
Siegfried
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail
From: Siegfried Heintze [EMAIL PROTECTED]
This works and does what I want it to:
perl -e '@x = split(\\., a.b.c); print $x[0];'
Why does not this work?
perl -e 'print @{split(\\., a.b.c)}[0];'
Is there a compact way to take a slice of a split (or other function
that returns an array
This works and does what I want it to:
perl -e '@x = split(\\., a.b.c); print $x[0];'
Why does not this work?
perl -e 'print @{split(\\., a.b.c)}[0];'
Is there a compact way to take a slice of a split (or other function that
returns an array) without creating a temporary variable
From: Wiggins d Anconia [EMAIL PROTECTED]
This works and does what I want it to:
perl -e '@x = split(\\., a.b.c); print $x[0];'
Why does not this work?
perl -e 'print @{split(\\., a.b.c)}[0];'
Is there a compact way to take a slice of a split (or other function
that returns
can anyone tell me how I can remove the period at the end of each line
below??
.
.
.
.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
On Monday, September 29, 2003, at 10:53 AM, SilverFox wrote:
can anyone tell me how I can remove the period at the end of each line
below??
Sure. Place your cursor at the end of each line in turn and push the
backspace (or similar key) once... Oh, did you mean in Perl? ;)
What part are you
On Mon, 29 Sep 2003 11:53:16 -0400, SilverFox [EMAIL PROTECTED] wrote:
can anyone tell me how I can remove the period at the end of each line
below??
.
.
.
.
Let's see if I can start a flame war ;-)...
perldoc -f chop
I need to slice an array such that it gives me the first through the 4th to
last in a variable length array. I thought I could just do:
@comments[0..-4]
but Perl seems to choke on this. It's perfectly okay with a slice using two
negative #s:
@comments[-2..-4]
Anyone know why
I need to slice an array such that it gives me the first through the 4th to
last in a variable length array. I thought I could just do:
@comments[0..-4]
but Perl seems to choke on this. It's perfectly okay with a slice using two
negative #s:
@comments[-2..-4]
Anyone know why it doesn't
Bryan Harris wrote:
I need to slice an array such that it gives me the first through the 4th to
last in a variable length array. I thought I could just do:
@comments[0..-4]
but Perl seems to choke on this. It's perfectly okay with a slice using two
negative #s:
@comments[-2..-4
Rob Dixon [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]...
Hi Bryan
Bryan Harris [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
I need to slice an array such that it gives me the first through the 4th
to
last in a variable length a
I need to slice an array such that it gives me the first through the 4th to
last in a variable length array. I thought I could just do:
@comments[0..-4]
but Perl seems to choke on this. It's perfectly okay with a slice using two
negative #s:
@comments[-2..-4]
Anyone know why it doesn't
on Sun, 30 Jun 2002 12:08:23 GMT, Dan Fish wrote:
What is the most efficient (or at least AN efficient :-) way of
obtaining a slice from an array wherein the slice contains only
unique values found in the array?
See
perldoc -q duplicate
--
felix
This is the example d cited
What is the most efficient (or at least AN efficient :-) way of obtaining a
slice from an array wherein the slice contains only unique values found in
the array?
I.E.
if @array = (1,3,5,5,3,5,2,1) then @slice = (1,3,5,2)
Thanks,
-Dan
--
To unsubscribe, e-mail: [EMAIL PROTECTED
Hi!
As a perl beginner, I have a silly question about
array-slices-syntax:
That's clear:
perl -e '@a=(a,b,c);print @a[1..2]\n'
== b c
perl -e '@a=(a,b,c);print $a[1]\n'
== b
But why does $array[range] always give the first array-entry?
perl -e '@a=(a,b,c);print $a[1..2]\n'
== a
(OK, maybe
On Sat, Nov 03, 2001 at 05:49:37PM +0100, Thomas Hofer wrote:
Hi!
As a perl beginner, I have a silly question about
array-slices-syntax:
That's clear:
perl -e '@a=(a,b,c);print @a[1..2]\n'
== b c
perl -e '@a=(a,b,c);print $a[1]\n'
== b
But why does $array[range] always give
I am attempting to create a hash slice from a hash. The hash is:
%hash =(test1 = test10,
test2 = test12 ,
test3 = test13)
I want the slice to include only the keys test1 and test3. How can I
accomplish this?
--
To unsubscribe
--- Lisa Neclos [EMAIL PROTECTED] wrote:
I am attempting to create a hash slice from a hash. The hash is:
%hash =(test1 = test10,
test2 = test12 ,
test3 = test13)
I want the slice to include only the keys test1 and test3
LN I am attempting to create a hash slice from a hash. The hash is:
LN %hash =(test1 = test10,
LNtest2 = test12 ,
LN test3 = test13)
LN I want the slice to include only the keys test1 and test3. How can I
LN accomplish
Hi,
I have an unnamed array which I created from splitting up a colon separated string:
$_ = 0th:1st:2nd:3rd:4th:5th:6th:7th:Some random text: might have :colons: or
might not
print ((split /:/)[1,6,8]);
...but I really need to print everything after the 8th element. If the
are not field delimiters, but just part of the text.
Other than that, you may need to bite the bullet and name the array.
-Original Message-
From: Bradford Ritchie [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 26, 2001 1:46 PM
To: [EMAIL PROTECTED]
Subject: array slice question
Hi,
I
Bradford wrote:
Hi,
I have an unnamed array which I created from
splitting up a colon separated string:
$_ = 0th:1st:2nd:3rd:4th:5th:6th:7th:Some
random text: might have :colons: or might not
print ((split /:/)[1,6,8]);
...but I really need to print everything after
[1,6,8..-1]
in this case - is seen as a metacharacter inside the character class and
is not seen as -1
Hi,
I have an unnamed array which I created from splitting up a colon separated
string:
$_ = 0th:1st:2nd:3rd:4th:5th:6th:7th:Some random text: might have
:colons: or might not
, but specifying
... [1,6,8..-1] doesn't work.
However, this I will elaborate on. If you think about it you will be able
to tell why a slice of [8..-1] doesn't work. The .. operator is not just
used in array slicing, it's a more general range operator. What sense does
8 .. -1 make outside of the context
100 matches
Mail list logo