in reply to reading from a text file

Try something like this (simple though)
#!/usr/bin/perl -w use strict; open(F,"test.txt"); foreach(<F>){ if ($_ =~ /.*(\d\d).*(\d\w+)/){ print "$1 : $2 \n"; } } close F;


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

Replies are listed 'Best First'.
Re^2: reading from a text file
by samy_kumar (Scribe) on Jun 07, 2005 at 12:13 UTC
    if ($_ =~ /.*(\d\d).*(\d\w+)/){
    I think you might have forgot that \w indeed accepts digits.
    
    -madasamy-
    
      No i didn't forget.
      But its either a '\d' inside the '()' like this (\d\w+)
      or a '\s' outside like this \s(\w+)
      Do you see any big difference?
      Cause if you don't use either of them and write it like this
      ($_ =~ /.*(\d\d).*(\w+)/)
      Then the only thing that $2 will have inside, will be a single 'T'.
      So i suggest you study a bit of regex more, before coming to conclusions

      ``The wise man doesn't give the right answers, he poses the right questions.'' TIMTOWTDI
      The only thing you can take out is the first ' .* '
      Which i put there for educational reasons, cause the guy doesn't know too much of regex, so there is no need to give him a hard time, yet.

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