Solved

how to open a file??

Posted on 2000-05-15
11
145 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:Dewaana
Comment Utility
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
Comment Utility
and please tell me how i can give u more points?? :)
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 19

Expert Comment

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

Author Comment

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

Author Comment

by:Dewaana
Comment Utility
thank u very much
0
 

Author Comment

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

Author Comment

by:Dewaana
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
OTRS Installation 1 276
HTTP Error 502.2 - Bad Gateway 3 197
collecting information 2 128
PERL - Find newest folder 12 101
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now