On Jul 9, Craig S Monroe said:
>I have split a string successfully into two variables. No big feat. The
>problem I am having is that the string I have set the script to look for
>occurs twice. So I encounter the string. split is as necessary, and
>assign the variables. It then encounters the string and does the above
>again. What I would like to do is separate the values into "dynamic"
>variables of a sort.
Nononon. When I hear "dynamic variables", I think "the user is not
thinking about anything bigger than a scalar."
You should be using arrays or hashes.
>while (defined ($line = <$remote>)) {
> $line = substr("$line",1);
> if ($line =~ /^ inet/){ # if line begins with space and inet, grab and
> $line =~ s/^\s+//; # and remove the blank space preceding the line.
> ($interface, $ipaddress) = split(/\s+/, $line); # split the line into two
>variables.
> }
Notice how I'm using $_ (implicitly) instead of $line.
while (<$remote>) {
$_ = substr $_, 1;
# or, maybe simpler:
# substr($_, 0, 1, '');
# remove leading spaces if followed by 'inet'
s/^\s+(?=inet)//;
my ($interface, $ipaddr) = split;
push @inter, $interface;
push @addr, $ipaddr;
}
Now you have $inter[0], $inter[1], ..., and $addr[0], $addr[1], ...
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter. Brother #734
** Manning Publications, Co, is publishing my Perl Regex book **