By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,372 Members | 1,906 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,372 IT Pros & Developers. It's quick & easy.

trying to chomp a file by date factor

P: 12
Expand|Select|Wrap|Line Numbers
  1. 12 my $name = ls -l /home/grimp/tg`date +%d*`.doc;
  2. 13 my $dir = '/home/grimp/dump';
  3. 14 my $zip = Archive::Zip->new();
  4. 15 my $zipped;
  5. 16 my $new_dir = "/home/grimp/dump";
  6. 17 
  7. 18 chomp($name);
  8. 19 open IN, "< /home/grimp/$name" or die "Can't open $name : $!";
  9. 20
  10. 21 open (OUT,'>>tg_1');
  11. 22 $outcount = 1;
  12. 23
  13. 24
  14. 25 while (<IN>)    
  15. 26
  16. 27        { 
  17. 28
  18. 29    print OUT;

this is the error i am getting
Warning: Use of "-l" without parentheses is ambiguous at line 12.
Bareword found where operator expected at line 12, near "/home/grimp"
(Missing operator before rimp?)
Backticks found where operator expected at line 12, near "tg`date +%d*`"
syntax error at line 12, near "ls -l "
Jun 4 '09 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 100+
P: 589
Your solution to fixing the problem is in answering this question.

How do you execute an external command and capture its output?
hint: what are you doing with the date command?

There is no valid reason to spawn 2 shell commands just to get the desired filename.
Jun 5 '09 #2

P: 12
the bigest problem i am having with this is the file naming part. When the application that creates the file in the first place names it it is TGfollowed by the day then the hour then the minutes then the seconds which looks like this
tg02115413.doc the only referance that matters for my search is the tg and the day as i want to cron this and have it run automaticaly in the unix .sh the format would be tg`date +%d*`.doc but perl does not seem to like that from what i have read perl used mday for the day so how would i have this work in perl syntax
Jun 5 '09 #3

Expert Mod 100+
P: 589
The verbose and not very portable method:
Expand|Select|Wrap|Line Numbers
  1. my $date = `date +%d`;
  2. chomp $date;
  3. my $name = "/home/grimp/tg$date.doc";
The Perl way:
Expand|Select|Wrap|Line Numbers
  1. use POSIX qw/strftime/;
  2. my $name = strftime("/home/grimp/tg%d.doc", localtime);
Jun 5 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.