|
|
#21 |
|
Guest
Posts: n/a
|
Ah, thanks again. I'm just curious about that trailing d though, in
$app=~tr/!$&\"'*()]}{[|;<>?~`\ //d; What does that do? Is this a regexp thing that I don't get yet? |
|
|
|
#22 |
|
Major Leaguer
Join Date: Jan 2002
Location: Adelaide, South Australia
Posts: 470
|
The "d" modifier to the "tr" operator means "delete any characters in the first chunk (ie between the first pair of forward slashes in the examples we've been using up to now) that don't have replacements listed in the second chunk. If you just leave the second chunk empty, as in
$app=~tr/!$&\"'*()]}{[|;<>?~`\ //; the default behaviour of "tr" is to replicate the search list in the replacement list (ie to act as if the second chunk contained everything in the first chunk). This has the useful side-effect of giving a quick way to count characters. #!/usr/bin/perl -w use strict; my $string = "A honking great piece of text with some newlines in it, and a plethora of a's"; my $count = ($string=~tr/a//); print $count; # prints 5 (there are five a's in the string) my $newlines = ($string=~tr/\n//); print $newlines; # prints 2 (there are two newlines in the string) ### BUT NOW### $string=~tr/\n//d; # adding in the delete modifier print $string; # Strips the newlines to produce the single line version of $string A honking great piece of text with some newlines in it, and a plethora of a's Cheers, Paul |
|
|
|
|
|
#23 |
|
Guest
Posts: n/a
|
The light of understanding is creeping in. Thanks!
|
|
|
|
#24 |
|
All Star
Join Date: Jan 2002
Posts: 534
|
After carefully reading through everything and making the necessary adjustments as described, it works flawlessly. Awesome, you're a wizard!
|
|
|
|
|
|
#25 |
|
Major Leaguer
Join Date: Jan 2002
Location: Adelaide, South Australia
Posts: 470
|
Thanks for the feedback thatch, and sorry that the road through this thread is both long and a little bumpy. Still, I guess it illustrates rather nicely the sort of nonsense that it takes to get a script in reasonable working order; warts and all.
For what it's worth, after a little experimentation I've found the "empty" version to be easily the most useful: that is, where spaces and quotes and ampersands and the like are replaced by nothingness. So /Applications/Utilities/Disk Copy.app/ is called by "diskcopy" and so forth. Underscores are too hard to type! Cheers, Paul |
|
|
|
|
|
#26 |
|
All Star
Join Date: Jan 2002
Posts: 534
|
The bumpy road provided an excellent learning experience for everyone. And it wasn't really all that rough anyhow. I enjoyed the ride. Tomorrow's journey may be the smoother for it all.
And, I agree that keeping the typing simple is the best course. In its refined state, this adventure is one to be proud of for sure. I hope many others partake in the thrill. You're very inspiring, Paul. I hope you never stop this behavior. It becomes you. Regards, thatch
|
|
|
|
![]() |
|
|