<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Perl Help in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3328920#M188685</link>
    <description>Fixed records are easiest to deal with using pack and unpack.&lt;BR /&gt;sprintf is a not so good choice here. Either substr () or unpack is better. Most severe error you made is a numeric comparison between ID and "9999..." which both extend the maximum storable integer value, even in 64bit environment. You will have to deal with the keys/ID's in string context, using 'eq' instead of '=='&lt;BR /&gt;&lt;BR /&gt;If every record is 1563 bytes, with 21 bytes to introduce the ID,&lt;BR /&gt;&lt;BR /&gt;while (read (I_FILE, $buf, 1563)) {&lt;BR /&gt;($id) = unpack "A21", $buf;&lt;BR /&gt;if ($id eq "9"x21){&lt;BR /&gt;# yadayadayada&lt;BR /&gt;next;&lt;BR /&gt;}&lt;BR /&gt;# this for all in "99999...." stuff&lt;BR /&gt;print O_FILE "$buf\n";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
    <pubDate>Mon, 12 Jul 2004 12:43:10 GMT</pubDate>
    <dc:creator>H.Merijn Brand (procura</dc:creator>
    <dc:date>2004-07-12T12:43:10Z</dc:date>
    <item>
      <title>Perl Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3328919#M188684</link>
      <description>I am trying to manipulate a data file to retrieve information for down-stream processing.&lt;BR /&gt;&lt;BR /&gt;The records are 1563 bytes long, start with an ascii 'soh' (001) and end with a 'C'. The record id is the first data field and is 21 bytes long.&lt;BR /&gt;&lt;BR /&gt;I want to ignore records with id = all '9's., but I do need to include the 'soh' as the first byte for the downstream app. I also need to add an newline after the end of record 'C'.&lt;BR /&gt;&lt;BR /&gt;The following snippet works, except for trying to match the $id with the 'soh' included as the first charactor in the buffer, IE: if I slew the reads so that the 'soh' is the last char of the previous record, it will drop the ids = all 9s.&lt;BR /&gt;&lt;BR /&gt;The basic problem is how do I get the "if $id != 'soh'(9x21)" statement to catch only the good records? or what sprintf format do I need to tack the 'soh' back on in the right place.  I have tried several formats with no success.&lt;BR /&gt;&lt;BR /&gt;Hope that states what I am trying to do - skills with Perl are a bit ruff, in case you hadn't guessed.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Snippet:&lt;BR /&gt;&lt;BR /&gt;while (read(I_FILE, $buf, 1563)) {&lt;BR /&gt;  $id = sprintf("%-21s",$buf);&lt;BR /&gt;    if ($debug) {&lt;BR /&gt;    printf("%s\n",$id );&lt;BR /&gt;      if ($id == "999999999999999999999") {&lt;BR /&gt;        printf("%s",$buf);&lt;BR /&gt;        print("\n");&lt;BR /&gt;      }&lt;BR /&gt;    }&lt;BR /&gt;    if (!$debug) {&lt;BR /&gt;      if ($id != "999999999999999999999") {&lt;BR /&gt;        printf(O_FILE "%s",$buf);&lt;BR /&gt;        print(O_FILE "\n");&lt;BR /&gt;      }&lt;BR /&gt;    }&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Rt.</description>
      <pubDate>Mon, 12 Jul 2004 09:41:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3328919#M188684</guid>
      <dc:creator>Robert True</dc:creator>
      <dc:date>2004-07-12T09:41:26Z</dc:date>
    </item>
    <item>
      <title>Re: Perl Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3328920#M188685</link>
      <description>Fixed records are easiest to deal with using pack and unpack.&lt;BR /&gt;sprintf is a not so good choice here. Either substr () or unpack is better. Most severe error you made is a numeric comparison between ID and "9999..." which both extend the maximum storable integer value, even in 64bit environment. You will have to deal with the keys/ID's in string context, using 'eq' instead of '=='&lt;BR /&gt;&lt;BR /&gt;If every record is 1563 bytes, with 21 bytes to introduce the ID,&lt;BR /&gt;&lt;BR /&gt;while (read (I_FILE, $buf, 1563)) {&lt;BR /&gt;($id) = unpack "A21", $buf;&lt;BR /&gt;if ($id eq "9"x21){&lt;BR /&gt;# yadayadayada&lt;BR /&gt;next;&lt;BR /&gt;}&lt;BR /&gt;# this for all in "99999...." stuff&lt;BR /&gt;print O_FILE "$buf\n";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Mon, 12 Jul 2004 12:43:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3328920#M188685</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2004-07-12T12:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: Perl Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3328921#M188686</link>
      <description>Procura is right the pack/unpack for fixed length of course. But don't rule out the simble 'substr':  $id = substr($buf,1,21);&lt;BR /&gt;&lt;BR /&gt;Here are a few more ideas for a solution&lt;BR /&gt;&lt;BR /&gt;- switch to binmode ?!&lt;BR /&gt;- use a regexp to find proper record&lt;BR /&gt;. starts "^" with soh "\x01" for hex 1&lt;BR /&gt;. remember "(.{21})" 21 characters in $1&lt;BR /&gt;. haveing a "C" just before the end "$"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;open (I_FILE, "&lt;X&gt;&lt;/X&gt;binmode (I_FILE);&lt;BR /&gt;while (read (I_FILE, $_, 1536)) {&lt;BR /&gt;  $i++;&lt;BR /&gt;  if (/^\x01(.{21}).*C$/) {&lt;BR /&gt;    $id = $1;&lt;BR /&gt;    if ($id eq "9"x21) {&lt;BR /&gt;         print "record $i : skipped\n";&lt;BR /&gt;         } else {&lt;BR /&gt;         print (O_FILE, "$_\n");&lt;BR /&gt;         }&lt;BR /&gt;    } else {&lt;BR /&gt;    print "record $i : bad head or tail\n";&lt;BR /&gt;    }&lt;BR /&gt;  }&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if you are garantueed the contents is good, you could also just test for the soh followed by 9999 and skip those prinnting everything else using something like:&lt;BR /&gt;&lt;BR /&gt;while (read (I_FILE, $_, 1536)) {&lt;BR /&gt;   next if (/^\x{01}9{21}/)&lt;BR /&gt;   print (O_FILE, "$_\n");&lt;BR /&gt;   }&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;or even replace the exact match for soh with the \x{01} by just any-char:  (/^.9{21}/)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Have fun, &lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 12 Jul 2004 16:02:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3328921#M188686</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2004-07-12T16:02:29Z</dc:date>
    </item>
    <item>
      <title>Re: Perl Help</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3328922#M188687</link>
      <description>Thanks guys! You're right about the unpack, it was the key to completing the record picking portion, and I now understand both unpack and substr a bit, after reading the man page along with your examples, which give me more ideas for this and some other projects I am currently working on.  Trying to ramp up on Perl skills.&lt;BR /&gt;&lt;BR /&gt;The '==' instead of 'eq' is a bad habit from  sloppy 'ksh' work that I need to rid myself of.  Most of the time in ksh it will work, but it is a bad habit.&lt;BR /&gt;&lt;BR /&gt;Thanks again.&lt;BR /&gt;&lt;BR /&gt;Rt.</description>
      <pubDate>Tue, 13 Jul 2004 07:19:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-help/m-p/3328922#M188687</guid>
      <dc:creator>Robert True</dc:creator>
      <dc:date>2004-07-13T07:19:44Z</dc:date>
    </item>
  </channel>
</rss>

