in reply to How can I split a string into fixed-length parts, rather than on delimiters?
You can combine two nifty (i.e. rarely used) tricks:
sub fixed_width_records($$) { my( $size, $string ) = @_; open my $f, '<', \$string or die; # read from a string as if it were + a file local $/ = \$size; # "records" will be this many chars, rather than +to some end-of-line thing <$f> # parse! (i.e. read) and return the list of "records" } my( $first, $second ) = fixed_width_records( 4, "41084109.udp" ); print ">$first\n>$second\n";
|
|---|