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: Beginner:
Extracting data from file and modifying without changing actual file

 



tej.87g
Novice

Aug 25, 2010, 10:24 PM

Post #1 of 3 (277 views)
Extracting data from file and modifying without changing actual file Can't Post

Hello,

I am working on a project in which i have to work on txt file and want to edit few things like tables in it and save as new file.

I am saving whole data in a variable (scalar)

from it i am extracting table with regex and because of which my original data is getting modified.

To extract table i am using


Code

  

$wholefile=~s/(pattern for table)/sub($&)/segx;






I want to save table in different scalar without modifying $wholefile, can anybody please tell me how to do it?


(This post was edited by tej.87g on Aug 26, 2010, 12:18 AM)


FishMonger
Veteran / Moderator

Aug 26, 2010, 5:27 AM

Post #2 of 3 (267 views)
Re: [tej.87g] Extracting data from file and modifying without changing actual file [In reply to] Can't Post


Code
$copywholefile = $wholefile; 
$copywholefile =~ s/(pattern for table)/sub($&)/segx;



tej.87g
Novice

Aug 26, 2010, 7:19 PM

Post #3 of 3 (256 views)
Re: [FishMonger] Extracting data from file and modifying without changing actual file [In reply to] Can't Post

I got the solution,

Instead of using substitution i did


Code
 if ($wholefile=~m/(pattern for table)/sgx) {my $table=$&;my $pre=$`;my $post=$';}



$& is storing whole data of table without modifying actual content.

 
 


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

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