in reply to Check if a file exists and if not create it

Learning is great. There are tons of modern packages that make this stuff really easy. Path::Tiny, for example, saved me a lot of headache just yesterday in a one-liners renaming a bunch of wget files that had query strings in the file names and couldn't be shared with a Windows user who needed them… I digress. One of many ways to do your task–

perl -MPath::Tiny -le 'path("ohai")->touch'

Replies are listed 'Best First'.
Re^2: Check if a file exists and if not create it
by Your Mother (Archbishop) on Aug 22, 2014 at 01:52 UTC

    Gonna reply to myself while I remember the digression because it was one of those MY LORD, I LOVE PERL moments–

    find . -type f | perl -MPath::Tiny -lne '/^(.+?)\?/ && path($_)->move($1)'

    Finds names like /this/was-not-a/good.aspx?idea=for&a%20filename and turns them into /this/was-not-a/good.aspx.