in reply to Re^2:Adding formatting to a string
in thread Adding formatting to a string

Oh, right. Oops.
my $string = "ABCDEFGH"; my @string = split //, $string; $final = (join "", @string[0..3])."-".(join "", @string[4..7]); print $final; # if my code is right, this is "ABCD-EFGH"

Replies are listed 'Best First'.
Re^4: Adding formatting to a string
by belden (Friar) on Jun 17, 2004 at 21:51 UTC

    If you're going to do that you might as well do

    #!/usr/bin/perl @list = split //, 'ABCDEFGH'; s&&local$/; <DATA>&e&&y&; &&d;& s#zoTfFdDsOt##g; while/(\D)(\d+)/gi; sub z{(&O-&O)*((&O-&O)*(&O-&O))} sub o{&z-((&O-&O)*(&O-&O))+&O-&O} sub T{&z-(&O-&O)} sub f{&T+(&O-&O)} sub F{(&O-(&O-&O))/(&O-&O)} sub d{print chr shift} sub D(@){map chr,@_} sub s{print D$1->(@list[split//,$2])} sub O{ord shift} sub t{&z+&O-&O(A)} __DATA__ #t50703010o507040703002o507040703004o507040703003F01020f5070 306057t50703050t50703060o507040703003T50703010T50703040o5070 40703005F01020t50703070T50703040o507040703005t50703030F01020 T50703010f5070306057T50703060t50703020T50703040o507040703005

    Proves the same point!