•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Perl section within the Software Development category of DaniWeb, a massive community of 391,559 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,743 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Perl advertiser:
Views: 2179 | Replies: 9
![]() |
•
•
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 174
Reputation:
Rep Power: 1
Solved Threads: 20
•
•
•
•
hi
i want to write all the elements of an array to a file to generate a report
i tried the following code.
foreach(@main_time)
{
system("echo \"@{$_}\" 1>> $file_name 2>&1");
}
But the its not writing into the file.
please suggest me how to do this
Why are you using 'system' to write to a file? Have you not heard of Perl's file managing functions? Have you read any documentation about this?
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
"Others make web sites. We make web sites work!"
•
•
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 174
Reputation:
Rep Power: 1
Solved Threads: 20
•
•
Join Date: Oct 2007
Location: Russia, St-Petersburg
Posts: 8
Reputation:
Rep Power: 0
Solved Threads: 0
http://perldoc.perl.org/functions/open.html
for example, your code should be like the following:
Perl Syntax (Toggle Plain Text)
foreach ( @main_time ) { open FH, ">>$file_name" or die "can't open '$file_name': $!"; print FH $_; close FH; }
Last edited by cerf_machine : Oct 16th, 2007 at 7:36 pm.
•
•
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 174
Reputation:
Rep Power: 1
Solved Threads: 20
•
•
•
•
http://perldoc.perl.org/functions/open.html
for example, your code should be like the following:
Perl Syntax (Toggle Plain Text)
foreach ( @main_time ) { open FH, ">>$file_name" or die "can't open '$file_name': $!"; print FH $_; close FH; }
What you mean, I'm sure is
open FH, ">>$file_name" or die "can't open '$file_name': $!"; # <<<< outside the loop
foreach ( @main_time )
{
print FH $_;
}
close FH; # <<<<<<<< outside the loopAnd nowadays, the '3-argument' with lexical file handle syntax is suggested:
open my $FH,'>>',$file_name' or die "Can't open $file_name: $!";
Last edited by trudge : Oct 16th, 2007 at 8:27 pm.
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
"Others make web sites. We make web sites work!"
•
•
Join Date: Oct 2007
Location: Russia, St-Petersburg
Posts: 8
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 174
Reputation:
Rep Power: 1
Solved Threads: 20
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
"Others make web sites. We make web sites work!"
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Perl Marketplace
Similar Threads
- deleting array elements (C)
- user input and arrays (Visual Basic 4 / 5 / 6)
- Trying to creating an array from a text file (C++)
- Help with a 2D array from a text file (C++)
- save ARRay elements to a file (C++)
- how do i call an .exe file from perl script (Perl)
- Getting an array from a txt file (C)
Other Threads in the Perl Forum
- Previous Thread: Return values from Perl to asterisk
- Next Thread: Correct my code plz


i wrote it at deep night
Linear Mode