Solved

how to open a file??

Posted on 2000-05-15
11
188 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
[X]
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
  • 7
  • 3
11 Comments
 
LVL 19

Accepted Solution

by:
Kim Ryan earned 100 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
Independent Software Vendors: 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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

624 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