Home > Archive > PERL Beginners > March 2007 > Re: Learning Perl with shells operations
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: Learning Perl with shells operations
|
|
| Rodrigo Tavares 2007-03-27, 10:01 pm |
| Hello,
With this line the script run, no errors.
system "su postgres -c '/usr/local/pgsql/bin/pg_ctl
start -D /opt/@bancos[$i]'";
two things :
I use of stricts and warnings, and come this error
compilation when i wrote into my code.
Global symbol "$x" requires explicit package name at
../start-banco.pl line 7.
Global symbol "@word" requires explicit package name
at ./start-banco.pl line 11.
Global symbol "@bancos" requires explicit package name
at ./start-banco.pl line 17.
The compilation show there are variables globals.
What I can to resolve this problem ?
And How I can to use perldoc to read a directory and
store your names in a array ?
equal with x =`ls opt`; @word = split /\s+/, $x;
I'm bash programmer, and i want learn perl.
Best regards,
Rodrigo Faria
> On Mar 23, 10:43 am, digolinop...@yahoo.com.br
(Rodrigo Tavares)
> wrote:
>
> You should start your script with the following two
lines:
> use strict;
> use warnings;
>
> You could use Perl's builtin 'readdir' function to
get the contents of
> a directory.
> Type 'perldoc -f readdir' for more info.
>
> No need for the initialization.
>
> Use a more descriptive name than $i.
> $dir or $directory, possibly.
>
> No need for a 'c' style for loop.
>
> foreach my $dir ( @bancos )
> {
> `su postgres -c "/usr/local/pgsql/bin/pg_ctl
start -D $dir`
> }
>
> You forgot the backticks for issuing a system
command.
start -D[color=darkred]
"postgres"[color=darkred]
../teste.pl[color=darkred]
> HTH, Ken
________________________________________
__________
Fale com seus amigos de graça com o novo Yahoo! Messenger
http://br.messenger.yahoo.com/
| |
| Rob Dixon 2007-03-28, 6:59 pm |
| Rodrigo Tavares wrote:
> Hello,
>
> With this line the script run, no errors.
>
> system "su postgres -c '/usr/local/pgsql/bin/pg_ctl
> start -D /opt/@bancos[$i]'";
>
> two things :
>
> I use of stricts and warnings, and come this error
> compilation when i wrote into my code.
>
> Global symbol "$x" requires explicit package name at
> ./start-banco.pl line 7.
> Global symbol "@word" requires explicit package name
> at ./start-banco.pl line 11.
> Global symbol "@bancos" requires explicit package name
> at ./start-banco.pl line 17.
>
> The compilation show there are variables globals.
>
> What I can to resolve this problem ?
>
> And How I can to use perldoc to read a directory and
> store your names in a array ?
>
> equal with x =`ls opt`; @word = split /\s+/, $x;
>
> I'm bash programmer, and i want learn perl.
As Alan has explained, $x, @word and @bancos need declaring before you use
them, with 'my'.
You will also have got the message
Scalar value @bancos[$i] better written as $bancos[$i]
which is self-explanatory.
Rob
| |
|
| On Tuesday 27 March 2007 06:47, Rodrigo Tavares wrote:
> Hello,
[ . . ]
> I use of stricts and warnings, and come this error
> compilation when i wrote into my code.
>
> Global symbol "$x" requires explicit package name at
> ./start-banco.pl line 7.
> Global symbol "@word" requires explicit package name
> at ./start-banco.pl line 11.
> Global symbol "@bancos" requires explicit package name
> at ./start-banco.pl line 17.
>
> The compilation show there are variables globals.
>
> What I can to resolve this problem ?
When that happen, it's typically due to: have not used "my" which, when used,
declares a lexical variable. This has to do with the scope of the varaiable.
I don't see your latest code. Hopefully I didn't miss the mark (as in some
other sort of a library/package issue).
http://perl.plover.com/FAQs/Namespaces.html
http://groups.google.com/group/perl...arch+this+group
http://groups.google.com/group/perl...arch+this+group
--
Alan.
|
|
|
|
|