Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: search a particular file

by ungalnanban (Pilgrim)
on Mar 10, 2010 at 12:30 UTC ( #827773=note: print w/replies, xml ) Need Help??

in reply to search a particular file

See the following sample code.
it will match the file name starting with dump and followed by some text and ending with.txt
#!/usr/bin/perl use strict; use warnings; my @files = qw(dump123.txt abc dump124.txt 123 xyz 12dumpa.txt); foreach (@files) { if ( $_ =~ m/^dump.*txt$/) { print $_."\n"; } } <br>


Replies are listed 'Best First'.
Re^2: search a particular file
by raghu_shekar (Novice) on Mar 11, 2010 at 04:14 UTC
    Hi, Here find the piece of code im using.. pls tell me where im going wrong... i took all your advice and since glob din workout i did the last piece of code. here it is
    #!/usr/bin/perl $path = "path to the directory"; chomp($path); chdir($path); @lis = `ls`; foreach (@lis) { if ($_ =~ m/^dump*txt$/) #say the file i want is dump_234_129_15.txt { print $_."\n"; } }
    here the @lis has all the different files in the directory... but the specific file is not fetched..
      Hi All, I managed to find the mistake i was doing..U guys have been very very helpful.. i missed out the . if ($_ =~ m/^dump.*txt$/) in the if statement. So i guess the script was looking for a file starting with dump and ending with txt. but now its working fine.. Thanks a lot.. you guys rock.. will be back for more... :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://827773]
[atcroft]: Discipulus: I looked back at your note about my Padre question from a while back, and it made me look again... as a result, I found what I was missing and was able to make the change. Thank you!
[LanX]: maybe better /msg discipulus ?
[atcroft]: I thought I saw them on, and just wanted to let them know.
[LanX]: hmm ... or even better /msg /msg [discipulus]

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2018-02-24 20:35 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (311 votes). Check out past polls.