Your code expects fixed size records but the data you show consists of variable length lines. It is not at all clear what you are trying to achieve, unless you simply want the first 63 characters from each line. Ignoring most of the extra formatting code that could be just:

#!/usr/bin/perl use strict; use warnings; my $fileData = <<FILE; 19:39:44.765096 IP 10.195.32.212.49152 > 255.255.255.255.trivnet1: UDP +, length 12 19:39:44.765572 IP 10.195.32.212.49152 > 239.0.82.11.trivnet1: UDP, le +ngth 12 19:39:45.202568 IP 10.195.32.96.61804 > 255.255.255.255.sentinelsrm: U +DP, length 40 19:39:45.265116 IP 10.195.32.212.49152 > 255.255.255.255.trivnet1: UDP +, length 12 19:39:45.265590 IP 10.195.32.212.49152 > 239.0.82.11.trivnet1: UDP, le +ngth 12 19:39:45.411153 IP 10.195.32.198.netbios-ns > 10.195.32.255.netbios-ns +: NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST 19:39:45.412136 IP 10.195.32.198.netbios-dgm > 10.195.32.255.netbios-d +gm: NBT UDP PACKET(138) 19:39:45.620442 STP 802.1d, Config, Flags [none], bridge-id 8020.00:22 +:56:29:3a:00.8014, length 43 19:39:45.765086 IP 10.195.32.212.49152 > 255.255.255.255.trivnet1: UDP +, length 12 FILE open my $fIn, '<', \$fileData; while (<$fIn>) { chomp; printf ">> $. %s\n", substr $_, 0, 63; }

Prints:

>> 1 19:39:44.765096 IP 10.195.32.212.49152 > 255.255.255.255.trivne >> 2 19:39:44.765572 IP 10.195.32.212.49152 > 239.0.82.11.trivnet1: >> 3 19:39:45.202568 IP 10.195.32.96.61804 > 255.255.255.255.sentine >> 4 19:39:45.265116 IP 10.195.32.212.49152 > 255.255.255.255.trivne >> 5 19:39:45.265590 IP 10.195.32.212.49152 > 239.0.82.11.trivnet1: >> 6 19:39:45.411153 IP 10.195.32.198.netbios-ns > 10.195.32.255.net >> 7 19:39:45.412136 IP 10.195.32.198.netbios-dgm > 10.195.32.255.ne >> 8 19:39:45.620442 STP 802.1d, Config, Flags [none], bridge-id 802 >> 9 19:39:45.765086 IP 10.195.32.212.49152 > 255.255.255.255.trivne
True laziness is hard work

In reply to Re: Test Code to read data from file by GrandFather
in thread Test Code to read data from file by 1hab

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.