Dewaana
asked on
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{'fmilea ge'};
$myvar = "Not Cancelled";
and i want to save or put them into a file
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{'fmilea
$myvar = "Not Cancelled";
and i want to save or put them into a file
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
$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
ASKER
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.
ASKER
and please tell me how i can give u more points?? :)
If you want to open your file and append contents to the end,
open(FH,">>values.txt");
open(FH,">>values.txt");
ASKER
and please tell me how i can give u more points?? :)
ASKER
thank u very much
ASKER
One more question for u Henrik, is it possible to call a C program from ur perl script??
ASKER
I am sorry, asking to many questions but am at the piont where don't know where i stand
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
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
ASKER
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