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

I am using the command "wget -q -nv -U "sonicbox/imtuner_build81 ($2)" 'http://mail.sonicbox.com:'$1'/tuner/SetZBand?UserID=testuser;StationNumber='$3'" for the shell and i am getting the result. How can i use this wget command in the perl script?

Replies are listed 'Best First'.
(bbfu)Re: How do i use the wget command in perl
by bbfu (Curate) on Jan 30, 2001 at 06:19 UTC

    Well, you could just use qx(): qx(wget -q -nv -U "sonicbox/imtuner_build81 ($2)" 'http://mail.sonicbox.com:'$1'/tuner/SetZBand?UserID=testuser;StationNumber='$3')

    Or back-quotes (``): `wget -q -nv -U "sonicbox/imtuner_build81 ($2)" 'http://mail.sonicbox.com:'$1'/tuner/SetZBand?UserID=testuser;StationNumber='$3'`

    Both of those will execute the external command and return the output as an array (1 line/index) or a scalar (all in one line with embeded newlines). See here for more information on qx() and ``.

    However, if you're interested in portability (not everyone may have wget installed on their system or have access to it) and this is for more than just a quick-and-dirty, one-use script, you might consider using the LWP module. LWP::Simple should do what you're looking to do with wget, or you can use LWP::UserAgent for more control.

    Your call. =)

    bbfu

Re: How do i use the wget command in perl
by Fastolfe (Vicar) on Jan 30, 2001 at 06:19 UTC
    If you're doing this in Perl anyway, why not do it the "correct" way and retrieve your URL via LWP:
    use LWP::Simple my $data = get("http://www.example.com/");
    It looks like you're going through a lot of headache getting things quoted on the command-line, when it's reasonably unnecessary.
Re: How do i use the wget command in perl
by BlueLines (Hermit) on Jan 30, 2001 at 06:12 UTC
    like this:
    #!/usr/bin/perl -w use strict; my $result = `your shell command here`; parseResult ($result); sub parseResult { #do your magic here }
    NoteThose are supposed to be backticks around "your shell command here", but for some reason today's mozilla build doesn't seem to display them as such. Are they showing up correctly for anyone?

    BlueLines

    Disclaimer: This post may contain inaccurate information, be habit forming, cause atomic warfare between peaceful countries, speed up male pattern baldness, interfere with your cable reception, exile you from certain third world countries, ruin your marriage, and generally spoil your day. No batteries included, no strings attached, your mileage may vary.