in reply to Inserting an element into an array after a certain element

% perl -le 'print"@{[split//,join q(x),split/(?<=c)/,join(q(),qw(a b c + d c e f)),2]}"' a b c x d c e f
Pretty perverse (perl-verse?).

the lowliest monk

Replies are listed 'Best First'.
Re^2: Inserting an element into an array after a certain element
by CountZero (Bishop) on Apr 01, 2005 at 05:22 UTC
    This works for the example given, but will break if one of the elements contain white-space.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      Oh, it breaks if any of the elements consists of more than one character:

      % perl -le 'print"@{[split//,join q(x),split/(?<=c)/,join(q(),qw(a b c + d c e foo f)),2]}"' a b c x d c e f o o f
      but single spaces are fine:
      % perl -le 'print"@{[split//,join q(x),split/(?<=c)/,join(q(),qw(a b c + d c e),q( ),q(f)),2]}"' a b c x d c e f
      To fix this, I guess one could do something like
      perl -le 'print"@{[split/\0/,join qq(\0x),split/(?<=c)/,join(qq(0),qw( +a b c d c e foo f)),2]}"' a b c x d c e foo f

      the lowliest monk