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:
Storing search results in array

 



xlerator
Novice

Dec 7, 2011, 8:44 AM

Post #1 of 2 (1265 views)
Storing search results in array Can't Post

I have a search script that simply prints all instances of a search term given as an argument on the command line. Instead of printing, I'd like to store them in an array or something but haven't been able to find the right operator for IO::File. Any thoughts?


Code
#!/usr/bin/perl -w 

use strict;
use IO::File;


use constant FILE => 'File_1.htm';

use constant FIND => $ARGV[0];

IO::File->input_record_separator(FIND);

my $fh = IO::File->new(FILE, O_RDONLY)

or die 'Could not open file ', FILE, ": $!";

$fh->getline; #fast forward to the first match

#print each occurence in the file
print IO::File->input_record_separator

while $fh->getline;


$fh->close;



wickedxter
User

Dec 7, 2011, 12:37 PM

Post #2 of 2 (1228 views)
Re: [xlerator] Storing search results in array [In reply to] Can't Post

just use the push function to add the matching lines to an array

push @array, $something_to_add;


(This post was edited by wickedxter on Dec 7, 2011, 12:40 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