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 .

-- 
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