LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 04-30-2007, 05:19 AM   #1
noir911
Member
 
Registered: Apr 2004
Location: Baltimore, MD
Posts: 681

Rep: Reputation: Disabled
[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.

Last edited by noir911; 04-30-2007 at 05:24 AM.
 
Old 04-30-2007, 05:54 AM   #2
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 718

Rep: Reputation: 72
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
 
Old 04-30-2007, 06:28 AM   #3
noir911
Member
 
Registered: Apr 2004
Location: Baltimore, MD
Posts: 681

Original Poster
Rep: Reputation: Disabled
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;
}
 
Old 04-30-2007, 06:39 AM   #4
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 718

Rep: Reputation: 72
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
 
  


Reply

Tags
perl, wget


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
perl @INC variable nodger Programming 3 07-10-2006 11:17 PM
Perl wont print my Variable!!! socceroos Programming 10 03-15-2006 05:04 PM
Tainted variable problem (PERL) rajatgarg Programming 1 07-29-2004 01:54 PM
Perl variable string search ugenn Programming 1 05-07-2004 08:19 PM
question about $_ (default variable) in Perl realos Programming 4 07-04-2003 05:09 PM


All times are GMT -5. The time now is 08:31 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration