array not printing what I want

Discussion in 'Perl Misc' started by Nene, Mar 15, 2011.

  1. Nene

    Nene Guest

    #!/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.
    Nene, Mar 15, 2011
    #1
    1. Advertising

  2. On 2011-03-15 12:14, Nene <> wrote:
    > 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
    Peter J. Holzer, Mar 15, 2011
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon B
    Replies:
    7
    Views:
    7,483
    =?Utf-8?B?SmFzb25DaG9p?=
    Jan 30, 2006
  2. JustSomeGuy
    Replies:
    13
    Views:
    502
    msalters
    Dec 9, 2004
  3. iffy agbim
    Replies:
    1
    Views:
    98
    Mark Andrews
    May 24, 2004
  4. Replies:
    4
    Views:
    142
    Ted Zlatanov
    Sep 13, 2006
  5. pavi
    Replies:
    0
    Views:
    1,323
Loading...

Share This Page