in reply to Re^2: double quote vs single quote oddities. I need enlightenment
in thread double quote vs single quote oddities. I need enlightenment

So what you said makes sense for me up until the single quote doubled escaped

For the expression split "\\.", 'data.txt', first Perl interpolates "\\." to the literal string [\.]. This string is then fed to the regular expression engine, making split "\\.", 'data.txt' equivalent to split /\./, 'data.txt'. The input is split on literal periods and then result is then ('data','txt').

why doesn't split bust the expression apart into NULL and ata1.txt

You would get your expected result if you include a limit on the expression, i.e. split /./, $foo, 2;. Unless an explicit limit is included, split will operate on every match. Therefore, the initial result of the split is a list of nine empty strings. As documented in split,

empty trailing ones are deleted. (If all fields are empty, they are considered to be trailing.)

Therefore, it returns an empty list.

Replies are listed 'Best First'.
Re^4: double quote vs single quote oddities. I need enlightenment
by lyapunov (Novice) on Jul 08, 2010 at 18:05 UTC

    Thanks again, I catch the second part now. I poorly phrased my first question. Let me take another stab at it.

    Both split('\.',$foo) and split('\\.',$foo) return two parts "data1" and "txt". Since they are not interpolated the first one working really make sense. The second is still elusive. I would think it would be equivalent then to split /\\./, $foo but that is split into data1.txt and nothing as the literal [\.] is not encountered e.g. a real backslash following by any printable character and not an escaped dot getting passed to the regex engine.

    Again, I am really trying not be a pest, but there is some subtlety that I am missing. I have gotten my head around everything except for this. Thanks!

      In non-interpolated strings, a double-backslash is interpreted as a single back slash.

      print '\\.', "\n", '\.', "\n"; ------ \. \.

      If you look at the docs for split, it specifically says it's expecting a /PATTERN/. So it interprets both '\\.' and '\.' as /\./.

      --marmot