Home > Archive > Linux/Unix > February 2003 > What's wrong with this Perl script?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author What's wrong with this Perl script?
ccieToBe

2003-02-07, 1:20 pm

I'm writing a perl script that extracts information from mod_watch and presents it in a more human readable format. I've run into a problem that I can't figure out, so if any of you have any ideas, I'd appreciate it.

Here's the problem code (@domainsdata was defined earlier in the script):

code:
$dnumber = $#domainsdata; $tnumber = 4; while($tnumber <= $dnumber) { $domain=@domainsdata[$tnumber] ; system "/usr/bin/fetch -o /var/tmp/resources/watch-info http://$domain/watch-info"; $tnumber = $tnumber + 1; }


This portion of the script is supposed to download http://$domain/watch-info to /var/tmp/resources/watch-info. For some reason it's providing a directory index instead. If I edit the script, and replace $mydomain with the actual domain, it downloads fine.

Any ideas?
Mr. Linux Guy

2003-02-07, 1:52 pm

Try editing the script and print what is in your $mydomain variable just prior to executing the fetch . . . that might give you a hint as to what is fouling the script up.
ccieToBe

2003-02-07, 1:59 pm

The $domain variable is set to what it should be. I can subsitute "print" for "system", and it prints the exact command that I want to execute.
Mr. Linux Guy

2003-02-07, 3:05 pm

I recall reading something about the "exec" call which i think also applies to "system". If there is more than one argument in the list, the function calls some C routine (I think it's something like execvp), it bypasses the shell processing of the command. You might want to try scalarising this to avoid this problem (or at least rule it out as a possible error).
Mr. Linux Guy

2003-02-07, 3:21 pm

quote:
Originally posted by Mr. Linux Guy
I recall reading something about the "exec" call which i think also applies to "system". If there is more than one argument in the list, the function calls some C routine (I think it's something like execvp), it bypasses the shell processing of the command. You might want to try scalarising this to avoid this problem (or at least rule it out as a possible error).


I think this might be it . . . worth a try anyhow. See pp. 163-64, 230 in "Programming Perl". To fix this, try to scalarise: to reference an element in an array, prefix it with $ (for scalar) instead of @ (for array). If it were an array of arrays, then you would be correctly referring to the $tnumber-th array element in the @domainsdata array. But @domainsdata contains scalar elements, so when referring to a single element of @domainsdata, you use $domainsdata[$tnumber]. Try this and see if it helps.
ccieToBe

2003-02-07, 5:33 pm

That worked, thanks
Mr. Linux Guy

2003-02-07, 5:50 pm

Just called me Mr. Geek Guy!
Sponsored Links





Free Braindumps | MCSE braindumps software forum

Copyright 2003 - 2009 examnotes.net