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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner: Re: [ogit2] moving to a certain line in perl: Edit Log

Veteran / Moderator

Oct 10, 2017, 11:16 PM

Views: 3324
Re: [ogit2] moving to a certain line in perl

Hi ogit2,

Congratulations for willing to help others even though, as you say yourself, you're a beginner. IMHO, this is a very good mind set and I am sure that with that spirit you'll become quickly a seasoned Perl programmer.

Just one quick note on your code:

In Reply To

my $data = join ('',<gdata>);
close (gdata);
#END : Read in script file to memory, ok if small files

# ...

#START: Split data into separate lines and store
my @lines=split(/\n/,$data);

In this code, you first store the content of the file into a scalar variable and then split this content into an array. You're making two copies of the content in memory, which is not very efficient (both from the standpoint of memory usage and time spent), especially if the file content is large. You can store the content directly into an array:

my @lines = <gdata>;


(This post was edited by Laurent_R on Oct 10, 2017, 11:18 PM)

Edit Log:
Post edited by Laurent_R (Veteran) on Oct 10, 2017, 11:18 PM: Added name of addressee for clarity

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

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