
sorting report
--_000_D225040F2D0F75448937B83D9527991A01232AF57Bdenex1crick et_
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
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 thi=
s way?
Thanks in advance.
Chris
#!/usr/bin/perl
use warnings;
#use strict;
use FileHandle;
use IO::Handle;
RAW->format_lines_per_page(10000000000);
format RAW_TOP =3D
[at] |||||||||||||||||||||||||||||||||||||||
"######--> Smart Phone report. <--######",
Market ESN/MIN Mobile Cell Sector Carrier B=
ytes
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
..
format RAW =3D
[at] <<<<<<<< [at] |||||||||||||| [at] |||||||||||||| [at] |||||||| [at] |||||||| [at] ||||||| [at] >>>=
>>>>>
$mkt,$mtype,$smartPhone,$cell,$sector,$carrier,$rlptxat
..
# SmartPhone type Hash based on ESN or MEID HEX number
my %smartPhone =3D (
"CURVE850a" =3D> { start =3D> "a000001ca64E38",
end =3D> "a00000255c29c0", },
"KYOM6000" =3D> { start =3D> "a0000012b71b00",
end =3D> "a0000012fef1a0", },
"CURVE850" =3D> { start =3D> "ffffffff001388",
end =3D> "ffffffff001770", },
# "Huawei" =3D> { start =3D> "a00000130fa7d0",
# end =3D> "ffffffff001770", },
);
#### Market assignment Hash based on cell number
my %marketInfo =3D (
MCI =3D> { start =3D> 1,
end =3D> 299, },
STL =3D> { start =3D> 300,
end =3D> 599, },
ICT =3D> { start =3D> 800,
end =3D> 850, },
);
sub getSmartPhone
{
my $val =3D shift;
foreach my $k (keys %smartPhone)
{
my ($start, $end) =3D [at] {$smartPhone{$k}}{qw/start end/};
return $k if $start ge $val and $val le $end;
}
return "";
}
sub getMarket
{
my $val =3D shift;
foreach my $k (keys %marketInfo)
{
my ($start, $end) =3D [at] {$marketInfo{$k}}{qw/start end/};
return $k if $start <=3D $val and $val <=3D $end;
}
return "";
}
open(RAW, ">test.rpt");
while (<>) {
chomp;
if (/;/) {
[at] data =3D split /;/;
if ($data[31] =3D~ m/^-?\d+$/) { #### regular expression for real numer=
ical value
$mkt =3D getMarket($data[31]);
}
else
{
$mkt =3D "";
}
if ( length($data[5]) > 12) {
$smartPhone =3D getSmartPhone(substr($data[5],2,14));
}
else
{
$smartPhone =3D "";
}
($mtype,$cell,$sector,$carrier,$rlptxat) =3D ($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);
--_000_D225040F2D0F75448937B83D9527991A01232AF57Bdenex1crick et_--
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 =
> [at] |||||||||||||||||||||||||||||||||||||||
> "######--> 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 =
> [at] <<<<<<<< [at] |||||||||||||| [at] |||||||||||||| [at] |||||||| [at] |||||||| [at] |||||||
> [at] >>>>>>>> $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) = [at] {$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) = [at] {$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 (/;/) {
> [at] 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-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
RE: sorting report
Shlomi,
See far bottom for my updated code.
Chris Stinemetz
-----Original Message-----
From: Shlomi Fish [mailto:shlomif [at] iglu.org.il]
Sent: Tuesday, February 01, 2011 4:18 AM
To: beginners [at] 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 =3D
> [at] |||||||||||||||||||||||||||||||||||||||
> "######--> Smart Phone report. <--######",
> Market ESN/MIN Mobile Cell Sector Carrier =
> Bytes
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D .
>
Don't use perlform:
http://perl-begin.org/tutorials/bad-elements/#perlform
>
> format RAW =3D
> [at] <<<<<<<< [at] |||||||||||||| [at] |||||||||||||| [at] |||||||| [at] |||||||| [at] |||||||
> [at] >>>>>>>> $mkt,$mtype,$smartPhone,$cell,$sector,$carrier,$rlptxat
> .
>
> # SmartPhone type Hash based on ESN or MEID HEX number
> my %smartPhone =3D (
> "CURVE850a" =3D> { start =3D> "a000001ca64E38",
> end =3D> "a00000255c29c0", },
> "KYOM6000" =3D> { start =3D> "a0000012b71b00",
> end =3D> "a0000012fef1a0", },
> "CURVE850" =3D> { start =3D> "ffffffff001388",
> end =3D> "ffffffff001770", },
> # "Huawei" =3D> { start =3D> "a00000130fa7d0",
> # end =3D> "ffffffff001770", },
> );
>
> #### Market assignment Hash based on cell number
> my %marketInfo =3D (
> MCI =3D> { start =3D> 1,
> end =3D> 299, },
> STL =3D> { start =3D> 300,
> end =3D> 599, },
> ICT =3D> { start =3D> 800,
> end =3D> 850, },
> );
>
> sub getSmartPhone
> {
>
> my $val =3D shift;
> foreach my $k (keys %smartPhone)
> {
> my ($start, $end) =3D [at] {$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 =3D shift;
> foreach my $k (keys %marketInfo)
> {
> my ($start, $end) =3D [at] {$marketInfo{$k}}{qw/start end/};
> return $k if $start <=3D $val and $val <=3D $end;
> }
>
> return "";
> }
>
> open(RAW, ">test.rpt");
Use three-args-open and lexical filehandles.
> while (<>) {
You should iterate using an explicit variable:
while (my $line =3D <>)
Regards,
Shlomi Fish
> chomp;
> if (/;/) {
> [at] data =3D split /;/;
> if ($data[31] =3D~ m/^-?\d+$/) { #### regular expression for real
> numerical value $mkt =3D getMarket($data[31]);
> }
> else
> {
> $mkt =3D "";
> }
>
> if ( length($data[5]) > 12) {
> $smartPhone =3D getSmartPhone(substr($data[5],2,14));
> }
> else
> {
> $smartPhone =3D "";
> }
>
>
> ($mtype,$cell,$sector,$carrier,$rlptxat) =3D
> ($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 .
#!/usr/bin/perl
use warnings;
use strict;
use IO::Handle;
RAW->format_lines_per_page(10000000000); # I will change this once I get st=
rict pragma to work.
format RAW_TOP =3D
[at] ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||=
|||||||||
"######--> SMART PHONE REPORT <--######",
Market ESN/MEID Mobile Cell Sector Carrier =
Bytes
-------- ---------- -------- ------ -------- --------- =
-------
..
format RAW =3D
[at] |||||||| [at] |||||||||||||| [at] |||||||||||||| [at] ||||||| [at] |||||||| [at] |||||||||| [at] |=
||||||||||||
my ($mtype,$smartPhone,$cell,$sector,$carrier,$rlptxat)
..
# SmartPhone type Hash based on ESN or MEID HEX number # I will change this=
once I get strict pragma to work.
my %smartPhone =3D (
"CURVE850a" =3D> { start =3D> "a000001ca64E38",
end =3D> "a00000255c29c0", },
"KYOM6000" =3D> { start =3D> "a0000012b71b00",
end =3D> "a0000012fef1a0", },
"CURVE850" =3D> { start =3D> "ffffffff001388",
end =3D> "ffffffff001770", },
# "Huawei" =3D> { start =3D> "a00000130fa7d0",
# end =3D> "ffffffff001770", },
);
#### Market assignment Hash based on cell number
my %marketInfo =3D (
MCI =3D> { start =3D> 1,
end =3D> 299, },
STL =3D> { start =3D> 300,
end =3D> 599, },
ICT =3D> { start =3D> 800,
end =3D> 850, },
);
sub getSmartPhone
{
my $val =3D shift;
foreach my $k (keys %smartPhone)
{
my ($start, $end) =3D [at] {$smartPhone{$k}}{qw/start end/};
return $k if $start ge $val and $val le $end;
}
return "";
}
sub getMarket
{
my $val =3D shift;
foreach my $k (keys %marketInfo)
{
my ($start, $end) =3D [at] {$marketInfo{$k}}{qw/start end/};
return $k if $start <=3D $val and $val <=3D $end;
}
return "";
}
open(RAW, ">test.rpt");
while (<>) {
chomp;
if (/;/) {
my [at] data =3D split /;/;
if ($data[31] =3D~ m/^-?\d+$/) { #### regular expression for real numer=
ical value
my $mkt =3D getMarket($data[31]);
}
else
{
my $mkt =3D "";
}
if ( length($data[5]) > 12) {
my $smartPhone =3D getSmartPhone(substr($data[5],2,14));
}
else
{
my $smartPhone =3D "";
}
my ($mtype,$cell,$sector,$carrier,$rlptxat) =3D ($data[5],$data[31],$d=
ata[32],$data[38],$data[44]);
# print "$mkt\t $mtype\t $smartPhone\t $cell\t $sector\t $rlptxat\n=
";
write(RAW);
}
}
select(RAW);
close(RAW);
When I use the strict pragma I have the following warning and nothing is ou=
tputted to the report 'test.rpt'.
Once I get this resolved I will take your recommendations from original ema=
il and apply them to my program.
I hope you can help I know the importance of using strict pragma and would =
be very happy to get it to work.
I have declared all my variables after enabling strict pragma.
Warnings I get:
Not enough format arguments at ./io.pl line 24, <> line 481.
Use of uninitialized value $mtype in formline at ./io.pl line 24, <> line 4=
82.
Use of uninitialized value $smartPhone in formline at ./io.pl line 24, <> l=
ine 482.
Use of uninitialized value $cell in formline at ./io.pl line 24, <> line 48=
2.
Use of uninitialized value $sector in formline at ./io.pl line 24, <> line =
482.
Use of uninitialized value $carrier in formline at ./io.pl line 24, <> line=
482.
Use of uninitialized value $rlptxat in formline at ./io.pl line 24, <> line=
482.
Not enough format arguments at ./io.pl line 24, <> line 482.
Use of uninitialized value $mtype in formline at ./io.pl line 24, <> line 4=
83.
Use of uninitialized value $smartPhone in formline at ./io.pl line 24, <> l=
ine 483.
Use of uninitialized value $cell in formline at ./io.pl line 24, <> line 48=
3.
Use of uninitialized value $sector in formline at ./io.pl line 24, <> line =
483.
Use of uninitialized value $carrier in formline at ./io.pl line 24, <> line=
483.
Use of uninitialized value $rlptxat in formline at ./io.pl line 24, <> line=
483.
Not enough format arguments at ./io.pl line 24, <> line 483.
Use of uninitialized value $mtype in formline at ./io.pl line 24, <> line 4=
84.
Use of uninitialized value $smartPhone in formline at ./io.pl line 24, <> l=
ine 484.
Use of uninitialized value $cell in formline at ./io.pl line 24, <> line 48=
4.
Use of uninitialized value $sector in formline at ./io.pl line 24, <> line =
484.
Use of uninitialized value $carrier in formline at ./io.pl line 24, <> line=
484.
Use of uninitialized value $rlptxat in formline at ./io.pl line 24, <> line=
484.
Not enough format arguments at ./io.pl line 24, <> line 484.
Use of uninitialized value $mtype in formline at ./io.pl line 24, <> line 4=
85.
Use of uninitialized value $smartPhone in formline at ./io.pl line 24, <> l=
ine 485.
Use of uninitialized value $cell in formline at ./io.pl line 24, <> line 48=
5.
Use of uninitialized value $sector in formline at ./io.pl line 24, <> line =
485.
Use of uninitialized value $carrier in formline at ./io.pl line 24, <> line=
485.
Use of uninitialized value $rlptxat in formline at ./io.pl line 24, <> line=
485.
Not enough format arguments at ./io.pl line 24, <> line 485.
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
RE: sorting report
I bottom posted. Any help is greatly appreciated.
Chris
-----Original Message-----
From: Chris Stinemetz [mailto:cstinemetz [at] cricketcommunications.com]
Sent: Tuesday, February 01, 2011 8:03 AM
To: Shlomi Fish; beginners [at] perl.org
Subject: RE: sorting report
Shlomi,
See far bottom for my updated code.
Chris Stinemetz
-----Original Message-----
From: Shlomi Fish [mailto:shlomif [at] iglu.org.il]
Sent: Tuesday, February 01, 2011 4:18 AM
To: beginners [at] 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 =3D
> [at] |||||||||||||||||||||||||||||||||||||||
> "######--> Smart Phone report. <--######",
> Market ESN/MIN Mobile Cell Sector Carrier =
> Bytes
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D .
>
Don't use perlform:
http://perl-begin.org/tutorials/bad-elements/#perlform
>
> format RAW =3D
> [at] <<<<<<<< [at] |||||||||||||| [at] |||||||||||||| [at] |||||||| [at] |||||||| [at] |||||||
> [at] >>>>>>>> $mkt,$mtype,$smartPhone,$cell,$sector,$carrier,$rlptxat
> .
>
> # SmartPhone type Hash based on ESN or MEID HEX number
> my %smartPhone =3D (
> "CURVE850a" =3D> { start =3D> "a000001ca64E38",
> end =3D> "a00000255c29c0", },
> "KYOM6000" =3D> { start =3D> "a0000012b71b00",
> end =3D> "a0000012fef1a0", },
> "CURVE850" =3D> { start =3D> "ffffffff001388",
> end =3D> "ffffffff001770", },
> # "Huawei" =3D> { start =3D> "a00000130fa7d0",
> # end =3D> "ffffffff001770", },
> );
>
> #### Market assignment Hash based on cell number
> my %marketInfo =3D (
> MCI =3D> { start =3D> 1,
> end =3D> 299, },
> STL =3D> { start =3D> 300,
> end =3D> 599, },
> ICT =3D> { start =3D> 800,
> end =3D> 850, },
> );
>
> sub getSmartPhone
> {
>
> my $val =3D shift;
> foreach my $k (keys %smartPhone)
> {
> my ($start, $end) =3D [at] {$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 =3D shift;
> foreach my $k (keys %marketInfo)
> {
> my ($start, $end) =3D [at] {$marketInfo{$k}}{qw/start end/};
> return $k if $start <=3D $val and $val <=3D $end;
> }
>
> return "";
> }
>
> open(RAW, ">test.rpt");
Use three-args-open and lexical filehandles.
> while (<>) {
You should iterate using an explicit variable:
while (my $line =3D <>)
Regards,
Shlomi Fish
> chomp;
> if (/;/) {
> [at] data =3D split /;/;
> if ($data[31] =3D~ m/^-?\d+$/) { #### regular expression for real
> numerical value $mkt =3D getMarket($data[31]);
> }
> else
> {
> $mkt =3D "";
> }
>
> if ( length($data[5]) > 12) {
> $smartPhone =3D getSmartPhone(substr($data[5],2,14));
> }
> else
> {
> $smartPhone =3D "";
> }
>
>
> ($mtype,$cell,$sector,$carrier,$rlptxat) =3D
> ($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 repor=
t. 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 =3D (
"CURVE850a" =3D> { start =3D> "a000001ca64E38",
end =3D> "a00000255c29c0", },
"KYOM6000" =3D> { start =3D> "a0000012b71b00",
end =3D> "a0000012fef1a0", },
"CURVE850" =3D> { start =3D> "ffffffff001388",
end =3D> "ffffffff001770", },
# "Huawei" =3D> { start =3D> "a00000130fa7d0",
# end =3D> "ffffffff001770", },
);
#### Market assignment Hash based on cell number
my %marketInfo =3D (
MCI =3D> { start =3D> 1,
end =3D> 299, },
STL =3D> { start =3D> 300,
end =3D> 599, },
ICT =3D> { start =3D> 800,
end =3D> 850, },
);
sub getSmartPhone
{
my $val =3D shift;
foreach my $k (keys %smartPhone)
{
my ($start, $end) =3D [at] {$smartPhone{$k}}{qw/start end/};
return $k if $start ge $val and $val le $end;
}
return "";
}
sub getMarket
{
my $val =3D shift;
foreach my $k (keys %marketInfo)
{
my ($start, $end) =3D [at] {$marketInfo{$k}}{qw/start end/};
return $k if $start <=3D $val and $val <=3D $end;
}
return "";
}
open(RAW, ">test.rpt");
while (<DATA>) {
chomp;
if (/;/) {
my [at] data =3D split /;/;
if ($data[31] =3D~ m/^-?\d+$/) { #### regular expression for real numer=
ical value
my $mkt =3D getMarket($data[31]);
}
else
{
my $mkt =3D "";
}
if ( length($data[5]) > 12) {
my $smartPhone =3D getSmartPhone(substr($data[5],2,14));
}
else
{
my $smartPhone =3D "";
}
my ($mtype,$cell,$sector,$carrier,$rlptxat) =3D ($data[5],$data[31],$d=
ata[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) =3D
getMarket($data[31], $data[5], $data[31], $data[32], $data[38], $data[44]);
print form,
' =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D ',
'| Market | Meid ESN | Mobile | Cell | Sector | Carrier | =
Bytes |',
'|---------------------------------------------------------- ---------------=
----------|',
'| {[[[} | {||||||||||||||||} | {||||||||} | {|||} | {||||} | {|||||} | {|=
||||||||} |',
$mkt, $mtype, $smartPhone, $cell, $sector, $carrier, $r=
lptxat,
;
write(RAW);
}
}
select(RAW);
close(RAW);
_DATA_
PACE | EVDOPCMD | 33.0 | 101218 | 07 |
8;1023240136;1218;0;1;00a000001a2bcdc7;0310003147702376;ac01 6d4a;;;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;432 34169;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;16 78442111;5.6.12=
8.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;5=
0;;0;1;2;0;68;5.6.128.8;;;;;;;301;5.6.128.8;;;8;372;2;;;;1;4 3244207;;;1;18;=
43243423;0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;1;;;;;;432425=
44;0;0;372;2;21;19;175;15;177;3;1;0;0;0;68;1;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|43 243753;0;0;372;=
2;21;19;175;15;177;3;1;1;1;0;71;1;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|
8;1023240138;1218;0;1;00a000002017ccdb;0310003147833882;aca3 44d7;;;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.12=
8.13;;;;;;;306;5.6.128.13;;;8;320;2;;;;1;43244164;;;1;18;432 34160;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;aca3 141e;;;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;43235 644;0;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1;;;;;;43235887;0; 0;502;1;21;19;1=
75;15;27;1;1;1;1;0;127;1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;|
8;1023240140;1218;0;1;00a100000fb342be;0310003147858660;ac21 c6e9;;;5.6.128.=
9;0;;;;;43235440;43235634;;;9000;1;1;;0;;19;5.6.128.31;172.3 0.151.5;383;2;3=
83;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;3 83;2;21;19;175;=
15;333;3;1;1;1;0;64;1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;=
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;|
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Re: sorting report
On 01/02/2011 14:02, Chris Stinemetz wrote:
>
> #!/usr/bin/perl
>
> use warnings;
> use strict;
> use IO::Handle;
>
> RAW->format_lines_per_page(10000000000); # I will change this once I get strict pragma to work.
>
>
> format RAW_TOP =
> [at] ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ||||||||||||||||||||||||
> "######--> SMART PHONE REPORT <--######",
> Market ESN/MEID Mobile Cell Sector Carrier Bytes
> -------- ---------- -------- ------ -------- --------- -------
> .
>
>
> format RAW =
> [at] |||||||| [at] |||||||||||||| [at] |||||||||||||| [at] ||||||| [at] |||||||| [at] |||||||||| [at] |||||||||||||
> my ($mtype,$smartPhone,$cell,$sector,$carrier,$rlptxat)
> .
You cannot declare variables within a format declaration. The values to
be output must be in scope and therefore declared mefore the format.
my ($mtype,$smartPhone,$cell,$sector,$carrier,$rlptxat)
format RAW =
[at] |||||||| [at] |||||||||||||| [at] |||||||||||||| [at] ||||||| [at] |||||||| [at] ||||||||||
[at] |||||||||||||
$mtype, $smartPhone, $cell, $sector, $carrier, $rlptxat
..
Also, these variables may not be declared again later, otherwise this
first set of values will remained unchanged and undefined. See below.
> # SmartPhone type Hash based on ESN or MEID HEX number # I will change this once I get strict pragma to work.
> 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) = [at] {$smartPhone{$k}}{qw/start end/};
> return $k if $start ge $val and $val le $end;
This is incorrect. The last line should read
return $k if $start le $val and $val le $end;
> }
>
> return "";
> }
>
>
> sub getMarket
> {
>
> my $val = shift;
> foreach my $k (keys %marketInfo)
> {
> my ($start, $end) = [at] {$marketInfo{$k}}{qw/start end/};
> return $k if $start <= $val and $val <= $end;
> }
>
> return "";
> }
>
> open(RAW, ">test.rpt");
> while (<>) {
> chomp;
> if (/;/) {
> my [at] 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 = "";
> }
A $smartPhone has already been declared. Declaring a new one and
setting its value is pointless. In any case, a block like
{
my $smartPhone = "";
}
will do nothing useful whatsoever. The variable is declared and
initialised, and then thrown away at the closing brace. There should be
no declarations here, and the code should be something like:
$smartPhone = '';
if (length $data[5] > 12) {
$smartPhone = getSmartPhone(substr($data[5],2,14));
}
> my ($mtype,$cell,$sector,$carrier,$rlptxat) = ($data[5],$data[31],$data[32],$data[38],$data[44]);
The same applies here. These values have already been declared, and
setting up an independent set of variables isn't a useful thing to do.
This should be:
($mtype,$cell,$sector,$carrier,$rlptxat) = [at] data[5,31,32,38,44];
> # print "$mkt\t $mtype\t $smartPhone\t $cell\t $sector\t $rlptxat\n";
> write(RAW);
> }
> }
>
>
> select(RAW);
> close(RAW);
>
> When I use the strict pragma I have the following warning and nothing is outputted to the report 'test.rpt'.
>
> Once I get this resolved I will take your recommendations from original email and apply them to my program.
>
> I hope you can help I know the importance of using strict pragma and would be very happy to get it to work.
>
> I have declared all my variables after enabling strict pragma.
>
> Warnings I get:
> Not enough format arguments at ./io.pl line 24, <> line 481.
> Use of uninitialized value $mtype in formline at ./io.pl line 24, <> line 482.
> Use of uninitialized value $smartPhone in formline at ./io.pl line 24, <> line 482.
> Use of uninitialized value $cell in formline at ./io.pl line 24, <> line 482.
> Use of uninitialized value $sector in formline at ./io.pl line 24, <> line 482.
> Use of uninitialized value $carrier in formline at ./io.pl line 24, <> line 482.
> Use of uninitialized value $rlptxat in formline at ./io.pl line 24, <> line 482.
> Not enough format arguments at ./io.pl line 24, <> line 482.
> Use of uninitialized value $mtype in formline at ./io.pl line 24, <> line 483.
> Use of uninitialized value $smartPhone in formline at ./io.pl line 24, <> line 483.
> Use of uninitialized value $cell in formline at ./io.pl line 24, <> line 483.
> Use of uninitialized value $sector in formline at ./io.pl line 24, <> line 483.
> Use of uninitialized value $carrier in formline at ./io.pl line 24, <> line 483.
> Use of uninitialized value $rlptxat in formline at ./io.pl line 24, <> line 483.
> Not enough format arguments at ./io.pl line 24, <> line 483.
> Use of uninitialized value $mtype in formline at ./io.pl line 24, <> line 484.
> Use of uninitialized value $smartPhone in formline at ./io.pl line 24, <> line 484.
> Use of uninitialized value $cell in formline at ./io.pl line 24, <> line 484.
> Use of uninitialized value $sector in formline at ./io.pl line 24, <> line 484.
> Use of uninitialized value $carrier in formline at ./io.pl line 24, <> line 484.
> Use of uninitialized value $rlptxat in formline at ./io.pl line 24, <> line 484.
> Not enough format arguments at ./io.pl line 24, <> line 484.
> Use of uninitialized value $mtype in formline at ./io.pl line 24, <> line 485.
> Use of uninitialized value $smartPhone in formline at ./io.pl line 24, <> line 485.
> Use of uninitialized value $cell in formline at ./io.pl line 24, <> line 485.
> Use of uninitialized value $sector in formline at ./io.pl line 24, <> line 485.
> Use of uninitialized value $carrier in formline at ./io.pl line 24, <> line 485.
> Use of uninitialized value $rlptxat in formline at ./io.pl line 24, <> line 485.
> Not enough format arguments at ./io.pl line 24, <> line 485.
HTH,
Rob
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/