<?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 - String Subsitution problem in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-string-subsitution-problem/m-p/5178286#M682452</link>
    <description>&lt;!--!*#--&gt;If the original date format is always the same, and is assured to have leading zeroes, why not simply:&lt;BR /&gt;&lt;BR /&gt;  ($l = $k) =~ s/\D//g;&lt;BR /&gt;&lt;BR /&gt;As a side note, parsing dates and/or calculations with dates are usually better done with modules:&lt;BR /&gt;&lt;BR /&gt;  Date::Calc&lt;BR /&gt;  Date::Parse&lt;BR /&gt;  Date::Manip&lt;BR /&gt;  DateTime&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
    <pubDate>Sat, 30 May 2009 05:53:46 GMT</pubDate>
    <dc:creator>H.Merijn Brand (procura</dc:creator>
    <dc:date>2009-05-30T05:53:46Z</dc:date>
    <item>
      <title>Perl - String Subsitution problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-string-subsitution-problem/m-p/5178280#M682446</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I have a problem regarding date conversion actually. The date format will be in the following format : 2008/09/20-01-04-30.17.&lt;BR /&gt;I have to convert it to 2008092001043017.&lt;BR /&gt;Its working in the following format :&lt;BR /&gt;echo "2008/09/20-01-04-30.17" | perl -pi -e 's/\///g,s/-//g,s/\.//g'&lt;BR /&gt;&lt;BR /&gt;But when i try the same like this:&lt;BR /&gt;perl -pi -e '&lt;BR /&gt;  $k="2008/09/20-01-04-30.17"; &lt;BR /&gt;  $l= print $k; s/\///g,s/-//g,s/\.//g; &lt;BR /&gt;  print $l; '&lt;BR /&gt;&lt;BR /&gt;its not working, it gives the output like this : 20081&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Priya&lt;BR /&gt;</description>
      <pubDate>Fri, 29 May 2009 08:11:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-string-subsitution-problem/m-p/5178280#M682446</guid>
      <dc:creator>pgp_acc1</dc:creator>
      <dc:date>2009-05-29T08:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: Perl - String Subsitution problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-string-subsitution-problem/m-p/5178281#M682447</link>
      <description>Hi Priya:&lt;BR /&gt;&lt;BR /&gt;There are several things here.&lt;BR /&gt;&lt;BR /&gt;In your original post, the use of the '-i' switch is meaningless since there is no file to update.  Otherwise the substitution is correct for removing the "/", "-" and ".".&lt;BR /&gt;&lt;BR /&gt;In the second case (your question), you need to drop the '-p' switch since there is no input file to process.  Drop the extraneous '-i' too.  Now, to better see what's happening, add '-l' to automatically add a newline to print() statements:&lt;BR /&gt;&lt;BR /&gt;# perl -le '$k="2008/09/20-01-04-30.17";$l=print $k;s/\///g,s/-//g,s/\.//g;print $l'&lt;BR /&gt;2008/09/20-01-04-30.17&lt;BR /&gt;1&lt;BR /&gt;&lt;BR /&gt;Now, you see that the line with the "1" is from the scalar result of 'print $k' which is a true value since it isn't zero.  A true value is one (1) and that's what is printed.&lt;BR /&gt;&lt;BR /&gt;The substitution that you wrote operates on '$_' but that's not what you wanted.  You should have done:&lt;BR /&gt;&lt;BR /&gt;# perl -le '$k="2008/09/20-01-04-30.17";print $k;($l=$k)=~s/\///g;$l=~s/-//g;$l=~s/\.//g;print $l'    &lt;BR /&gt;&lt;BR /&gt;Lastly, if you find this helpful, please remember to evaluate the help you receive:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums11.itrc.hp.com/service/forums/helptips.do?#28" target="_blank"&gt;http://forums11.itrc.hp.com/service/forums/helptips.do?#28&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;You can appply that to your previous query too:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1313088" target="_blank"&gt;http://forums11.itrc.hp.com/service/forums/questionanswer.do?threadId=1313088&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Doing so improves the quality of this community and helps its members find the most useful solutions.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 29 May 2009 09:23:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-string-subsitution-problem/m-p/5178281#M682447</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-05-29T09:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: Perl - String Subsitution problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-string-subsitution-problem/m-p/5178282#M682448</link>
      <description>Hi James,&lt;BR /&gt;&lt;BR /&gt;Thanks for the detailed reply.&lt;BR /&gt;It really helped.&lt;BR /&gt;One more doubt is there any way to combine all three commands into one single one?&lt;BR /&gt;As this date change will have to be done most frequently.&lt;BR /&gt;&lt;BR /&gt;Thanks,&lt;BR /&gt;Priya</description>
      <pubDate>Fri, 29 May 2009 10:05:04 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-string-subsitution-problem/m-p/5178282#M682448</guid>
      <dc:creator>pgp_acc1</dc:creator>
      <dc:date>2009-05-29T10:05:04Z</dc:date>
    </item>
    <item>
      <title>Re: Perl - String Subsitution problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-string-subsitution-problem/m-p/5178283#M682449</link>
      <description>Hi (again) Priya:&lt;BR /&gt;&lt;BR /&gt;&amp;gt; One more doubt is there any way to combine all three commands into one single one?&lt;BR /&gt;&lt;BR /&gt;Yes.  You could use a bracket expresssion like:&lt;BR /&gt;&lt;BR /&gt;# perl -le '$k="2008/09/20-01-04-30.17";print $k;($l=$k)=~s/[\/\.-]//g;print $l'&lt;BR /&gt;2008/09/20-01-04-30.17&lt;BR /&gt;2008092001043017&lt;BR /&gt;&lt;BR /&gt;Notice that the "-" character is placed last in the bracket expression so that it isn't interpreted as a range.  The "." doesn't need to be escaped within a bracket class, so we can keep it clean looking.&lt;BR /&gt;&lt;BR /&gt;By the way, your original '$l= print $k' was simply capturing the return value of the print statement (not so meaningful, but one, or true, nevertheless).  I misspoke about that before, not having had coffee, I mis-scanned :-).&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Fri, 29 May 2009 10:51:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-string-subsitution-problem/m-p/5178283#M682449</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-05-29T10:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: Perl - String Subsitution problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-string-subsitution-problem/m-p/5178284#M682450</link>
      <description>James,&lt;BR /&gt;&lt;BR /&gt;Thanks a lot for the reply&lt;BR /&gt;:) &lt;BR /&gt;&lt;BR /&gt;Priya</description>
      <pubDate>Fri, 29 May 2009 11:10:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-string-subsitution-problem/m-p/5178284#M682450</guid>
      <dc:creator>pgp_acc1</dc:creator>
      <dc:date>2009-05-29T11:10:30Z</dc:date>
    </item>
    <item>
      <title>Re: Perl - String Subsitution problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-string-subsitution-problem/m-p/5178285#M682451</link>
      <description>Got the solution from James</description>
      <pubDate>Fri, 29 May 2009 11:11:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-string-subsitution-problem/m-p/5178285#M682451</guid>
      <dc:creator>pgp_acc1</dc:creator>
      <dc:date>2009-05-29T11:11:10Z</dc:date>
    </item>
    <item>
      <title>Re: Perl - String Subsitution problem</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/perl-string-subsitution-problem/m-p/5178286#M682452</link>
      <description>&lt;!--!*#--&gt;If the original date format is always the same, and is assured to have leading zeroes, why not simply:&lt;BR /&gt;&lt;BR /&gt;  ($l = $k) =~ s/\D//g;&lt;BR /&gt;&lt;BR /&gt;As a side note, parsing dates and/or calculations with dates are usually better done with modules:&lt;BR /&gt;&lt;BR /&gt;  Date::Calc&lt;BR /&gt;  Date::Parse&lt;BR /&gt;  Date::Manip&lt;BR /&gt;  DateTime&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Sat, 30 May 2009 05:53:46 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/perl-string-subsitution-problem/m-p/5178286#M682452</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2009-05-30T05:53:46Z</dc:date>
    </item>
  </channel>
</rss>

