On Aug 17, David T-G said: >% > 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?
Ther 'perlsub' documentation sets the record straight. Basically, a '&' is only needed... 1. when calling a user-defined function with the same name as a built-in 2. when taking a reference to a function 3. to avoid the function's prototype 4. when used with goto &function to avoid another stack level 5. in conjunction with no argument list, to pass the current @_ >% ($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? Exactly, since the arguments to a function are placed into an ordinary array (with a special name). >% sub parse_it { >% my ($tmpl, $user) = @_; # hash references are scalars >% 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. Very important thing you've noted. Yes, %template is just a COPY of the hash stored in $tmpl. However, if any of the values in %$tmpl are references themselves, changing them in %template would change them in %$tmpl, because a "copy" of a reference is just the reference. my $data = { name => [ "Jeffrey", "Pinyan" ], age => 21, }; my %copy = %$data; ++$copy{age}; # in november $copy{name}[0] = "Jeff"; # please, call me Jeff print "@{ $data->{name} } is $data->{age} years old\n"; # "Jeff Pinyan is 21 years old" print "@{ $copy{name} } is $copy{age} years old\n"; # "Jeff Pinyan is 22 years old" You can see from that example that, since 'age' is not a reference, changing it in %copy doesn't affect it in %$data. However, 'name' points to an array reference, so $data->{name} and $copy{name} are really the same array reference. (Read more about this in perlref and the like.) -- 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. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]