Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

very simple problem---very new to Perl

Status
Not open for further replies.

ihopeto

Programmer
Joined
Dec 23, 2006
Messages
3
Location
CA
Ok I have the following code...only part of the total

I am very new to Perl, so this probably very obvious to most of you.

Basically the total code opens a socket and the data comes to here as "$_"....and then is sent to the parser module. And I am trying to break down the hash...

-----------------------------------------
while(<$sock>) {
print $_;
#packets end in \n\r
chop();
chop();

my %aprsPacket;

my($aprsPacket) = parseAPRSPacket($_);

print Dumper($aprsPacket);
print $aprsPacket;
print "\r\n";

while(my ($k, $v) = each %aprsPacket) {
print "key: $k, value: $v\n";
}
}
-------------------------------------------------
My problem is that I dont get any output from the the hash separation in the last while section.

Here is the output

$VAR1 = {
'SYMBOL' => '/-',
'LAT' => '##.714',
'FROM' => '*****',
'COMMENT' => '****** in service. {UIV32N}',
'MESSAGING' => '0',
'LON' => '-###.208333333333',
'PATH' => 'TCPIP*,qAC,T2ONTARIO',
'TO' => 'APU25N',
'AMBIGUITY' => 0
};
HASH(0x8159e74)

---------------------------------------------------------

So as you can see I get Dumper to print the hash for me just fine....and the Hash value is printed....but the last section doesn't work like I expected it to.

while I am here....I want to eventually put all this stuff into a mysql database...maybe yu could point me in the right directon

Thanks to all
and
have a good holiday.

Brian
 
these are two different things:

my %aprsPacket;
my($aprsPacket)

they have no connection to each other at all, at least not by looking at the code you posted. The function:

parseAPRSPacket($_);

is returning a reference to a hash: $aprsPacket.

you can dereference it:

Code:
        while(my ($k, $v) = each %{ $aprsPacket }) {
                print "key: $k, value: $v\n";
        }

your code above becomes:

Code:
while(<$sock>) {
        print  $_;
        #packets end in \n\r
        chop();
        chop();
  
        my($aprsPacket) = parseAPRSPacket($_);

        print Dumper($aprsPacket);
        print $aprsPacket;
        print "\r\n";

        while(my ($k, $v) = each %{ $aprsPacket }) {
                print "key: $k, value: $v\n";
        }
}

- Kevin, perl coder unexceptional!
 
Ok Kevin,

I have it working now....thanks a million.

Now I get the contents of the hash.

Now I want to put that into a mysql table....so now have figure this out.

thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top