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

I have the following (reduced) code:
use Socket; socket(my $socket, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
This works fine for me and many other versions of Perl. But in Perl 5.5 (at least, maybe lower versions as well), it results in the error:
Can't use an undefined value as a symbol reference at ...
(this is coming from a CPAN test FAIL Device-CableModem-SURFboard-0.02)

My suspicion is the use of 'my $socket' instead of named literal. I can easily replace it with a named literal (say 'SOCKET') if that will work on lower Perl versions, but I have no way to test it.

If the failure is the result of something else (the other socket() parameters) then I'm at a loss as to how/if I should modify the code.

Replies are listed 'Best First'.
Re: Perl 5.5 and socket
by Burak (Chaplain) on Dec 22, 2007 at 17:41 UTC
    Using lexicals instead of globs is a feature that came with the 5.6 series. You must use a glob or get a lexical referencing a glob from the Symbol module.
      Or just increase the requirement of the distribution to 5.6.0:
      use 5.006;
      in your Makefile.PL should do it.
        I may resort to a version limit yet, but for now I simply changed the lexical (it's a small piece of code). Besides, I had to clean up some documentation anyway.

        When the new updates have finished running through tests, I find out how much further I should bother to go with version limiting.
Re: Perl 5.5 and socket
by grinder (Bishop) on Dec 22, 2007 at 21:41 UTC

    You may use gensym to work around this particular issue. Have a look at rmtree (or verily _rmtree in a recent(2.0+) version of File::Path for One Way To Do It.

    • another intruder with the mooring in the heart of the Perl