Re: Nice-to-have class methods
On Wed, Jan 27, 2016 at 7:09 AM, Elizabeth Mattijsen wrote: >> On 27 Jan 2016, at 14:00, Tom Browder wrote: >> >> Given so many handy methods for built-in classes, it would be nice to have a >> couple of more for some, for instance: >> >> IO:Path.stemname >> Like basename except any suffix is removed > > Seems like a nice idea. I've found the pertinent bits and added necessary code (no docs or tests yet) in the Rakudo source, and I've filed a feature request via e-mail to . I've also made a pull request. But how does such a feature request really work when the Perl 6 spec, as I understand it, is frozen for now. Isn't a new method a spec change? Best regards, -Tom
RE: Nice-to-have class methods
From: Tom Browder [mailto:tom.brow...@gmail.com] > > Given so many handy methods for built-in classes, it would be nice to have a > couple of more for some, for instance: > > IO:Path.stemname > Like basename except any suffix is removed > > IO::Handle.say (or println) > Like print except with an added newline. A way to tell if an IO-type handle (so socket, filehandle, pipe etc) is seekable. [Apologies in advance if it already exists & I’ve missed it] Paul
Re: Nice-to-have class methods
On Wed, Jan 27, 2016 at 7:09 AM, Elizabeth Mattijsen wrote: >> On 27 Jan 2016, at 14:00, Tom Browder wrote: >> >> Given so many handy methods for built-in classes, it would be nice to have a >> couple of more for some, for instance: ... >> IO::Handle.say (or println) >> Like print except with an added newline. > > IO::Handle already has a .say ? Oops, the docs confused me. say is only mentioned as a role sub while print is mentioned as both method and role sub for IO::Handle. It works fine, though. Thanks, Liz. Cheers! -Tom P.S. Do you or any other Perl 6 developers plan to attend the recently-announced YAPC::NA in Orlando, Florida, in June? I hope so because I plan to attend only if there are significant Perl 6 events.
Re: Nice-to-have class methods
On Wednesday, January 27, 2016, Peter Pentchev wrote: > > On Wed, Jan 27, 2016 at 07:00:11AM -0600, Tom Browder wrote: > > Given so many handy methods for built-in classes, it would be nice to have > > a couple of more for some, for instance: > > > > IO:Path.stemname > > Like basename except any suffix is removed > > Hmm, this sounds like a nice idea on a first glance, but then again, > can you tell me exactly what situations would that be useful for? Well, for decades I have used Perl 5 File::Basename for getting the stem of a file name which I used in many automated data processing situations where the suffix indicates a type of product and the stem is, say, the project name. The docs show it done like this: my ($filename, $dirs, $suffix) = fileparse($path, @suffixes); where @suffixes can be a regular expression that includes all text after and including the last period. And any suffix is removed from the filename. > So a function that would remove *any* filename extensions, that is, > anything after and including the first dot, would produce really weird > results if applied to filenames created by such people. No, like IO:Path.suffix defines the suffix as at the last dot, stemname should consider the last dot. Thanks, Peter. -Tom
Re: Nice-to-have class methods
On Wed, 27 Jan 2016 14:14:17 +, Philip Hazelden wrote: > For a "convert files to $format" thing, you'd want to replace the > extension. You don't need to specify the previous extension(s) if it's a > quick-and-dirty thing where you know everything passed to it will be > acceptable; and you don't want to, if you're passing out to some other > service which can handle various input formats. (e.g. a wrapper around > ffmpeg or ImageMagick or something - they can handle a lot of filetypes > with a lot of likely extensions.) > > On Wed, Jan 27, 2016 at 1:43 PM Peter Pentchev wrote: > > > On Wed, Jan 27, 2016 at 07:00:11AM -0600, Tom Browder wrote: > > > Given so many handy methods for built-in classes, it would be nice to > > have > > > a couple of more for some, for instance: > > > > > > IO:Path.stemname > > > Like basename except any suffix is removed > > > > Hmm, this sounds like a nice idea on a first glance, but then again, > > can you tell me exactly what situations would that be useful for? > > Is it for compressed files (e.g. .zip vs .tar.gz) or MS-DOS/Windows > > executables (.com, .exe, .bat), or something else? > > When I strip filename extensions, I usually know exactly what extensions > > I want to strip - e.g. ".conf" or ".pl" or something like that. There > > are very, very rare cases when any extension should be stripped - and > > there's also a problem with that. tcsh has stackable modifiers % set s=/tmp/bar/foo.a.b.c.d.e.f % echo $s /tmp/bar/foo.a.b.c.d.e.f % echo $s:h /tmp/bar % echo $s:r /tmp/bar/foo.a.b.c.d.e % echo $s:r:r /tmp/bar/foo.a.b.c.d % echo $s:r:r:r /tmp/bar/foo.a.b.c % echo $s:r:r:r:r /tmp/bar/foo.a.b % echo $s:r:r:r:r:r /tmp/bar/foo.a % echo $s:r:r:r:r:r:r /tmp/bar/foo % echo $s:r:r:r:r:r:r:r /tmp/bar/foo % echo $s:r:r:r:r:r:r:r:r /tmp/bar/foo % echo $s:t foo.a.b.c.d.e.f % echo $s:t:t foo.a.b.c.d.e.f % echo $s:t:t:r foo.a.b.c.d.e > > You see, I was kind of surprised many years ago when I first met > > somebody who routinely used a dot as a word separator in filenames - > > a file that I would've called "yearly-report.txt" or "YearlyReport.txt", > > he would call "yearly.report.txt". Over the years after that, I > > stumbled into many other people who do that - not a majority, certainly, > > but, well, many people indeed. > > > > So a function that would remove *any* filename extensions, that is, > > anything after and including the first dot, would produce really weird > > results if applied to filenames created by such people. > > > > G'luck, > > Peter -- H.Merijn Brand http://tux.nl Perl Monger http://amsterdam.pm.org/ using perl5.00307 .. 5.23 porting perl5 on HP-UX, AIX, and openSUSE http://mirrors.develooper.com/hpux/http://www.test-smoke.org/ http://qa.perl.org http://www.goldmark.org/jeff/stupid-disclaimers/ pgpQrS7SNX6Xe.pgp Description: OpenPGP digital signature
Re: Nice-to-have class methods
On Wed, Jan 27, 2016 at 9:50 AM, Peter Pentchev wrote: > Right, so that would probably mean that you need a function that removes > the *last* extension; that might indeed make sense, although it's > trivial to implement as a regular expression substitution (but also beware > the case of a filename with no dots at all). > Or starting with a dot (Unix), or even all-dots (someone called it on . or .. for some reason). -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net
Re: Nice-to-have class methods
On Wed, Jan 27, 2016 at 02:14:17PM +, Philip Hazelden wrote: > On Wed, Jan 27, 2016 at 1:43 PM Peter Pentchev wrote: > > > On Wed, Jan 27, 2016 at 07:00:11AM -0600, Tom Browder wrote: > > > Given so many handy methods for built-in classes, it would be nice to > > have > > > a couple of more for some, for instance: > > > > > > IO:Path.stemname > > > Like basename except any suffix is removed > > > > Hmm, this sounds like a nice idea on a first glance, but then again, > > can you tell me exactly what situations would that be useful for? > > Is it for compressed files (e.g. .zip vs .tar.gz) or MS-DOS/Windows > > executables (.com, .exe, .bat), or something else? > > When I strip filename extensions, I usually know exactly what extensions > > I want to strip - e.g. ".conf" or ".pl" or something like that. There > > are very, very rare cases when any extension should be stripped - and > > there's also a problem with that. [snip my explanation of a problem with removing everything after the first dot] > > For a "convert files to $format" thing, you'd want to replace the > extension. You don't need to specify the previous extension(s) if it's a > quick-and-dirty thing where you know everything passed to it will be > acceptable; and you don't want to, if you're passing out to some other > service which can handle various input formats. (e.g. a wrapper around > ffmpeg or ImageMagick or something - they can handle a lot of filetypes > with a lot of likely extensions.) Right, so that would probably mean that you need a function that removes the *last* extension; that might indeed make sense, although it's trivial to implement as a regular expression substitution (but also beware the case of a filename with no dots at all). G'luck, Peter -- Peter Pentchev r...@ringlet.net r...@freebsd.org p...@storpool.com PGP key:http://people.FreeBSD.org/~roam/roam.key.asc Key fingerprint 2EE7 A7A5 17FC 124C F115 C354 651E EFB0 2527 DF13 signature.asc Description: PGP signature
Re: Nice-to-have class methods
For a "convert files to $format" thing, you'd want to replace the extension. You don't need to specify the previous extension(s) if it's a quick-and-dirty thing where you know everything passed to it will be acceptable; and you don't want to, if you're passing out to some other service which can handle various input formats. (e.g. a wrapper around ffmpeg or ImageMagick or something - they can handle a lot of filetypes with a lot of likely extensions.) On Wed, Jan 27, 2016 at 1:43 PM Peter Pentchev wrote: > On Wed, Jan 27, 2016 at 07:00:11AM -0600, Tom Browder wrote: > > Given so many handy methods for built-in classes, it would be nice to > have > > a couple of more for some, for instance: > > > > IO:Path.stemname > > Like basename except any suffix is removed > > Hmm, this sounds like a nice idea on a first glance, but then again, > can you tell me exactly what situations would that be useful for? > Is it for compressed files (e.g. .zip vs .tar.gz) or MS-DOS/Windows > executables (.com, .exe, .bat), or something else? > When I strip filename extensions, I usually know exactly what extensions > I want to strip - e.g. ".conf" or ".pl" or something like that. There > are very, very rare cases when any extension should be stripped - and > there's also a problem with that. > > You see, I was kind of surprised many years ago when I first met > somebody who routinely used a dot as a word separator in filenames - > a file that I would've called "yearly-report.txt" or "YearlyReport.txt", > he would call "yearly.report.txt". Over the years after that, I > stumbled into many other people who do that - not a majority, certainly, > but, well, many people indeed. > > So a function that would remove *any* filename extensions, that is, > anything after and including the first dot, would produce really weird > results if applied to filenames created by such people. > > G'luck, > Peter > > -- > Peter Pentchev r...@ringlet.net r...@freebsd.org p...@storpool.com > PGP key:http://people.FreeBSD.org/~roam/roam.key.asc > Key fingerprint 2EE7 A7A5 17FC 124C F115 C354 651E EFB0 2527 DF13 >
Re: Nice-to-have class methods
On Wed, Jan 27, 2016 at 07:00:11AM -0600, Tom Browder wrote: > Given so many handy methods for built-in classes, it would be nice to have > a couple of more for some, for instance: > > IO:Path.stemname > Like basename except any suffix is removed Hmm, this sounds like a nice idea on a first glance, but then again, can you tell me exactly what situations would that be useful for? Is it for compressed files (e.g. .zip vs .tar.gz) or MS-DOS/Windows executables (.com, .exe, .bat), or something else? When I strip filename extensions, I usually know exactly what extensions I want to strip - e.g. ".conf" or ".pl" or something like that. There are very, very rare cases when any extension should be stripped - and there's also a problem with that. You see, I was kind of surprised many years ago when I first met somebody who routinely used a dot as a word separator in filenames - a file that I would've called "yearly-report.txt" or "YearlyReport.txt", he would call "yearly.report.txt". Over the years after that, I stumbled into many other people who do that - not a majority, certainly, but, well, many people indeed. So a function that would remove *any* filename extensions, that is, anything after and including the first dot, would produce really weird results if applied to filenames created by such people. G'luck, Peter -- Peter Pentchev r...@ringlet.net r...@freebsd.org p...@storpool.com PGP key:http://people.FreeBSD.org/~roam/roam.key.asc Key fingerprint 2EE7 A7A5 17FC 124C F115 C354 651E EFB0 2527 DF13 signature.asc Description: PGP signature
Nice-to-have class methods
Given so many handy methods for built-in classes, it would be nice to have a couple of more for some, for instance: IO:Path.stemname Like basename except any suffix is removed IO::Handle.say (or println) Like print except with an added newline. Cheers! -Tom
Re: Nice-to-have class methods
> On 27 Jan 2016, at 14:00, Tom Browder wrote: > > Given so many handy methods for built-in classes, it would be nice to have a > couple of more for some, for instance: > > IO:Path.stemname > Like basename except any suffix is removed Seems like a nice idea. > IO::Handle.say (or println) > Like print except with an added newline. IO::Handle already has a .say ? $ 6 '$*OUT.say("hello world")' hello world Liz
Nice-to-have class methods
Given so many handy methods for built-in classes, it would be nice to have a couple of more for some, for instance: IO:Path.stemname Like basename except any suffix is removed IO::Handle.say (or println) Like print except with an added newline. Cheers! -Tom