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

Hi, I need to make a loop to open several web pages.
* The issue I have is $i in the last line of the script below does not work. Any help is appreciated.
-------------------------------------------------
#!c:\perl\bin\perl -w use strict; my $i = 0; while ($i < 10) { $i++; print "$i\n"; system('"C:\Program Files\Internet Explorer\IEXPLORE.EXE" http://abc +.com/bbs?=x&b=x&mid=$i'); }

2005-02-22 Janitored by Arunbear - added code tags, as per Monastery guidelines

Replies are listed 'Best First'.
Re: need help with system command and single quote
by Zaxo (Archbishop) on Feb 22, 2005 at 08:44 UTC

    Single quotes do not interpolate variables. You need to make the second argument an argumenr with a comma, and to double-quote that string.

    system( 'C:\Program Files\Internet Explorer\IEXPLORE.EXE', "http://abc.com/bbs?=x&b=x&mid=$i") or next;
    There may still be problems with winders shell trickiness, but there shouldn't be.

    After Compline,
    Zaxo

Re: need help with system command and single quote
by lidden (Curate) on Feb 22, 2005 at 08:40 UTC
    Change it to:
    system('"C:\Program Files\Internet Explorer\IEXPLORE.EXE" http://abc.c +om/bbs?=x&b=x&mid='.$i);
    and it chould work.
Re: need help with system command and single quote
by Roy Johnson (Monsignor) on Feb 22, 2005 at 15:27 UTC
    Just a style note: the construct you have above -- iteration -- suggests a for loop:
    for my $i (1..10) { # print and system }

    Caution: Contents may have been coded under pressure.
Re: need help with system command and single quote
by rev_1318 (Chaplain) on Feb 22, 2005 at 09:05 UTC
    Any reason why you don't use something like LWP?

    Paul

      My guess is that LWP merely downloads the page, instead of displaying it nicely in a browser window. Some times, users want data displayed. Which is why I wrote HTML::Display.