in reply to how to print out a variable name and its value

Is the 'Passing by Named Parameter' recipe (Recipe 10.7), from the Perl Cookbook of no use ?

e.g.

use data::Dumper; sub some_sub { my $args = { first_name => '', surname => '', @_ }; print Dumper $args; } some_sub qw/Edward Lear/;
will return something along the lines of...
$VAR1 = { first_name => 'Edward', surname => 'Lear', };

It's what I tend to use ...

Update Thanx to massa who pointed out the obvious error in my example code:

some_sub qw/Edward Lear/;
doesn't call the sub with named parameters, had it read:
some_sub first_name => 'Edward', surname => 'Lear';
it would.
Thanx again massa.

HTH ,

At last, a user level that overstates my experience :-))

Replies are listed 'Best First'.
Re^2: how to print out a variable name and its value
by massa (Hermit) on Jul 30, 2008 at 12:07 UTC
    Your example is expecting named parameters, but it's not sending the named parameters:
    use Data::Dumper; sub some_sub { my $args = { first_name => '', surname => '', @_ }; print Dumper $args; } some_sub first_name => 'Edward', surname => 'Lear';
    will work!
    []s, HTH, Massa (κς,πμ,πλ)