CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Re: [Divya] Not going thro' the loop: Edit Log



Kenosis
User

May 4, 2013, 2:26 PM


Views: 689
Re: [Divya] Not going thro' the loop

Perhaps the following will be helpful:

Code
use strict; 
use warnings;

FILE: for my $file (<>) {
push @ARGV, $file;
while (<>) {
if ( $. == 1 ) {
print;
}
elsif ( $. == 2 ) {
print substr $_, 10;
close ARGV;
next FILE;
}
}
}


Usage: perl script.pl scores.txt >outfile.txt

The script iterates through the names in scores.txt, pushing each onto Perl's @ARGV to let Perl handle the file i/o.

As a file's being read, if it's the first line, that line is printed. If the second, a substring of that line is printed, the current file is closed and the next file is processed.

The >outfile.txt notation directs output to a file. Omit that last parameter if you'd first like to see the results on the screen.


(This post was edited by Kenosis on May 4, 2013, 5:08 PM)


Edit Log:
Post edited by Kenosis (User) on May 4, 2013, 2:33 PM
Post edited by Kenosis (User) on May 4, 2013, 2:37 PM
Post edited by Kenosis (User) on May 4, 2013, 2:39 PM
Post edited by Kenosis (User) on May 4, 2013, 5:08 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives