ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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.
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;
}
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;
}
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.