Hi Rodrigo,

On 2007/03/16, at 18:09, Rodrigo Faria Tavares wrote:

Hello,

In shell-script I get a variable with command line:

AUXIP=`cat $INPUTDB/postgresql.conf | grep "localhost"
| awk '{print $3}' | head -n1`

In C++, I use the functions read, write and others for
manipulation files.

And Pearl ?

After I open the file, i like to get a simple word and
store in a scalar variable. Or write after line 10 for
example. And others.

<code>
use strict;
use warnings;

open my $fh, "<", "$ENV{'INPUTDB'}/postgresql.conf" or die $!;

my $auxip;

while (my $line = <$fh>) {
    next unless $line =~ /localhost/;
    $auxip = (split ' ', $line)[2];
    last;
}

close $fh or die $!;

print "$auxip\n";
</code>

The code is untested, but I think it works. I can't remember if awk's index for fields starts with 0 or 1, so please check out. For more information about the above code:

$ perldoc strict
$ perldoc warnings
$ perldoc perlsyn
$ perldoc perlfunc

--
Igor Sutton
[EMAIL PROTECTED]



Reply via email to