473,480 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Create 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 4440
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
107903
by: Jesper | last post by:
How can I open a textfile from C# using notepad (or the user assigned application for this).
3
4834
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...
2
1170
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...
3
7021
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...
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...
1
3130
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...
3
1825
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...
6
4377
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...
1
3150
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...
1
3947
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...
0
7037
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,...
0
6904
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7032
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
6873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5321
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,...
0
4471
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...
0
2990
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...
0
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
174
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...

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.