in reply to Global Variables

Put a my $shipment_request_id before the if block, in the same block where you later use the variable (and remove the my inside the if).

Replies are listed 'Best First'.
Re^2: Global Variables
by kmullin (Acolyte) on Nov 27, 2007 at 22:22 UTC
    Wonderful, that did it. So, you need to define variables before getting into a block, because if you declare them in a block, they are local to the block?
      Yes. Each block is a scope. Even bare curlies (without any flow control statements) make a block.
      use strict; { my $foo = 2; { my $foo = 1; # masks outer $foo my $bar = $foo; print "foo is '$foo'\n"; # foo is '1' } print "foo is '$foo'\n"; # foo is '2' print $bar; # # error, $bar not visible here my $foo; # warning: $foo already declared # as lexical in this scope. } print "foo = $foo\n"; # error, $foo not visible here

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
      Exactly.
      Well...close, but not exactly. If you are using "use strict", which you evidently are, this is 100% correct. But you should know that without the strict option, a variable can be declared anywhere simply by using it. When not using the strict constraints, the best way I know to describe scoping is "global once declared".
        But you should know that without the strict option, a variable can be declared anywhere simply by using it.

        IMHO, since kmullin is a self-confessed mewbie, you should add a strong health warning to that statement, perhaps something along these lines. Don't be tempted to turn off strictures to silence intractable compilation errors; always use strict;.

        Cheers,

        JohnGG