running some code within a script prior to running next pl

Posted on 1997-12-28
Last Modified: 2013-12-25
I have written a perl script that retrieves the mail headers of a user. I now want to click on the header to view the message... EASY! but!!! I don't want to re-login to the mail server (which u would have to do if u run a separate perl script when u click on the header)... SO, is there a way you can click on a "link-like" text (ie. text which is underlined so u know when u click on it u will go view your message) but have the current perl script retrieve you mail then and there and then run the next perl script with the data sent to it via POST... thereby defeating the need to relogin to your mail server...??? this question is very difficult to explain so if you are confused tell me where and I will try and clarify that part...
Question by:ramsay
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3

Accepted Solution

icd earned 360 total points
ID: 1831761
The only way to avoid logging onto the mail server again would be to retrieve the mail message at the same time as the header.

For each header retrieved there would be a local file stored which holds the message contents.

When the user clicks on the message header, rather than connect to the mail server it simply retrieves the message content previously stored in the local file store.

To answer this question more specifically then more information would need to be given, such as the details of the script you are using, what server you are running on etc.

Author Comment

ID: 1831762
I thought of the same approach.. but it is a poor solution because retrieving the mail headers should just be that. Retreiving the whole message would take considerably longer than just the header especially when you mailbox had quite a few messages too... Hence the solution I am striving towards requires some way I can click on a header.. and before the next page arrives via the next cgi I want to read the mail then and there and then process the link... ***OR*** is there some way I can pass to my next CGI the connection details so in my next cgi I still have the same connection to the server...?? Here are some more details:

POP3 Server.. connected via:

socket(SOCK, &PF_INET, &SOCK_STREAM, $proto);
connect(SOCK, pack($sockaddr, &PF_INET, $port));
select((select(SOCK) , $| = 1)[0]);

... the problem is now when I call my next CGI I lose the connection to my POP3 server and have to connect again... I want to avoid this... and I can only see 2 ways of doing so.. sending some info to the 2nd cgi so it can remain connected to the mail server OR somehow do the processing before I run the next cgi BUT after a header has been selected..


Expert Comment

ID: 1831763
Unfortunately cgi is stateless, although you can pass data from one script to the next you cannot pass file handles. As each script terminates all file handles are closed. Socket connections would be treated in the same way.

The only way I can see to do this is to have a daemon process running in the background which handles the socket connection. Your scripts would then open a pipe to the daemon to, for example, request headers or message bodies. This is not something I have ever done myself so I can't comment on the technicalities.

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.


Author Comment

ID: 1831764
cookies? You know anything about them? I hear they could be a solution...?

Expert Comment

ID: 1831765
It does not matter what method you use to pass data from one cgi script to the next, it still applies that file handles and allocated memory, buffers etc will all be freed at the end of a cgi script. You can't pass a file handle from one script to another unless a third process, which remains running, holds it open. I understand that socket connections work in the same way.

Cookies can also be a problem since there seems to be a backlash against their use with some people turning them off or disabling them.

Author Comment

ID: 1831766
True... I've decided to use cookies because I actually got it working successfully first try and it didn't cause any problems... Cool! for all those people who may read this in the future go to Matt's archive and download the cookie.lib file! Cookies allow you to communicate between CGIs!!!
Thanx for yer help icd!


Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Questions about this React unit test 4 70
How can i open a .fxp file 3 50
Find unused columns in a table 12 68
debug scriptblock parameters in powershell script 2 21
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question