Jeff, et al -- ...and then Jeff 'japhy' Pinyan said... % % On Aug 17, David T-G said: % % >I've gotten rusty and so I'm back again as a rank amateur :-) % % That's not very professional of you. ;)
No, it isn't :-) There isn't much call for perl when hanging sheet rock or cleaning basements, though. It's been a tough year, and what coding I *have* done has mostly been php. Glad to have the work, though! % % > 45 my $body = % > 46 &parseit % > 47 ( % > 48 {ASCII=>$ascii,HTML=>$html}, % > 49 {flag=>$flag,EMAIL=>$email,NAME_FIRST=>$fn,NAME_LAST=>$ln} % > 50 ) ; % % First, you can drop the & on the function call. It's not necessary. Interesting. I thought it was a good thing for clarification. Not needed because I'm passing params, maybe? % % But this is where the crux of the issue lies... you aren't passing ANY % hashes to parseit(), you're passing hash *references*. And as such, you % can't expect Perl to magically turn them into hashes for you. Ohhhh... I think I get it. % % > 62 sub parseit % > 63 { % > 64 my (%template,%userdata) = @_ ; % > 65 print "template is .$template.\n"; ### % > 66 } % % You can never extract more than one list (array OR hash) from a list at a % time. Watch: Well, I saw that in "Programming". That's when I got really frustrated :-) % % ($a, $b, @c) = (1, 2, 3, 4, 5); # $a=1, $b=2, @c=(3,4,5) % ($a, @b, $c) = (1, 2, 3, 4, 5); # $a=1, @b=(2,3,4,5) $c=undef % ($a, @b, @c) = (1, 2, 3, 4, 5); # $a=1, @b=(2,3,4,5) @c=() All of that makes sense. I guess it can only follow for passing to a function, eh? % % An array (or a hash) slurps the rest of the elements of the list. % Therefore, even if your code did "work", you'd end up with everything in % the %template hash and nothing in the %userdata hash. As it turns out, % the %template hash is the only one with stuff in it -- one key (a % stringified hash reference) and one value (the user-data hash reference). I follow that. % % Here's how to get them: % % sub parse_it { % my ($tmpl, $user) = @_; # hash references are scalars Ahhhh... % % Then you can access the contents in one of two ways: % % print "user's name is $user->{NAME_FIRST} $user->{NAME_LAST}\n"; Gotcha. % % or % % my %template = %$tmpl; # remember, hashes slurp, so we couldn't % my %userdata = %$user; # have done (%a, %b) = (%$c, %$d) Right; I can see that. So I still get a local %template that I could change as I like without trashing the original. Yay. % print "user's name is @userdata{'NAME_FIRST', 'NAME_LIST'}\n"; Hey, that's slick. % % That @hashname{...} syntax, if you've never seen it, is called a hash % slice. It's accessing multiple keys of the hash at the same time. It sounds familiar. It's been a while :-/ % % To do it with the hash reference, the syntax is % % @$user{'NAME_FIRST', 'NAME_LAST'} % % Also, note that I used SINGLE quotes around the key names, because I'm % already using double quotes around the string. I could have said Yep. % % @userdata{qw( NAME_FIRST NAME_LAST )} % % too. It's up to you. I like qw; it's quite handy sometimes. % % Anyway, there you go. Thanks! % % -- % Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ % RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ % <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course. % [ I'm looking for programming work. If you like my work, let me know. ] I like your work so far. If you get any that is either beneath you or doesn't fit in your schedule, let ME know :-) Thanks again & HAND :-D -- David T-G * There is too much animal courage in (play) [EMAIL PROTECTED] * society and not sufficient moral courage. (work) [EMAIL PROTECTED] -- Mary Baker Eddy, "Science and Health" http://justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg!
pgp00000.pgp
Description: PGP signature