Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: how to use perl variable in system command to run on unix

by betterworld (Curate)
on Sep 03, 2013 at 16:58 UTC ( #1052144=note: print w/replies, xml ) Need Help??


in reply to how to use perl variable in system command to run on unix

Fwiw

use Path::Class qw(dir file); use Time::localtime; my $dirpath = dir("/waslogs1/vfoneLog/cposapp"); my $outfile = file("/home/cpos/CRM_Reports/output/filelist.txt")->open +w; my @names = grep { my $st = $_->stat or die $!; localtime($st->mtime)->mon == 8 && # 8 means September localtime($st->mtime)->mday == 3 } $dirpath->children; $outfile->print($_->basename, "\n") for @names; $outfile->close or die $!;

Ok, it's a bit longer. However you don't suffer any problems like

  • Incompatible versions of awk, ls
  • File names with spaces, or file names which have a date in them
  • Executable shell code in your $arr[2] variable
  • Flexible handling of error conditions like when one of those two path names is missing.
  • I think there is more

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1052144]
help
Chatterbox?
[Discipulus]: Eily adjust the shot: i'll be at seaside when it will happen
[Eily]: oh, I'll have to find something else then, don't want to litter the sea. Fireworks maybe?
Eily time to eat

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (10)
As of 2017-07-27 10:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (409 votes). Check out past polls.