in reply to Re: Please help with arrays
in thread Please help with arrays

Hi robot_tourist,

many thanx for your help!

$refaLines has following data:
1 cat-itd-05 (10.1.254.253) 1.16 ms 4.352 ms 2.714 ms
2 gate (10.1.254.254) 0.792 ms 1.178 ms 7.758 ms
3 router (193.83.153.254) 9.341 ms * 14.323 ms

I only want a list which looks like this:
1 cat-itd-05 (10.1.254.253)
2 gate (10.1.254.254)
3 router (193.83.153.254)

I wrote following code:
sub ExtractHopHostIp{ my $refaLines=shift; my @Fields; my @FoundHops; print @$refaLines,"\n"; for (@$refaLines) { s/[ \t]+/ /g; # remove duplicate blanks and tabs @Fields=split / /,$_; splice(@Fields,4); # get fields from the array push @FoundHops,@Fields; } @FoundHops = join " ",@FoundHops; print @FoundHops,"\n"; }
But I get this:
1 cat-itd-05 (10.1.254.253) 2 gate (10.1.254.254) 3 router (193.83.153.254)

Many thanx for any help!

Clint

20050623 Edit by ysth: code tags

Replies are listed 'Best First'.
Re^3: Please help with arrays
by halley (Prior) on Jun 22, 2005 at 13:48 UTC
    Please contain your code (or program output) in <code> tags, as follows.

    <code>

    This is code and will be formatted as such.
    </code>

    --
    [ e d @ h a l l e y . c c ]

Re^3: Please help with arrays
by robot_tourist (Hermit) on Jun 22, 2005 at 13:39 UTC

    I do not think the last join is doing what you want it to. It is putting your list of values into one long string.

    How can you feel when you're made of steel? I am made of steel. I am the Robot Tourist.
    Robot Tourist, by Ten Benson

Re^3: Please help with arrays
by robot_tourist (Hermit) on Jun 23, 2005 at 11:17 UTC

    Check the three lines after the s/\t+/ /g; and think about where your data are actually going. You really just want an array of strings. One string for each line, in this case one string for each hop. Each separate element of @Fields became a separate element of @FoundHops. Then you joined it all together into one long string.

    e.g. after the first time round the loop, @FoundHops is the following list of scalars: ("1", "cat-itd-05", "10.1.254.253")

    How can you feel when you're made of steel? I am made of steel. I am the Robot Tourist.
    Robot Tourist, by Ten Benson