how to open a file??

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
DewaanaAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Kim RyanConnect With a Mentor IT ConsultantCommented:
Yes, should be quite simple

open(FH,">values.txt");
print(FH "$fdi\n"); # include line terminator
....etc
print(FH "$myvar\n");
close(FH);
0
 
DewaanaAuthor Commented:
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
 
hvCommented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
DewaanaAuthor Commented:
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
 
DewaanaAuthor Commented:
and please tell me how i can give u more points?? :)
0
 
Kim RyanIT ConsultantCommented:
If you want to open your file and append contents to the end,
open(FH,">>values.txt");
0
 
DewaanaAuthor Commented:
and please tell me how i can give u more points?? :)
0
 
DewaanaAuthor Commented:
thank u very much
0
 
DewaanaAuthor Commented:
One more question for u Henrik, is it possible to call a C program from ur perl script??
0
 
DewaanaAuthor Commented:
I am sorry, asking to many questions but am at the piont where don't know where i stand
0
 
Kim RyanIT ConsultantCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.