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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-19 07:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found