Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by monk2b (Pilgrim)
on Jun 08, 2001 at 01:46 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-25 07:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found