Quoth April <
[email protected]>:
Um... you seem to be somewhat confused. Each separate invocation of perl
is completely separate: variables and such never carry over from one to
the next. If you want to execute several statements one after the other,
you can separate them with ; like this:
perl -e "$_ = 2; print \"$_\n\""
but it's usually better to put them in a file and run that.
If you're running perl from the command line, it's worth getting used to
the q// and qq// forms of quoting. You can rewrite you're first example
as
perl -e "print qq/Hello world\n/"
where the qq means 'double quotes' and the slashes go either end of the
quoted material. This avoids needing to put backslashes all over the
place. Read perldoc perlop for the full details.
If you're just experimenting you can run
perl -de1
which will give you a prompt something like
Loading DB routines from perl5db.pl version 1.28
Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
main:
-e:1): 1
DB<1>
where you can type Perl statements which will be immediately run: since
this is all within one execution of perl, variables will carry across
from statement to statement as you seem to expect.
Ben