in reply to Hashes or arrays in the command line

The code you posted will try to execute:
cp /home/wbill/lazarus/file1 file2 .
You probably want something like:
#! /usr/bin/perl use strict; use warnings; my @FILES = ('file1',' file2'); my $path = "/home/wbill/lazarus"; foreach my $this_file ( @FILES ) { `cp $path/$this_file .`; }
What the foreach does is take every item in the array @FILES and places it in the variable $this_file - which is then used in the backticks

More likely though you should consider using a module such as File::Copy rather than use backticks - it makes the code less platform dependent.

--tidiness is the memory loss of environmental mnemonics

Replies are listed 'Best First'.
Re: Re: Hashes or arrays in the command line
by EvdB (Deacon) on Nov 20, 2003 at 18:29 UTC
    You probably also want to change
    my @FILES = ('file1',' file2');
    to:
    my @FILES = ('file1', 'file2');
    note the removal of the space in front of file2.

    --tidiness is the memory loss of environmental mnemonics

Re: Re: Hashes or arrays in the command line
by tux242 (Acolyte) on Nov 20, 2003 at 18:47 UTC

    Ok I goofed the file is static like /etc/passwd and I am taking it from a backup sub directory and the server is the variable that changes not the file itself, so it should be like:

    #! /usr/bin/perl use strict; use warnings; my @SERVERS = ('sneezy','sleepy','dopey','grumpy'); my $path = "/home/backup/"; foreach my $this_server ( @SERVERS ) { `cp $path/$this_server/etc/passwd .`; }

    Does this lokk right??

      It looks fine.

      If you want to do a sanity check try doing this:

      foreach my $this_server ( @SERVERS ) { my $command = "cp $path/$this_server/etc/passwd ."; warn "Will execute '$command'\n"; # system ($command); # uncomment when ready. }

      --tidiness is the memory loss of environmental mnemonics