Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Perl script to delete files using regex

by GrandFather (Saint)
on Nov 24, 2020 at 00:52 UTC ( [id://11124099]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl script to delete files using regex
in thread Perl script to delete files using regex

For filtering lists grep is often used:

use warnings; use strict; opendir(my $dir, '.'); my ($file) = grep {$_ eq 'carlos.txt'} readdir($dir); closedir ($dir); print "$file <------------- Found File\n" if $file;
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Replies are listed 'Best First'.
Re^3: Perl script to delete files using regex
by Bod (Parson) on Nov 24, 2020 at 01:01 UTC

    Yes indeed - much nicer and much more Perl-ish!

    I deliberately didn't write it that way though so that CarlosN could (hopefully) understand what is going on.

      Clarity is rather in the eye of the beholder. But as a general thing smaller code (as long as it's not obfuscated) is easier to unpack. In this case there are two Perlish things that are likely to trip up a novice. The first is grep which is easy to find documentation for. The second is the list assignment which is kinda hard to formulate a good search for!

      The saving grace is for novices who don't know what they don't know the assignment looks kinda innocuous and it's likely their eyes just glaze over for a moment as they recognize it as a wobbly assignment and move on. For this example that's pretty much OK because the real lesson is filtering a list. That said, YMMV!

      Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11124099]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-24 22:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found