![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Industry Role:
Join Date: Jul 2004
Location: New York ICQ#348007554
Posts: 4,212
|
Any perl programmers here? have a question.
Don't ask why...long story.
Need to insert a line into an array to be written to file (or more accurately a file containing a list) So, example, I have a file containing: a b c d e f I need to insert z on the 4th line ex: a b c d z e f Any ideas? |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Too lazy to set a custom title
Industry Role:
Join Date: May 2004
Location: West Coast, Canada.
Posts: 10,217
|
ideas?? or do you want someone to write it for you.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Join Date: Jan 2007
Location: Vienna, Austria
Posts: 374
|
Code:
#!/usr/bin/perl -w use strict; my $INPUT = 'blabla.txt'; my $OUTPUT = 'blabla2.txt'; my $FOURTH_LINE = 'z'; open(my $fhi, $INPUT) or die "Cannot open $INPUT : $!"; open(my $fho, '>', $OUTPUT) or die "Cannot open $OUTPUT (writing): $!"; while (defined(my $line = <$fhi>)) { print $fho $line; print $fho $FOURTH_LINE, "\n" if ($. == 4); } close($fhi); close($fho) or die "Cannot close $OUTPUT : $!"; |
![]() |
![]() ![]() ![]() ![]() ![]() |