[Solved] Database – SQL Table to Perl Script

Introduction [ad_1] Solution [ad_2] If you add use strict and use warnings you’ll probably get some feedback about needing to declare @tran in the code below: while(my @row = $tran->fetchrow_hash) { my $tran = join ‘,’, @row; $trans{$tran[2]}{$tran[3]} += $tran[4]; } $tran is 657520,02-07-1999,016901581432,Debit,16000 when you try and use it as an array. Use Data::Dumper … Read more

[Solved] Perl on Modules-Inheritance,Polymorphism [closed]

[ad_1] Ok. The object constructor syntax you are using is a bit akward, I’d prefer my $obj = Stats->new(13,4,56,43,33); In Perl, new is not an ordinary keyword, but a simple sub, and should be used as such. The Foo->sub(@args) syntax is exactly equivalent to Foo::sub(‘Foo’, @args), and thus takes care of passing the correct class … Read more

[Solved] split string into several substring using indexes

[ad_1] You can use substr() as an lvalue and start replacing the string from right side of it, my $string = ‘GATGCAGTTAGGCGTAGCAGAGTGAGACGACGACGATATTAGGACCCGGTAAGGCACAATATAGC’; my %coord_colors = ( 10 => “red”, 48 => “orange”, 60 => “purple”, ); substr($string,$_,0) = $coord_colors{$_} for sort { $b <=> $a } keys %coord_colors; print $string; output GATGCAGTTAredGGCGTAGCAGAGTGAGACGACGACGATATTAGGACCCGorangeGTAAGGCACAATpurpleATAGC using regex, $string … Read more

[Solved] Sort words and then the sentence including digits and characters in Shell scripting or perl scripting [closed]

[ad_1] The algorithm to sort this problem is simple, just like you said in your question description, sort characters in each word first, then sort these sorted-word again. Like this: $ echo heya64 this is21 a good89 day91 | perl -anE ‘say(join ” “, sort(map { join “”, sort split // } @F))’ 12is 19ady … Read more