I have a pearl script that right now takes a tracking file and from our shipping software and converts it into the format we need to import into our Software. the issue is the tracking # is too long and I just found out from our carrier that we can strip the first 8 characters. Is this possible?

here is the current code ("trackingno") it the ending field
use Text::CSV_XS; use Date::Manip; sub trim($); # Formatting variables $quote_char = '"'; $sep_char = ','; $NumHeaderRowsToSkip = 6; #$AuctionSite_EmailBlank = "amazon|pay"; $out=$ARGV[0]; # Name output file $out =~ s/(^.*).csv/$1-FS.txt/; # open file handle for output file open OUT, ">$out" or die "Cannot open $out for write :$!"; # Remove linefeeds and build array while (<>) { chomp; push (@rows, $_); } # Init csv object $csvin = Text::CSV_XS->new({ 'quote_char' => $quote_char, 'sep_char' => $sep_char }); $csvout = Text::CSV_XS->new({ 'quote_char' => $quote_char, 'sep_char' => ",", 'always_quote' => true }); # build array of header fields $headers = $rows[0]; $csvin->parse($headers); my @headers = $csvin->fields; my @rowscolumns = map { chomp; $csvin->parse($_); [$csvin->fields]; } +@rows; # build array of hashes with column name as hash index foreach my $row(@rowscolumns) { my %hashrow; my $index = 0; foreach my $val(@$row) { $hashrow{trim($headers[$index])} = trim($val); $index++ } push @arrayhash, \%hashrow; } $arrayhash[0]->{'Reference'} = 'Reference'; $arrayhash[0]->{'trackingno'} = 'trackingno'; $arrayhash[0]->{'packwt'} = 'packwt'; $arrayhash[0]->{'shipdate'} = 'shipdate'; $arrayhash[0]->{'paytype'} = 'paytype'; # construct output csv lines my $index = 0; foreach my $row(@arrayhash) { if($index>0) { $row->{'shipdate'} = &UnixDate(&ParseDate($row->{'shipdate'})," +%m/%d/%Y"); } my @output_fields = ( $row->{'Reference'}, $row->{'trackingno'}, $row->{'packwt'}, $row->{'shipdate'}, $row->{'paytype'}, ); $csvout->combine(@output_fields); $outrow[$index] = $csvout->string; $index++; } #print result to file foreach (@outrow) { print OUT "$_\n"; } sub trim($) { my $string = shift; $string =~ s/^\s+//; $string =~ s/\s+$//; return $string; }
any help would be appreciated! thanks.

In reply to need to strip the first 8 characters out of a tracking # by bdepew

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.