Joined March 2012
·
Posted to
Correctly opening a file in Perl
over 1 year
ago
Thanks for the feedback.
I made sure to only call open
if $filename isn't a falsey value, and to explain my reasoning behind die
in the protip
Posted to
Constants in Perl
over 1 year
ago
Thanks for the response. TIL taking a reference of a literal or a return value.
Const::Fast still provides faster access by removing the function call every time you access your constant.
Posted to
Exclude directory from grep, e.g. .git, .svn
over 1 year
ago
I tend to use ack. It's a great tool - definitely worth a look.
Achievements
538 Karma
52,593 Total ProTip Views
24PullRequests Participant
Sent at least one pull request during the first 24 days of December 2014
Beaver 3
Have at least three original repo where go is the dominant language
Beaver
Have at least one original repo where go is the dominant language
T-Rex 3
Have at least three original repos where C is the dominant language
Python
Would you expect anything less? Have at least one original repo where Python is the dominant language
Honey Badger
Have at least one original Node.js-specific repo
Epidexipteryx
Have at least one original repo where C++ is the dominant language
Altruist
Increase developer well-being by sharing at least 20 open source projects
Komodo Dragon
Have at least one original repo where Java is the dominant language
Velociraptor
Have at least one original repo where Perl is the dominant language
Velociraptor 3
Have at least three original repos where Perl is the dominant language
Walrus
The walrus is no stranger to variety. Use at least 4 different languages throughout all your repos
Forked
Have a project valued enough to be forked by someone else
Charity
Fork and commit to someone's open source project in need
T-Rex
Have at least one original repo where C is the dominant language
Lab
Have at least one original repo where C# is the dominant language
Raven
Have at least one original repo where some form of shell script is the dominant language
Calling
find
with -delete is probably faster, since you don't have to executerm
on each file, it just passes the filename directly tounlink(2)
.However it's definitely not safer.
My advice here is to switch to using the
xargs
command. One of the nicer things is that it will build the longest possiblerm
command and then execute that rather than doing it individually (like say if you were to loop over the output of find in a for loop), which decreases the number of times you callfork(2)
andexecve(2)
.Additionally, it's worth mentioning that @Kwpolska's solution is dangerous as well. If you have any files with spaces in the names, you'll get some unintended results.
xargs
(as well asrm
) will treat those as separate arguments and they won't be split properly.The way to get around that (provided you're using GNU
xargs
/find
(you probably are)) is to add the -0 flag toxargs
and -print0 to find. find will now delimit its output with NULL bytes, andxargs
will use the NULL byte as the delimiter instead of any space character.Your final command will look like:
Cheers