CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Re: [raghupise] Pattern seacrh in Perl and redirecting to other file: Edit Log



Chris Charley
User

Oct 15, 2013, 5:09 PM


Views: 6442
Re: [raghupise] Pattern seacrh in Perl and redirecting to other file

Hello Raghu,

The changes you made have made the program unworkable. I revised my program, 't7.pl' to read and write to and from the files you want. 't7.pl' gives the correct results.

I am pretty sure you don't understand the program or else you wouldn't have made the changes to it.

Try running my program as is, and then ask questions about what you don't understand.

Chris

Update: One reason your approach isn't working is that you are processing the file line by line. My program reads in a paragraph at a time instead. That's what the local $/ = ''; statement does. It changes the line endings from '\n' effectively to '\n\n+'. So the whitespace separating the different sections of your CSD.txt file act as 'line endings'. The program reads in these chunks rather then line by line.

Your reading the lines into an array defeats this method. You need to read a chunk at a time using the while loop.

Hope this sheds some light on what is happening.

Update 2: After thinking about it, you could read all the file into an array rather than using a while loop, but it would be necessary to read the file into the array where the input record separator is set to 'paragraph' mode, $/ = ''. It would probably be easier though to just use the program as is with the while loop, (unless you know where to read the file into an array to get the right effect).


(This post was edited by Chris Charley on Oct 15, 2013, 7:41 PM)


Edit Log:
Post edited by Chris Charley (User) on Oct 15, 2013, 5:14 PM
Post edited by Chris Charley (User) on Oct 15, 2013, 5:27 PM
Post edited by Chris Charley (User) on Oct 15, 2013, 5:28 PM
Post edited by Chris Charley (User) on Oct 15, 2013, 7:41 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives