good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: While loop not printing anything after using grepby shmem (Chancellor) |
on Dec 30, 2020 at 00:24 UTC ( [id://11125958]=note: print w/replies, xml ) | Need Help?? |
My ultimate gall here is to search for the string 'Friday' in the file 'input.txt', if 'Friday' is missing, add'Friday' to 'input.txt on line 2. Just do it! But first a code review.
A filehandle is a filehandle, not the content of the file. In the while-loop you read the file line-wise, but you don't do anything but printing what you've read. Also, you don't look for line number 2. The line number read is stored in the perl special variable $. which you should test, if you want to add (append?) the string "Friday" to line two. Fix:
If you want inplace edit, you can place the directives for that after the first line of the script and omit the file opening and the while()-loop as well as the print statement. See perlrun. Read that.
Hope that helps (HTH).
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
In Section
Seekers of Perl Wisdom
|
|