in reply to about split

I think the confusion here is that "split" is not the same as "split / /". Rather, "split" is the same as "split /\s+/".

Also, if you "split $_", Perl thinks you're using $_ as your pattern. You can't leave out the pattern and still pass a string to split. If you specify a string, you also have to specify a pattern.

Replies are listed 'Best First'.
Re^2: about split
by BrowserUk (Patriarch) on Mar 12, 2008 at 16:22 UTC
    Rather, "split" is the same as "split /\s+/"

    Actually, it's not. The only way to avail yourself of the magical default split whilst processing other than $_, is to use ' ' or " " in place of the regex. See the first and last examples below:

    C:\test>p1 $_ = ' the quick brown fox ';; print join'|', split;; ## default split no args (leading null field +omitted) the|quick|brown|fox print join'|', split /\s+/;; ## \s+ includes leading null field |the|quick|brown|fox print join'|', split / /;; ## same as split /\s/ |||the|quick||||brown|fox print join'|', split ' ';; ## Same as no arg split the|quick|brown|fox

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
Re^2: about split
by Not_a_Number (Prior) on Mar 12, 2008 at 16:21 UTC
    "split" is the same as "split /\s+/".

    Not quite the same:

    no warnings 'uninitialized'; $_ = ' a string with leading whitespace'; print join( ':', split ), "\n"; print join( ':', split /\s+/ ), "\n"; ______ a:string:with:leading:whitespace :a:string:with:leading:whitespace