Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I am trying to understand split and its documentation. To do this I have implement split by using m{} and the variables @- and @+. By this I have found some problems

This script shows some of them:

use strict; use warnings; use 5.010; use Data::Dump qw(dump dd ddx); sub split_e { } split_e( // ); # Warning: Use of uninitialized value $_ in pattern match (m//) at pm_ +1.pl ... my @rv = split( //, '' ); # Warning: none my $str = '1-10,20'; my $pat = '(-)|(,)'; @rv = split( $pat, $str ); warn dump @rv; # (1, "-", undef, 10, undef , ",", 20) @rv = $str =~ m{$pat}g; warn dump @rv; # ("-", undef, undef, ",") while ( my $rv = $str =~ m{$pat}gc ) { for my $ix ( 0 .. 99 ) { if ( defined $-[$ix] ) { say sprintf '$ix= %d (%d,%d)<%s>', $ix, $-[$ix], $+[$ix], substr $str, $-[$ix], $+[$ix] - $-[$ix]; } } } say "Strawberry Perl $^V"; say $^O; __DATA__ output: $ix= 0 (1,2)<-> $ix= 1 (1,2)<-> $ix= 0 (4,5)<,> $ix= 2 (4,5)<,> Strawberry Perl v5.30.1 MSWin32

Questions

Magic in split

This split_e( // ); gives the warning: Use of uninitialized value $_ in pattern match (m//) at pm_1.pl ... but this split( // ); does not.

Is there some magic in split indicate by the /s in /PATTERN/ in the documentation?

Bug in the variables @- and @+

I find that the result from split, m{} and when using $-[$ix] $+[$ix] are inconsistent.

Split gives (1, "-", undef, 10, undef , ",", 20).

m{} gives ("-", undef, undef, ",").

Using $-[$ix] $+[$ix] does not include the undefs

Is this a bug in the last case?


In reply to Re: Function Split, bug or error in the documentation? by bojinlund
in thread Function Split, bug or error in the 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (3)
    As of 2020-10-31 07:25 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My favourite web site is:












      Results (287 votes). Check out past polls.

      Notices?