Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: system command with arguments Error

by blue_cowdawg (Monsignor)
on Jan 07, 2013 at 19:15 UTC ( #1012095=note: print w/replies, xml ) Need Help??

in reply to system command with arguments Error

boo hiss! I hate seeing one Perl script calling another. Sloppy...

What might help you out is to do one of two things in descending levels of difficulty:

  • Convert the functionality of to a module
  • Convert the functionality of to a sub
In the first case you'd have to take the time to examine what does and write a module for it that does the same thing. Not quite as easy as just doing
$ cp
you'd actually have to wrap the logic in some fashion that makes sense. For instance, here's a small Perl script I want to convert.
#!/usr/bin/perl -w use strict; # # This is the main part of the script here... my ($parm1,$parm2,$parm3,$parm4)=@ARGV; func1($parm1,$parm2) $func2($parm3,$parm4) exit(0); sub func1{ #logic here. } sub func2{ #logic here } | | etc |
which could become:
package Cart; sub new { shift; my $self={}; bless $self,"Cart"; return $self; } sub doCart { my ($self,$parm1,$parm2,$parm3,$parm4)=@_; # main part of original script goes here } sub func1{ } sub func2{ } 1;
You could then invoke it as:
#!/usr/bin/perl -w use strict; use lib qw @ /path/to/directory/my/binary/runs/from @; use Cart; my $cart = new Cart(); | | hand waving | $cart->doCart($arg1,$arg2,$arrg3,$arrr_ahoy_matey); | | etcetera... |
the important part is the use lib part which causes Perl to look for your module where it lives. In this case I'm saying the same place the script lives. You could also do
use FindBin qw/ $Bin /; use lib "$Bin"; | etc

Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

Replies are listed 'Best First'.
Re^2: system command with arguments Error
by ansh batra (Friar) on Jan 07, 2013 at 19:41 UTC

      I was just wondering if it's in the same directory, maybe the permissions are not sufficient, and you should source the file?

      #!/usr/bin/perl use strict; use warnings; print system (qw/.\/ filename1.out/); print system (qw/.\/ filename2.out/);

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1012095]
[1nickt]: Is anyone using Method::Signatures ?
[choroba]: 10 bugs in the tracker?
[1nickt]: Yes, and recommendation against using it, in the doc for Devel::Declare, on whcih it is based.
[1nickt]: I asked the new $boiss what I should brush up on before starting work next week, and he named Moo, DBIx::Class and Method::Signatures
[1nickt]: choroba That's why I asked if anyone is using it :-)
choroba only has used Moo from the htree

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2017-11-24 13:21 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (349 votes). Check out past polls.