If you call split like this @rv = split $_[0], @_[ 1 .. 2 ] you get the return value undef.

This is not true, it gives (99). Update 1: Presuming @_ = (qr{:}, 'a:b:c', 99) from the given example. Update 2: A capturing group in the regex does not change the result for this case.

To understand this behaviour you need to consider function prototypes. The compiler recognises split being called with two arguments, where the second is a list that gets assigned to a single scalar. This results in the last element of the list being assigned to the scalar, just like in

$x = (1, 2, 4); # $x = 4
This behaviour is caused by the usage of an array slice. A "pure" array would be evaluated in scalar context giving its length.

In the following example the sub show_args sees its arguments just like split.

UPDATE 3: As suspected by bojinlund in Re^2: My problems to understand the Perl documentation and proven by LanX in Re^4: My problems to understand the Perl documentation, the sub show_args does not see its arguments exactly as split.

#!/usr/bin/perl use strict; use warnings; use Data::Dump 'dd'; use feature 'say'; sub show_args ($_;$) { dd @_; } sub call_show_args { say "single:"; show_args $_[0], $_[1], $_[2]; say "flat:"; show_args @_; say "slice:"; show_args @_[0 .. 2]; say "slice split:"; show_args $_[0], @_[1 .. 2]; say "array split:"; my $p = shift; show_args $p, @_; } $_ = 'default'; call_show_args qr{:}, 'a:b:c', 99; __DATA__ single: (qr/:/, "a:b:c", 99) flat: (3, "default") slice: (99, "default") slice split: (qr/:/, 99) array split: (qr/:/, 2)

Greetings,
-jo

$gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$

In reply to Re: My problems to understand the Perl documentation [updated] by jo37
in thread My problems to understand the Perl documentation by bojinlund

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.