[pm-h] write to empty files

Michael R. Davis mrdvt92 at yahoo.com
Fri Jun 8 06:32:22 PDT 2018


 On Thursday, June 7, 2018, 11:42:26 PM EDT, rlharris at oplink.net <rlharris at oplink.net> wrote:
 > My need is to write a string to each file in a directory (the same string,> such as, "project xyz", needs to be written to each file).  The files have
> been created with "touch", run from a bash script; so the file length is
> zero.  My system is Debian.
No need for Perl when a simple Bash for loop will do.
 [temp]$ ls -ltotal 0-rw-rw-r--. 1 0 Jun  8 13:24 x.txt-rw-rw-r--. 1 0 Jun  8 13:24 y.txt-rw-rw-r--. 1 0 Jun  8 13:24 z.txt
[temp]$ for F in `ls`; do echo project.xyz > $F; done
[temp]$ ls -ltotal 12-rw-rw-r--. 1 12 Jun  8 13:24 x.txt-rw-rw-r--. 1 12 Jun  8 13:24 y.txt-rw-rw-r--. 1 12 Jun  8 13:24 z.txt
[temp]$ more *::::::::::::::x.txt::::::::::::::project.xyz::::::::::::::y.txt::::::::::::::project.xyz::::::::::::::z.txt::::::::::::::project.xyz
However, in Perl Path::Class::dir->spew is nice
[temp]$ perl -MPath::Class=dir -e '$_->spew("project.xyz2") foreach dir(".")->children;'
[temp]$ more *::::::::::::::x.txt::::::::::::::project.xyz2::::::::::::::y.txt::::::::::::::project.xyz2::::::::::::::z.txt::::::::::::::project.xyz2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/houston/attachments/20180608/193415d2/attachment-0001.html>


More information about the Houston mailing list