Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Opening external files with arguements

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

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 Transient (Hermit) on Apr 28, 2005 at 15: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.
        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.
        Ahh, so you want to be able to call this program with arguments, then? Have you tried qx//?
        It is a simple test program.
        Post your code. That will help a lot.


        holli, /regexed monk/
Re: Opening external files with arguements
by blazar (Canon) on Apr 28, 2005 at 15: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!)
      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 $!;
      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?

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
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2024-04-18 13:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found