[30967] in Perl-Users-Digest
Perl-Users Digest, Issue: 2212 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 16 14:09:50 2009
Date: Mon, 16 Feb 2009 11:09:14 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 16 Feb 2009 Volume: 11 Number: 2212
Today's topics:
Determine whether STDIN is a pipe? <amphetamachine@gmail.com>
Re: Determine whether STDIN is a pipe? <amphetamachine@gmail.com>
Re: Determine whether STDIN is a pipe? <spamtrap@dot-app.org>
Re: Determine whether STDIN is a pipe? <ben@morrow.me.uk>
Re: FAQ 6.14 How do I process each word on each line? <hjp-usenet2@hjp.at>
Re: FAQ 6.14 How do I process each word on each line? <tadmc@seesig.invalid>
how do I print the name and value of a scalar <cartercc@gmail.com>
Re: how do I print the name and value of a scalar <cwilbur@chromatico.net>
Re: how do I print the name and value of a scalar <cartercc@gmail.com>
Re: how do I print the name and value of a scalar <1usa@llenroc.ude.invalid>
Re: how do I print the name and value of a scalar <tadmc@seesig.invalid>
Re: how do I print the name and value of a scalar <cwilbur@chromatico.net>
Re: how do I print the name and value of a scalar <cartercc@gmail.com>
Re: how do I print the name and value of a scalar <jurgenex@hotmail.com>
Re: how do I print the name and value of a scalar <jurgenex@hotmail.com>
Re: how do I print the name and value of a scalar <noreply@gunnar.cc>
Re: how do I print the name and value of a scalar <tadmc@seesig.invalid>
Re: how do I print the name and value of a scalar <glex_no-spam@qwest-spam-no.invalid>
Re: how do I print the name and value of a scalar <cwilbur@chromatico.net>
Re: how do I print the name and value of a scalar <jurgenex@hotmail.com>
Re: how do I print the name and value of a scalar <ben@morrow.me.uk>
Re: how do I print the name and value of a scalar <syscjm@sumire.gwu.edu>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 16 Feb 2009 10:04:10 -0800 (PST)
From: h3xx <amphetamachine@gmail.com>
Subject: Determine whether STDIN is a pipe?
Message-Id: <93930843-2796-429a-9924-4265eef3c730@r24g2000vbp.googlegroups.com>
I have a program that uses Term::ANSIColor to print colored output,
but would like for it not to output the coloring escape sequences if
the output is being redirected to a program through a pipe.
In essence, it would act like grep's "--color=auto" flag.
Is there any way to test whether STDIN is going into a pipe?
------------------------------
Date: Mon, 16 Feb 2009 10:07:41 -0800 (PST)
From: h3xx <amphetamachine@gmail.com>
Subject: Re: Determine whether STDIN is a pipe?
Message-Id: <f7df9878-de34-4665-b1f5-308f0cd46241@m15g2000vbp.googlegroups.com>
> Is there any way to test whether STDIN is going into a pipe?
Oops. I meant STDOUT.
------------------------------
Date: Mon, 16 Feb 2009 13:27:10 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Determine whether STDIN is a pipe?
Message-Id: <m1prhime4h.fsf@dot-app.org>
h3xx <amphetamachine@gmail.com> writes:
> Is there any way to test whether STDIN is going into a pipe?
if (-t STDIN) {
# It's a tty
} else {
# It's a pipe
}
See: perldoc -f -x
sherm--
--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Mon, 16 Feb 2009 18:30:13 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Determine whether STDIN is a pipe?
Message-Id: <luno66-en3.ln1@osiris.mauzo.dyndns.org>
Quoth h3xx <amphetamachine@gmail.com>:
>
<optional coloured output>
> >
> > Is there any way to test whether STDIN is going into a pipe?
>
> Oops. I meant STDOUT.
You don't actually want to know if it's a pipe, you want to know if it's
a terminal. If it's redirected to a file presumably you still want b/w
output.
In any case: see the -p and -t operators in perlfunc (you have to use
perldoc -f -X
to get the entry).
Ben
------------------------------
Date: Mon, 16 Feb 2009 09:47:58 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 6.14 How do I process each word on each line?
Message-Id: <slrngpia1u.4o3.hjp-usenet2@hrunkner.hjp.at>
On 2009-02-16 05:02, Larry Gates <larry@example.invalid> wrote:
> On Sat, 14 Feb 2009 06:03:01 -0800, PerlFAQ Server wrote:
>> while (<>) {
>> foreach $word (m/(\w+)/g) {
>> # do something with $word here
>> }
>> }
>
> So if your data are
> quick brown %% fixed %noise
> you will do something with $word 4 times?
Yes.
hp
------------------------------
Date: Mon, 16 Feb 2009 07:43:10 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: FAQ 6.14 How do I process each word on each line?
Message-Id: <slrngpirbe.a98.tadmc@tadmc30.sbcglobal.net>
Larry Gates <larry@example.invalid> wrote:
> On Sat, 14 Feb 2009 06:03:01 -0800, PerlFAQ Server wrote:
>
>> To work with only alphanumeric sequences (including underscores), you
>> might consider
>>
>> while (<>) {
>> foreach $word (m/(\w+)/g) {
>> # do something with $word here
>> }
>> }
>
> So if your data are
> quick brown %% fixed %noise
> you will do something with $word 4 times?
What happened when you tried it?
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Mon, 16 Feb 2009 05:51:33 -0800 (PST)
From: cartercc <cartercc@gmail.com>
Subject: how do I print the name and value of a scalar
Message-Id: <cadf8d90-1c32-4420-a8c5-20aec62c41ae@k19g2000yqg.googlegroups.com>
Given a list of scalars, such as:
<code>
my $name;
my $address;
my $city;
my $state;
my $zip;
my @scalar_names = ($name, $address, $city, $state, $zip);
my %var_names_and_values;
</code>
How do I do this:
<pseudocode>
foreach my $element (@scalar_names)
{
$var_names_and_values{?ELEMENT_NAME?} => $element;
}
</pseudocode>
So that I can do this:
<code>
print "Variable names and values\n";
foreach my $key (sort keys %var_names_and_values)
{
print " * $key => $var_names_and_values{$key}\n";
}
</code>
With the objective of producing output like this:
<output>
Variable names and values
* name => John Smith
* address => 1234 Easy Street
* city => Paradise
...
</output>
As always, thanks, CC.
------------------------------
Date: Mon, 16 Feb 2009 09:37:45 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: how do I print the name and value of a scalar
Message-Id: <863aeesb0m.fsf@mithril.chromatico.net>
>>>>> "cc" == cartercc <cartercc@gmail.com> writes:
cc> How do I do this: [...] So that I can do this:
cc> With the objective of producing output like this:
If what you really want is a hash, use a hash in the first place.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Mon, 16 Feb 2009 06:43:04 -0800 (PST)
From: cartercc <cartercc@gmail.com>
Subject: Re: how do I print the name and value of a scalar
Message-Id: <9555e950-cb69-4b84-aac9-78128b815ac8@v19g2000yqn.googlegroups.com>
On Feb 16, 9:37=A0am, Charlton Wilbur <cwil...@chromatico.net> wrote:
> >>>>> "cc" =3D=3D cartercc =A0<carte...@gmail.com> writes:
>
> =A0 =A0 cc> How do I do this: [...] So that I can do this:
> =A0 =A0 cc> With the objective of producing output like this:
>
> If what you really want is a hash, use a hash in the first place.
>
> Charlton
>
> --
> Charlton Wilbur
> cwil...@chromatico.net
What I need is a way to get at the NAME of a variable as well as a
value.
CC
------------------------------
Date: Mon, 16 Feb 2009 15:26:41 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: how do I print the name and value of a scalar
Message-Id: <Xns9BB46A3F7699Basu1cornelledu@127.0.0.1>
cartercc <cartercc@gmail.com> wrote in news:9555e950-cb69-4b84-aac9-
78128b815ac8@v19g2000yqn.googlegroups.com:
> On Feb 16, 9:37 am, Charlton Wilbur <cwil...@chromatico.net> wrote:
>> >>>>> "cc" == cartercc <carte...@gmail.com> writes:
>>
>> cc> How do I do this: [...] So that I can do this:
>> cc> With the objective of producing output like this:
>>
>> If what you really want is a hash, use a hash in the first place.
[ don't quote sigs ]
> What I need is a way to get at the NAME of a variable as well as a
> value.
Nope. What you need to do is to use a hash in the first place, if you want
a hash.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
------------------------------
Date: Mon, 16 Feb 2009 09:49:54 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: how do I print the name and value of a scalar
Message-Id: <slrngpj2p2.but.tadmc@tadmc30.sbcglobal.net>
cartercc <cartercc@gmail.com> wrote:
> On Feb 16, 9:37 am, Charlton Wilbur <cwil...@chromatico.net> wrote:
>> >>>>> "cc" == cartercc <carte...@gmail.com> writes:
>>
>> cc> How do I do this: [...] So that I can do this:
>> cc> With the objective of producing output like this:
>>
>> If what you really want is a hash, use a hash in the first place.
> What I need is a way to get at the NAME of a variable as well as a
> value.
That is what using a hash will give you.
What you need is a way to get at the KEY of a hash variable as
well as a value. :-)
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Mon, 16 Feb 2009 11:06:20 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: how do I print the name and value of a scalar
Message-Id: <86tz6uqscj.fsf@mithril.chromatico.net>
>>>>> "cc" == cartercc <cartercc@gmail.com> writes:
cc> On Feb 16, 9:37 am, Charlton Wilbur <cwil...@chromatico.net> wrote:
>> If what you really want is a hash, use a hash in the first place.
cc> What I need is a way to get at the NAME of a variable as well as
cc> a value.
Yes, which means that what you want is a hash.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Mon, 16 Feb 2009 08:38:27 -0800 (PST)
From: cartercc <cartercc@gmail.com>
Subject: Re: how do I print the name and value of a scalar
Message-Id: <78a5c3aa-2a6b-41d7-a503-778c0b132bb7@v39g2000yqm.googlegroups.com>
On Feb 16, 11:06=A0am, Charlton Wilbur <cwil...@chromatico.net>
> Yes, which means that what you want is a hash. =A0
Okay, I'm confused, and I don't mind admitting it. (sorry about that)
In my little app, I've reached a point where the sheer volume of
scalar values has become burdensome. I don't know whether I really
need a hash or something else. I can print out the values of my
variables with no problem. The problem is that some of the variables
have similar values and I need to distinguish them, e.g., $password1,
$password2, $password3.
Maybe I'm approaching this in the wrong way, and to be honest, I
haven't given it a lot of thought. I have an array, which I have been
populating manually, which consists of the variable names, and I have
been using this array to print out the values of the variables. This
array looks like either one of these two examples:
my @vars =3D qw(name,address,city,state,zip);
my @vars =3D qw($name,$address,$city,$state,$zip);
I find that I can print either the (1) variable names, or (2) the
variable values -- but not both. What I would really like to do is
automate a print to console a list that looks like this:
name =3D> John Doe
pw1 =3D> qwerty
pw2 =3D> qwertx
#pw2 should match pw1
email =3D> some(at)domain(dot)com
#intentionally not valid, can't use a RE because of the variances of
falsifying email addresses
I might add that in Lisp I can do this without a problem, by printing
the symbol and then the value of the symbol. I ought to be able to do
this easily in Perl, but I can't. I'm willing to take the hit for my
confusion, or my ignorance.
CC
------------------------------
Date: Mon, 16 Feb 2009 09:06:09 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: how do I print the name and value of a scalar
Message-Id: <oh6jp45tr2c7tbfv2ef2effna3bllb2eo1@4ax.com>
cartercc <cartercc@gmail.com> wrote:
>Given a list of scalars, such as:
><code>
>my $name;
>my $address;
>my $city;
>my $state;
>my $zip;
>my @scalar_names = ($name, $address, $city, $state, $zip);
>my %var_names_and_values;
></code>
>
>How do I do this:
><pseudocode>
>foreach my $element (@scalar_names)
>{
> $var_names_and_values{?ELEMENT_NAME?} => $element;
>}
></pseudocode>
As has been pointed out last week already (did you read the replies?)
you are looking for symbolic references. It has also been pointed out
that symbolic references have _A_LOT_ of issues and that in 99.99999% of
all cases you absolutely, definately don't want to use them. The
remaining 0.000001% or so are for those experts, who know what they are
doing and really truly understand the purpose and limitations of
symbolic references for very special applications that involves
deep-down, dirty perl interna and access to the system symbol table.
In short: symbolic references allow you to access the internal symbol
table and for 99.9999% of all cases there is no good reason to use the
internal symobl table instead of creating your own private symbol table
in form of a hash.
my @scalar_names = qw/name address city state zip);
my %vars;
for (@scalar_names) { #strictly speaking initialisation is unnecessary!
$vars{$_} = undef;
}
Now you got your scalar values $vars{name}, $var{address}, and so on.
jue
------------------------------
Date: Mon, 16 Feb 2009 09:10:58 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: how do I print the name and value of a scalar
Message-Id: <s97jp49bljr0bbrtb6pn71nonp6fc9rv6j@4ax.com>
cartercc <cartercc@gmail.com> wrote:
>On Feb 16, 9:37 am, Charlton Wilbur <cwil...@chromatico.net> wrote:
>> >>>>> "cc" == cartercc <carte...@gmail.com> writes:
>>
>> cc> How do I do this: [...] So that I can do this:
>> cc> With the objective of producing output like this:
>>
>> If what you really want is a hash, use a hash in the first place.
>
>What I need is a way to get at the NAME of a variable as well as a
>value.
Then use a hash. In
my $name = 'foobar';
$myhash{ $name} = 'whatever';
you got the name of the variable ('foobar') as well as the value
('whatever').
jue
------------------------------
Date: Mon, 16 Feb 2009 18:15:51 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: how do I print the name and value of a scalar
Message-Id: <6vtl6lFljd1fU1@mid.individual.net>
I believe that what others who have replied mean is that doing literally
what you asked about is considered bad Perl practice; see
perldoc -q "variable name"
There are other approaches available, without a need to use symrefs. See
Jürgen's reply.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 16 Feb 2009 11:09:54 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: how do I print the name and value of a scalar
Message-Id: <slrngpj7f2.ctg.tadmc@tadmc30.sbcglobal.net>
cartercc <cartercc@gmail.com> wrote:
> On Feb 16, 11:06 am, Charlton Wilbur <cwil...@chromatico.net>
>> Yes, which means that what you want is a hash.
>
> Okay, I'm confused, and I don't mind admitting it. (sorry about that)
>
> In my little app, I've reached a point where the sheer volume of
> scalar values has become burdensome. I don't know whether I really
> need a hash or something else.
That may make it difficult to rework into using a hash instead
of a bunch of (I assume) file-scoped lexical variables...
> What I would really like to do is
> automate a print to console a list that looks like this:
>
> name => John Doe
> pw1 => qwerty
> pw2 => qwertx
rework your program to use a hash instead of standalone named variables:
my %v; # all of the variables
$v{name} = 'John Doe'; # instead of: my $name = 'John Doe'
$v{pw1} = 'qwerty'; # instead of: my $pw1 = 'qwerty'
...
then dump them out:
print "$_ => $v{$_}\n" for keys %v;
> I might add that in Lisp I can do this without a problem, by printing
> the symbol and then the value of the symbol. I ought to be able to do
> this easily in Perl, but I can't.
You can do that relatively easily in Perl if the variables
are package variables (by examining the Symbol Table).
But package variables are global variables, and come with all of
the negative baggage associated with global variables.
For lexical variables (declared with my()), you could perhaps work
out something using the PadWalker module...
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Mon, 16 Feb 2009 11:18:26 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: how do I print the name and value of a scalar
Message-Id: <49999fe3$0$87064$815e3792@news.qwest.net>
cartercc wrote:
> On Feb 16, 11:06 am, Charlton Wilbur <cwil...@chromatico.net>
>> Yes, which means that what you want is a hash.
>
> Okay, I'm confused, and I don't mind admitting it. (sorry about that)
>
> In my little app, I've reached a point where the sheer volume of
> scalar values has become burdensome. I don't know whether I really
> need a hash or something else. I can print out the values of my
> variables with no problem. The problem is that some of the variables
> have similar values and I need to distinguish them, e.g., $password1,
> $password2, $password3.
I'd suggest using more meaningful variable names.
>
> Maybe I'm approaching this in the wrong way, and to be honest, I
> haven't given it a lot of thought. I have an array, which I have been
> populating manually, which consists of the variable names, and I have
> been using this array to print out the values of the variables. This
> array looks like either one of these two examples:
>
> my @vars = qw(name,address,city,state,zip);
> my @vars = qw($name,$address,$city,$state,$zip);
Really? Take a look at what's in @vars after those statements.
>
> I find that I can print either the (1) variable names, or (2) the
> variable values -- but not both. What I would really like to do is
> automate a print to console a list that looks like this:
>
> name => John Doe
> pw1 => qwerty
> pw2 => qwertx
> #pw2 should match pw1
> email => some(at)domain(dot)com
> #intentionally not valid, can't use a RE because of the variances of
> falsifying email addresses
my %data = ( name => 'abc', address => '123 abc', city => 'Some city' );
for my $k ( keys %data )
{
print "$k => $data{$k}\n";
}
If you want the keys in a particular order:
my @keys = qw(name address city);
for my $k ( @keys ) { ... }
>
> I might add that in Lisp I can do this without a problem, by printing
> the symbol and then the value of the symbol. I ought to be able to do
> this easily in Perl, but I can't. I'm willing to take the hit for my
> confusion, or my ignorance.
Take a peek at: perldoc perldsc
------------------------------
Date: Mon, 16 Feb 2009 12:24:12 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: how do I print the name and value of a scalar
Message-Id: <86ljs6qoqr.fsf@mithril.chromatico.net>
>>>>> "cc" == cartercc <cartercc@gmail.com> writes:
cc> The problem is that some of the variables have similar values
cc> and I need to distinguish them, e.g., $password1, $password2,
cc> $password3.
Any time you have variables that end in numbers, like those, it's a sign
that what you really wanted was an array.
cc> Maybe I'm approaching this in the wrong way, and to be honest, I
cc> haven't given it a lot of thought.
You will save yourself a great deal of time and frustration if you think
*first* and code *second*.
cc> my @vars = qw(name,address,city,state,zip); my @vars =
cc> qw($name,$address,$city,$state,$zip);
my %var;
my $var{name} = $name;
my $var{address} = $address;
and so on.
You may make things easier on yourself by dispensing with $name,
$address, etc., and just using $var{name}, $var{address} throughout.
cc> I might add that in Lisp I can do this without a problem, by
cc> printing the symbol and then the value of the symbol.
If you want Lisp, you know where to find it. This is Perl. You do what
you want by printing the key and then the associated value.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Mon, 16 Feb 2009 09:38:37 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: how do I print the name and value of a scalar
Message-Id: <eb8jp4d2eagibu657ck5hg5sf2ifgee62l@4ax.com>
cartercc <cartercc@gmail.com> wrote:
>In my little app, I've reached a point where the sheer volume of
>scalar values has become burdensome.
That is almost always a sure sign, that you are using a poor design for
your data structure.
>I don't know whether I really
>need a hash or something else. I can print out the values of my
>variables with no problem. The problem is that some of the variables
>have similar values and I need to distinguish them, e.g., $password1,
>$password2, $password3.
YIKES! That hurts.
Names like that are a very strong indication that an array would have
been a better choice:
$password[1];
$password[2];
$password[3];
Or often maybe instead of an index a more identifying name, i.e. a hash
with
$password{local};
$password{server};
$password{web};
>Maybe I'm approaching this in the wrong way, and to be honest, I
>haven't given it a lot of thought.
Yeah, most people underestimate the benefits of a carefully thought out
datastructure as well as the pain of a randomly created one.
>I have an array, which I have been
>populating manually, which consists of the variable names, and I have
>been using this array to print out the values of the variables. This
>array looks like either one of these two examples:
>
>my @vars = qw(name,address,city,state,zip);
>my @vars = qw($name,$address,$city,$state,$zip);
>I find that I can print either the (1) variable names, or (2) the
>variable values -- but not both. What I would really like to do is
>automate a print to console a list that looks like this:
What is so difficult about creating a hash with the elements
$myhash{name}, $myhash{address}, $myhash{city}, ....
instead of the individual variables $name,$address,$city, ...?
>name => John Doe
>pw1 => qwerty
>pw2 => qwertx
>email => some(at)domain(dot)com
for (qw/name pw1 pw2 email/) {
print "$_=>$myhash{$_}\n";
}
>I might add that in Lisp I can do this without a problem, by printing
>the symbol and then the value of the symbol. I ought to be able to do
>this easily in Perl, but I can't. I'm willing to take the hit for my
>confusion, or my ignorance.
To jump the boundary between code and data in Perl you can use eval().
But it has it's own set of potential risks. After all there is a very
good reason why modern programming languages made a clear distinction
between code and data and don't mingle them as in LISP.
jue
------------------------------
Date: Mon, 16 Feb 2009 17:33:37 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: how do I print the name and value of a scalar
Message-Id: <hkko66-p42.ln1@osiris.mauzo.dyndns.org>
Quoth Tad J McClellan <tadmc@seesig.invalid>:
> cartercc <cartercc@gmail.com> wrote:
> > On Feb 16, 11:06 am, Charlton Wilbur <cwil...@chromatico.net>
> >> Yes, which means that what you want is a hash.
> >
> > Okay, I'm confused, and I don't mind admitting it. (sorry about that)
> >
> > In my little app, I've reached a point where the sheer volume of
> > scalar values has become burdensome. I don't know whether I really
> > need a hash or something else.
>
>
> That may make it difficult to rework into using a hash instead
> of a bunch of (I assume) file-scoped lexical variables...
>
>
> > What I would really like to do is
> > automate a print to console a list that looks like this:
> >
> > name => John Doe
> > pw1 => qwerty
> > pw2 => qwertx
>
> rework your program to use a hash instead of standalone named variables:
>
> my %v; # all of the variables
> $v{name} = 'John Doe'; # instead of: my $name = 'John Doe'
> $v{pw1} = 'qwerty'; # instead of: my $pw1 = 'qwerty'
> ...
You may also want to use Hash::Util::lock_keys to regain the advantages
of 'use strict'.
Ben
------------------------------
Date: Mon, 16 Feb 2009 12:09:50 -0600
From: Chris Mattern <syscjm@sumire.gwu.edu>
Subject: Re: how do I print the name and value of a scalar
Message-Id: <slrngpjave.a0q.syscjm@sumire.gwu.edu>
On 2009-02-16, cartercc <cartercc@gmail.com> wrote:
> On Feb 16, 9:37 am, Charlton Wilbur <cwil...@chromatico.net> wrote:
>> >>>>> "cc" == cartercc <carte...@gmail.com> writes:
>>
>> cc> How do I do this: [...] So that I can do this:
>> cc> With the objective of producing output like this:
>>
>> If what you really want is a hash, use a hash in the first place.
>>
>> Charlton
>>
>> --
>> Charlton Wilbur
>> cwil...@chromatico.net
>
>
> What I need is a way to get at the NAME of a variable as well as a
> value.
>
No, what you need is a hash. We've already been over this.
--
Christopher Mattern
NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 2212
***************************************