in reply to Issue destroying image using perl/TK

my $fn =@_;

does not do what you think it does


Cheers, Christoph

Replies are listed 'Best First'.
Re^2: Issue destroying image using perl/TK
by AnomalousMonk (Archbishop) on Mar 23, 2011 at 01:58 UTC

    Specifically,
        my $fn = @_;
    initializes  $fn with the number of elements in the  @_ array (array evaluated in scalar context). What is almost certainly wanted is
        my ($fn) = @_;
    or better yet
        my $fn = shift;
    to initialize  $fn with the first element (index 0) of the array, Update: which, in this case, is an object reference by which an object method is called.

      This did the trick. Thanks

      @_ is the list of incoming parameters to a subroutine. What is the significants of () around the scaler pv?

        () make the left hand side a list. Arrays return their elements when evaluated in list context.

        See also perldata :
        Assignment is a little bit special in that it uses its left argument t +o determine the context for the right argument. Assignment to a scala +r evaluates the right-hand side in scalar context, while assignment t +o an array or hash evaluates the righthand side in list context. Assi +gnment to a list (or slice, which is just a list anyway) also evaluat +es the righthand side in list context.

        Cheers, Christoph