Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: How can I split a string into fixed-length parts, rather than on delimiters?

by jdporter (Paladin)
on Apr 07, 2021 at 00:33 UTC ( [id://11130925]=note: print w/replies, xml ) Need Help??


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";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2024-03-28 10:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found