[Solved] Database – SQL Table to Perl Script

Introduction Solution 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 to show … Read more

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

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 name … Read more

[Solved] Take second of three numbers from a line in a file [closed]

One thing you could do is extract all numbers, then use the second one: my $astring = “cool more 23423 random words of 1234 random other [wordssssssss] 23”; my @numbers = $astring =~ /[0-9]+/g; print “The second number is $numbers[1]\n”; 1 solved Take second of three numbers from a line in a file [closed]

[Solved] split string into several substring using indexes

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]

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 46aehy … Read more