I don't know how usefull this will be to anyone. It's rather obscure. Perldoc -f split says:

As a special case, specifying a PATTERN of space (’ ’) will split on white space just as "split" with no arguments does.  Thus, "split(’ ’)" can be used to emulate awk’s default behavior, whereas "split(/ /)" will give you as many null initial fields as there are leading spaces.  A "split" on "/\s+/" is like a "split(’ ’)" except that any leading whitespace produces a null first field.  A "split" with no arguments really does a "split(’ ’, $_)" internally.

That reads like stereo instructions. I think I understand it but it appears that B::Deparse is having problems with it:

#!/usr/bin/perl -w $string = ' abc def '; @array1 = split " ", $string; @array2 = split ?\s+?, $string; print '2: ' . ( join '|', @array1 ) . "\n"; print '3: ' . ( join '|', @array2 ) . "\n";

Run it through deparse and you get:

BEGIN { $^W = 1; } $string = ' abc def '; @array1 = split(?\s+?, $string, 0); @array2 = split(?\s+?, $string, 0); print '2: ' . join('|', @array1) . "\n"; print '3: ' . join('|', @array2) . "\n";

Run this script and you get the following output:

2: abc|def 3: |abc|def

This caused me to not trust Deparse quite so much. I'm going to be a little more careful about trusting what Deparse spits out.

Harley J Pig

In reply to Deparse isn't as reliable as I thought by harleypig

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.