[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] duh: A small puzzler



>>>>> "John" == John Porter <jdporter@min.net> writes:

John> Only if, as in this case, there are no runs of whitespace longer
John> than one.  But in general, you need /\s+/ if you want the same
John> behavior as ' '.

But it's not precisely the same... witness:

    for (split /\n/, <<'EOF') {
    fred   barney   dino   betty
      elroy  jane  george  astro
    EOF
      print "split ' ': ", (map "<$_>", split ' '), "\n";
      print "split /\s+/: ", (map "<$_>", split /\s+/), "\n";
    }

    ==>

    split ' ': <fred><barney><dino><betty>
    split /s+/: <fred><barney><dino><betty>
    split ' ': <elroy><jane><george><astro>
    split /s+/: <><elroy><jane><george><astro>

Note the extra empty element in front of 'elroy'.  That's because
split ' ' emulates an awk-style split, which discards a leading empty
element.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe