I bottom posted. Any help is greatly appreciated.

Chris 

-----Original Message-----
From: Chris Stinemetz [mailto:cstinem...@cricketcommunications.com] 
Sent: Tuesday, February 01, 2011 8:03 AM
To: Shlomi Fish; beginners@perl.org
Subject: RE: sorting report

Shlomi,

See far bottom for my updated code. 


Chris Stinemetz 

-----Original Message-----
From: Shlomi Fish [mailto:shlo...@iglu.org.il] 
Sent: Tuesday, February 01, 2011 4:18 AM
To: beginners@perl.org
Cc: Chris Stinemetz
Subject: Re: sorting report

Hi Chris,

a few comments on your code:

On Tuesday 01 Feb 2011 06:43:43 Chris Stinemetz wrote:
> I would like to sort my final report in the following order:
> 
> $data[31],$data[32],$data[38]
> 
> How would I add this into my following program to get the report sorted
> this way?
> 
> Thanks in advance.
> 
> Chris
> 
> #!/usr/bin/perl
> 
> use warnings;
> #use strict;

Why is "use strict;" commented out? It should be active.

> use FileHandle;

Why are you using the FileHandle module? It is deprecated.

> use IO::Handle;
> 

Yes, IO::Handle is better.

> RAW->format_lines_per_page(10000000000);

This number will overflow the integer word on perls with 32-bit integers.

> 
> 
> format RAW_TOP =
> @|||||||||||||||||||||||||||||||||||||||
> "######--> Smart Phone report. <--######",
> Market      ESN/MIN          Mobile         Cell    Sector    Carrier    
> Bytes
> ==========================================================================
> ============== .
> 

Don't use perlform:

http://perl-begin.org/tutorials/bad-elements/#perlform

> 
> format RAW =
> @<<<<<<<< @|||||||||||||| @|||||||||||||| @|||||||| @|||||||| @|||||||
> @>>>>>>>> $mkt,$mtype,$smartPhone,$cell,$sector,$carrier,$rlptxat
> .
> 
> # SmartPhone type Hash based on ESN or MEID HEX number
> my %smartPhone = (
>    "CURVE850a" => { start => "a000001ca64E38",
>                    end   => "a00000255c29c0", },
>    "KYOM6000" => { start => "a0000012b71b00",
>                    end   => "a0000012fef1a0", },
>    "CURVE850" => { start => "ffffffff001388",
>                    end   => "ffffffff001770", },
> #   "Huawei"   => { start => "a00000130fa7d0",
> #                   end   => "ffffffff001770", },
> );
> 
> #### Market assignment Hash based on cell number
> my %marketInfo = (
>     MCI => { start => 1,
>              end   => 299, },
>     STL => { start => 300,
>              end   => 599, },
>     ICT => { start => 800,
>              end   => 850, },
> );
> 
> sub getSmartPhone
> {
> 
>    my $val = shift;
>    foreach my $k (keys %smartPhone)
>    {
>       my ($start, $end) = @{$smartPhone{$k}}{qw/start end/};
>       return $k if $start ge $val and $val le $end;
>    }
> 
>    return "";
> }

This algorithm will work fine if %smartPhone is small, but is not very 
efficient. You may wish to look at making an array (or a binary search tree) 
of start/end pairs and doing a binary search if it gets very large.

> 
> 
> sub getMarket
> {
> 
>    my $val = shift;
>    foreach my $k (keys %marketInfo)
>    {
>      my ($start, $end) = @{$marketInfo{$k}}{qw/start end/};
>      return $k if $start <= $val and $val <= $end;
>    }
> 
>    return "";
> }



> 
> open(RAW, ">test.rpt");

Use three-args-open and lexical filehandles.

> while (<>) {

You should iterate using an explicit variable:

while (my $line = <>)

Regards,

        Shlomi Fish

>    chomp;
>    if (/;/) {
>       @data = split /;/;
>    if ($data[31] =~ m/^-?\d+$/) {  #### regular expression for real
> numerical value $mkt = getMarket($data[31]);
>    }
>    else
>    {
>       $mkt = "";
>    }
> 
>    if ( length($data[5]) > 12) {
>       $smartPhone = getSmartPhone(substr($data[5],2,14));
>    }
>    else
>    {
>       $smartPhone = "";
>    }
> 
> 
>      ($mtype,$cell,$sector,$carrier,$rlptxat) =
> ($data[5],$data[31],$data[32],$data[38],$data[44]); #     print "$mkt\t 
> $mtype\t $smartPhone\t  $cell\t  $sector\t  $rlptxat\n"; write(RAW);
>    }
> }
> select(RAW);
> close(RAW);

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Stop Using MSIE - http://www.shlomifish.org/no-ie/

Chuck Norris can make the statement "This statement is false" a true one.

Please reply to list if it's a mailing list post - http://shlom.in/reply .






I loaded Perl6::Form from CPAN, but I am still having issues creating report. 
Any help is greatly appreciated.

Thank you,

#!/usr/bin/perl

use warnings;
use strict;
use IO::Handle;
use Perl6::Form;


# SmartPhone type Hash based on ESN or MEID HEX number
my %smartPhone = (
   "CURVE850a" => { start => "a000001ca64E38",
                   end   => "a00000255c29c0", },
   "KYOM6000" => { start => "a0000012b71b00",
                   end   => "a0000012fef1a0", },
   "CURVE850" => { start => "ffffffff001388",
                   end   => "ffffffff001770", }, 
#   "Huawei"   => { start => "a00000130fa7d0",
#                   end   => "ffffffff001770", },
);

