CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
stopped at the start

 



iperli
New User

Oct 3, 2010, 4:22 AM

Post #1 of 4 (511 views)
stopped at the start Can't Post

Hello,

I installed Active Perl 5.12.2 Build 1202

Why does the first script run correctly and the second only displays a black window during 1/100 second ?


Code
  #!C:\\Perl\\bin\\perl   
use strict;
use warnings;

$a = 'earth';
print "$a\n";
$b = 'wind';
print "$b\n";
sleep(5);




Code
  #!C:\\Perl\\bin\\perl   
use strict;
use warnings;

$a = 'earth';
print "$a\n";
$b = 'wind';
print "$b\n";
$c = 'and fire';
print "$c\n";
sleep(5);



Thanks.

(This post was edited by iperli on Oct 3, 2010, 5:01 AM)


FishMonger
Veteran / Moderator

Oct 3, 2010, 8:37 AM

Post #2 of 4 (502 views)
Re: [iperli] stopped at the start [In reply to] Can't Post

Open a cmd window first then run your script and you will have the answer.

That answer should generate another question.


(This post was edited by FishMonger on Oct 3, 2010, 8:38 AM)


iperli
New User

Oct 3, 2010, 10:27 AM

Post #3 of 4 (496 views)
Re: [FishMonger] stopped at the start [In reply to] Can't Post


In Reply To
Open a cmd window first then run your script ...



Aaaah yes.... How stupid I was.


In Reply To
... and you will have the answer.

That answer should generate another question.



The error message was:

Global symbol $c requires explicit package name

I searched for package name and read :

In Perl, a namespace is held in a package.

So its a matter of namespace. At this point I reminded me that the use strict; instruction isnt there to make pretty.

Then the following code runs nice:


Code
   #!C:\\Perl\\bin\\perl    
use strict;
use warnings; $a = 'earth';
print "$a\n";
$b = 'wind';
print "$b\n";
my $c = 'and fire';
print "$c";
sleep(5);



But the question is: why $a and $b, without my before them, dont provoque the same error ?



Additionnaly, I noticed something:

the 5 seconds sleep takes place BEFORE the display of the value of $c although the sleep(5) instruction is placed AFTER the print $c; instruction.

But with instruction print $c\n; , the sleep is made after the display of $cs value.

Why ?



Thank you very much for your answer which unstopped me, FishMonger.





NB:

Please, excuse my incorrect english.

I would be glad if any Anglophone would correct it.


(This post was edited by iperli on Oct 3, 2010, 10:30 AM)


FishMonger
Veteran / Moderator

Oct 4, 2010, 7:34 AM

Post #4 of 4 (470 views)
Re: [iperli] stopped at the start [In reply to] Can't Post


Quote
But the question is: why $a and $b, without my before them, dont provoque the same error ?

$a and $b are 2 of Perl's special built-in global vars, which is why they didn't produce the error. Those vars are used in sort routines.

Search for those vars in 'perldoc perlvar'


Quote
Additionnaly, I noticed something:

the 5 seconds sleep takes place BEFORE the display of the value of $c although the sleep(5) instruction is placed AFTER the print $c; instruction.

But with instruction print $c\n; , the sleep is made after the display of $cs value.

Why ?

See: 'perldoc -q buffer'

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives