'R#' as a hash key?

E

entropy123

Hey all,

Am pretty new to Perl and find myself writing a parser. One of the
items my parser is reading is 'R#'. R# would make a nice key, but R#
in my program automatically comments out the rest of the line. R\#
results in a compilation error, is there some way to allow my key to
be R#, or, alternatively, Change 'R#' to 'R' which is better for my
purposes...

Thanks,
ent
 
T

Tony Curtis

On 25 Aug 2004 13:13:55 -0700,
Hey all, Am pretty new to Perl and find myself writing a
parser. One of the items my parser is reading is 'R#'. R#
would make a nice key, but R# in my program automatically
comments out the rest of the line. R\# results in a
compilation error, is there some way to allow my key to be
R#, or, alternatively, Change 'R#' to 'R' which is better

^^^^ the answer
for my purposes...

e.g.

$hash{'R#'} = 42;

use Data::Dumper;
print Dumper(\%hash);

$VAR1 = {
'R#' => 42
};

hth
t
 
J

John Bokma

(e-mail address removed) (entropy123) wrote in
Hey all,

Am pretty new to Perl and find myself writing a parser. One of the
items my parser is reading is 'R#'. R# would make a nice key, but R#
in my program automatically comments out the rest of the line.

fix the program then.
R\#
results in a compilation error,

By Perl, your program, what?
is there some way to allow my key to
be R#, or, alternatively, Change 'R#' to 'R' which is better for my
purposes...

No idea what you are talking about. R# just works as a hash key.
 
B

Brian McCauley

Am pretty new to Perl and find myself writing a parser. One of the
items my parser is reading is 'R#'. R# would make a nice key, but R#
in my program automatically comments out the rest of the line. R\#
results in a compilation error, is there some way to allow my key to
be R#, or, alternatively, Change 'R#' to 'R' which is better for my
purposes...

Since we are obviously taking about the literal code of your program
here the way to change R# to R depends on the text-editor you are using
to edit your program but typically you'd place the cursor either before
or after the # and hit delete forwards or delete backwards as appropriate.

Hash keys can be any string.

$foo{'R#'}

The bit in the {...} of a hash element reference is interpreted as an
expression unless it is a 'word' i.e. something made up of letter,
number and underscores. If it is a word then it's interpreted as
literal string.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top