Here is an SSCCE showing that it works fine for me.

#!/usr/bin/env perl use strict; use warnings; my $debug = 1; my @input = <DATA>; read_gage_header (\@input); sub read_gage_header { my ($data, $header, @headers, $ettb_no, $year); $data = shift; #Now get ettb_no $header = $data->[0]; @headers = split / /, $header; #NOTE: this print yields expected results print "HEADERS before ettb_no @headers\n" if defined ($debug); #NOTE: this gets the proper ettb_no $ettb_no = $headers[4]; #Skip to get to Year shift @$data; shift @$data; shift @$data; $header = shift @$data; #NOTE: this gives me "Year 201" print "HEADER before year $header\n" if defined ($debug); } __DATA__ Gage Information - 240CN - 240 FEEDER CANAL SUPPLY TO 240 FEEDER FROM BELEN HIGH LINE CANAL + Year 2019 Month Day Time Height Discharge (mst) (HP ft) (QR cfs) ----- --- ---- ------ --------- July 29 1230 5.54 80 ... more data ...

Which produces this output when run:

$ perl 11109714.pl HEADERS before ettb_no Gage Information - 240CN - 240 FEEDER CANAL + HEADER before year Year 2019

In other words, the problem is with the code that you haven't shown us - the part where you read in the input and populate your $data.


In reply to Re: Perl appears to be dropping last character of line by hippo
in thread Perl appears to be dropping last character of line by cmarra

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.