Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,
Noobie here, need help :(.
Here is a code snippet:

foreach $ttt (@syshosts) { $cname = Host::get_cname($ttt); if( $cname =~ m/(Workstation|AnalogGateway)/ ) { push @serialOperations, $ttt; } }

Basically, if I have a Workstation or AnalogGateway I want to pust the contents of $ttt onto serialOperations. But I keep getting the error message:

Invalid value for shared scalar at r21shutdown_parallel.pl line 131, < +FILE> line 15.

serialOperations is shared.
Any help is greatly appreciated.

Thanks

20051103 Janitored by Corion: Added formatting

Replies are listed 'Best First'.
Re: using push
by ikegami (Patriarch) on Nov 03, 2005 at 21:34 UTC
    IIRC, that error message means a handle or other non-shareable value ($ttt or something in $ttt?) was assigned to a shared variable (@serialOperations?) in a threaded environment. Did you try adding use diagnostics; to get more info?
Re: using push
by GrandFather (Saint) on Nov 03, 2005 at 21:27 UTC

    Give us a complete stand alone piece of code that shows the problem. Here we haven't enough context and can't infer the line that generates the error from your code. You may like to modify this until it shows the problem:

    use strict; use warnings; my @syshosts = ('This is a Workstation'); my @serialOperations; foreach my $ttt (@syshosts) { if( $ttt =~ m/(Workstation|AnalogGateway)/ ) { push @serialOperations, $ttt; } }

    Add use strict; use warnings; at the start of your code. They will save you a lot of grief!


    Perl is Huffman encoded by design.
Re: using push
by Roy Johnson (Monsignor) on Nov 03, 2005 at 21:28 UTC
    What is the type of $ttt? Are any of them objects or refs?

    Apropos of nothing, you could do the whole loop as one statement:

    push @serialOperations, grep { Host::get_cname($_) =~ /Workstation|Ana +logGateway/ } @syshosts;

    Caution: Contents may have been coded under pressure.
Re: using push
by Fletch (Bishop) on Nov 03, 2005 at 21:31 UTC

    You might also add what version of Perl and what platform you're on; I don't see the error message Invalid value for shared scalar ... in my copy of perldoc perldiag for 5.6.1 or 5.8.6.

Re: using push
by hubb0r (Pilgrim) on Nov 04, 2005 at 05:45 UTC

    I'd suggest beginning your debugging by adding:

    use warnings; use strict;

    to your code. After that, give us some more context to work with. On a side note, I've never seen that error message before.