perl.beginners http://www.nntp.perl.org/group/perl.beginners/ ... Copyright 1998-2015 perl.org Thu, 02 Apr 2015 02:43:20 +0000 ask@perl.org Re: Bizarre copy of HASH in list assignment... by Andy Bach On Tue, Mar 31, 2015 at 3:28 AM, Manfred Lotz &lt;manfred.lotz@arcor.de&gt; wrote:<br/><br/>&gt;<br/>&gt; Bizarre copy of HASH in list assignment<br/>&gt; at /usr/share/perl/5.20/Carp.pm line 228.<br/>&gt;<br/><br/>Hmm:<br/>http://stackoverflow.com/questions/6217317/bizarre-copy-of-unknown-in-subroutine-entry<br/><br/>which suggests:<br/><br/>A &quot;Bizarre copy&quot; occurs when Perl&#39;s stack is corrupted or contains<br/>non-scalars. It occurs as the result of bugs in Perl itself or in XS<br/>modules. (Brian Gerard&#39;s example exercises one of a long list of known bugs<br/>related to the stack not being ref-counted.)<br/><br/>You could isolate the problem by adding the following to the anon sub:<br/><br/>...<br/><br/><br/><br/>-- <br/><br/>a<br/><br/>Andy Bach,<br/>afbach@gmail.com<br/>608 658-1890 cell<br/>608 261-5738 wk http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125278.html Tue, 31 Mar 2015 16:19:17 +0000 Re: Good books to study perl interpreter by Sam On 03/30/2015 11:42 AM, rakesh sharma wrote:<br/>&gt; Hi all<br/>&gt;<br/>&gt; Please suggest nice books to know perl interpreter. In depth books is that i am looking for.<br/>&gt;<br/>&gt; Thanks<br/>&gt; Rakesh<br/>&gt;<br/><br/><br/>Perl guts can be nice:<br/>http://cpansearch.perl.org/src/RURBAN/illguts-0.49/index.html<br/>http://perldoc.perl.org/perlguts.html<br/><br/>--Sam<br/> http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125277.html Tue, 31 Mar 2015 11:25:24 +0000 Re: Bizarre copy of HASH in list assignment... by Shlomi Fish Hi Manfred,<br/><br/>On Tue, 31 Mar 2015 10:28:13 +0200<br/>Manfred Lotz &lt;manfred.lotz@arcor.de&gt; wrote:<br/><br/>&gt; Hi there,<br/>&gt; I have a script where I use croak and somebody else using that script<br/>&gt; gets<br/>&gt; <br/>&gt; Bizarre copy of HASH in list assignment<br/>&gt; at /usr/share/perl/5.20/Carp.pm line 228.<br/>&gt; <br/>&gt; I get a message like this, instead:<br/>&gt; <br/>&gt; Variable b has empty value! at ./x.pl line 23.<br/>&gt; main::myfunc() called at ./x.pl line 8<br/>&gt; <br/>&gt; which is what should happen.<br/>&gt; <br/>&gt; Any idea what this message means? I&#39;m not able to reproduce it.<br/>&gt; <br/>&gt; Here a minimal example:<br/>&gt; <br/>&gt; #! /usr/bin/perl<br/>&gt; <br/>&gt; use strict;<br/>&gt; use warnings;<br/>&gt; <br/>&gt; use Carp;<br/>&gt; <br/>&gt; myfunc();<br/>&gt; <br/>&gt; <br/>&gt; <br/>&gt; sub myfunc {<br/>&gt; my %vars = (<br/>&gt; &#39;a&#39; =&gt; &#39;some val&#39;,<br/>&gt; &#39;b&#39; =&gt; q{},<br/>&gt; );<br/>&gt; <br/>&gt; while ( my ( $key, $val ) = each %vars ) {<br/>&gt; if ( not defined $val ) {<br/>&gt; croak &quot;No value given for $key&quot;;<br/>&gt; }<br/>&gt; if ( $val eq q{} ) {<br/>&gt; croak &quot;Variable $key has empty value!&quot;;<br/>&gt; }<br/>&gt; }<br/>&gt; return;<br/>&gt; }<br/>&gt; <br/><br/>This code looks fine to me (except for some \t|4-space-indent mixup, which is<br/>relatively minor). I cannot reproduce the reported problem here<br/>( perl-5.20.1-8.mga5 on Mageia Linux x86-64 5 - I&#39;m getting something similar<br/>to what you are getting).<br/><br/>Can you please ask your friend for:<br/><br/>1. Operating system + version.<br/><br/>2. The perl 5 distribution and its version.<br/><br/>3. Version of Carp.pm and the surrounding lines.<br/><br/>4. Other parameters of their environment.<br/><br/>Maybe this way we&#39;ll be able to reproduce it.<br/><br/>Regards,<br/><br/> Shlomi Fish<br/><br/>-- <br/>-----------------------------------------------------------------<br/>Shlomi Fish http://www.shlomifish.org/<br/>http://www.shlomifish.org/humour/bits/facts/Summer-Glau/<br/><br/>95% of Programmers consider 95% of the code they did not write, in the bottom<br/>5%.<br/><br/>Please reply to list if it&#39;s a mailing list post - http://shlom.in/reply .<br/> http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125276.html Tue, 31 Mar 2015 10:24:41 +0000 Bizarre copy of HASH in list assignment... by Manfred Lotz Hi there,<br/>I have a script where I use croak and somebody else using that script<br/>gets<br/><br/>Bizarre copy of HASH in list assignment<br/>at /usr/share/perl/5.20/Carp.pm line 228.<br/><br/>I get a message like this, instead:<br/><br/>Variable b has empty value! at ./x.pl line 23.<br/> main::myfunc() called at ./x.pl line 8<br/><br/>which is what should happen.<br/><br/>Any idea what this message means? I&#39;m not able to reproduce it.<br/><br/>Here a minimal example:<br/><br/>#! /usr/bin/perl<br/><br/>use strict;<br/>use warnings;<br/><br/>use Carp;<br/><br/>myfunc();<br/><br/><br/><br/>sub myfunc {<br/> my %vars = (<br/> &#39;a&#39; =&gt; &#39;some val&#39;,<br/> &#39;b&#39; =&gt; q{},<br/> );<br/><br/> while ( my ( $key, $val ) = each %vars ) {<br/> if ( not defined $val ) {<br/> croak &quot;No value given for $key&quot;;<br/> }<br/> if ( $val eq q{} ) {<br/> croak &quot;Variable $key has empty value!&quot;;<br/> }<br/> }<br/> return;<br/>}<br/><br/><br/>-- <br/>Manfred<br/><br/> http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125275.html Tue, 31 Mar 2015 08:34:52 +0000 Re: Good books to study perl interpreter by Brock Wilcox It&#39;d be neat if there was an equivalent to &quot;Ruby Under A Microscope&quot; for<br/>Perl5. That book is FANTASTIC at exploring the internals of the YARV<br/>(c-ruby) data structures and general inner-workings.<br/><br/>--Brock<br/><br/><br/>On Mon, Mar 30, 2015 at 1:13 PM, Hao Wu &lt;echowuhao@gmail.com&gt; wrote:<br/><br/>&gt; Hi, rakesh,<br/>&gt;<br/>&gt; search &#39;perl internal&#39;, will give you most of the result.<br/>&gt;<br/>&gt; *Extending and Embedding Perl* is the book you are looking for.<br/>&gt;<br/>&gt; On Mon, Mar 30, 2015 at 9:42 AM, rakesh sharma &lt;rakeshsharma14@hotmail.com<br/>&gt; &gt; wrote:<br/>&gt;<br/>&gt;&gt; Hi all<br/>&gt;&gt;<br/>&gt;&gt; Please suggest nice books to know perl interpreter. In depth books is<br/>&gt;&gt; that i am looking for.<br/>&gt;&gt;<br/>&gt;&gt; Thanks<br/>&gt;&gt; Rakesh<br/>&gt;<br/>&gt;<br/>&gt; http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125274.html Tue, 31 Mar 2015 00:22:10 +0000 Re: Good books to study perl interpreter by Hao Wu Hi, rakesh,<br/><br/>search &#39;perl internal&#39;, will give you most of the result.<br/><br/>*Extending and Embedding Perl* is the book you are looking for.<br/><br/>On Mon, Mar 30, 2015 at 9:42 AM, rakesh sharma &lt;rakeshsharma14@hotmail.com&gt;<br/>wrote:<br/><br/>&gt; Hi all<br/>&gt;<br/>&gt; Please suggest nice books to know perl interpreter. In depth books is that<br/>&gt; i am looking for.<br/>&gt;<br/>&gt; Thanks<br/>&gt; Rakesh http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125273.html Mon, 30 Mar 2015 17:13:32 +0000 Re: Good books to study perl interpreter by Jim Gibson The best book on Perl (in my opinion) is &ldquo;Programming Perl, 4th ed.&rdquo;, Christiansen, foy, Wall, &amp; Orwant. <br/> <br/>See &ldquo;perldoc perlbook&rdquo; for other recommendations, as well as &lt;http://books.perl.org&gt; <br/> <br/> <br/>&gt; On Mar 30, 2015, at 9:42 AM, rakesh sharma &lt;rakeshsharma14@hotmail.com&gt; wrote: <br/>&gt; <br/>&gt; Hi all <br/>&gt; <br/>&gt; Please suggest nice books to know perl interpreter. In depth books is that i am looking for. <br/>&gt; <br/>&gt; Thanks <br/>&gt; Rakesh <br/> <br/> http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125272.html Mon, 30 Mar 2015 17:11:08 +0000 Re: Good books to study perl interpreter by Shawn H Corey On Mon, 30 Mar 2015 22:12:51 +0530 <br/>rakesh sharma &lt;rakeshsharma14@hotmail.com&gt; wrote: <br/> <br/>&gt; Hi all <br/>&gt; <br/>&gt; Please suggest nice books to know perl interpreter. In depth books is <br/>&gt; that i am looking for. <br/>&gt; <br/>&gt; Thanks <br/>&gt; Rakesh <br/> <br/>FYI: some useful Perl links. <br/>&bull; Official site &lt;http://www.perl.org/&gt; <br/>&bull; Beginners&#39; help &lt;http://learn.perl.org/faq/beginners.html&gt; <br/>&bull; Advance help &lt;http://perlmonks.org/&gt; <br/>&bull; News &lt;http://perlsphere.net/&gt; <br/>&bull; Documentation &lt;http://perldoc.perl.org/&gt; <br/>&bull; Online Books &lt;http://www.perl.org/books/library.html&gt; <br/>&bull; Real World Books &lt;http://learn.perl.org/books/&gt; <br/>&bull; Repository &lt;http://metacpan.org/&gt; <br/>&bull; Blog &lt;http://blogs.perl.org/&gt; <br/>&bull; Regional groups &lt;http://www.pm.org/&gt; <br/>&bull; Videos &lt;http://perltv.org/&gt; <br/> <br/> <br/>-- <br/>Don&#39;t stop where the ink does. <br/> Shawn <br/> http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125271.html Mon, 30 Mar 2015 17:10:27 +0000 Re: Good books to study perl interpreter by Shlomi Fish Hi Rakesh, <br/> <br/>On Mon, 30 Mar 2015 22:12:51 +0530 <br/>rakesh sharma &lt;rakeshsharma14@hotmail.com&gt; wrote: <br/> <br/>&gt; Hi all <br/>&gt; <br/>&gt; Please suggest nice books to know perl interpreter. In depth books is that i <br/>&gt; am looking for. <br/>&gt; <br/> <br/>are you interested in learning how to write code in the Perl 5 programming <br/>language (using CPAN modules/etc.) that will run on the Perl interpreter, or <br/>are you interested in learning the internals of it? <br/> <br/>Regards, <br/> <br/> Shlomi Fish <br/> <br/>&gt; Thanks <br/>&gt; Rakesh <br/> <br/> <br/>-- <br/>----------------------------------------------------------------- <br/>Shlomi Fish http://www.shlomifish.org/ <br/>Apple Inc. is Evil - http://www.shlomifish.org/open-source/anti/apple/ <br/> <br/>Buffy Summers does not really need stakes to slay vampires, because her kisses <br/>are deadly for them. And that includes those that she blows in the air. <br/> &mdash; http://www.shlomifish.org/humour/bits/facts/Buffy/ <br/> <br/>Please reply to list if it&#39;s a mailing list post - http://shlom.in/reply . <br/> http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125270.html Mon, 30 Mar 2015 17:03:32 +0000 Good books to study perl interpreter by rakesh sharma Hi all<br/><br/>Please suggest nice books to know perl interpreter. In depth books is that i am looking for.<br/><br/>Thanks<br/>Rakesh http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125269.html Mon, 30 Mar 2015 16:43:45 +0000 Re: Doubt by John SJ Anderson Please show exactly what commands you ran and what output you got. In what<br/>you&#39;re reporting, there&#39;s a typo, and it&#39;s not clear if that&#39;s a copy-paste<br/>error or a problem in the actual command.<br/><br/>chrs,<br/>john.<br/><br/><br/>On Mon, Mar 30, 2015 at 1:16 AM, Frank Vino &lt;vinofrank3@gmail.com&gt; wrote:<br/><br/>&gt; When i try to install Alias.pm file from environment i was getting an<br/>&gt; error message as cannot locate alimas.pm file, then i checked in cpan it<br/>&gt; was showing, In case how to fix this and update the Alias.pm file.<br/>&gt;<br/>&gt; Frank<br/>&gt; http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125268.html Mon, 30 Mar 2015 05:21:47 +0000 Doubt by Frank Vino When i try to install Alias.pm file from environment i was getting an error<br/>message as cannot locate alimas.pm file, then i checked in cpan it was<br/>showing, In case how to fix this and update the Alias.pm file.<br/><br/>Frank http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125267.html Mon, 30 Mar 2015 05:16:35 +0000 Re: Module Not Getting Installed by Uri Guttman On 03/27/2015 04:29 PM, Frank Vino wrote:<br/>&gt; Sorry Shlomi it is our own module, i am still working on this. once it <br/>&gt; is update i will get the details.<br/>&gt;<br/>&gt;<br/><br/>you don&#39;t install your own module with cpan or related things. you just <br/>need to copy it into the proper dir. if you run perl -V it will show you <br/>the list (among much other stuff) of dirs your perl uses to search for <br/>modules. put your module in the dir called site_perl and it should be <br/>found by your program. if your module name has :: in it, you need to <br/>make subdirs (under site_perl) for each of the higher level namespaces.<br/><br/>uri<br/> http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125266.html Fri, 27 Mar 2015 21:35:34 +0000 Re: Module Not Getting Installed by Frank Vino Sorry Shlomi it is our own module, i am still working on this. once it is <br/>update i will get the details. <br/> <br/> -Franky <br/> <br/>On Fri, Mar 27, 2015 at 3:58 PM, Shlomi Fish &lt;shlomif@shlomifish.org&gt; wrote: <br/> <br/>&gt; Hi Franklin, <br/>&gt; <br/>&gt; On Fri, 27 Mar 2015 14:00:05 +0530 <br/>&gt; Frank Vino &lt;vinofrank3@gmail.com&gt; wrote: <br/>&gt; <br/>&gt; &gt; Hi Team, <br/>&gt; &gt; <br/>&gt; &gt; When i trying to install FWConfig.pm from cpan it is saying that unable <br/>&gt; &gt; to locate. Could you please let me know how to download this module? <br/>&gt; &gt; <br/>&gt; <br/>&gt; I cannot find FWConfig.pm either here - <br/>&gt; https://metacpan.org/search?q=FWConfig <br/>&gt; or here - https://www.google.com/search?q=%22FWConfig.pm%22&amp;gws_rd=ssl . <br/>&gt; Where <br/>&gt; do you see the &quot;use&quot; or &quot;require&quot; statement that requires it? <br/>&gt; <br/>&gt; Regards, <br/>&gt; <br/>&gt; Shlomi Fish <br/>&gt; <br/>&gt; -- <br/>&gt; ----------------------------------------------------------------- <br/>&gt; Shlomi Fish http://www.shlomifish.org/ <br/>&gt; Buffy Factoids - http://www.shlomifish.org/humour/bits/facts/Buffy/ <br/>&gt; <br/>&gt; Medusa&rsquo;s gaze can turn people into stone. Buffy&rsquo;s gaze can turn Medusa into <br/>&gt; stone. <br/>&gt; &mdash; http://www.shlomifish.org/humour/bits/facts/Buffy/ <br/>&gt; <br/>&gt; Please reply to list if it&#39;s a mailing list post - http://shlom.in/reply . <br/>&gt; <br/>&gt; -- <br/>&gt; To unsubscribe, e-mail: beginners-unsubscribe@perl.org <br/>&gt; For additional commands, e-mail: beginners-help@perl.org <br/>&gt; http://learn.perl.org/ <br/>&gt; <br/>&gt; <br/>&gt; http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125265.html Fri, 27 Mar 2015 20:29:30 +0000 Re: Module Not Getting Installed by Shlomi Fish Hi Franklin, <br/> <br/>On Fri, 27 Mar 2015 14:00:05 +0530 <br/>Frank Vino &lt;vinofrank3@gmail.com&gt; wrote: <br/> <br/>&gt; Hi Team, <br/>&gt; <br/>&gt; When i trying to install FWConfig.pm from cpan it is saying that unable <br/>&gt; to locate. Could you please let me know how to download this module? <br/>&gt; <br/> <br/>I cannot find FWConfig.pm either here - https://metacpan.org/search?q=FWConfig <br/>or here - https://www.google.com/search?q=%22FWConfig.pm%22&amp;gws_rd=ssl . Where <br/>do you see the &quot;use&quot; or &quot;require&quot; statement that requires it? <br/> <br/>Regards, <br/> <br/> Shlomi Fish <br/> <br/>-- <br/>----------------------------------------------------------------- <br/>Shlomi Fish http://www.shlomifish.org/ <br/>Buffy Factoids - http://www.shlomifish.org/humour/bits/facts/Buffy/ <br/> <br/>Medusa&rsquo;s gaze can turn people into stone. Buffy&rsquo;s gaze can turn Medusa into <br/>stone. <br/> &mdash; http://www.shlomifish.org/humour/bits/facts/Buffy/ <br/> <br/>Please reply to list if it&#39;s a mailing list post - http://shlom.in/reply . <br/> http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125264.html Fri, 27 Mar 2015 10:28:52 +0000 Module Not Getting Installed by Frank Vino Hi Team,<br/><br/> When i trying to install FWConfig.pm from cpan it is saying that unable<br/>to locate. Could you please let me know how to download this module?<br/><br/>-Franklin http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125263.html Fri, 27 Mar 2015 08:30:10 +0000 Re: OTRS module by Benjamin Fernandis Hi Jim, <br/> <br/>Thanks , Yes your given link is perfect. we use that one. <br/> <br/>Yes, it looks complicated too , I can code out of otrs straight away but <br/>don&#39;t how to inject my code and get this work done. <br/> <br/>Thanks <br/> <br/>On Fri, Mar 27, 2015 at 12:15 PM, Jim Gibson &lt;jimsgibson@gmail.com&gt; wrote: <br/> <br/>&gt; <br/>&gt; &gt; On Mar 26, 2015, at 3:54 PM, Benjamin Fernandis &lt;benjo11111@gmail.com&gt; <br/>&gt; wrote: <br/>&gt; &gt; <br/>&gt; &gt; Hi, <br/>&gt; &gt; <br/>&gt; &gt; We are using otrs help desk system which is in fully perl. We require to <br/>&gt; append automatic comment when our specific customer raise ticket to us. We <br/>&gt; have iteam no for each customer.So when customer send mail and in body he <br/>&gt; mentioned iteam code ( like 43222222) , so otrs automatically checks sender <br/>&gt; email id and then fetch iteam code from body and according to that otrs <br/>&gt; fetch respective information from database or excel sheet and add comment <br/>&gt; to that ticket. <br/>&gt; &gt; <br/>&gt; &gt; I can write logic out side of otrs. but i never tried to write any <br/>&gt; module for 3rd party applications. <br/>&gt; &gt; <br/>&gt; &gt; Can you please suggest me a way to do this. <br/>&gt; &gt; <br/>&gt; &gt; Thanks <br/>&gt; &gt; Ben <br/>&gt; <br/>&gt; You don&rsquo;t mention which OTRS Help Desk system you are using, but a Google <br/>&gt; search turns up this one: <br/>&gt; <br/>&gt; &lt;https://otrs.github.io/doc/manual/admin/stable/en/html/otrs.html&gt; <br/>&gt; <br/>&gt; Is that the one? <br/>&gt; <br/>&gt; Perl modules are installed as source code files, so you can modify the <br/>&gt; module&rsquo;s source and add whatever functionality you need. The OTRS Help Desk <br/>&gt; looks like a fairly complicated system, so adding functionality without <br/>&gt; breaking it could be a significant task. In any case, it is probably <br/>&gt; outside the scope of a Perl beginner&rsquo;s list. <br/>&gt; <br/>&gt; Good luck. <br/>&gt; <br/>&gt; <br/>&gt; -- <br/>&gt; To unsubscribe, e-mail: beginners-unsubscribe@perl.org <br/>&gt; For additional commands, e-mail: beginners-help@perl.org <br/>&gt; http://learn.perl.org/ <br/>&gt; <br/>&gt; <br/>&gt; http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125262.html Thu, 26 Mar 2015 23:33:42 +0000 Re: OTRS module by Jim Gibson <br/>&gt; On Mar 26, 2015, at 3:54 PM, Benjamin Fernandis &lt;benjo11111@gmail.com&gt; wrote: <br/>&gt; <br/>&gt; Hi, <br/>&gt; <br/>&gt; We are using otrs help desk system which is in fully perl. We require to append automatic comment when our specific customer raise ticket to us. We have iteam no for each customer.So when customer send mail and in body he mentioned iteam code ( like 43222222) , so otrs automatically checks sender email id and then fetch iteam code from body and according to that otrs fetch respective information from database or excel sheet and add comment to that ticket. <br/>&gt; <br/>&gt; I can write logic out side of otrs. but i never tried to write any module for 3rd party applications. <br/>&gt; <br/>&gt; Can you please suggest me a way to do this. <br/>&gt; <br/>&gt; Thanks <br/>&gt; Ben <br/> <br/>You don&rsquo;t mention which OTRS Help Desk system you are using, but a Google search turns up this one: <br/> <br/>&lt;https://otrs.github.io/doc/manual/admin/stable/en/html/otrs.html&gt; <br/> <br/>Is that the one? <br/> <br/>Perl modules are installed as source code files, so you can modify the module&rsquo;s source and add whatever functionality you need. The OTRS Help Desk looks like a fairly complicated system, so adding functionality without breaking it could be a significant task. In any case, it is probably outside the scope of a Perl beginner&rsquo;s list. <br/> <br/>Good luck. <br/> <br/> http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125261.html Thu, 26 Mar 2015 23:16:07 +0000 OTRS module by Benjamin Fernandis Hi,<br/><br/>We are using otrs help desk system which is in fully perl. We require to<br/>append automatic comment when our specific customer raise ticket to us. We<br/>have iteam no for each customer.So when customer send mail and in body he<br/>mentioned iteam code ( like 43222222) , so otrs automatically checks sender<br/>email id and then fetch iteam code from body and according to that otrs<br/>fetch respective information from database or excel sheet and add comment<br/>to that ticket.<br/><br/>I can write logic out side of otrs. but i never tried to write any module<br/>for 3rd party applications.<br/><br/>Can you please suggest me a way to do this.<br/><br/>Thanks<br/>Ben http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125260.html Thu, 26 Mar 2015 22:54:17 +0000 Re: Spliting and creating small files from a main files based on line number by Jim Gibson <br/>&gt; On Mar 25, 2015, at 10:07 AM, Anirban Adhikary &lt;anirban.adhikary@gmail.com&gt; wrote: <br/>&gt; <br/>&gt; Hi List <br/>&gt; I have a configuration file and I would like to split the main file into multiple small files and push the small temp. files into an array. My config file looks like this <br/>&gt; <br/>&gt; GRC01;8;8;1;1;323U6_SIU-8;2048;2048;20;0;OFF <br/>&gt; (30 lines snipped) <br/>&gt; GRC01;335;335;32;32;335U6_SIU-335;2048;2048;20;0;OFF <br/>&gt; <br/>&gt; This config file has got 32 lines so I am planning to write a code which will create four tmp. files out of the main config file. I have written the following code. <br/>&gt; <br/>&gt; #!/usr/bin/perl <br/>&gt; use Tie::File; <br/>&gt; use strict; <br/>&gt; use warnings; <br/>&gt; <br/>&gt; my @config_file_contents; <br/>&gt; tie @config_file_contents, &#39;Tie::File&#39;, &quot;GRC01_TG_SCGR_IPM_LIST&quot; ###&lt;-- This is main config file <br/>&gt; or die &quot;Can&#39;t open filename&quot;; <br/>&gt; <br/>&gt; my @tmp_config_array=@config_file_contents; <br/>&gt; untie @config_file_contents; <br/>&gt; my $last_element_index = $#tmp_config_array; <br/>&gt; my $counter = 1; <br/>&gt; my $start_index = 0; <br/>&gt; my $next_index = 8; <br/>&gt; <br/>&gt; for (my $i=0; $i&lt;= $last_element_index; $i++) { <br/> <br/>You are iterating over all of the lines in the configuration file, which is 32. I think you only want to execute this loop four times, one for each subfile. <br/> <br/>&gt; print &quot;inside for loop\n&quot;; <br/>&gt; print &quot;START=$start_index\n&quot;; <br/>&gt; print &quot;NEXT=$next_index\n&quot;; <br/>&gt; my $file_to_write = &quot;GRC01_TG_SCGR_IPM_LIST_$counter&quot;; <br/>&gt; my @tmp_line_content = splice (@tmp_config_array,&quot;$start_index&quot;,&quot;$next_index&quot;); <br/>&gt; open my $WFH,&#39;&gt;&#39;,$file_to_write; <br/>&gt; foreach my $el (@tmp_line_content) { <br/>&gt; print &quot;EL=[$el]\n&quot;; <br/>&gt; next if /^\s*$/; <br/>&gt; print $WFH &quot;$el\n&quot;; <br/>&gt; } <br/>&gt; close($WFH); <br/>&gt; $start_index = ($next_index+1); <br/>&gt; $next_index = ($start_index+8); <br/>&gt; $i = $start_index; <br/>&gt; $counter++; <br/>&gt; # @tmp_line_content = undef; <br/>&gt; <br/>&gt; } <br/>&gt; <br/>&gt; while executing the code 4 tmp files are created but all of them are zero byte. Though in the print for first time &quot;EL&quot; I am getting 8 lines and second time &quot;EL&quot; prints <br/>&gt; 15 lines but line number 9-15 are skipped.Second time EL should start printing from line number 9 instead it starts printing from line number 18. <br/>&gt; But the counters like $start_index,$next_index are incrementing properly. <br/>&gt; Also I am getting warning message &quot;splice() offset past end of array at ./tie_file.pl line 22&rdquo; <br/> <br/>After the first four iterations of your outer loop, $start_index will be beyond the last element index in @tmp_config_array, and @tmp_line_content will be empty. That is why your subfiles have zero bytes. The subfiles may be correct after the first four iterations, but they are getting overwritten in the subsequent 28 iterations. <br/> <br/> http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125259.html Wed, 25 Mar 2015 19:44:45 +0000 Re: Spliting and creating small files from a main files based on line number by Anirban Adhikary Hi Sholmi <br/>I am using write mode for file writing because filename with counter value <br/>has assigned so there is no possibility of overwriting. <br/> <br/>What I would like to do i already said create some small file out of a main <br/>config file. IfI do not assign on $i then the for loop will not start from <br/>the next index value. <br/> <br/>On Wed, Mar 25, 2015 at 11:31 PM, Shlomi Fish &lt;shlomif@shlomifish.org&gt; <br/>wrote: <br/> <br/>&gt; Hi Anirban, <br/>&gt; <br/>&gt; On Wed, 25 Mar 2015 22:37:39 +0530 <br/>&gt; Anirban Adhikary &lt;anirban.adhikary@gmail.com&gt; wrote: <br/>&gt; <br/>&gt; &gt; Hi List <br/>&gt; &gt; I have a configuration file and I would like to split the main file into <br/>&gt; &gt; multiple small files and push the small temp. files into an array. My <br/>&gt; &gt; config file looks like this <br/>&gt; &gt; <br/>&gt; &gt; GRC01;8;8;1;1;323U6_SIU-8;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;12;12;2;2;134S1_SIU-12;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;25;25;3;3;016S1_SIU-25;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;29;29;4;4;018S1_SIU-29;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;31;31;5;5;060S1_SIU-31;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;48;48;6;6;023S1_SIU-48;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;49;49;7;7;023S1_SIU-49;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;51;51;8;8;030S1_SIU-51;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;52;52;9;9;031S1_SIU-52;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;54;54;10;10;033S1_SIU-54;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;69;69;11;11;078S1_SIU-69;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;77;77;12;12;097S1_SIU-77;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;86;86;13;13;070S1_SIU-86;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;103;103;14;14;039S1_SIU-103;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;110;110;15;15;047S1_SIU-110;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;114;114;16;16;051S1_SIU-114;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;115;115;17;17;052S1_SIU-115;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;120;120;18;18;089S1_SIU-120;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;125;125;19;19;140S2_SIU-125;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;133;133;20;20;300S2_SIU-133;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;140;140;21;21;315S2_SIU-140;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;154;154;22;22;100S1_SIU-154;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;156;156;23;23;103U6_SIU-156;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;160;160;24;24;120S1_SIU-160;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;162;162;25;25;126S1_SIU-162;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;165;165;26;26;101S1_SIU-165;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;175;175;27;27;302S1_SIU-175;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;207;207;28;28;203S1_SIU-207;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;225;225;29;29;321U6_SIU-225;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;233;233;30;30;333S1_SIU-233;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;238;238;31;31;338S1_SIU-238;2048;2048;20;0;OFF <br/>&gt; &gt; GRC01;335;335;32;32;335U6_SIU-335;2048;2048;20;0;OFF <br/>&gt; &gt; <br/>&gt; &gt; This config file has got 32 lines so I am planning to write a code which <br/>&gt; &gt; will create four tmp. files out of the main config file. I have written <br/>&gt; the <br/>&gt; &gt; following code. <br/>&gt; &gt; <br/>&gt; <br/>&gt; Some comments on your code: <br/>&gt; <br/>&gt; &gt; #!/usr/bin/perl <br/>&gt; &gt; use Tie::File; <br/>&gt; &gt; use strict; <br/>&gt; &gt; use warnings; <br/>&gt; <br/>&gt; You may opt to use &quot;use autodie;&quot; here. <br/>&gt; <br/>&gt; &gt; <br/>&gt; &gt; my @config_file_contents; <br/>&gt; &gt; tie @config_file_contents, &#39;Tie::File&#39;, &quot;GRC01_TG_SCGR_IPM_LIST&quot; ###&lt;-- <br/>&gt; &gt; This is main config file <br/>&gt; &gt; or die &quot;Can&#39;t open filename&quot;; <br/>&gt; &gt; <br/>&gt; &gt; my @tmp_config_array=@config_file_contents; <br/>&gt; &gt; untie @config_file_contents; <br/>&gt; <br/>&gt; Doing all that with Tie::File is unnecessary. Just slurp the array (using <br/>&gt; File-Slurp-Tiny or Path-Tiny or whatever) or iterate it normally using <br/>&gt; &laquo;while <br/>&gt; (&lt;&gt;)&raquo;. See: <br/>&gt; <br/>&gt; http://perl-begin.org/topics/files-and-directories/ <br/>&gt; <br/>&gt; (Note - perl-begin.org is a site I originated and maintain.) <br/>&gt; <br/>&gt; &gt; my $last_element_index = $#tmp_config_array; <br/>&gt; &gt; my $counter = 1; <br/>&gt; &gt; my $start_index = 0; <br/>&gt; &gt; my $next_index = 8; <br/>&gt; &gt; <br/>&gt; &gt; for (my $i=0; $i&lt;= $last_element_index; $i++) { <br/>&gt; <br/>&gt; This is better done using a foreach loop: <br/>&gt; <br/>&gt; foreach my $i (0 .. $last_element_index) { <br/>&gt; } <br/>&gt; <br/>&gt; Or use keys(@array) if your Perl version ois recent enough. <br/>&gt; <br/>&gt; &gt; print &quot;inside for loop\n&quot;; <br/>&gt; &gt; print &quot;START=$start_index\n&quot;; <br/>&gt; &gt; print &quot;NEXT=$next_index\n&quot;; <br/>&gt; &gt; my $file_to_write = &quot;GRC01_TG_SCGR_IPM_LIST_$counter&quot;; <br/>&gt; &gt; my @tmp_line_content = splice <br/>&gt; &gt; (@tmp_config_array,&quot;$start_index&quot;,&quot;$next_index&quot;); <br/>&gt; <br/>&gt; What are you trying to do here? The intention of this splice is not clear <br/>&gt; enough. <br/>&gt; <br/>&gt; Also see: <br/>&gt; <br/>&gt; http://perl-begin.org/tutorials/bad-elements/#vars_in_quotes <br/>&gt; <br/>&gt; &gt; open my $WFH,&#39;&gt;&#39;,$file_to_write; <br/>&gt; <br/>&gt; use autodie for an exception here. And note that &#39;&gt;&#39; will <br/>&gt; overwrite/clobber the <br/>&gt; file instead of appending to it. the <br/>&gt; <br/>&gt; &gt; foreach my $el (@tmp_line_content) { <br/>&gt; &gt; print &quot;EL=[$el]\n&quot;; <br/>&gt; &gt; next if /^\s*$/; <br/>&gt; &gt; print $WFH &quot;$el\n&quot;; <br/>&gt; &gt; } <br/>&gt; &gt; close($WFH); <br/>&gt; &gt; $start_index = ($next_index+1); <br/>&gt; &gt; $next_index = ($start_index+8); <br/>&gt; &gt; $i = $start_index; <br/>&gt; <br/>&gt; Why are you assigning to $i? It&#39;s the iteration variable - it seems like <br/>&gt; bad <br/>&gt; design. <br/>&gt; <br/>&gt; &gt; $counter++; <br/>&gt; &gt; # @tmp_line_content = undef; <br/>&gt; <br/>&gt; That&#39;s not the way to empty an array: <br/>&gt; <br/>&gt; Regards, <br/>&gt; <br/>&gt; Shlomi Fish <br/>&gt; <br/>&gt; -- <br/>&gt; ----------------------------------------------------------------- <br/>&gt; Shlomi Fish http://www.shlomifish.org/ <br/>&gt; &ldquo;So, who the hell is Qoheleth?&rdquo; - http://shlom.in/qoheleth <br/>&gt; <br/>&gt; Selina: How may I be of service? <br/>&gt; Alan: Well, according to the Codex, we&rsquo;re supposed to be slain by you. <br/>&gt; &mdash; http://www.shlomifish.org/humour/Selina-Mandrake/ <br/>&gt; <br/>&gt; Please reply to list if it&#39;s a mailing list post - http://shlom.in/reply . <br/>&gt; http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125258.html Wed, 25 Mar 2015 18:11:21 +0000 Re: Spliting and creating small files from a main files based online number by Shlomi Fish Hi Anirban, <br/> <br/>On Wed, 25 Mar 2015 22:37:39 +0530 <br/>Anirban Adhikary &lt;anirban.adhikary@gmail.com&gt; wrote: <br/> <br/>&gt; Hi List <br/>&gt; I have a configuration file and I would like to split the main file into <br/>&gt; multiple small files and push the small temp. files into an array. My <br/>&gt; config file looks like this <br/>&gt; <br/>&gt; GRC01;8;8;1;1;323U6_SIU-8;2048;2048;20;0;OFF <br/>&gt; GRC01;12;12;2;2;134S1_SIU-12;2048;2048;20;0;OFF <br/>&gt; GRC01;25;25;3;3;016S1_SIU-25;2048;2048;20;0;OFF <br/>&gt; GRC01;29;29;4;4;018S1_SIU-29;2048;2048;20;0;OFF <br/>&gt; GRC01;31;31;5;5;060S1_SIU-31;2048;2048;20;0;OFF <br/>&gt; GRC01;48;48;6;6;023S1_SIU-48;2048;2048;20;0;OFF <br/>&gt; GRC01;49;49;7;7;023S1_SIU-49;2048;2048;20;0;OFF <br/>&gt; GRC01;51;51;8;8;030S1_SIU-51;2048;2048;20;0;OFF <br/>&gt; GRC01;52;52;9;9;031S1_SIU-52;2048;2048;20;0;OFF <br/>&gt; GRC01;54;54;10;10;033S1_SIU-54;2048;2048;20;0;OFF <br/>&gt; GRC01;69;69;11;11;078S1_SIU-69;2048;2048;20;0;OFF <br/>&gt; GRC01;77;77;12;12;097S1_SIU-77;2048;2048;20;0;OFF <br/>&gt; GRC01;86;86;13;13;070S1_SIU-86;2048;2048;20;0;OFF <br/>&gt; GRC01;103;103;14;14;039S1_SIU-103;2048;2048;20;0;OFF <br/>&gt; GRC01;110;110;15;15;047S1_SIU-110;2048;2048;20;0;OFF <br/>&gt; GRC01;114;114;16;16;051S1_SIU-114;2048;2048;20;0;OFF <br/>&gt; GRC01;115;115;17;17;052S1_SIU-115;2048;2048;20;0;OFF <br/>&gt; GRC01;120;120;18;18;089S1_SIU-120;2048;2048;20;0;OFF <br/>&gt; GRC01;125;125;19;19;140S2_SIU-125;2048;2048;20;0;OFF <br/>&gt; GRC01;133;133;20;20;300S2_SIU-133;2048;2048;20;0;OFF <br/>&gt; GRC01;140;140;21;21;315S2_SIU-140;2048;2048;20;0;OFF <br/>&gt; GRC01;154;154;22;22;100S1_SIU-154;2048;2048;20;0;OFF <br/>&gt; GRC01;156;156;23;23;103U6_SIU-156;2048;2048;20;0;OFF <br/>&gt; GRC01;160;160;24;24;120S1_SIU-160;2048;2048;20;0;OFF <br/>&gt; GRC01;162;162;25;25;126S1_SIU-162;2048;2048;20;0;OFF <br/>&gt; GRC01;165;165;26;26;101S1_SIU-165;2048;2048;20;0;OFF <br/>&gt; GRC01;175;175;27;27;302S1_SIU-175;2048;2048;20;0;OFF <br/>&gt; GRC01;207;207;28;28;203S1_SIU-207;2048;2048;20;0;OFF <br/>&gt; GRC01;225;225;29;29;321U6_SIU-225;2048;2048;20;0;OFF <br/>&gt; GRC01;233;233;30;30;333S1_SIU-233;2048;2048;20;0;OFF <br/>&gt; GRC01;238;238;31;31;338S1_SIU-238;2048;2048;20;0;OFF <br/>&gt; GRC01;335;335;32;32;335U6_SIU-335;2048;2048;20;0;OFF <br/>&gt; <br/>&gt; This config file has got 32 lines so I am planning to write a code which <br/>&gt; will create four tmp. files out of the main config file. I have written the <br/>&gt; following code. <br/>&gt; <br/> <br/>Some comments on your code: <br/> <br/>&gt; #!/usr/bin/perl <br/>&gt; use Tie::File; <br/>&gt; use strict; <br/>&gt; use warnings; <br/> <br/>You may opt to use &quot;use autodie;&quot; here. <br/> <br/>&gt; <br/>&gt; my @config_file_contents; <br/>&gt; tie @config_file_contents, &#39;Tie::File&#39;, &quot;GRC01_TG_SCGR_IPM_LIST&quot; ###&lt;-- <br/>&gt; This is main config file <br/>&gt; or die &quot;Can&#39;t open filename&quot;; <br/>&gt; <br/>&gt; my @tmp_config_array=@config_file_contents; <br/>&gt; untie @config_file_contents; <br/> <br/>Doing all that with Tie::File is unnecessary. Just slurp the array (using <br/>File-Slurp-Tiny or Path-Tiny or whatever) or iterate it normally using &laquo;while <br/>(&lt;&gt;)&raquo;. See: <br/> <br/>http://perl-begin.org/topics/files-and-directories/ <br/> <br/>(Note - perl-begin.org is a site I originated and maintain.) <br/> <br/>&gt; my $last_element_index = $#tmp_config_array; <br/>&gt; my $counter = 1; <br/>&gt; my $start_index = 0; <br/>&gt; my $next_index = 8; <br/>&gt; <br/>&gt; for (my $i=0; $i&lt;= $last_element_index; $i++) { <br/> <br/>This is better done using a foreach loop: <br/> <br/>foreach my $i (0 .. $last_element_index) { <br/>} <br/> <br/>Or use keys(@array) if your Perl version ois recent enough. <br/> <br/>&gt; print &quot;inside for loop\n&quot;; <br/>&gt; print &quot;START=$start_index\n&quot;; <br/>&gt; print &quot;NEXT=$next_index\n&quot;; <br/>&gt; my $file_to_write = &quot;GRC01_TG_SCGR_IPM_LIST_$counter&quot;; <br/>&gt; my @tmp_line_content = splice <br/>&gt; (@tmp_config_array,&quot;$start_index&quot;,&quot;$next_index&quot;); <br/> <br/>What are you trying to do here? The intention of this splice is not clear <br/>enough. <br/> <br/>Also see: <br/> <br/>http://perl-begin.org/tutorials/bad-elements/#vars_in_quotes <br/> <br/>&gt; open my $WFH,&#39;&gt;&#39;,$file_to_write; <br/> <br/>use autodie for an exception here. And note that &#39;&gt;&#39; will overwrite/clobber the <br/>file instead of appending to it. the <br/> <br/>&gt; foreach my $el (@tmp_line_content) { <br/>&gt; print &quot;EL=[$el]\n&quot;; <br/>&gt; next if /^\s*$/; <br/>&gt; print $WFH &quot;$el\n&quot;; <br/>&gt; } <br/>&gt; close($WFH); <br/>&gt; $start_index = ($next_index+1); <br/>&gt; $next_index = ($start_index+8); <br/>&gt; $i = $start_index; <br/> <br/>Why are you assigning to $i? It&#39;s the iteration variable - it seems like bad <br/>design. <br/> <br/>&gt; $counter++; <br/>&gt; # @tmp_line_content = undef; <br/> <br/>That&#39;s not the way to empty an array: <br/> <br/>Regards, <br/> <br/> Shlomi Fish <br/> <br/>-- <br/>----------------------------------------------------------------- <br/>Shlomi Fish http://www.shlomifish.org/ <br/>&ldquo;So, who the hell is Qoheleth?&rdquo; - http://shlom.in/qoheleth <br/> <br/>Selina: How may I be of service? <br/>Alan: Well, according to the Codex, we&rsquo;re supposed to be slain by you. <br/> &mdash; http://www.shlomifish.org/humour/Selina-Mandrake/ <br/> <br/>Please reply to list if it&#39;s a mailing list post - http://shlom.in/reply . <br/> http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125257.html Wed, 25 Mar 2015 18:01:54 +0000 Spliting and creating small files from a main files based on line number by Anirban Adhikary Hi List<br/>I have a configuration file and I would like to split the main file into<br/>multiple small files and push the small temp. files into an array. My<br/>config file looks like this<br/><br/>GRC01;8;8;1;1;323U6_SIU-8;2048;2048;20;0;OFF<br/>GRC01;12;12;2;2;134S1_SIU-12;2048;2048;20;0;OFF<br/>GRC01;25;25;3;3;016S1_SIU-25;2048;2048;20;0;OFF<br/>GRC01;29;29;4;4;018S1_SIU-29;2048;2048;20;0;OFF<br/>GRC01;31;31;5;5;060S1_SIU-31;2048;2048;20;0;OFF<br/>GRC01;48;48;6;6;023S1_SIU-48;2048;2048;20;0;OFF<br/>GRC01;49;49;7;7;023S1_SIU-49;2048;2048;20;0;OFF<br/>GRC01;51;51;8;8;030S1_SIU-51;2048;2048;20;0;OFF<br/>GRC01;52;52;9;9;031S1_SIU-52;2048;2048;20;0;OFF<br/>GRC01;54;54;10;10;033S1_SIU-54;2048;2048;20;0;OFF<br/>GRC01;69;69;11;11;078S1_SIU-69;2048;2048;20;0;OFF<br/>GRC01;77;77;12;12;097S1_SIU-77;2048;2048;20;0;OFF<br/>GRC01;86;86;13;13;070S1_SIU-86;2048;2048;20;0;OFF<br/>GRC01;103;103;14;14;039S1_SIU-103;2048;2048;20;0;OFF<br/>GRC01;110;110;15;15;047S1_SIU-110;2048;2048;20;0;OFF<br/>GRC01;114;114;16;16;051S1_SIU-114;2048;2048;20;0;OFF<br/>GRC01;115;115;17;17;052S1_SIU-115;2048;2048;20;0;OFF<br/>GRC01;120;120;18;18;089S1_SIU-120;2048;2048;20;0;OFF<br/>GRC01;125;125;19;19;140S2_SIU-125;2048;2048;20;0;OFF<br/>GRC01;133;133;20;20;300S2_SIU-133;2048;2048;20;0;OFF<br/>GRC01;140;140;21;21;315S2_SIU-140;2048;2048;20;0;OFF<br/>GRC01;154;154;22;22;100S1_SIU-154;2048;2048;20;0;OFF<br/>GRC01;156;156;23;23;103U6_SIU-156;2048;2048;20;0;OFF<br/>GRC01;160;160;24;24;120S1_SIU-160;2048;2048;20;0;OFF<br/>GRC01;162;162;25;25;126S1_SIU-162;2048;2048;20;0;OFF<br/>GRC01;165;165;26;26;101S1_SIU-165;2048;2048;20;0;OFF<br/>GRC01;175;175;27;27;302S1_SIU-175;2048;2048;20;0;OFF<br/>GRC01;207;207;28;28;203S1_SIU-207;2048;2048;20;0;OFF<br/>GRC01;225;225;29;29;321U6_SIU-225;2048;2048;20;0;OFF<br/>GRC01;233;233;30;30;333S1_SIU-233;2048;2048;20;0;OFF<br/>GRC01;238;238;31;31;338S1_SIU-238;2048;2048;20;0;OFF<br/>GRC01;335;335;32;32;335U6_SIU-335;2048;2048;20;0;OFF<br/><br/>This config file has got 32 lines so I am planning to write a code which<br/>will create four tmp. files out of the main config file. I have written the<br/>following code.<br/><br/>#!/usr/bin/perl<br/>use Tie::File;<br/>use strict;<br/>use warnings;<br/><br/>my @config_file_contents;<br/>tie @config_file_contents, &#39;Tie::File&#39;, &quot;GRC01_TG_SCGR_IPM_LIST&quot; ###&lt;--<br/>This is main config file<br/> or die &quot;Can&#39;t open filename&quot;;<br/><br/>my @tmp_config_array=@config_file_contents;<br/>untie @config_file_contents;<br/>my $last_element_index = $#tmp_config_array;<br/>my $counter = 1;<br/>my $start_index = 0;<br/>my $next_index = 8;<br/><br/>for (my $i=0; $i&lt;= $last_element_index; $i++) {<br/>print &quot;inside for loop\n&quot;;<br/> print &quot;START=$start_index\n&quot;;<br/> print &quot;NEXT=$next_index\n&quot;;<br/> my $file_to_write = &quot;GRC01_TG_SCGR_IPM_LIST_$counter&quot;;<br/> my @tmp_line_content = splice<br/>(@tmp_config_array,&quot;$start_index&quot;,&quot;$next_index&quot;);<br/> open my $WFH,&#39;&gt;&#39;,$file_to_write;<br/> foreach my $el (@tmp_line_content) {<br/> print &quot;EL=[$el]\n&quot;;<br/> next if /^\s*$/;<br/> print $WFH &quot;$el\n&quot;;<br/> }<br/> close($WFH);<br/> $start_index = ($next_index+1);<br/> $next_index = ($start_index+8);<br/> $i = $start_index;<br/> $counter++;<br/># @tmp_line_content = undef;<br/><br/>}<br/><br/>while executing the code 4 tmp files are created but all of them are zero<br/>byte. Though in the print for first time &quot;EL&quot; I am getting 8 lines and<br/>second time &quot;EL&quot; prints<br/>15 lines but line number 9-15 are skipped.Second time EL should start<br/>printing from line number 9 instead it starts printing from line number 18.<br/>But the counters like $start_index,$next_index are incrementing properly.<br/>Also I am getting warning message &quot;splice() offset past end of array at ./<br/>tie_file.pl line 22&quot;<br/><br/>Please provides some pointers on those points.<br/><br/>Best Regards<br/>Anirban. http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125256.html Wed, 25 Mar 2015 17:08:29 +0000 Re: Regular Expression Help. by Frank Vino Thanks a lot Simon<br/><br/>-Frank<br/><br/>On Wed, Mar 25, 2015 at 5:44 PM, Simon Reinhardt &lt;simon@keinstein.org&gt;<br/>wrote:<br/><br/>&gt; Hi Frank,<br/>&gt;<br/>&gt; when first learning regexps I read the section &quot;In the World of Regular<br/>&gt; Expressions&quot; in the Lama-Book [1]. If you find this introduction to<br/>&gt; slow, you might also take a look at chromatic&#39;s Modern Perl, which is<br/>&gt; available for free [2].<br/>&gt;<br/>&gt; Regards, Simon<br/>&gt;<br/>&gt; Am 25.03.2015 um 06:01 schrieb Frank Vino:<br/>&gt; &gt; Hi Team,<br/>&gt; &gt;<br/>&gt; &gt; How to understand Regular Expression in a easy way?<br/>&gt; &gt;<br/>&gt; &gt; Thanks,<br/>&gt; &gt; Frank<br/>&gt;<br/>&gt; [1] Learning Perl, Sixth Edition by Randal L. Schwartz, brian d foy, and<br/>&gt; Tom Phoenix<br/>&gt;<br/>&gt; [2] http://onyxneon.com/books/modern_perl/<br/>&gt;<br/>&gt; --<br/>&gt; To unsubscribe, e-mail: beginners-unsubscribe@perl.org<br/>&gt; For additional commands, e-mail: beginners-help@perl.org<br/>&gt; http://learn.perl.org/<br/>&gt;<br/>&gt;<br/>&gt; http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125255.html Wed, 25 Mar 2015 16:34:21 +0000 Re: Regular Expression Help. by Shawn H Corey On Wed, 25 Mar 2015 10:31:40 +0530 <br/>Frank Vino &lt;vinofrank3@gmail.com&gt; wrote: <br/> <br/>&gt; Hi Team, <br/>&gt; <br/>&gt; How to understand Regular Expression in a easy way? <br/>&gt; <br/>&gt; Thanks, <br/>&gt; Frank <br/> <br/>Sorry Frank but there&#39;s no easy way. &#x2639; <br/> <br/>Some things to remember: <br/> <br/>Some punctuation marks have special meaning, like periods, question <br/>marks, and asterisks. But if there is a backslash before them, then <br/>they match themselves. This is true for all punctuation marks. <br/> <br/>And the opposite is true for ASCII letters and numbers. A backslash <br/>before them may give them special meaning but if there is none, then <br/>they match themselves. <br/> <br/> <br/>-- <br/>Don&#39;t stop where the ink does. <br/> Shawn <br/> http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125254.html Wed, 25 Mar 2015 12:29:39 +0000 Re: Regular Expression Help. by Simon Reinhardt Hi Frank,<br/><br/>when first learning regexps I read the section &quot;In the World of Regular<br/>Expressions&quot; in the Lama-Book [1]. If you find this introduction to<br/>slow, you might also take a look at chromatic&#39;s Modern Perl, which is<br/>available for free [2].<br/><br/>Regards, Simon<br/> <br/>Am 25.03.2015 um 06:01 schrieb Frank Vino:<br/>&gt; Hi Team,<br/>&gt; <br/>&gt; How to understand Regular Expression in a easy way?<br/>&gt; <br/>&gt; Thanks,<br/>&gt; Frank<br/><br/>[1] Learning Perl, Sixth Edition by Randal L. Schwartz, brian d foy, and<br/>Tom Phoenix<br/><br/>[2] http://onyxneon.com/books/modern_perl/<br/> http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125253.html Wed, 25 Mar 2015 12:14:40 +0000 Re: Regular Expression Help. by Shlomi Fish Hi Frank, <br/> <br/>On Wed, 25 Mar 2015 10:31:40 +0530 <br/>Frank Vino &lt;vinofrank3@gmail.com&gt; wrote: <br/> <br/>&gt; Hi Team, <br/>&gt; <br/>&gt; How to understand Regular Expression in a easy way? <br/>&gt; <br/> <br/>This page has links to some recommended tutorials about learning regular <br/>expressions: <br/> <br/>http://perl-begin.org/topics/regular-expressions/ <br/> <br/>*NOTE*: I originated perl-begin.org and still maintain it, but everyone is <br/>welcome to contribute to it. <br/> <br/>Regards, <br/> <br/> Shlomi Fish <br/> <br/>-- <br/>----------------------------------------------------------------- <br/>Shlomi Fish http://www.shlomifish.org/ <br/>List of Text Processing Tools - http://shlom.in/text-proc <br/> <br/>When it comes to terminators, you have a better shot at Arnold Schwarzenegger <br/>than at Summer Glau. (Via The Big Bang Theory) <br/> &mdash; http://www.shlomifish.org/humour/bits/facts/Summer-Glau/ <br/> <br/>Please reply to list if it&#39;s a mailing list post - http://shlom.in/reply . <br/> http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125252.html Wed, 25 Mar 2015 06:57:20 +0000 Re: Regular Expression Help. by Rahul Gojame Frank,<br/><br/>Just go through below site, it helps to build regex and test same easily.<br/>http://www.regexr.com/<br/><br/>~Rahul<br/><br/>On Wed, Mar 25, 2015 at 10:42 AM, Akshay Mohit &lt;akshaymohit2001@gmail.com&gt;<br/>wrote:<br/><br/>&gt; Just start using it and you will find it very easy to understand.<br/>&gt;<br/>&gt; -Akshay<br/>&gt;<br/>&gt; On Wed, Mar 25, 2015 at 10:31 AM, Frank Vino &lt;vinofrank3@gmail.com&gt; wrote:<br/>&gt;<br/>&gt;&gt; Hi Team,<br/>&gt;&gt;<br/>&gt;&gt; How to understand Regular Expression in a easy way?<br/>&gt;&gt;<br/>&gt;&gt; Thanks,<br/>&gt;&gt; Frank<br/>&gt;&gt;<br/>&gt;<br/>&gt; http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125251.html Wed, 25 Mar 2015 05:16:39 +0000 Re: Regular Expression Help. by Akshay Mohit Just start using it and you will find it very easy to understand.<br/><br/>-Akshay<br/><br/>On Wed, Mar 25, 2015 at 10:31 AM, Frank Vino &lt;vinofrank3@gmail.com&gt; wrote:<br/><br/>&gt; Hi Team,<br/>&gt;<br/>&gt; How to understand Regular Expression in a easy way?<br/>&gt;<br/>&gt; Thanks,<br/>&gt; Frank<br/>&gt; http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125250.html Wed, 25 Mar 2015 05:12:31 +0000 Regular Expression Help. by Frank Vino Hi Team,<br/><br/>How to understand Regular Expression in a easy way?<br/><br/>Thanks,<br/>Frank http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125249.html Wed, 25 Mar 2015 05:01:48 +0000 Re: How to sort a file based on numerical values exists in each line by Jim Gibson <br/>&gt; On Mar 24, 2015, at 7:27 AM, Anirban Adhikary &lt;anirban.adhikary@gmail.com&gt; wrote: <br/>&gt; <br/>&gt; Hi Jim <br/>&gt; <br/>&gt; In your code there is some hard coded value [ /RXMOI:MO=RXOTRX <br/>&gt; But I can&#39;t put any hard coded value since I use this code as a function and pass the filename as an argument. <br/>&gt; As you can see in my code there is no hard coded value. <br/> <br/>You can modify the regular expression used to extract the sort values depending upon the circumstances under which your function will be used. I was just giving an example of how to combine all of the individual steps into one command. I based the regex I used on the sample data you had provided. <br/> <br/>If you have any lines that do not match the regular expression, then the method I showed will produce errors, as there will be no extracted values to sort on for those lines. <br/> <br/>If I were writing a general purpose function, then I would not combine the steps as I have shown, but keep them as separate functions with any necessary error-checking and ilne filtering. <br/> <br/> http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125248.html Tue, 24 Mar 2015 16:01:00 +0000 Re: Is DBD installed with DBI? by Shlomi Fish Hi Sherman, <br/> <br/>On Tue, 24 Mar 2015 08:23:07 -0600 <br/>Sherman Willden &lt;sherman.willden@gmail.com&gt; wrote: <br/> <br/>&gt; Thank you, Shlomi. I am on Ubuntu when I try to install. I am looking at <br/>&gt; the links and I see there is also a DBD::msql. I will try that. <br/>&gt; <br/> <br/>DBD::mSQL is part of https://metacpan.org/release/Msql-Mysql-modules (whose <br/>last release was at 2001) and is intended for <br/>https://en.wikipedia.org/wiki/MSQL (mSQL or Mini-SQL), which is now a historic <br/>curiosity. To install DBD::mysql on Ubuntu use the command: <br/> <br/>&laquo; <br/>apt-get install libdbd-mysql-perl <br/>&raquo; <br/> <br/>(without the quotes) as root. <br/> <br/>Regards, <br/> <br/> Shlomi Fish <br/> <br/>-- <br/>----------------------------------------------------------------- <br/>Shlomi Fish http://www.shlomifish.org/ <br/>Apple Inc. is Evil - http://www.shlomifish.org/open-source/anti/apple/ <br/> <br/>Chuck Norris can construct any logical expression using only AND gates. <br/>Summer Glau can replace Chuck with a very small AND gate. <br/> &mdash; http://www.shlomifish.org/humour/bits/facts/Summer-Glau/ <br/> <br/>Please reply to list if it&#39;s a mailing list post - http://shlom.in/reply . <br/> http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125247.html Tue, 24 Mar 2015 14:33:17 +0000 Re: How to sort a file based on numerical values exists in each line by Anirban Adhikary Hi Jim<br/><br/>In your code there is some hard coded value [<br/>* /RXMOI:MO=RXOTRX*<br/>But I can&#39;t put any hard coded value since I use this code as a function<br/>and pass the filename as an argument.<br/>As you can see in my code there is no hard coded value.<br/><br/>Best Regards<br/>Anirban.<br/><br/><br/>On Tue, Mar 24, 2015 at 7:44 PM, Jim Gibson &lt;jimsgibson@gmail.com&gt; wrote:<br/><br/>&gt;<br/>&gt; &gt; On Mar 24, 2015, at 3:42 AM, Anirban Adhikary &lt;<br/>&gt; anirban.adhikary@gmail.com&gt; wrote:<br/>&gt; &gt;<br/>&gt; &gt; Hi List<br/>&gt; &gt; I have a file like this.<br/>&gt; &gt; RXMOI:MO=RXOTRX-473-0,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&amp;&amp;186,TEI=0;<br/>&gt; &gt; RXMOI:MO=RXOTRX-473-5,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&amp;&amp;231,TEI=5;<br/>&gt; &gt; RXMOI:MO=RXOTRX-473-1,SC=0,DCP1=187,SIG=SCCONC,DCP2=188&amp;&amp;195,TEI=1;<br/>&gt; ...<br/>&gt;<br/>&gt; &gt; This file is from a testing environment. But in production environment<br/>&gt; this file can be more than 500 lines. So my goal is to sort the file based<br/>&gt; on the bold numbers and create a new file.<br/>&gt; &gt; This is required for data validation. If the file is not in sorted order<br/>&gt; then it will be very difficult to validate the file manually.<br/>&gt;<br/>&gt; This is a typical application of a technique called a Schwartzian<br/>&gt; Transform (google it). You can combine all of the steps of extracting the<br/>&gt; keys and original line into an anonymous array, sorting the array<br/>&gt; references, and extracting the original line into one command:<br/>&gt;<br/>&gt; #!/usr/bin/perl<br/>&gt; use strict;<br/>&gt; use warnings;<br/>&gt;<br/>&gt; my @lines = &lt;DATA&gt;;<br/>&gt;<br/>&gt; my @sorted =<br/>&gt; map { $_-&gt;[2] }<br/>&gt; sort { $a-&gt;[0] &lt;=&gt; $b-&gt;[0] or $a-&gt;[1] &lt;=&gt; $b-&gt;[1] }<br/>&gt; map { [ /RXMOI:MO=RXOTRX-(\d+)-(\d+)/, $_ ] }<br/>&gt; @lines;<br/>&gt;<br/>&gt; print for @sorted;<br/>&gt;<br/>&gt; __DATA__<br/>&gt; RXMOI:MO=RXOTRX-473-0,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&amp;&amp;186,TEI=0;<br/>&gt; RXMOI:MO=RXOTRX-473-5,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&amp;&amp;231,TEI=5;<br/>&gt; RXMOI:MO=RXOTRX-473-1,SC=0,DCP1=187,SIG=SCCONC,DCP2=188&amp;&amp;195,TEI=1;<br/>&gt; RXMOI:MO=RXOTRX-1-8,SC=0,DCP1=250,SIG=SCCONC,DCP2=251&amp;&amp;258,TEI=8;<br/>&gt; RXMOI:MO=RXOTRX-1-2,SC=0,DCP1=196,SIG=SCCONC,DCP2=197&amp;&amp;204,TEI=2;<br/>&gt; RXMOI:MO=RXOTRX-1-0,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&amp;&amp;186,TEI=0;<br/>&gt; RXMOI:MO=RXOTRX-460-9,SC=0,DCP1=259,SIG=SCCONC,DCP2=260&amp;&amp;267,TEI=9;<br/>&gt; RXMOI:MO=RXOTRX-460-4,SC=0,DCP1=214,SIG=SCCONC,DCP2=215&amp;&amp;222,TEI=4;<br/>&gt; RXMOI:MO=RXOTRX-460-8,SC=0,DCP1=250,SIG=SCCONC,DCP2=251&amp;&amp;258,TEI=8;<br/>&gt;<br/>&gt;<br/>&gt; --<br/>&gt; To unsubscribe, e-mail: beginners-unsubscribe@perl.org<br/>&gt; For additional commands, e-mail: beginners-help@perl.org<br/>&gt; http://learn.perl.org/<br/>&gt;<br/>&gt;<br/>&gt; http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125246.html Tue, 24 Mar 2015 14:28:37 +0000 Re: Is DBD installed with DBI? by Sherman Willden Thank you, Shlomi. I am on Ubuntu when I try to install. I am looking at <br/>the links and I see there is also a DBD::msql. I will try that. <br/> <br/>Sherman <br/> <br/>On Tue, Mar 24, 2015 at 1:37 AM, Shlomi Fish &lt;shlomif@shlomifish.org&gt; wrote: <br/> <br/>&gt; Hi Sherman, <br/>&gt; <br/>&gt; On Mon, 23 Mar 2015 14:42:54 -0600 <br/>&gt; Sherman Willden &lt;sherman.willden@gmail.com&gt; wrote: <br/>&gt; <br/>&gt; &gt; I am trying to use perl with mysql. I have a tutorial open which prompted <br/>&gt; &gt; me to perform the following. <br/>&gt; &gt; <br/>&gt; &gt; $ sudo perl -MCPAN -e shell <br/>&gt; &gt; cpan&gt; install DBI <br/>&gt; &gt; cpan[2]&gt; install DBD::mysql <br/>&gt; &gt; <br/>&gt; &gt; DBI installed. The &#39;install DBD::mysql&#39; failed. Is DBD part of DBI? What <br/>&gt; am <br/>&gt; &gt; I missing? <br/>&gt; <br/>&gt; DBI stands for Data-Base Interface and is a unified SQL-databases&#39; access <br/>&gt; API <br/>&gt; for Perl 5 with several backends for the APIs of each database providers. <br/>&gt; These <br/>&gt; backends are called &quot;Database Drivers&quot; or &quot;DBDs&quot;. There&#39;s DBD::mysql, <br/>&gt; DBD::Pg , <br/>&gt; DBD::SQLite and many others - see https://metacpan.org/search?q=dbd , and <br/>&gt; &quot;DBD&quot; <br/>&gt; by itself is not a thing. <br/>&gt; <br/>&gt; &gt; <br/>&gt; &gt; The DBD run is in the attached installlation-help.txt file <br/>&gt; &gt; <br/>&gt; &gt; Thank you; <br/>&gt; &gt; <br/>&gt; &gt; Sherman <br/>&gt; <br/>&gt; What is your operating system, its version, its Linux/etc. distribution, <br/>&gt; perl, <br/>&gt; perl version, etc.? There may be a better way to install this CPAN module <br/>&gt; there: <br/>&gt; <br/>&gt; * http://perl-begin.org/topics/cpan/ <br/>&gt; <br/>&gt; (Note: perl-begin.org a domain that I originated and maintain.). <br/>&gt; <br/>&gt; Regards, <br/>&gt; <br/>&gt; Shlomi Fish <br/>&gt; <br/>&gt; -- <br/>&gt; ----------------------------------------------------------------- <br/>&gt; Shlomi Fish http://www.shlomifish.org/ <br/>&gt; Why I Love Perl - http://shlom.in/joy-of-perl <br/>&gt; <br/>&gt; Fortran - there isn&rsquo;t a way to do it... oh wait! Now there is. <br/>&gt; &mdash; http://www.shlomifish.org/humour/ways_to_do_it.html <br/>&gt; <br/>&gt; Please reply to list if it&#39;s a mailing list post - http://shlom.in/reply . <br/>&gt; <br/>&gt; -- <br/>&gt; To unsubscribe, e-mail: beginners-unsubscribe@perl.org <br/>&gt; For additional commands, e-mail: beginners-help@perl.org <br/>&gt; http://learn.perl.org/ <br/>&gt; <br/>&gt; <br/>&gt; http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125245.html Tue, 24 Mar 2015 14:23:24 +0000 Re: How to sort a file based on numerical values exists in each line by Jim Gibson <br/>&gt; On Mar 24, 2015, at 3:42 AM, Anirban Adhikary &lt;anirban.adhikary@gmail.com&gt; wrote: <br/>&gt; <br/>&gt; Hi List <br/>&gt; I have a file like this. <br/>&gt; RXMOI:MO=RXOTRX-473-0,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&amp;&amp;186,TEI=0; <br/>&gt; RXMOI:MO=RXOTRX-473-5,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&amp;&amp;231,TEI=5; <br/>&gt; RXMOI:MO=RXOTRX-473-1,SC=0,DCP1=187,SIG=SCCONC,DCP2=188&amp;&amp;195,TEI=1; <br/>... <br/> <br/>&gt; This file is from a testing environment. But in production environment this file can be more than 500 lines. So my goal is to sort the file based on the bold numbers and create a new file. <br/>&gt; This is required for data validation. If the file is not in sorted order then it will be very difficult to validate the file manually. <br/> <br/>This is a typical application of a technique called a Schwartzian Transform (google it). You can combine all of the steps of extracting the keys and original line into an anonymous array, sorting the array references, and extracting the original line into one command: <br/> <br/>#!/usr/bin/perl <br/>use strict; <br/>use warnings; <br/> <br/>my @lines = &lt;DATA&gt;; <br/> <br/>my @sorted = <br/> map { $_-&gt;[2] } <br/> sort { $a-&gt;[0] &lt;=&gt; $b-&gt;[0] or $a-&gt;[1] &lt;=&gt; $b-&gt;[1] } <br/> map { [ /RXMOI:MO=RXOTRX-(\d+)-(\d+)/, $_ ] } <br/> @lines; <br/> <br/>print for @sorted; <br/> <br/>__DATA__ <br/>RXMOI:MO=RXOTRX-473-0,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&amp;&amp;186,TEI=0; <br/>RXMOI:MO=RXOTRX-473-5,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&amp;&amp;231,TEI=5; <br/>RXMOI:MO=RXOTRX-473-1,SC=0,DCP1=187,SIG=SCCONC,DCP2=188&amp;&amp;195,TEI=1; <br/>RXMOI:MO=RXOTRX-1-8,SC=0,DCP1=250,SIG=SCCONC,DCP2=251&amp;&amp;258,TEI=8; <br/>RXMOI:MO=RXOTRX-1-2,SC=0,DCP1=196,SIG=SCCONC,DCP2=197&amp;&amp;204,TEI=2; <br/>RXMOI:MO=RXOTRX-1-0,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&amp;&amp;186,TEI=0; <br/>RXMOI:MO=RXOTRX-460-9,SC=0,DCP1=259,SIG=SCCONC,DCP2=260&amp;&amp;267,TEI=9; <br/>RXMOI:MO=RXOTRX-460-4,SC=0,DCP1=214,SIG=SCCONC,DCP2=215&amp;&amp;222,TEI=4; <br/>RXMOI:MO=RXOTRX-460-8,SC=0,DCP1=250,SIG=SCCONC,DCP2=251&amp;&amp;258,TEI=8; <br/> <br/> http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125244.html Tue, 24 Mar 2015 14:14:43 +0000 Re: How to sort a file based on numerical values exists in each line by Simon Reinhardt Am 24.03.2015 um 14:03 schrieb Shlomi Fish:<br/>&gt; This can be more idiomatically written as:<br/>&gt; <br/>&gt; $a-&gt;[1] &lt;=&gt; $b-&gt;[1] or $a-&gt;[2] &lt;=&gt; $b-&gt;[2]<br/>I agree, a<br/><br/>sort {<br/> $a-&gt;[0] &lt;=&gt; $b-&gt;[0] or<br/> $a-&gt;[1] &lt;=&gt; $b-&gt;[1] or<br/> $a-&gt;[2] &lt;=&gt; $b-&gt;[2]<br/>}<br/><br/>is certainly more readable than the C-style<br/><br/>sort {<br/> $a-&gt;[0] &lt;=&gt; $b-&gt;[0] ? $a-&gt;[0] &lt;=&gt; $b-&gt;[0] :<br/> $a-&gt;[1] &lt;=&gt; $b-&gt;[1] ? $a-&gt;[1] &lt;=&gt; $b-&gt;[1] :<br/> $a-&gt;[2] &lt;=&gt; $b-&gt;[2] ? $a-&gt;[2] &lt;=&gt; $b-&gt;[2] :<br/> $a-&gt;[3] &lt;=&gt; $b-&gt;[3]<br/>}<br/><br/>Simon<br/> http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125243.html Tue, 24 Mar 2015 14:11:01 +0000 Re: How to sort a file based on numerical values exists in eachline by Shlomi Fish Hi Simon, <br/> <br/>thanks for helping Anirban, but I have a small comment about your code: <br/> <br/>On Tue, 24 Mar 2015 13:11:56 +0100 <br/>Simon Reinhardt &lt;simon@keinstein.org&gt; wrote: <br/> <br/>&gt; Hi Anirban, <br/>&gt; <br/>&gt; first we have to be clear how you want to sort the lines. <br/>&gt; Does 10-1 sort before 1-11 ? <br/>&gt; Do you want numeric (use &lt;=&gt;) or alphabetic (use cmp) order? <br/>&gt; <br/>&gt; &gt; while (my $line = &lt;$RFH&gt;) { <br/>&gt; &gt; chomp($line); <br/>&gt; &gt; if ($line =~ m/.*?\-(\d+)\-(\d+).*/) { <br/>&gt; &gt; $sequence_no = &quot;$1$2&quot;; <br/>&gt; &gt; # print &quot;$sequence_no-- $line\n&quot;; <br/>&gt; &gt; $file_content_hash{$sequence_no}=&quot;$line&quot;; <br/>&gt; &gt; } <br/>&gt; &gt; } <br/>&gt; <br/>&gt; this will only work as long as the sequence numbers are unique. If two <br/>&gt; different lines have the same sequence number, the latter will be discarded. <br/>&gt; <br/>&gt; My suggestion would be <br/>&gt; <br/>&gt; #!/usr/bin/env perl <br/>&gt; use 5.010; <br/>&gt; use warnings; <br/>&gt; use strict; <br/>&gt; use autodie; <br/>&gt; my $file_name = &quot;RXMOI_TRX_CMD&quot;; <br/>&gt; my @lines; <br/>&gt; <br/>&gt; open(my $fh, &quot;&lt;&quot;, $file_name); <br/>&gt; <br/>&gt; while(&lt;$fh&gt;) { <br/>&gt; chomp; <br/>&gt; if (/^RXMOI:MO=RXOTRX-([0-9]+)-([0-9]+)/) { <br/>&gt; push @lines, [$_, $1, $2]; <br/>&gt; } <br/>&gt; else { <br/>&gt; warn(&quot;line &#39;$_&#39; does not match&quot;); <br/>&gt; } <br/>&gt; } <br/>&gt; <br/>&gt; my @sorted = sort { <br/>&gt; # if the numbers before the &quot;-&quot; are equal, compare the numbers after the &quot;-&quot; <br/>&gt; $a-&gt;[1] &lt;=&gt; $b-&gt;[1] ? $a-&gt;[1] &lt;=&gt; $b-&gt;[1] : $a-&gt;[2] &lt;=&gt; $b-&gt;[2] <br/> <br/>This can be more idiomatically written as: <br/> <br/>$a-&gt;[1] &lt;=&gt; $b-&gt;[1] or $a-&gt;[2] &lt;=&gt; $b-&gt;[2] <br/> <br/>This is because in Perl (as opposed to in C and in other languages) <br/>and/or/&quot;||&quot;/&quot;&amp;&amp;&quot; return the last true value instead of just 0 or 1. As a <br/>result, using &quot;or&quot; for chaining comparators is a common Perl idiom. <br/> <br/>&gt; } <br/>&gt; @lines; <br/>&gt; <br/>&gt; say $_-&gt;[0] for @sorted; <br/>&gt; <br/> <br/>Regards, <br/> <br/> Shlomi Fish <br/> <br/> <br/>-- <br/>----------------------------------------------------------------- <br/>Shlomi Fish http://www.shlomifish.org/ <br/>Funny Anti-Terrorism Story - http://shlom.in/enemy <br/> <br/>Chuck Norris doesn&#39;t celebrate holidays -- holidays celebrate Chuck Norris. <br/>(By sevvie: http://sevvie.github.io/ .) <br/> &mdash; http://www.shlomifish.org/humour/bits/facts/Chuck-Norris/ <br/> <br/>Please reply to list if it&#39;s a mailing list post - http://shlom.in/reply . <br/> http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125242.html Tue, 24 Mar 2015 13:04:30 +0000 Re: How to sort a file based on numerical values exists in each line by Simon Reinhardt Hi Anirban,<br/><br/>first we have to be clear how you want to sort the lines.<br/>Does 10-1 sort before 1-11 ?<br/>Do you want numeric (use &lt;=&gt;) or alphabetic (use cmp) order?<br/><br/>&gt; while (my $line = &lt;$RFH&gt;) {<br/>&gt; chomp($line);<br/>&gt; if ($line =~ m/.*?\-(\d+)\-(\d+).*/) {<br/>&gt; $sequence_no = &quot;$1$2&quot;;<br/>&gt; # print &quot;$sequence_no-- $line\n&quot;;<br/>&gt; $file_content_hash{$sequence_no}=&quot;$line&quot;;<br/>&gt; }<br/>&gt; }<br/><br/>this will only work as long as the sequence numbers are unique. If two<br/>different lines have the same sequence number, the latter will be discarded.<br/><br/>My suggestion would be<br/><br/>#!/usr/bin/env perl<br/>use 5.010;<br/>use warnings;<br/>use strict;<br/>use autodie;<br/>my $file_name = &quot;RXMOI_TRX_CMD&quot;;<br/>my @lines;<br/><br/>open(my $fh, &quot;&lt;&quot;, $file_name);<br/><br/>while(&lt;$fh&gt;) {<br/> chomp;<br/> if (/^RXMOI:MO=RXOTRX-([0-9]+)-([0-9]+)/) {<br/> push @lines, [$_, $1, $2];<br/> }<br/> else {<br/> warn(&quot;line &#39;$_&#39; does not match&quot;);<br/> }<br/>}<br/><br/>my @sorted = sort {<br/># if the numbers before the &quot;-&quot; are equal, compare the numbers after the &quot;-&quot;<br/>$a-&gt;[1] &lt;=&gt; $b-&gt;[1] ? $a-&gt;[1] &lt;=&gt; $b-&gt;[1] : $a-&gt;[2] &lt;=&gt; $b-&gt;[2]<br/>}<br/>@lines; <br/><br/>say $_-&gt;[0] for @sorted;<br/><br/>You might also take a look at the section &quot;Sorting Efficiently&quot; in the<br/>Alpacca book.<br/><br/>All the best, Simon<br/><br/><br/><br/><br/> http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125241.html Tue, 24 Mar 2015 12:12:06 +0000 Re: How to sort a file based on numerical values exists in each line by Shaji Kalidasan Hi Anirban,<br/><br/>In case if you print the complete data (the full line) then the following<br/>approach may help.<br/><br/>Here is one way to do it<br/><br/>[code]<br/>use strict;<br/>use warnings;<br/><br/>my %data;<br/>open my $fin, &#39;&lt;&#39;, &#39;data.txt&#39; or die &quot;Cannot open file ($!)&quot;;<br/><br/>while(&lt;$fin&gt;) {<br/> chomp;<br/> my($val) = split &#39;,&#39;, $_; #split the data using comma<br/> my($key, $value) = split &#39;=&#39;, $val; #split the values using equal sign<br/>(=)<br/> $value =~ /.*?-([\d\-]+)$/; #extract the numbers following the pattern<br/>(-DIGIT-DIGIT)<br/> $data{$1} = $_;<br/>}<br/><br/>#sort in ascending order<br/>foreach my $key (sort {$a cmp $b} keys %data) {<br/> print &quot;$data{$key}\n&quot;;<br/>}<br/>[/code]<br/><br/>[output]<br/>RXMOI:MO=RXOTRX-1-0,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&amp;&amp;186,TEI=0;<br/>RXMOI:MO=RXOTRX-1-1,SC=0,DCP1=187,SIG=SCCONC,DCP2=188&amp;&amp;195,TEI=1;<br/>RXMOI:MO=RXOTRX-1-2,SC=0,DCP1=196,SIG=SCCONC,DCP2=197&amp;&amp;204,TEI=2;<br/>RXMOI:MO=RXOTRX-1-4,SC=0,DCP1=214,SIG=SCCONC,DCP2=215&amp;&amp;222,TEI=4;<br/>RXMOI:MO=RXOTRX-1-5,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&amp;&amp;231,TEI=5;<br/>RXMOI:MO=RXOTRX-1-8,SC=0,DCP1=250,SIG=SCCONC,DCP2=251&amp;&amp;258,TEI=8;<br/>RXMOI:MO=RXOTRX-460-0,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&amp;&amp;186,TEI=0;<br/>RXMOI:MO=RXOTRX-460-1,SC=0,DCP1=187,SIG=SCCONC,DCP2=188&amp;&amp;195,TEI=1;<br/>RXMOI:MO=RXOTRX-460-4,SC=0,DCP1=214,SIG=SCCONC,DCP2=215&amp;&amp;222,TEI=4;<br/>RXMOI:MO=RXOTRX-460-5,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&amp;&amp;231,TEI=5;<br/>RXMOI:MO=RXOTRX-460-8,SC=0,DCP1=250,SIG=SCCONC,DCP2=251&amp;&amp;258,TEI=8;<br/>RXMOI:MO=RXOTRX-460-9,SC=0,DCP1=259,SIG=SCCONC,DCP2=260&amp;&amp;267,TEI=9;<br/>RXMOI:MO=RXOTRX-473-0,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&amp;&amp;186,TEI=0;<br/>RXMOI:MO=RXOTRX-473-1,SC=0,DCP1=187,SIG=SCCONC,DCP2=188&amp;&amp;195,TEI=1;<br/>RXMOI:MO=RXOTRX-473-4,SC=0,DCP1=214,SIG=SCCONC,DCP2=215&amp;&amp;222,TEI=4;<br/>RXMOI:MO=RXOTRX-473-5,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&amp;&amp;231,TEI=5;<br/>RXMOI:MO=RXOTRX-473-9,SC=0,DCP1=259,SIG=SCCONC,DCP2=260&amp;&amp;267,TEI=9;<br/>[/output]<br/><br/>On Tue, Mar 24, 2015 at 4:39 PM, Shaji Kalidasan &lt;shajiindia@gmail.com&gt;<br/>wrote:<br/><br/>&gt; Hi Anirban,<br/>&gt;<br/>&gt; Here is one way to do it<br/>&gt;<br/>&gt; [code]<br/>&gt; use strict;<br/>&gt; use warnings;<br/>&gt;<br/>&gt; my @data;<br/>&gt; open my $fin, &#39;&lt;&#39;, &#39;data.txt&#39; or die &quot;Cannot open file ($!)&quot;;<br/>&gt;<br/>&gt; while(&lt;$fin&gt;) {<br/>&gt; my($val) = split &#39;,&#39;, $_; #split the data using comma<br/>&gt; my($key, $value) = split &#39;=&#39;, $val; #split the values using equal sign<br/>&gt; (=)<br/>&gt; $value =~ /.*?-([\d\-]+)$/; #extract the numbers following the pattern<br/>&gt; (-DIGIT-DIGIT)<br/>&gt; push @data, $1;<br/>&gt; }<br/>&gt;<br/>&gt; #sort in ascending order<br/>&gt; @data = sort {$a cmp $b} @data;<br/>&gt; print join &quot;\n&quot;, @data;<br/>&gt; [/code]<br/>&gt;<br/>&gt; [data.txt]<br/>&gt; RXMOI:MO=RXOTRX-473-0,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&amp;&amp;186,TEI=0;<br/>&gt; RXMOI:MO=RXOTRX-473-5,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&amp;&amp;231,TEI=5;<br/>&gt; RXMOI:MO=RXOTRX-473-1,SC=0,DCP1=187,SIG=SCCONC,DCP2=188&amp;&amp;195,TEI=1;<br/>&gt; RXMOI:MO=RXOTRX-473-9,SC=0,DCP1=259,SIG=SCCONC,DCP2=260&amp;&amp;267,TEI=9;<br/>&gt; RXMOI:MO=RXOTRX-473-4,SC=0,DCP1=214,SIG=SCCONC,DCP2=215&amp;&amp;222,TEI=4;<br/>&gt; RXMOI:MO=RXOTRX-1-8,SC=0,DCP1=250,SIG=SCCONC,DCP2=251&amp;&amp;258,TEI=8;<br/>&gt; RXMOI:MO=RXOTRX-1-2,SC=0,DCP1=196,SIG=SCCONC,DCP2=197&amp;&amp;204,TEI=2;<br/>&gt; RXMOI:MO=RXOTRX-1-0,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&amp;&amp;186,TEI=0;<br/>&gt; RXMOI:MO=RXOTRX-1-5,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&amp;&amp;231,TEI=5;<br/>&gt; RXMOI:MO=RXOTRX-1-1,SC=0,DCP1=187,SIG=SCCONC,DCP2=188&amp;&amp;195,TEI=1;<br/>&gt; RXMOI:MO=RXOTRX-1-4,SC=0,DCP1=214,SIG=SCCONC,DCP2=215&amp;&amp;222,TEI=4;<br/>&gt; RXMOI:MO=RXOTRX-460-9,SC=0,DCP1=259,SIG=SCCONC,DCP2=260&amp;&amp;267,TEI=9;<br/>&gt; RXMOI:MO=RXOTRX-460-4,SC=0,DCP1=214,SIG=SCCONC,DCP2=215&amp;&amp;222,TEI=4;<br/>&gt; RXMOI:MO=RXOTRX-460-8,SC=0,DCP1=250,SIG=SCCONC,DCP2=251&amp;&amp;258,TEI=8;<br/>&gt; RXMOI:MO=RXOTRX-460-5,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&amp;&amp;231,TEI=5;<br/>&gt; RXMOI:MO=RXOTRX-460-1,SC=0,DCP1=187,SIG=SCCONC,DCP2=188&amp;&amp;195,TEI=1;<br/>&gt; RXMOI:MO=RXOTRX-460-0,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&amp;&amp;186,TEI=0;<br/>&gt; [/data.txt]<br/>&gt;<br/>&gt; [output]<br/>&gt; 1-0<br/>&gt; 1-1<br/>&gt; 1-2<br/>&gt; 1-4<br/>&gt; 1-5<br/>&gt; 1-8<br/>&gt; 460-0<br/>&gt; 460-1<br/>&gt; 460-4<br/>&gt; 460-5<br/>&gt; 460-8<br/>&gt; 460-9<br/>&gt; 473-0<br/>&gt; 473-1<br/>&gt; 473-4<br/>&gt; 473-5<br/>&gt; 473-9<br/>&gt; [/output]<br/>&gt;<br/>&gt; On Tue, Mar 24, 2015 at 4:12 PM, Anirban Adhikary &lt;<br/>&gt; anirban.adhikary@gmail.com&gt; wrote:<br/>&gt;<br/>&gt;&gt; Hi List<br/>&gt;&gt; I have a file like this.<br/>&gt;&gt; RXMOI:MO=RXOTRX-*473-0*,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&amp;&amp;186,TEI=0;<br/>&gt;&gt; RXMOI:MO=RXOTRX-*473-5*,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&amp;&amp;231,TEI=5;<br/>&gt;&gt; RXMOI:MO=RXOTRX-*473-1*,SC=0,DCP1=187,SIG=SCCONC,DCP2=188&amp;&amp;195,TEI=1;<br/>&gt;&gt; RXMOI:MO=RXOTRX-*473-9*,SC=0,DCP1=259,SIG=SCCONC,DCP2=260&amp;&amp;267,TEI=9;<br/>&gt;&gt; RXMOI:MO=RXOTRX-*473-4,*SC=0,DCP1=214,SIG=SCCONC,DCP2=215&amp;&amp;222,TEI=4;<br/>&gt;&gt; RXMOI:MO=RXOTRX-*1-8*,SC=0,DCP1=250,SIG=SCCONC,DCP2=251&amp;&amp;258,TEI=8;<br/>&gt;&gt; RXMOI:MO=RXOTRX-*1-2,*SC=0,DCP1=196,SIG=SCCONC,DCP2=197&amp;&amp;204,TEI=2;<br/>&gt;&gt; RXMOI:MO=RXOTRX-*1-0*,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&amp;&amp;186,TEI=0;<br/>&gt;&gt; RXMOI:MO=RXOTRX-*1-5*,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&amp;&amp;231,TEI=5;<br/>&gt;&gt; RXMOI:MO=RXOTRX-*1-1,*SC=0,DCP1=187,SIG=SCCONC,DCP2=188&amp;&amp;195,TEI=1;<br/>&gt;&gt; RXMOI:MO=RXOTRX-*1-4,*SC=0,DCP1=214,SIG=SCCONC,DCP2=215&amp;&amp;222,TEI=4;<br/>&gt;&gt; RXMOI:MO=RXOTRX-*460-9*,SC=0,DCP1=259,SIG=SCCONC,DCP2=260&amp;&amp;267,TEI=9;<br/>&gt;&gt; RXMOI:MO=RXOTRX-*460-4*,SC=0,DCP1=214,SIG=SCCONC,DCP2=215&amp;&amp;222,TEI=4;<br/>&gt;&gt; RXMOI:MO=RXOTRX-*460-8*,SC=0,DCP1=250,SIG=SCCONC,DCP2=251&amp;&amp;258,TEI=8;<br/>&gt;&gt; RXMOI:MO=RXOTRX-*460-5*,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&amp;&amp;231,TEI=5;<br/>&gt;&gt; RXMOI:MO=RXOTRX-*460-1*,SC=0,DCP1=187,SIG=SCCONC,DCP2=188&amp;&amp;195,TEI=1;<br/>&gt;&gt; RXMOI:MO=RXOTRX-*460-0*,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&amp;&amp;186,TEI=0;<br/>&gt;&gt;<br/>&gt;&gt; This file is from a testing environment. But in production environment<br/>&gt;&gt; this file can be more than 500 lines. So my goal is to sort the file based<br/>&gt;&gt; on the bold numbers and create a new file.<br/>&gt;&gt; This is required for data validation. If the file is not in sorted order<br/>&gt;&gt; then it will be very difficult to validate the file manually.<br/>&gt;&gt;<br/>&gt;&gt; For this I have started with the following code<br/>&gt;&gt;<br/>&gt;&gt; #!/usr/bin/perl<br/>&gt;&gt; use strict;<br/>&gt;&gt; use warnings;<br/>&gt;&gt; my $file_name = &quot;RXMOI_TRX_CMD&quot;;<br/>&gt;&gt; open my $RFH, &#39;&lt;&#39;, $file_name;<br/>&gt;&gt; my $sequence_no;<br/>&gt;&gt; my $lowest_no;<br/>&gt;&gt; while (my $line = &lt;$RFH&gt;) {<br/>&gt;&gt; chomp($line);<br/>&gt;&gt; if ($line =~ m/.*?\-(\d+)\-(\d+).*/) {<br/>&gt;&gt; $sequence_no = &quot;$1$2&quot;;<br/>&gt;&gt; print &quot;$sequence_no\n&quot;;<br/>&gt;&gt; }<br/>&gt;&gt; }<br/>&gt;&gt;<br/>&gt;&gt; I can extract the number into a variable but after that not getting any<br/>&gt;&gt; idea how to proceed. Could you please provide some logic so that I can<br/>&gt;&gt; proceed further.<br/>&gt;&gt;<br/>&gt;&gt; Best Regards<br/>&gt;&gt; Anirban.<br/>&gt;&gt;<br/>&gt;&gt;<br/>&gt;&gt;<br/>&gt;<br/>&gt;<br/>&gt; --<br/>&gt; best,<br/>&gt; Shaji<br/>&gt;<br/>&gt; ----------------------------------------------------------------------------------------------------------------------------------------------<br/>&gt; Your talent is God&#39;s gift to you. What you do with it is your gift back to<br/>&gt; God.<br/>&gt;<br/>&gt; ----------------------------------------------------------------------------------------------------------------------------------------------<br/>&gt;<br/><br/><br/><br/>-- <br/>best,<br/>Shaji<br/>----------------------------------------------------------------------------------------------------------------------------------------------<br/>Your talent is God&#39;s gift to you. What you do with it is your gift back to<br/>God.<br/>---------------------------------------------------------------------------------------------------------------------------------------------- http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125240.html Tue, 24 Mar 2015 11:21:39 +0000 Re: How to sort a file based on numerical values exists in each line by Shaji Kalidasan Hi Anirban,<br/><br/>Here is one way to do it<br/><br/>[code]<br/>use strict;<br/>use warnings;<br/><br/>my @data;<br/>open my $fin, &#39;&lt;&#39;, &#39;data.txt&#39; or die &quot;Cannot open file ($!)&quot;;<br/><br/>while(&lt;$fin&gt;) {<br/> my($val) = split &#39;,&#39;, $_; #split the data using comma<br/> my($key, $value) = split &#39;=&#39;, $val; #split the values using equal sign<br/>(=)<br/> $value =~ /.*?-([\d\-]+)$/; #extract the numbers following the pattern<br/>(-DIGIT-DIGIT)<br/> push @data, $1;<br/>}<br/><br/>#sort in ascending order<br/>@data = sort {$a cmp $b} @data;<br/>print join &quot;\n&quot;, @data;<br/>[/code]<br/><br/>[data.txt]<br/>RXMOI:MO=RXOTRX-473-0,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&amp;&amp;186,TEI=0;<br/>RXMOI:MO=RXOTRX-473-5,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&amp;&amp;231,TEI=5;<br/>RXMOI:MO=RXOTRX-473-1,SC=0,DCP1=187,SIG=SCCONC,DCP2=188&amp;&amp;195,TEI=1;<br/>RXMOI:MO=RXOTRX-473-9,SC=0,DCP1=259,SIG=SCCONC,DCP2=260&amp;&amp;267,TEI=9;<br/>RXMOI:MO=RXOTRX-473-4,SC=0,DCP1=214,SIG=SCCONC,DCP2=215&amp;&amp;222,TEI=4;<br/>RXMOI:MO=RXOTRX-1-8,SC=0,DCP1=250,SIG=SCCONC,DCP2=251&amp;&amp;258,TEI=8;<br/>RXMOI:MO=RXOTRX-1-2,SC=0,DCP1=196,SIG=SCCONC,DCP2=197&amp;&amp;204,TEI=2;<br/>RXMOI:MO=RXOTRX-1-0,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&amp;&amp;186,TEI=0;<br/>RXMOI:MO=RXOTRX-1-5,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&amp;&amp;231,TEI=5;<br/>RXMOI:MO=RXOTRX-1-1,SC=0,DCP1=187,SIG=SCCONC,DCP2=188&amp;&amp;195,TEI=1;<br/>RXMOI:MO=RXOTRX-1-4,SC=0,DCP1=214,SIG=SCCONC,DCP2=215&amp;&amp;222,TEI=4;<br/>RXMOI:MO=RXOTRX-460-9,SC=0,DCP1=259,SIG=SCCONC,DCP2=260&amp;&amp;267,TEI=9;<br/>RXMOI:MO=RXOTRX-460-4,SC=0,DCP1=214,SIG=SCCONC,DCP2=215&amp;&amp;222,TEI=4;<br/>RXMOI:MO=RXOTRX-460-8,SC=0,DCP1=250,SIG=SCCONC,DCP2=251&amp;&amp;258,TEI=8;<br/>RXMOI:MO=RXOTRX-460-5,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&amp;&amp;231,TEI=5;<br/>RXMOI:MO=RXOTRX-460-1,SC=0,DCP1=187,SIG=SCCONC,DCP2=188&amp;&amp;195,TEI=1;<br/>RXMOI:MO=RXOTRX-460-0,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&amp;&amp;186,TEI=0;<br/>[/data.txt]<br/><br/>[output]<br/>1-0<br/>1-1<br/>1-2<br/>1-4<br/>1-5<br/>1-8<br/>460-0<br/>460-1<br/>460-4<br/>460-5<br/>460-8<br/>460-9<br/>473-0<br/>473-1<br/>473-4<br/>473-5<br/>473-9<br/>[/output]<br/><br/>On Tue, Mar 24, 2015 at 4:12 PM, Anirban Adhikary &lt;<br/>anirban.adhikary@gmail.com&gt; wrote:<br/><br/>&gt; Hi List<br/>&gt; I have a file like this.<br/>&gt; RXMOI:MO=RXOTRX-*473-0*,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&amp;&amp;186,TEI=0;<br/>&gt; RXMOI:MO=RXOTRX-*473-5*,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&amp;&amp;231,TEI=5;<br/>&gt; RXMOI:MO=RXOTRX-*473-1*,SC=0,DCP1=187,SIG=SCCONC,DCP2=188&amp;&amp;195,TEI=1;<br/>&gt; RXMOI:MO=RXOTRX-*473-9*,SC=0,DCP1=259,SIG=SCCONC,DCP2=260&amp;&amp;267,TEI=9;<br/>&gt; RXMOI:MO=RXOTRX-*473-4,*SC=0,DCP1=214,SIG=SCCONC,DCP2=215&amp;&amp;222,TEI=4;<br/>&gt; RXMOI:MO=RXOTRX-*1-8*,SC=0,DCP1=250,SIG=SCCONC,DCP2=251&amp;&amp;258,TEI=8;<br/>&gt; RXMOI:MO=RXOTRX-*1-2,*SC=0,DCP1=196,SIG=SCCONC,DCP2=197&amp;&amp;204,TEI=2;<br/>&gt; RXMOI:MO=RXOTRX-*1-0*,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&amp;&amp;186,TEI=0;<br/>&gt; RXMOI:MO=RXOTRX-*1-5*,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&amp;&amp;231,TEI=5;<br/>&gt; RXMOI:MO=RXOTRX-*1-1,*SC=0,DCP1=187,SIG=SCCONC,DCP2=188&amp;&amp;195,TEI=1;<br/>&gt; RXMOI:MO=RXOTRX-*1-4,*SC=0,DCP1=214,SIG=SCCONC,DCP2=215&amp;&amp;222,TEI=4;<br/>&gt; RXMOI:MO=RXOTRX-*460-9*,SC=0,DCP1=259,SIG=SCCONC,DCP2=260&amp;&amp;267,TEI=9;<br/>&gt; RXMOI:MO=RXOTRX-*460-4*,SC=0,DCP1=214,SIG=SCCONC,DCP2=215&amp;&amp;222,TEI=4;<br/>&gt; RXMOI:MO=RXOTRX-*460-8*,SC=0,DCP1=250,SIG=SCCONC,DCP2=251&amp;&amp;258,TEI=8;<br/>&gt; RXMOI:MO=RXOTRX-*460-5*,SC=0,DCP1=223,SIG=SCCONC,DCP2=224&amp;&amp;231,TEI=5;<br/>&gt; RXMOI:MO=RXOTRX-*460-1*,SC=0,DCP1=187,SIG=SCCONC,DCP2=188&amp;&amp;195,TEI=1;<br/>&gt; RXMOI:MO=RXOTRX-*460-0*,SC=0,DCP1=178,SIG=SCCONC,DCP2=179&amp;&amp;186,TEI=0;<br/>&gt;<br/>&gt; This file is from a testing environment. But in production environment<br/>&gt; this file can be more than 500 lines. So my goal is to sort the file based<br/>&gt; on the bold numbers and create a new file.<br/>&gt; This is required for data validation. If the file is not in sorted order<br/>&gt; then it will be very difficult to validate the file manually.<br/>&gt;<br/>&gt; For this I have started with the following code<br/>&gt;<br/>&gt; #!/usr/bin/perl<br/>&gt; use strict;<br/>&gt; use warnings;<br/>&gt; my $file_name = &quot;RXMOI_TRX_CMD&quot;;<br/>&gt; open my $RFH, &#39;&lt;&#39;, $file_name;<br/>&gt; my $sequence_no;<br/>&gt; my $lowest_no;<br/>&gt; while (my $line = &lt;$RFH&gt;) {<br/>&gt; chomp($line);<br/>&gt; if ($line =~ m/.*?\-(\d+)\-(\d+).*/) {<br/>&gt; $sequence_no = &quot;$1$2&quot;;<br/>&gt; print &quot;$sequence_no\n&quot;;<br/>&gt; }<br/>&gt; }<br/>&gt;<br/>&gt; I can extract the number into a variable but after that not getting any<br/>&gt; idea how to proceed. Could you please provide some logic so that I can<br/>&gt; proceed further.<br/>&gt;<br/>&gt; Best Regards<br/>&gt; Anirban.<br/>&gt;<br/>&gt;<br/>&gt;<br/><br/><br/>-- <br/>best,<br/>Shaji<br/>----------------------------------------------------------------------------------------------------------------------------------------------<br/>Your talent is God&#39;s gift to you. What you do with it is your gift back to<br/>God.<br/>---------------------------------------------------------------------------------------------------------------------------------------------- http://www.nntp.perl.org/group/perl.beginners/2015/03/msg125239.html Tue, 24 Mar 2015 11:09:50 +0000