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. Advertisements

  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. Advertisements

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:
    8,052
    =?Utf-8?B?SmFzb25DaG9p?=
    Jan 30, 2006
  2. JustSomeGuy
    Replies:
    13
    Views:
    732
    msalters
    Dec 9, 2004
  3. Hendrik Maryns
    Replies:
    8
    Views:
    389
    Hendrik Maryns
    Jan 25, 2008
  4. iffy agbim
    Replies:
    1
    Views:
    257
    Mark Andrews
    May 24, 2004
  5. iffy agbim
    Replies:
    0
    Views:
    372
    iffy agbim
    May 21, 2004
  6. Replies:
    4
    Views:
    390
    Ted Zlatanov
    Sep 13, 2006
  7. pavi
    Replies:
    0
    Views:
    1,599
  8. Amit
    Replies:
    0
    Views:
    403
Loading...