Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
XP is just a number
 
PerlMonks  

Opening external files with arguements

by void_Anthony() (Acolyte)
on Apr 28, 2005 at 11:25 UTC ( [id://452341]=perlquestion: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.

void_Anthony() has asked for the wisdom of the Perl Monks concerning the following question:

How would you open external files with specified arguements using perl code? I have tried open(), which does just fine but it will not let me type in arguements the way I thought it would. Any help is appreciated. P.S. --If someone can tell me as to how those arguements could be variables specified within the program, I would be very grateful.

Replies are listed 'Best First'.
Re: Opening external files with arguements
by blazar (Canon) on Apr 28, 2005 at 11:32 UTC
    Sorry, I can't understand what you mean. Care to expand?

    FWIW:

    #!/usr/bin/perl use strict; use warnings; my $file=shift or die "Usage: $0 <file>"; open my $fh, $file or die $!; print scalar <$fh>; __END__
    Can be used e.g. like thus:
    $ ./foo.pl 'ls|' 449133.pl
    (But then this is precisely the reason why I prefer the three args form of open() - there are situations in which you may want to do exactly the above, though!)
      some code... open("specified file" arguements?) ^Quotes not included ^I don't know some more code...
        some code... open("specified file" arguements?) ^Quotes not included ^I don't know some more code...
        Huh?!? Is this supposed to be Perl?

        Have you tried open?

        What should these "arguements" you keep talking about be?

      Three arguements form? Would you mind giving me a (simple) example?
        Three arguements form? Would you mind giving me a (simple) example?
        I must say i'm tempted to say: no! For I'm not here (and nobody is) to replace the best tool to answer this kind of questions, that is Perl's excellent documentation.

        However...

        open my $fh, '|-', "whatever" or die $!; # or open my $fh, '|-', "whatever", @more_args or die $!;
Re: Opening external files with arguements
by Transient (Hermit) on Apr 28, 2005 at 11:42 UTC
    Are you trying to pass arguments to a command? I don't see why you would be passing arguments to a "file" you want to read from.
      It is a simple test program. Basicically, whatever number is entered as the arguement, the program merely spits it back out. I want to be able to specify what arguements are passed to the program so I can get the appropriate output of that program and use it in my perl code. Preferably, I would like the arguement passed to be a variable I will have earlier declared in the code.
        Ahh, so you want to be able to call this program with arguments, then? Have you tried qx//?
        Then again open as of the documentation or "more simply" qx//, aka 'backticks', which personally I don't like. Remote chances are that you may be interested in IPC::Open2 or IPC::Open3 as well.
        It is a simple test program.
        Post your code. That will help a lot.


        holli, /regexed monk/

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://452341]
Approved by blazar
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.