in reply to Re: Add Perl Varibles in system()
in thread Add Perl Varibles in system()

Normally when list context is needed you might say (my $s)=func_returning_list();, with the my on the inside.

Based on all the posts I've seen here, that's actually much rarer than my ($s). In fact, I rarely see (my $s). It's just too wordy. Compare

(my $x, my $y, my $z) = @_;
with
my ($x, $y, $z) = @_;

I was going to count the nodes with "(my" and count those with "my (", but I don't have a handy way of avoiding open(my $fh, ...). Despite that common construct seriously throwing off the count, "my (" still appears more often.

And of course, your code is subject to the shell equivalent of Bobby Tables.

Replies are listed 'Best First'.
Re^3: Add Perl Varibles in system()
by ahjohnston25 (Initiate) on May 12, 2009 at 20:50 UTC
    Thank you for your quick response. And the reason why  $target was written the way it was is because it was orginally going to be mutiple varibles, and I forgot to remove the paraentheses when I took ou the other varible. But now I have a different problem I want to the success of the program. This is what I believe will work:
    system( 'nmap', $ver, $os, $target ' -oG pentest.txt')=0 || print "Nma +p failed! $!"; exit1;
    But there is probably a better way to write that. Any suggestions?

      Bugs:

      • Missing comma
      • "-oG" and "pentest.txt" are separate args. You can't pass them as one.
      • The dash should be the start of the arg, not a space.

      You also introduced four bugs in the error handling!

      Fixed:

      system( 'nmap', $ver, $os, $target, '-oG', 'pentest.txt' ) or die "nmap failed" $!/$?\n";