Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: perl script

by kennethk (Abbot)
on Jan 12, 2017 at 19:35 UTC ( [id://1179461]=note: print w/replies, xml ) Need Help??


in reply to perl script

First, please read How do I post a question effectively?. In particular, please wrap code in <code> tags so that we can be sure your content doesn't get mangled. I'll be working with
my $ex = QA::STK::Execute->new(ip=>'some ip',user=>'root'); $ex->command("ls-l"); my $rc = $ex->execute(); my $output = $ex->output();
I cannot find any reference to a module called QA::STK::Execute, but I will make assumptions based on syntax. If you review the Basic debugging checklist, the first thing you should check is does $output contain what you think it does. printing is the easiest basic check. Given that you are running ls-l in your posted code and not ls -l (note the space), I'd bet you've got empty output.

Once you've verified that it seems reasonable, you can either use index as Corion suggested, or craft a regular expression. A regular expression has the advantage of anchoring to the end of a line, since you are looking for a file name. Maybe something like:

if (/\s\Q$xyz\E$/) { # Code to run }
The easiest way to deal with this is for you to post some example output from ls -l and then what you tried in order to find the file's name, all wrapped in <code> tags.

You will note that your lack of adherence to site expectations has garnered you down votes. Read the links, and see if they make sense. You can even edit your posts to fix them up.


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Replies are listed 'Best First'.
Re^2: perl script
by Anonymous Monk on Jan 12, 2017 at 22:05 UTC
    print index($output); my $ex = QA::STK::Execute->new(ip=>'some ip',user=>'root'); $ex->command("ls-l"); my $rc = $ex->execute(); my $output = $ex->output();
      What do you expect this code to do?
      1. index takes two arguments, and you have not indicated what to look for. What you've posted is a compile time syntax error.
      2. $output cannot have any value until after you assign it, so the print statement would need to be at the end.
      3. You did not follow my previous direction to wrap code in code tags.
      4. You still don't have a space in ls -l
      5. Your code will not pass strict with your placement of your print statement. See Use strict warnings and diagnostics or die.
      What do you get when you run:
      my $ex = QA::STK::Execute->new(ip=>'some ip',user=>'root'); $ex->command("ls-l"); my $rc = $ex->execute(); my $output = $ex->output(); print $output;
      Does your module have a capability to read STDERR?

      #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1179461]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-28 12:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found