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

I'm using this code to get a url using LWP::Simple

one of the arguments I use is being input from command line when the perl script is starting. Since I'm using this script as a helper for a larger c++ app, there isn't much code:
#!/usr/bin/perl -w use LWP::Simple; use strict; my $word=$_; my $url="http://dictionary.reference.com/search?q=$word"; my $html=get $url; open(HTMLTRANS,">./htmlTransfer.lib"); print HTMLTRANS "$html"; close(HTMLTRANS);
thats all

when I run the script like this: perl getURL.pl test

I get the error uninitialized value in concatenation

I know the url I'm creating is correct, and I can't figure out where th error is coming from

any help?

Updated Steve_p - added code tags

Replies are listed 'Best First'.
Re: use of uninitialized value in concatenation
by William G. Davis (Friar) on Jan 04, 2005 at 02:55 UTC

    I think you want:

    my $word=shift;

    instead of:

    my $word=$_;

    Outside of a subroutine, shift removes the first element from the @ARGV array, which usually contains program arguments (like C and C++'s "argv" parameter to main()).

Re: use of uninitialized value in concatenation
by borisz (Canon) on Jan 04, 2005 at 02:58 UTC
    The error is
    my $word = $_; # I guess word is undefined here my $url="http://dictionary.reference.com/search?q=$word";
    perhaps you want my $word = $ARGV[0] || '';
    Boris
Re: use of uninitialized value in concatenation
by Zaxo (Archbishop) on Jan 04, 2005 at 03:00 UTC

    Try, my $word = shift; I doubt if $_ is defined at that point, and I figure you want to get it from @ARGV.

    You should also test the success of get.

    After Compline,
    Zaxo

Re: use of uninitialized value in concatenation
by tinita (Parson) on Jan 04, 2005 at 09:25 UTC
    additionally you can save opening the file yourself. getstore() instead of get() will do that for you.
    for explanation of errors/warnings it's always a good idea to look up perldiag