On Friday 05 May 2006 12:29, Steve Swift wrote: > I've written a tiny program to make it easy to test the syntax and > effects of a Perl statement. My program is called "perltry" and here it > is in its full gory (pun intended) > > #!/usr/bin/perl > use strict; > use warnings; > system('clear'); > system('perl -v'); > print "Go on - try a few... Enter 'exit' to end.\n"; > while (<>) { > eval $_; > if ($@) {print "[EMAIL PROTECTED]";} > print ' ','.'x50," perltry on $^O\n" > }; > > If I enter a statement, such as "$a=1;" (without the quotes) then I
my $a = 1; > would expect that scalar $a would get the value 1. If I then enter the > statement "print $a" I expected to see "1". What I saw was: > Use of uninitialized value in string at (eval 2) line 1, <> line 2. This is because the scope of the variable $a is only within the block. You might try using 'our' instead of 'my', but I'm also a beginner so I don't know the meanings of 'our'. > Could someone tell me why this happened, please? > Is it possible to change this so that the variable $a would get set? You might also use perl in oneliner-mode: perl -w -e '$a=1;print "$a\n";' See also the -n and -p parameters. > This is my very first post to a Perl newsgroup, so treat me gently, please! Welcome! -- Bjørge Solli - Office:+47 55205847 http://www.nersc.no Nansen Environmental and Remote Sensing Center - Bergen, Norway Dept.: Mohn-Sverdrup Center for Global Ocean Studies and Operational Oceanography -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>