Create Directory, 'cd' to it and download a file pipeline in Perl

Posted by neversaint on Stack Overflow See other posts from Stack Overflow or by neversaint
Published on 2010-05-25T08:16:02Z Indexed on 2010/05/25 8:21 UTC
Read the original article Hit count: 194

Filed under:
|
|

I have a file that looks like this:

ftp://url1/files1.tar.gz dir1
ftp://url2/files2.txt dir2
.... many more...

What I want to do are these steps:

  1. Create directory based on column 2
  2. Unix 'cd' to that directory
  3. Download file with 'wget' based on column1

But how come this approach of mine doesn't work

while(<>) {
  chomp;
  my ($url,$dir) = split(/\t/,$_);
  system("mkdir $dir");
  system("cd $dir");   # Fail here
  system("wget $url"); # here too
}

What's the right way to do it?

© Stack Overflow or respective owner

Related posts about linux

Related posts about perl