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
Solved

how to open a file??

Posted on 2000-05-15
11
174 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 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
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…

860 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