Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^3: Adding formatting to a string

by Anonymous Monk
on Jun 16, 2004 at 22:12 UTC ( [id://367456]=note: print w/replies, xml ) Need Help??


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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://367456]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2024-04-19 21:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found