Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Using UNIX commands inside Perl scripts, with Perl variables

by monk2b (Pilgrim)
on Jun 08, 2001 at 01:46 UTC ( #86771=note: print w/replies, xml ) Need Help??


in reply to Using UNIX commands inside Perl scripts, with Perl variables

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Re: Using UNIX commands inside Perl scripts, with Perl variables
by arturo (Vicar) on Jun 08, 2001 at 02:09 UTC

    Actually, that won't work. "." is the concatenation operator, and isn't part of a valid Perl identifier (variable name). Secondly, you're missing quotes on the right hand side of that assignment.

    perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'
Re: Re: Using UNIX commands inside Perl scripts, with Perl variables
by AYEq (Initiate) on Jun 08, 2001 at 04:43 UTC
    this may also work... (very little difference from above)
    system("cp","x.txt","$a_log.txt") && die("$!\n");

    if you "use strict" then you do need to declare $a somewhere in the file before you use it. Somebody else said that $a is a special variable so try to use something more descriptive.
Re: Re: Using UNIX commands inside Perl scripts, with Perl variables
by Anonymous Monk on Jun 08, 2001 at 02:01 UTC
    I have no UNIX prompt at my hand, so I cannot compile this ... but as far as I remember, it goes like this:

    I always use the pipe with the open command like this

    open(IN,"ls -l |");
    my @IN = <IN>;
    close IN
    Worx! The @IN array contains output from the system commando "ls -l" giving the file listing.
    Erik Østergaard
      I think Mr. Østergaard meant this:
      # Note -- bad way to do this open(IN, "ls -l |"); my @IN = <IN>; close(IN);
      For a better way of getting directory contents, see perlfunc:opendir and perlfunc:readdir.

      Which is a bit off-topic...

      stephen

        Nah, I meant this:
        # $command can be any system command, that would produce an acceptable output
        my $string = "my email is";
        my $dir = "/home/erik/*";
        my $command = "grep -ri '".$string."' ".$dir;
        open(IN, $command." |");
        my @IN = <IN>;
        close(IN);

        Better, Stephen? =) I agree, that opening dirs isn't the best purpose for this method.

        Erik

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2022-05-29 05:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (101 votes). Check out past polls.

    Notices?