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: Beginner:
Pulling certain information

 



keith2045
Deleted

Jan 21, 2001, 2:46 PM

Post #1 of 4 (216 views)
Pulling certain information Can't Post

Hi

I have a txt file. And if i number every line is there a way where i can just pull 1 line of information? Like i want to pull line 53. What would i put in my script to pull line 53??

Thanks

Keith



japhy
Enthusiast

Jan 21, 2001, 2:59 PM

Post #2 of 4 (215 views)
Re: Pulling certain information [In reply to] Can't Post

Unless you know the specific byte offset of any given line (example: all lines are the same length), there is no O(1) way to skip to a certain line. You have to wade through the other lines of the file first.


Code
$wanted = 18; 

open FILE, $file or die "can't read $file: $!";
while (<FILE>) {
$line = $_, last if $. == $wanted;
}
close FILE;


Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author


keith2045
Deleted

Jan 21, 2001, 4:59 PM

Post #3 of 4 (212 views)
Re: Pulling certain information [In reply to] Can't Post

Ok so is the information form the file stored in $line???

Thanks

Keith



japhy
Enthusiast

Jan 21, 2001, 7:32 PM

Post #4 of 4 (207 views)
Re: Pulling certain information [In reply to] Can't Post

Since the variable is named $line, I'd think the answer to your question should be pretty obvious.


Code
use sense 'common';

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author

 
 


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

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