Perl - How to change every $variable occurrence of ";" in a string -
very new here gentle. :)
here jist of want do:
i want take string made of numbers separated semi-colons (ex. 6;7;8;9;1;17;4;5;90) , replace every "x" number of semicolons "\n" instead. "x" number defined user.
so if:
$string = "6;7;8;9;1;17;4;5;90"; $nth_number_of_semicolons_to_replace = 3;
the output should be:
6;7;8\n9;1;17\n4;5;90
i've found lots on changing nth occurrence of haven't been able find on changing every nth occurrence of trying describe above.
thanks help!
use list::moreutils qw(natatime); $input_string = "6;7;8;9;1;17;4;5;90"; $it = natatime 3, split(";", $input_string); $output_string; while (my @vals = $it->()) { $output_string .= join(";", @vals)."\n"; }
Comments
Post a Comment