Rodrigo Tavares wrote: > Hello, Hello,
> My code is below: > > $aux = `ls /opt`; > @word = split /\s+/, $aux; That won't work very well if you have names with embeded spaces. A better option would be to assign the back-quote results to an array. > my @bancos = (); Why are you assigning nothing to an empty variable? > foreach my $i (@word) > { > if ( -e "/opt/$i/postgresql.conf" ) > { > push(@bancos,$i); > } > } Perhaps you want something like: my @bancos = map m!^/opt/(.+)/postgresql\.conf$!, glob "/opt/*/postgresql.conf" > for ($i = 0; $i < @bancos; $i++) > { > su postgres -c "/usr/local/pgsql/bin/pg_ctl start -D > @bancos[$i]"; > } > > After running the script como the error: > > Can't locate object method "su" via package "postgres" > (perhaps you forgot to load "postgres"?) at ./teste.pl > line 19. > > I don't understad this message ? $ perl -MO=Deparse -e' su postgres -c "/usr/local/pgsql/bin/pg_ctl start -D @bancos[$i]"; ' 'postgres'->su(-c "/usr/local/pgsql/bin/pg_ctl start -D @bancos[$i]"); -e syntax OK The barewords 'su' and 'postgres' are being interpreted by perl as the method su() belonging to the package 'postgres'. Also see: perldoc -q 'What is the difference between $array[1] and @array[1]' It looks like you want something like: for my $banco ( @bancos ) { system( qq{su postgres -c "/usr/local/pgsql/bin/pg_ctl start -D $banco"} ) == 0 or die "system su postgres failed: $?"; } John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/