in reply to look for a word

Do I understand correctly that '/usr' may vary?

my @dirs; while (<>) { m/^The dir is '([^']*)' and there are \d* files/ and push @dirs, $1; }
If the match is successful, the bit captured by parentheses between quotes is pushed onto @dirs. I've left out file opening and such by using the default diamond op. Read from an open handle for better control.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: look for a word
by Anonymous Monk on Jun 09, 2005 at 05:32 UTC
    Hello, Thank you for the reply, Yes the '/usr' may vary. It could be any other dir too like '/var'.
      Hi again, I am a beginner in perl and am not able to work this out. In the following string "05/27/05 03:03:30 ANS1802E The dir is '/usr' and there are 23 files" I want to be able to push the /usr to an array. I am not sure how to use the search pattern in perl.
        look at the first answer in this thread (Re: look for a word). There you can find the solution...
        Your regex can small like this(be sure the string you need is inside ' ' as you shown us).......but all of them do the same job.....so its your choise.
        #!/usr/bin/perl -w use strict; my @match; while(<>){ push (@match,$1) if /'(.*)'/; }


        ``The wise man doesn't give the right answers, he poses the right questions.'' TIMTOWTDI