Perl: 5.6.0
OS: Solaris 7
Goal: Scan a text file for key words/values and populate a hash

My parsing works, but the main() never sees the values properly.  If I'm
passing by reference, why isn't the hash I passed getting populated in the
main namespace?

Thanks

--Chuck

----------arg.pl---------------
#/usr/plx/bin/perl -w

use strict;

sub ref
{
        my      ($href, $aref) =@_;
        my      (@leftovers);

        foreach (@$aref) {
                chomp;
                if (/^UserID\s+:\s+(\d+)/) {
                        ${$href}{'UserID'} = $1;
                } elsif (/^SupportGroup\s+:\s+(\d+)/) {
                        ${$href}{'SupportGroup'} = $1;
                } elsif (/^Assigned To\s+:\s+(\d+)/) {
                        ${$href}{'AssignTo'} = $1;
                } elsif (/^DateOpened\s+:\s+(\d+)/) {
                        ${$href}{'DateOpened'} = $1;
                } else {
                        push(@leftovers, "$_\n");
                }
        }
        return(@leftovers);
}

my @array;
my @remains;
my (%hash);

open(F_TMP, "/tmp/tfile") || die("Cannot open text file");
@array = <F_TMP>;
close(F_TMP);

@remains = &ref(\%hash, \@array);
print "User ID = $hash{'$UserID'}\n";
print "Remains = " . @remains . "\n";
-----------output------------
User ID =
Remains = 2

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to