LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   [Perl] wget in variable (https://www.linuxquestions.org/questions/programming-9/%5Bperl%5D-wget-in-variable-550088/)

noir911 04-30-2007 05:19 AM

[Perl] wget in variable
 
I'm trying to write this script which will download a file but looks like it's not working. When I do "perl script.pl http://download" it shows the help message.

Can anyone tell me what's wrong? Here's the script. Thanks.

Code:


#!/usr/bin/perl

use strict;
use warnings;

my $wget='/usr/local/bin/wget';

my $fetch_file = $ARGV[1] || &usage;

system ($wget $fetch_file);

sub usage {
    print "\n";
    print "wgets source files and make RPMs\n\n";
    print "Usage: src_install.pl <source package>\n\n";
    exit;
}

Note: I don't want to use LWP:Simple as it's not on the core module list.

makyo 04-30-2007 05:54 AM

Hi.

I changed 1 to 0, and formed a string for the system call (and for display purposes made the system for echo, not wget):
Code:

#!/usr/bin/perl

# @(#) p1      Demonstrate system call.

use strict;
use warnings;

my $wget='/usr/local/bin/wget';
$wget = 'echo';

my $fetch_file = $ARGV[0] || &usage;

system ("$wget $fetch_file");

sub usage {
    print "\n";
    print "wgets source files and make RPMs\n\n";
    print "Usage: src_install.pl <source package>\n\n";
    exit;
}

which now produces:
Code:

% ./p1 some-url-of-your-choice.com
some-url-of-your-choice.com

Best wishes ... cheers, makyo

noir911 04-30-2007 06:28 AM

Hi.

Thanks for your code but it was just echoing and not doing the wget to download an URL. I just changed the ARGV to ARGV[0] and it's now going out to the Internet to download (wget) a file. Here's the new code

Code:


#!/usr/bin/perl

use strict;
use warnings;

my $wget='/usr/local/bin/wget';

my $fetch_file = $ARGV[0] || &usage;

system ("$wget $fetch_file");

sub usage {
    print "\n";
    print "wgets source files and make RPMs\n\n";
    print "Usage: src_install.pl <source package>\n\n";
    exit;
}


makyo 04-30-2007 06:39 AM

Hi, noir911.
Quote:

Originally Posted by noir911
Thanks for your code but it was just echoing and not doing the wget to download an URL. I just changed the ARGV to ARGV[0] and it's now going out to the Internet to download (wget) a file. Here's the new code

Yes, that's what I meant by "for display purposes", so that you could see the results of the changes. I'm sorry that I was not clear enough that you needed to remove the assignment of the echo statement.

Glad to hear it's working for you ... cheers, makyo


All times are GMT -5. The time now is 08:26 AM.