array not printing what I want

N

Nene

#!/usr/bin/perl -w
use strict;

my $SUBNET = '172.16.70.';
my @MEMBERS = qw/
${SUBNET}66
${SUBNET}68
${SUBNET}70
${SUBNET}72
/;

foreach my $node ( @MEMBERS )

{
print "$node\n"
}

####

I want it to print the IP address.
 
P

Peter J. Holzer

my $SUBNET = '172.16.70.';
my @MEMBERS = qw/
${SUBNET}66
${SUBNET}68
${SUBNET}70
${SUBNET}72
/;

See perldoc perlop, "Quote and Quote-like Operators" for why this
doesn't work.

To interpolate you need to use double quotes:

my @MEMBERS = (
"${SUBNET}66",
"${SUBNET}68",
"${SUBNET}70",
"${SUBNET}72",
);

and of course in this case a map could be used to save typing:

my @MEMBERS = map "${SUBNET}$_", qw(66 68 70 72);

hp
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top