Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Origin of 'md5sum' and 'sh' logs

by Marshall (Canon)
on Feb 26, 2019 at 01:14 UTC ( [id://1230541]=note: print w/replies, xml ) Need Help??


in reply to Origin of 'md5sum' and 'sh' logs

I am not sure what's going on here. But do you have use strict; use warnings; at the top of your script?

if (-e $filepath) { my $exception... } else { my $exception... }
shouldn't compile. In general a "my" variable cannot be declared within a conditional statement.
EDIT: yes this will compile, but $exception cannot be used outside of its lexical scope.

$exception is reference to a hash:

#!/usr/bin/perl use strict; use warnings; my $exception = {table => 'tablename', exception => 'outofdate'}; my $exception2 = {table => 'tablename2', exception => 'allOk'}; foreach my $error ($exception, $exception2 ) { print "$error->{exception}\n"; } __END__ outofdate allOk

Replies are listed 'Best First'.
Re^2: Origin of 'md5sum' and 'sh' logs
by morgon (Priest) on Feb 26, 2019 at 01:22 UTC
    In general a "my" variable cannot be declared within a conditional statement.
    Of course it can. Why should this be a problem?

    You can declare a "my" variable in any lexical scope - the branches of an if-statement are just one example:

    use strict; my $whatever; if($whatever) { my $something = "here"; } else { my $something = "there"; } print "look I compiled\n";
      can declare a "my" variable in any lexical scope. Well, ok but you can't use it outside of that scope. The OP's indenting is confusing to me. Your code works until you try to use $something outside of lexical scope.
      #!/usr/bin/perl use strict; use warnings; my $whatever; if($whatever) { my $something = "here"; } else { my $something = "there"; } print "look I compiled $something\n"; __END__ Global symbol "$something" requires explicit package name (did you for +get to declare "my $something"?) at Monks\Badcode.pl line 14. Execution of Monks\Badcode.pl aborted due to compilation errors. Process completed with exit code 255
        Of course you can't use it outside of it's scope.

        There is a reason it's called "my".

        I did not read the OP - I was just picking up on your statement.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1230541]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-25 19:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found