Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to open a file??

Posted on 2000-05-15
11
Medium Priority
?
192 Views
Last Modified: 2010-03-05
I am not sure if there is a way, but nothing wrong asking :)

I was just wondering if there is a way in perl to open up a file and save the values read in from a from in that file?? for example

i have these values


fid=$cgivars{'flightid'};
$aid=$cgivars{'airplaneid'};
$org=$cgivars{'org'};
$dest=$cgivars{'dest'};
$ddate=$cgivars{'ddate'};
$dtime=$cgivars{'dtime'};
$adate=$cgivars{'adate'};
$atime=$cgivars{'atime'};
$fmileage=$cgivars{'fmileage'};
$myvar = "Not Cancelled";

and i want to save or put them into a file
0
Comment
Question by:Dewaana
  • 7
  • 3
11 Comments
 
LVL 19

Accepted Solution

by:
Kim Ryan earned 400 total points
ID: 2813299
Yes, should be quite simple

open(FH,">values.txt");
print(FH "$fdi\n"); # include line terminator
....etc
print(FH "$myvar\n");
close(FH);
0
 

Author Comment

by:Dewaana
ID: 2813348
thanks a lot :)
one quick question, if i open this file again to add to it. Is that possible, or is it going to over write on what i have already save here
0
 

Expert Comment

by:hv
ID: 2813364
The following will open the file 'data.out', write the variable
$out into it, and close it again.
The pointer name choosen for the file,
OUT, is arbitrary.
 

open(OUT,">data.out");
print OUT "$cgivars{"flightid"}\n";
....
close(OUT);

This opening statement will overwrite
an eventual existing file of that name,
the > indicates the file is open for
writing.  Many options exists, both
concerning opening for input and/or output, and for positioning, if for example you want to write at the end of an existing file.  If you want to
open and read and existing file, then
write to it, you can open it as

open(OUT,"+<data.out");

you may use the "seek" command to
position yourself within the file
before writing into it. In particular
"seek(OUT,0,2);" will position you at the end of the file, where you may add new info to the file without overwriting the existing part of it.

regards,/ henrik



0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Dewaana
ID: 2813366
well actually i should be using C or c++ to take care of things. but have no clue how that works. Been working on that but not making much sense. Looking at couple of exapmles but not to clear. Maybe u can refer me to some book or some site where it is explained in a little details.
0
 

Author Comment

by:Dewaana
ID: 2813376
and please tell me how i can give u more points?? :)
0
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 2813386
If you want to open your file and append contents to the end,
open(FH,">>values.txt");
0
 

Author Comment

by:Dewaana
ID: 2813391
and please tell me how i can give u more points?? :)
0
 

Author Comment

by:Dewaana
ID: 2813392
thank u very much
0
 

Author Comment

by:Dewaana
ID: 2813406
One more question for u Henrik, is it possible to call a C program from ur perl script??
0
 

Author Comment

by:Dewaana
ID: 2813413
I am sorry, asking to many questions but am at the piont where don't know where i stand
0
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 2815351
Don't really understand your last comment about where you stand. If you want to offer more points, post a new question and title it point for hv, or points for teraplane, and refer back to this question.

You can make a call from Perl to any other external program (C or otherwise) just by saying
system("extern_prog");
If the program takes arguments these should be supplied as well
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

927 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