LoginSignup
1
2

More than 5 years have passed since last update.

Perl5,Perl6で配列の末尾からひとつ前の要素を取り出す

Last updated at Posted at 2015-10-30

Perlで配列の末尾からひとつ前の要素を取り出すには。

Perl5

#!/usr/bin/env perl

use v5.20;

my @a = ( 'a' .. 'z' );

# 配列の末尾からひとつ前の要素を取り出す
say $a[-2]; #=> 'y'

Perl6

use v6;

my @a = 'a' .. 'z';

# 配列の末尾からひとつ前の要素を取り出す
say @a[*-2]; #=> 'y'

おわりです。

参考や注釈

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2