On Fri, 16 Nov 2001, Tomasi, Chuck wrote:
> Good point. I should be a little more imaginative. Sometimes making up
> meaningful variable and function names is the hardest part of writing code.
It is indeed!
> Another thing I found about the references, the order of the parameters
> matter. If I pass the array ref first and the hash ref second, the
> foreach(@$aref) loop walks right over the hash ref and I get information at
> the end of @leftovers "main::hash".
I'm not surprised...look, the first line in your subroutine is:
my ($href, $aref) = @_;
Ok, so if you pass the array reference first, it will go into the
variable named $href. Just like, if you did this in C:
int ref(void *href, void *aref);
ref( &hash_struct, &array_struct );
ref( &array_struct, &hash_struct );
...you would expect to get different results from the two calls,
right?
Dave
>
> --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);
> > > > > }
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]