#### Market assignment Hash based on cell number
my %marketInfo = (
    MCI => { start => 1,
             end   => 299, },
    STL => { start => 300,
             end   => 599, },
    ICT => { start => 800,
             end   => 850, },
);

sub getSmartPhone
{

   my $val = shift;
   foreach my $k (keys %smartPhone)
   {
      my ($start, $end) = @{$smartPhone{$k}}{qw/start end/};
      return $k if $start ge $val and $val le $end;
   }

   return "";
}


sub getMarket
{

   my $val = shift;
   foreach my $k (keys %marketInfo)
   {
     my ($start, $end) = @{$marketInfo{$k}}{qw/start end/};
     return $k if $start <= $val and $val <= $end;   
   }

   return "";
}

open(RAW, ">test.rpt");
while (<DATA>) { 
   chomp;
   if (/;/) {
      my @data = split /;/;
   if ($data[31] =~ m/^-?\d+$/) {  #### regular expression for real numerical 
value
      my $mkt = getMarket($data[31]);
   } 
   else
   {
      my $mkt = "";
   }

   if ( length($data[5]) > 12) {
      my $smartPhone = getSmartPhone(substr($data[5],2,14));
   }
   else
   {
      my $smartPhone = "";
   }


     my ($mtype,$cell,$sector,$carrier,$rlptxat) = 
($data[5],$data[31],$data[32],$data[38],$data[44]); 
#     print "$mkt\t  $mtype\t $smartPhone\t  $cell\t  $sector\t  $rlptxat\n";

 ($mkt,$mtype,$smartPhone,$cell,$sector,$carrier,$rlptxat) = 
getMarket($data[31], $data[5], $data[31], $data[32], $data[38], $data[44]);

print form,
' 
===================================================================================
 ',
'| Market |      Meid ESN      |   Mobile   | Cell  | Sector | Carrier |    
Bytes    |',
'|-----------------------------------------------------------------------------------|',
'| {[[[}  | {||||||||||||||||} | {||||||||} | {|||} | {||||} | {|||||} | 
{|||||||||} |',
   $mkt,    $mtype,              $smartPhone, $cell,  $sector, $carrier, 
$rlptxat,
;
write(RAW);
  }
}

select(RAW);
close(RAW);


_DATA_
PACE | EVDOPCMD | 33.0 | 101218 | 07 | 
8;1023240136;1218;0;1;00a000001a2bcdc7;0310003147702376;ac016d4a;;;5.6.128.8;0;;;;;43234169;43234349;;;10000;1;1;;0;;19;5.6.128.22;172.30.151.5;304;3;304;3;;;;;15;175;15;175;15;175;1;1798;1251;0;0;2;19;20;;;;;1;1;1;0;128;5.6.128.8;;;;;;;301;5.6.128.8;;;8;304;3;;;;1;43244037;;;1;18;43234169;0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;43234416;0;0;304;3;21;19;175;15;405;1;1;1;1;0;125;1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|
8;1023240137;1218;0;1;00a000001db74ace;;ac0174ca;43243423;1678442111;5.6.128.8;1;0;;43242544;43244207;43243423;43243647;;;1000;1;1;;0;;19;5.6.128.26;;372;2;372;2;;43243012;0;43243562;15;175;15;175;15;175;1;;;;;5;48;19;20;49;50;;0;1;2;0;68;5.6.128.8;;;;;;;301;5.6.128.8;;;8;372;2;;;;1;43244207;;;1;18;43243423;0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;43242544;0;0;372;2;21;19;175;15;177;3;1;0;0;0;68;1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|43243753;0;0;372;2;21;19;175;15;177;3;1;1;1;0;71;1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|
8;1023240138;1218;0;1;00a000002017ccdb;0310003147833882;aca344d7;;;5.6.128.13;0;;;;;43234160;43234358;;;10000;1;1;;0;;19;5.6.128.31;172.30.151.5;320;2;320;2;;;;;15;75;15;75;15;75;1;2162;1317;0;0;2;19;20;;;;;1;1;1;0;104;5.6.128.13;;;;;;;306;5.6.128.13;;;8;320;2;;;;1;43244164;;;1;18;43234160;0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;43234404;0;0;320;2;21;19;75;15;279;6;1;1;1;0;64;1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|
8;1023240139;1218;0;1;00a1000009237b21;0310003147774000;aca3141e;;;5.6.128.13;0;;;;;43235644;43235820;;;9000;1;1;;0;;19;5.6.128.19;172.30.151.5;502;1;502;1;;;;;15;175;15;175;15;175;1;48;79;0;0;2;19;20;;;;;1;1;1;0;124;5.6.128.13;;;;;;;306;5.6.128.13;;;8;502;1;;;;1;43244194;;;1;18;43235644;0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;43235887;0;0;502;1;21;19;175;15;27;1;1;1;1;0;127;1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|
8;1023240140;1218;0;1;00a100000fb342be;0310003147858660;ac21c6e9;;;5.6.128.9;0;;;;;43235440;43235634;;;9000;1;1;;0;;19;5.6.128.31;172.30.151.5;383;2;383;2;;;;;15;175;15;175;15;175;1;0;112;0;0;2;19;20;;;;;1;1;1;0;104;5.6.128.9;;;;;;;302;5.6.128.9;;;8;383;2;;;;1;43244036;;;1;18;43235440;0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;43235681;0;0;383;2;21;19;175;15;333;3;1;1;1;0;64;1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to