in reply to How can I split a string into fixed-length parts, rather than on delimiters?
The $/ variable determines how much to read in. In this case its set to 4, to read in 4 bytes (its default value is "\n").open(FILE,'41084109.udp'); $/=\4; $a = <FILE>; $b = <FILE>;
This might be more useful if you need more than two sets of four numbers, for something like:
open(FILE,'41084109.udp'); $/=\4; while(<FILE>) { #count the occuarnce of the 4 digits $count{$_}++; }
{QA Editors note: The original question's subject line was somewhat ambiguous as to whether the person asking was trying to split a file, or a filename. The followup text was still somewhat unclear, but the example shown by the original poster clarified that he was trying to split a filename. This response will aid in splitting the contents of a file, which is different but worthy of mention.}
Originally posted as a Categorized Answer.
|
|---|