Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: handling files using regular expression

by hdb (Prior)
on Jun 28, 2013 at 13:54 UTC ( #1041259=note: print w/ replies, xml ) Need Help??


in reply to Re^2: handling files using regular expression
in thread handling files using regular expression

Just a few comments:

  • Your first while loop already runs through the whole file while not doing anything useful. Therefore the second while loop has nothing to do. Remove the first while loop altogether.
  • The statement while (<FILE>) of your second loop (now the only one...) will read a line at a time and assign it to $_. So you need to work with $_ within the loop block.
  • Your line $start =~ m/:(\d+)/; is applying the regex to the variable $start but you need to apply it to $_. Sou you might say $_ =~  m/:(\d+)/; which would work. It would be more Perlish to just say /:(\d+)/; as this would be applied to $_ by default.
  • The result of this match is that what was found in (...) is assigned to $1 so you need to write that to your file: print OFILE "$1\n";.
This is probably not all but if you re-read the earlier thread you should find more best practices.




Comment on Re^3: handling files using regular expression
Select or Download Code
Replies are listed 'Best First'.
Re^4: handling files using regular expression
by rocketperl (Sexton) on Jun 28, 2013 at 15:24 UTC
    Thank you so much. The code worked like a charm.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2015-07-30 10:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (271 votes), past polls