in reply to Re: Is it possible to split a hash key?
in thread Is it possible to split a hash key?

Just a side note. You wrote:

The first parameter to split is always a regexp even if you write a string (unless that string happens to be a single space).

A single space also results in (the equivalent of) a regex in split. The difference is that the regex is not the string itself (/ /) but /\s+/. Specifying ' ' is an alternaive way of invoking the default which is to split on white space.

Anno

Replies are listed 'Best First'.
Re^3: Is it possible to split a hash key?
by almut (Canon) on Jul 29, 2007 at 12:39 UTC
    ... The difference is that the regex is not the string itself (/ /) but /\s+/

    ...not to forget the subtle, additional magic of ' ' vs. /\s+/ in the handling of leading whitespace. Compare

    my $s = " foo bar baz"; print join("|", split /\s+/, $s), "\n"; # prints |foo|bar|baz print join("|", split ' ', $s), "\n"; # prints foo|bar|baz
      ...not to forget the subtle, additional magic of ' ' vs. /\s+/ in the handling of leading whitespace.

      Oh right, that too. split() is too clever for its own good by half.

      Anno

        Gee, see I thought most people would learn that one exception because it's the most useful mode for "text."

        ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