I think all you mention has already been said in the other answers. If I switch to

sysread

and compare buk with ike1 (reading one line at the time) and ike2 (reading two lines at the time), your method wins a bit but leaves all three methods withing the noise level. Also note how *all* numbers go up!

With these rates, I wonder if I would still use your substr ref method or the unpack approach, as I find the latter way easier to read and maintain. If however performance is vital, maybe XS code would squeeze out even more (with pre-bound variables).

Rate ike1 buk ike2 ike1 384977/s -- -2% -3% buk 392677/s 2% -- -1% ike2 394907/s 3% 1% --

Note that if you keep local $/ = \122; in ike1, it has a *huge* influence on performance, even if you'd say that it should not be used:

Rate ike1 buk ike2 ike1 275687/s -- -27% -30% buk 378299/s 37% -- -4% ike2 392677/s 42% 4% --
use strict; use warnings; use Benchmark qw(cmpthese); my $data = do { local $/; <DATA> } x 400; my @data; my $rec = chr (0) x 512; { # 1. BrowserUk my @type3l = split m/:/, "02:10:33:15:19:10:3:18:6:4"; my $n = 0; my @type3o = map { $n += $_; $n - $_; } @type3l; my @type3 = map \substr ($rec, $type3o[$_], $type3l[$_]), 0 .. $# +type3o; my @typeOl = split m/:/, "02:98:11:9"; $n = 0; my @typeOo = map { $n += $_; $n - $_; } @typeOl; my @typeO = map \substr ($rec, $typeOo[$_], $typeOl[$_]), 0 .. $# +typeOo; sub buk { open my $fh, "<", \$data; while (sysread $fh, $rec, 122, 0) { @data = map $$_, @type3; sysread $fh, $rec, 122, 0; @data = map $$_, @typeO; } } # buk } sub ike2 { open my $fh, "<", \$data; while (sysread $fh, $rec, 244, 0) { @data = unpack "A2 A10 A33 A15 A19 A10 A3 A18 A6 A4 x2" . "A2 A98 A11 A9 x2", $rec; } } # ike2 sub ike1 { # local $/ = \122; open my $fh, "<", \$data; while (sysread $fh, $rec, 122, 0) { @data = unpack "A2 A10 A33 A15 A19 A10 A3 A18 A6 A4 x2", $rec; sysread $fh, $rec, 122, 0; @data = unpack "A2 A98 A11 A9 x2", $rec; } } # ike1 cmpthese (-2, { ike1 => \&ike1, ike2 => \&ike2, buk => \&buk, }); __END__ 03002068454210482 000000004204.572011-04-14 + 19:53:41INTERNET C 750467375 0214833 + G02042954 03002068703214833 000000002558.662011-04-15 + 08:17:19INTERNET C 761212737 0211561 + 05601207284 03002068802911561 000000001463.702011-04-15 + 08:40:52INTERNET C 719807216 029911 + 00100275296

Enjoy, Have FUN! H.Merijn

In reply to Re^6: Working with fixed length files by Tux
in thread Working with fixed length files by vendion

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.