in reply to Re^2: splinting a line of text by comma
in thread splinting a line of text by comma

yeah, better.

I was already in bed half sleeping and was surprised about whitespace handling in glob.

> Still very much not recommended :)

Well if you find a way to escape curlies and other "wildcard characters" from the input... :)

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

  • Comment on Re^3: splinting a line of text by comma

Replies are listed 'Best First'.
Re^4: splinting a line of text by comma
by tybalt89 (Monsignor) on Nov 26, 2018 at 15:22 UTC
    if you find a way to escape curlies and other "wildcard characters"

    Sure, just move them out of the way :)

    #!/usr/bin/perl # https://perlmonks.org/?node_id=1226189 use strict; use warnings; #print glob qq("$_") =~ s/[^|\n]+/{$&}/gr while <DATA>; print map tr/\1-\7/{}[]"*?/r, glob +('"' . tr/{}[]"*?/\1-\7/r . '"') =~ s/[^|\n]+/{$&}/gr while <DATA>; __DATA__ some text foo | some text BAR | oh , no , commas | some text BAZ | som +e text QUX some,text,FOO{3} | some text BAR*? | "one" two | some , text , QUX

    Outputs:

    some text foo | some text BAR | oh | some text BAZ | some text QUX some text foo | some text BAR | no | some text BAZ | some text QUX some text foo | some text BAR | commas | some text BAZ | some text QUX some| some text BAR*? | "one" two | some some| some text BAR*? | "one" two | text some| some text BAR*? | "one" two | QUX text| some text BAR*? | "one" two | some text| some text BAR*? | "one" two | text text| some text BAR*? | "one" two | QUX FOO{3} | some text BAR*? | "one" two | some FOO{3} | some text BAR*? | "one" two | text FOO{3} | some text BAR*? | "one" two | QUX
      I had the same idea° but that's not really "escaping".

      And for a general purpose solution you would need to escape \1..\7 too. I'm afraid that's not feasible with tr.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      °) using this technique in my Wiki-nodelet-hack already