Avoiding lc on a reference value

T

Tony

Is there an elegant way to determine if a variable contains a plain
old value?

I'm working through an array, and lowercasing everything. I need to
skip over elements that are references, and the below seems a bit
ugly/prone to error:


if ($components[$i] !~ /(0x|SCALAR)/) {
$components[$i] = lc($components[$i]);
}


Thank you!
 
D

Dmitry Roslyakov

Tony said:
Is there an elegant way to determine if a variable contains a plain
old value?

I'm working through an array, and lowercasing everything. I need to
skip over elements that are references, and the below seems a bit
ugly/prone to error:


if ($components[$i] !~ /(0x|SCALAR)/) {
$components[$i] = lc($components[$i]);
}


Thank you!

$components[$i] = lc($components[$i]) unless ref($components[$i]);
 
D

David K. Wall

Tony said:
Is there an elegant way to determine if a variable contains a plain
old value?

I'm working through an array, and lowercasing everything. I need to
skip over elements that are references, and the below seems a bit
ugly/prone to error:


if ($components[$i] !~ /(0x|SCALAR)/) {
$components[$i] = lc($components[$i]);
}

I think you want ref(). See

perldoc -f ref
 
U

Uri Guttman

DR> Tony said:
Is there an elegant way to determine if a variable contains a plain
old value?
I'm working through an array, and lowercasing everything. I need to
skip over elements that are references, and the below seems a bit
ugly/prone to error:
if ($components[$i] !~ /(0x|SCALAR)/) {
$components[$i] = lc($components[$i]);
}
Thank you!

DR> $components[$i] = lc($components[$i]) unless ref($components[$i]);

GACK!!!

i will have to assume a c style loop in the OP's code there which is not
perlish

ref or $_ = lc for @components ;

uri
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top