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 =
@|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 "######--> SMART PHONE REPORT <--######",
 Market      ESN/MEID         Mobile        Cell     Sector    Carrier       
Bytes
--------    ----------       --------      ------   --------  ---------     
-------
.


format RAW =
@|||||||| @|||||||||||||| @|||||||||||||| @||||||| @|||||||| @|||||||||| 
@|||||||||||||
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 =
@|||||||| @|||||||||||||| @|||||||||||||| @||||||| @|||||||| @|||||||||| @|||||||||||||
$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) = @{$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) = @{$marketInfo{$k}}{qw/start end/};
     return $k if $start <= $val and $val <= $end;
   }

   return "";
}

open(RAW, ">test.rpt");
while (<>) {
   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 = "";
   }

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) = @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-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to