Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hello dk27,

What about some alternatives? Such as File::Find

#!/usr/bin/env perl use warnings; use strict; use File::Find; my $location="$var1/$var2/$var3/"; sub find_ksh { my $F = $File::Find::name; if ($F =~ /ksh$/ ) { print "$F\n"; } } find({ wanted => \&find_ksh, no_chdir=>1}, $location);

Or readdir:

opendir(my $dh, $some_dir) || die "Can't opendir $some_dir: $!"; my @files= map{s/\.[^.]+$//;$_}grep {/\.ksh$/} readdir DIR; closedir $dh;

Both solutions are untested but they should work straight out of the box.

Update: Also if you are running linuxOS or Cygwin terminal:

Update3: as monk haukex pointed out using back ticks is not a good option, read the link on his response bellow why.

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $path = shift || '.'; my @files = `find $path -name '*.ksh' -o -name '*.txt'`; chomp @files; print Dumper \@files;

WindowsOS with Cygwin:

my @files = `find $path \( -name '*.ksh' -o -name '*.txt' \)`;

Update2: Similar question with some maybe useful answers combining regex on search see (Re: File::Find find several strings in one directory).

Hope this helps.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: Use of special character "*" to retrieve the contents by thanos1983
in thread Use of special character "*" to retrieve the contents by dk27

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-19 17:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found