in reply to split and print
After just throwing at you, I'll try to explain it a little bit. First, I'll write it with some newlines:$var1 = 'abc~123~def'; print join("\n",split(/\~/,$var1))."\n";
Now let's discuss the lines. I'll take them from inside to outside because it should make the things a little bit easier to understand:1 print 2 join( 3 "\n", 4 split( 5 /\~/, 6 $var1 7 ) 8 ). 9 "\n";
The regular expression in this case has / as start and end chars and an escaped ~.@MyArray = split(/\~/,$var1);
While writing this, I got a really cool idea which would fit your request but I don't think it will fit your problem. Just to be complete, here ist another solution:
; This one replaces every ~ with a \n using a regular expression:$var1 = 'abc~123~def'; $var1 =~ s/\~/\n/g; print "$var1\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: split and print
by johngg (Canon) on Sep 04, 2009 at 21:25 UTC | |
|
Re^2: split and print
by sans-clue (Beadle) on Sep 04, 2009 at 20:58 UTC |