Re: How to I create a file?
On 03/21/2017 04:27 AM, Philip Hazelden wrote: $PathAndName.IO.f or $PathAndName.IO.open(:w).close; Note, the following sequence is possible: 1. .IO.f returns false 2. Someone creates the file and writes some data to it 3. .IO.open truncates the file Thus, this has a chance of editing the file. I suggest instead (untested): $PathAndName.IO.open(:a).close :a (append) will create the file if it doesn't exist, but will not truncate it if it does. There's no need to check first whether the file exists. Thank you! You guys are spoiling me!
Re: How to I create a file?
> $PathAndName.IO.f or $PathAndName.IO.open(:w).close; Note, the following sequence is possible: 1. .IO.f returns false 2. Someone creates the file and writes some data to it 3. .IO.open truncates the file Thus, this has a chance of editing the file. I suggest instead (untested): $PathAndName.IO.open(:a).close :a (append) will create the file if it doesn't exist, but will not truncate it if it does. There's no need to check first whether the file exists. On Tue, Mar 21, 2017 at 11:08 AM ToddAndMargowrote: > On 03/21/2017 04:02 AM, Simon Proctor wrote: > > It's a logical test but I'd probably use || instead. > > Thank you! >
Re: How to I create a file?
On 03/21/2017 04:02 AM, Simon Proctor wrote: It's a logical test but I'd probably use || instead. Thank you!
Re: How to I create a file?
It's a logical test but I'd probably use || instead. See : https://docs.perl6.org/language/traps#Loose_boolean_operators On Tue, 21 Mar 2017 at 10:56 ToddAndMargowrote: > On 03/21/2017 03:07 AM, Brent Laabs wrote: > > $PathAndName.IO.f or $PathAndName.IO.open(:w).close; > > Is that a coding "or" or an English "or"? > > > > -- > ~~ > Computers are like air conditioners. > They malfunction when you open windows > ~~ >
Re: How to I create a file?
On 03/21/2017 03:07 AM, Brent Laabs wrote: $PathAndName.IO.f or $PathAndName.IO.open(:w).close; Is that a coding "or" or an English "or"? -- ~~ Computers are like air conditioners. They malfunction when you open windows ~~
Re: How to I create a file?
On 03/21/2017 03:50 AM, Simon Proctor wrote: .e checks a path exists. .f checks it exists AND is a file. .d checks it exists AND is a directory. (Perl 5 was the -e, -f and -d tests) Beautiful explanation! Thank you! Perl 5 has the (about) same test as bash and I write a lot in that too. (I am trying to move all my new programming into Perl 6 and stop with bash and Perl 5.) -T
Re: How to I create a file?
.e checks a path exists. .f checks it exists AND is a file. .d checks it exists AND is a directory. (Perl 5 was the -e, -f and -d tests) On Tue, 21 Mar 2017 at 10:19 ToddAndMargowrote: > On 03/21/2017 03:07 AM, Brent Laabs wrote: > > You can create a file by opening a filehandle for writing. > > > > $PathAndName.IO.f or $PathAndName.IO.open(:w).close; > > > > What does the .f do? > > > > -- > ~~ > Computers are like air conditioners. > They malfunction when you open windows > ~~ >
Re: How to I create a file?
On Tue, Mar 21, 2017 at 3:01 AM, ToddAndMargo> wrote: Hi All, How to I do this bash code in Perl 6? if [ ! -f "$PathAndName" ]; then touch "$PathAndName" fi I am not finding the directions on how to create a "new" file at a specific location. Many thanks, -T On 03/21/2017 03:07 AM, Brent Laabs wrote: You can create a file by opening a filehandle for writing. $PathAndName.IO.f or $PathAndName.IO.open(:w).close; Hi Brent, Oh, so the act of opening it will create it, if it doesn't exist. Thank you! -T
Re: How to I create a file?
You can create a file by opening a filehandle for writing. $PathAndName.IO.f or $PathAndName.IO.open(:w).close; On Tue, Mar 21, 2017 at 3:01 AM, ToddAndMargowrote: > Hi All, > > How to I do this bash code in Perl 6? > > if [ ! -f "$PathAndName" ]; then touch "$PathAndName" fi > > I am not finding the directions on how to create a "new" > file at a specific location. > > > Many thanks, > -T > > -- > ~~ > Computers are like air conditioners. > They malfunction when you open windows > ~~ >
How to I create a file?
Hi All, How to I do this bash code in Perl 6? if [ ! -f "$PathAndName" ]; then touch "$PathAndName" fi I am not finding the directions on how to create a "new" file at a specific location. Many thanks, -T -- ~~ Computers are like air conditioners. They malfunction when you open windows ~~