[OT] slice vs. splice

2004-04-16 Thread Joel Rees
slice syntax  isn't deprecated or anything is it? Don't see it 
mentioned in O'Reilly's Nutshell or in the Cookbook's section on arrays.

(Sorry about the not-really-topical noise.)



Re: [OT] slice vs. splice

2004-04-16 Thread Randal L. Schwartz
 Joel == Joel Rees [EMAIL PROTECTED] writes:

Joel slice syntax  isn't deprecated or anything is it? Don't see it
Joel mentioned in O'Reilly's Nutshell or in the Cookbook's section on
Joel arrays.

Joel (Sorry about the not-really-topical noise.)

Well, according to the blding edge Perl 5.8.4-rc2 docs:

http://search.cpan.org/~nwclark/perl-5.8.4-RC2/pod/perldata.pod#Slices

it's still firmly in there. I suspect it won't ever go away.  There's
slice notation already in Perl6.  Slices are too useful to get
rid of. :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
[EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


Re: [OT] slice vs. splice

2004-04-16 Thread David Wheeler
On Apr 16, 2004, at 7:15 AM, Joel Rees wrote:

slice syntax  isn't deprecated or anything is it? Don't see it 
mentioned in O'Reilly's Nutshell or in the Cookbook's section on 
arrays.
There is no slice function. You can use the splice function, but this 
syntax is easier:

my @foo = qw(one two three four);
my @slice = @foo[1,3]; # (one, three)
Do it with array references like this:

my $ref = [EMAIL PROTECTED];
@slice = @{$ref}[2,4]; # (two, four)
You can also slice hashes:

my %bar = (one = 1, two = 2, three = 3, four = 4);
@slice = @bar{qw(one four)}; # (1, 4)
And hash references:

$ref = \%bar;
@slice = @{$ref}{qw(two four)}; # (2, 4)
HTH,

David (Who doesn't consider this off-topic)



Re: [OT] slice vs. splice

2004-04-16 Thread Sherm Pendley
On Apr 16, 2004, at 10:51 AM, David Wheeler wrote:

Remember, array indexes are zero-based:

my @foo = qw(one two three four);
my @slice = @foo[1,3]; # (one, three)
[EMAIL PROTECTED] = @foo[1,3]; # ('two', 'four')

my $ref = [EMAIL PROTECTED];
@slice = @{$ref}[2,4]; # (two, four)
@slice = @{$ref}[2,4]; # ('three', undef)

And that, ladies and gents, is my nit-pick for the day. ;-)

sherm--



Re: [OT] slice vs. splice

2004-04-16 Thread David Wheeler
On Apr 16, 2004, at 10:27 AM, Sherm Pendley wrote:

Remember, array indexes are zero-based:
Gah! That's what I get for using comments! ;-)

David



Re: [OT] slice vs. splice

2004-04-16 Thread Sherm Pendley
On Apr 16, 2004, at 1:35 PM, David Wheeler wrote:

Gah! That's what I get for using comments! ;-)
Darn right, stop that! Code is hard to write, it should be hard to 
read, too! ;-)

sherm--