Static variable problem

Discussion in 'Perl Misc' started by Dave Saville, Nov 13, 2012.

  1. Dave Saville

    Dave Saville Guest

    Apologies if this appears twice but I have not seen it and my sent
    posts folder does not have a copy - but I would swear I hit send :)


    Please can someone explain why the following throws an error?

    [T:\tmp]cat try.pl
    use strict;
    use warnings;

    foo("Hello World");
    exit;
    {
    my $bar = 1;

    sub foo
    {
    my $a = shift;
    print "$bar $a\n"; <== line 12
    return;
    }
    }

    [T:\tmp]try.pl
    Use of uninitialized value in concatenation (.) or string at try.pl
    line 12.
    Hello World

    $bar is private to foo - yes? So you can't initialize it?
    --
    Regards
    Dave Saville
    Dave Saville, Nov 13, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kookey
    Replies:
    3
    Views:
    20,759
    Andrew Thompson
    Aug 20, 2005
  2. Patrick Hoffmann
    Replies:
    3
    Views:
    2,833
    Christian Jan├čen
    Aug 8, 2003
  3. Marcin Vorbrodt

    Global static variable vs static method

    Marcin Vorbrodt, Sep 5, 2003, in forum: C++
    Replies:
    3
    Views:
    5,420
    Denis Perelyubskiy
    Sep 5, 2003
  4. Sam
    Replies:
    4
    Views:
    471
    The Directive
    Jan 13, 2004
  5. Vikram Kalra
    Replies:
    23
    Views:
    875
    Nigel Wade
    Sep 7, 2007
Loading...

Share This Page