473,597 Members | 2,726 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to open a text file for editing using perl

2 New Member
i am working on creating a Gui environment on a Ubuntu OS.

i have a .pl file.

i need to open a /run/auto.txt file for editing in a new window, so user can edit the file manually. You know if i was using vi editor, i would have vi /run/auto.txt and it will open auto.txt in a new window so i can edit and wq! when i am done.

Below is my code and i put some comments in the code so you can see where i want my file to be open.

Any help would be greatly appreciated.




Expand|Select|Wrap|Line Numbers
  1. sub beforeDrainRecoveryNotes
  2. {
  3.   $file = "$runDir/auto.txt";
  4.   while((my $key, my $value) = each %stationSelected)
  5.   {
  6.     if($value)
  7.     {
  8.  
  9.       if(my $pid = fork) { $pids{$pid}++; }
  10.       else
  11.       {
  12.       #  &runSysComm("$binDir/win $key");
  13.       #   This is where i want to open the auto.txt file in 
  14.       #   new window so user can edit this file. 
  15.       #   After editing is done, user will save and close the file
  16.       #   preferbally using wq!      
  17.  
  18.         CORE::exit();
  19.       }
  20.     }
  21.   }
  22.   printErr();
  23. }
May 11 '10 #1
5 4445
RonB
589 Recognized Expert Moderator Contributor
Why should the user use "wq" to save and close the file?

If you're creating a GUI, then you should have a menubar with a File dropdown like all other GUI's.

For editing the file, you need to use Perl's open function.
See: http://perldoc.perl.org/functions/open.html
May 11 '10 #2
numberwhun
3,509 Recognized Expert Moderator Specialist
@RonB He mentioned that that is what he does when editing with vi. That means that he probably has vi aliased to gvim (Graphical Vim), which still accepts the :wq to save and exit a file, but also has the "File" menu you mentioned.

Us Unix command line geeks still like our keyboard interface, even in the face of a gui. Its a nice added feature. :)
May 11 '10 #3
RonB
589 Recognized Expert Moderator Contributor
Jeff,

Ya, I knew that, I just wanted the OP to clarify what (s)he wants. I just made the same mistake, which was not making it clear what I was asking.

So, (usustarr) is this a Perl Tk GUI script, or are you wanting to use Perl to drive gvim? I've never tried, but it's probably possible to drive gvim, but that would be IMO the worst possible approach.
May 11 '10 #4
usustarr
2 New Member
@RonB
this piece of the code came from Gui environment.
1) i want to open this text file in a new window so a user (human) can edit. That part of the code needs to be located in side of that else statement.

2) when user done with editing i need a way to save and close this new window we opened. i prefer wq!, but i am open to any other ideas too.

i am new to Perl,. so i am having hard time with this. i know how to open a file for editing if editing was done by a script. Can you please help me out here?
May 20 '10 #5
RonB
589 Recognized Expert Moderator Contributor
We still seem to be dancing around the root of what you want, which means I don't have a clear picture of what you really want.

1) i want to open this text file in a new window so a user (human) can edit. That part of the code needs to be located in side of that else statement.
That tells me that you simply want Perl to launch gvim to edit your file.

2) when user done with editing i need a way to save and close this new window we opened. i prefer wq!, but i am open to any other ideas too.
That tells me that you want to use one of Perl's gui frameworks (possibly Perl/Tk) to create a gui that allows the user to modify the file and uses some of the (gvim) keyboard shortcuts to edit/save the file.

Those 2 approaches have entirely different solutions and requires completely different code base. Which do you want to do?

The ability to clearly state what you're doing and what you need will go a long way in us being able to suggest solutions.
May 21 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
107927
by: Jesper | last post by:
How can I open a textfile from C# using notepad (or the user assigned application for this).
3
4845
by: RN Das | last post by:
Hi expert, I have a small web application in C# and ASP.Net and I want to open a file in notepad when clicked on a linked button. Here is hander code when clicked on the link button. It can open a process of notepad on the server , but does not open the file in notepad. What am I doing wrong? can you show me how to do it please? What I am doing here is : I have datagrid data and when clicked on linkbutton (logFile), it finds the row...
2
1183
by: Jon | last post by:
I am trying to accomplish the following with a text file... 1 open the file 2 loop through it line by line 3 if need be, modify the current line 4 replace the old line in the file with the newly modified line 5 close the file I know how to do 1,2,3 and 5, but I'm not having any luck writing the modified line back to the file (preferably at the same position) and
3
7041
by: sohan | last post by:
hi I have hyperlink column in a datagrid. The column contains the name of a text file. I am able to appendthe full path of the file. The file is on D drive on the server. But on clicking on that hyperlink does not open the file. When I right click the link, I am able to save the file. I want the file to be opne in browser in a new window. I started a new webform and used a link
0
508
by: SimplySuzy | last post by:
Help I am trying to open a text file that I am naming dynamically through global variables in a dts package. When I print the file name to the screen, it is correct. When I use the dts package itself with this file name it opens only when I click on the elipsis, click on the file and click open. I have tried this with and without the text extension. I am trying a workaround by setting the properties of the text file in code and opening...
1
3143
by: sachin10 | last post by:
hi i m sachin, i m new to VB programming.i face some problem regarding the sorting of text file contents using arrays.text file have data in the format as below seq |consumerid|status1|status2|meter no1|meter no2|nameof consumer|routeno 234133210003040002222222222000003333333123098sasdcscasdsadsd9041 231433104000267232222278222000003333333123098shskdfkscasdsade9012 this is the format of text file.there are thosands of records in this...
3
1832
by: superc0red | last post by:
Hey, How i can open a text file using shellscripting, and new lines? for example i have the following text file: -------------------- Five Moroccans and a Syrian are charged with 191 murders and 1,755 attempted
6
4387
by: sainiamit25 | last post by:
Hi, I want to parse a file and from some of the attributes of this file, i want to create another file using perl. Can anybody suggest me a way out? It would be great if i dont have to use any module. Is it possible? Any sample code will be of a great help to me. Cheers, Amit
1
3157
by: sydmil | last post by:
Hello, I am relatively new to VB6 and I was wondering if anyone could show me an example of a VB6 code to do the following: Open text file (which is a column of numbers) in excel - comma delimited. Copy and paste file data into a specific location within another existing excel template. Save the excel template as a new excel file. Thanks for any info !
1
3964
by: hvivekw | last post by:
Hi, I would like to open a web page using Perl. I have a device on the internet whose web user interface I would like to open and subsequently automate some of the tabs on that web page. Is there any specific command for opening a webpage(if we know either the IP address or the DNS name like www.google.com) via Perl? Thanks.
0
7979
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8381
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6706
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5437
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3893
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3937
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2409
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1497
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.