<?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 script to add comma if... in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-to-add-comma-if/m-p/4861849#M396669</link>
    <description>Thanks</description>
    <pubDate>Wed, 23 Feb 2005 09:06:40 GMT</pubDate>
    <dc:creator>Ratzie</dc:creator>
    <dc:date>2005-02-23T09:06:40Z</dc:date>
    <item>
      <title>Perl script to add comma if...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-to-add-comma-if/m-p/4861845#M396665</link>
      <description>Thanks to the many that help with my script I have know been able to get it to working order.&lt;BR /&gt;&lt;BR /&gt;There is something that I still need to do with it...&lt;BR /&gt;Sometimes I may have a column with empty data. I need to insert a comma there. (For a deliminated file)&lt;BR /&gt;So after all is said and down the script produces this output...&lt;BR /&gt;&lt;BR /&gt;5555642,00 0 00 18,CUSTOMER HAS&lt;BR /&gt;5555656,MATCHING CUTTELN&lt;BR /&gt;5555661,00 0 06 08,TELN NOT&lt;BR /&gt;&lt;BR /&gt;I need to put an if statement after my script..&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;chomp; # Will remove the leading , or new line&lt;BR /&gt;s,^\s+,,; #Remove leading spaces&lt;BR /&gt;my @cols=split m/\s{2,}/, $_, -1; # Split on two (or more) white space characters&lt;BR /&gt;print join (',',@cols)."\n";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;That will, if 7digits (together), comma then characters, add a comma.&lt;BR /&gt;&lt;BR /&gt;So the output will look like this...&lt;BR /&gt;5555642,00 0 00 18,CUSTOMER HAS&lt;BR /&gt;5555656,,MATCHING CUTTELN&lt;BR /&gt;5555642,00 0 00 18,CUSTOMER HAS &lt;BR /&gt;</description>
      <pubDate>Tue, 21 Sep 2004 11:05:56 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-to-add-comma-if/m-p/4861845#M396665</guid>
      <dc:creator>Ratzie</dc:creator>
      <dc:date>2004-09-21T11:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: Perl script to add comma if...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-to-add-comma-if/m-p/4861846#M396666</link>
      <description>If I really understand, your script ends with 3 fields lines and 2 fields lines. For these ones, you want to insert an empty field between one and two...&lt;BR /&gt;&lt;BR /&gt;here it is (to put before print) :&lt;BR /&gt;@cols=($cols[0],"",$cols[1]) if $#cols=1;&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;&lt;BR /&gt;Fred&lt;BR /&gt;</description>
      <pubDate>Tue, 21 Sep 2004 11:51:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-to-add-comma-if/m-p/4861846#M396666</guid>
      <dc:creator>Fred Ruffet</dc:creator>
      <dc:date>2004-09-21T11:51:11Z</dc:date>
    </item>
    <item>
      <title>Re: Perl script to add comma if...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-to-add-comma-if/m-p/4861847#M396667</link>
      <description>Fred, better to write that using splice&lt;BR /&gt;&lt;BR /&gt;@cols == 2 and splice @cols, 1, 0, "";&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;==&amp;gt;&lt;BR /&gt;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;chomp; # Will remove the TRAILING optional new line&lt;BR /&gt;s/^\s+//; #Remove leading spaces&lt;BR /&gt;my @cols = split m/\s{2,}/, $_, -1; # Split on two (or more) white space characters&lt;BR /&gt;@cols == 2 and splice @cols, 1, 0, "";&lt;BR /&gt;print join (",", @cols), "\n";&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Tue, 21 Sep 2004 12:16:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-to-add-comma-if/m-p/4861847#M396667</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2004-09-21T12:16:15Z</dc:date>
    </item>
    <item>
      <title>Re: Perl script to add comma if...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-to-add-comma-if/m-p/4861848#M396668</link>
      <description>Procura,&lt;BR /&gt;&lt;BR /&gt;I never noticed that a 0 length in splice inserts elements... You are a living perldoc ! Are you eating a camel every morning for breakfast ? :)&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;&lt;BR /&gt;Fred&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Sep 2004 03:00:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-to-add-comma-if/m-p/4861848#M396668</guid>
      <dc:creator>Fred Ruffet</dc:creator>
      <dc:date>2004-09-22T03:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: Perl script to add comma if...</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-to-add-comma-if/m-p/4861849#M396669</link>
      <description>Thanks</description>
      <pubDate>Wed, 23 Feb 2005 09:06:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-script-to-add-comma-if/m-p/4861849#M396669</guid>
      <dc:creator>Ratzie</dc:creator>
      <dc:date>2005-02-23T09:06:40Z</dc:date>
    </item>
  </channel>
</rss>

