Sponsored Content
Top Forums Shell Programming and Scripting Simple Question about Reading file by Perl Post 302572405 by durden_tyler on Thursday 10th of November 2011 01:00:12 AM
Old 11-10-2011
Quote:
Originally Posted by Damon_Qu
...
I just write a simple function to read the file line by line.
But when I run it it says out of memory.
I am not sure about the root cause, Can someone help me out of this?

Code:
#! /usr/bin/perl

use strict;

sub checkAPs{
        my $NDPDir = "/home/eweiqqu/NCB/NDP_files/";
        my $gsnFile = $NDPDir . "gsn.cbd";
        print $gsnFile."\n";
        my @aps = ();
        open Handler, $gsnFile or die "cannot open gsn.cbd";
        my @lines =<Handler>;
        while (@lines){
                push @aps, $3;
        }
        close(Handler);
        while (@aps){
                print $_." ";
        }
}

&checkAPs;

You are **NOT** reading the file line by line. You are storing the entire file contents into an array called @lines. So if your file is huge, the program will run out of memory.

tyler_durden
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl Reading from File

is there a perl equivalent to sscanf? or something where I get the strings separated by spaces? (1 Reply)
Discussion started by: karyn1617
1 Replies

2. Shell Programming and Scripting

perl: simple question on string append

I want to append a decimal number to a string. But I want to restrict the number to only 2 decimal points for e.g: my $output = "\n The number is = "; my $number = 2.3333333; $output = $output . $number; But I want the $output as: "The number is = 2.33"; and not 2.3333333 (I do not... (1 Reply)
Discussion started by: the_learner
1 Replies

3. Shell Programming and Scripting

Reading File from Server - perl

Hey, I'm trying to read a file from a server. Simple file with some numbers. Here is the code i'm running. use Net::SSH::Perl::SSH1 ; $scon = Net::SSH::Perl->new ("com123.sever.mydomain.com",(protocol=>'2',port=>'22',debug=>'true')); $scon->login("user123","pass123"); open(FILE,... (9 Replies)
Discussion started by: Phi01
9 Replies

4. Shell Programming and Scripting

perl - reading from a file conditionally

Hi, I am new to perl. I want to read from a file on the basis of some conditions.. I want to define parameters in a configuration file in such a manner like... etc.. in my perl script, theer is a variable like this.. then i want to read values from first if block from the file... (1 Reply)
Discussion started by: shellwell
1 Replies

5. Shell Programming and Scripting

PERL: simple comparing arrays question

Hi there, i have been trying different methods and i wonder if somebody could explain to me how i would perform a comparison on two arrays for example my @array1 = ("gary" ,"peter", "paul"); my @array2 = ("gary" ,"peter", "joe"); I have two arrays above, and i want to something like this... (5 Replies)
Discussion started by: hcclnoodles
5 Replies

6. Shell Programming and Scripting

Simple perl question

I am totally new to perl. I am modifying someone else's script. I have the following output: # ./some-perlscript A B C D E B - E, is generated through the print command that I put in the script. I want to remove A, it seems it is generated automatically by a custom OS it is querying when... (3 Replies)
Discussion started by: streetfighter2
3 Replies

7. UNIX for Dummies Questions & Answers

reading a file in Perl

If a form's action is the following Perl script how do I make it print the entire contents of the file on the screen? if(param()) { my $uploadedFile = param('file');#in the html page 'file' is the value of the name attribute of the input my $fh = upload($uploadedFile); ... (1 Reply)
Discussion started by: zerohour
1 Replies

8. Shell Programming and Scripting

"Simple" echo/reading variable question...

Hello, I have a simple(I think) question! Although simple, I have been unable to resolve it, so I hope someone can help! OK, here it is: 1)I have an awk script that prints something, such as: awk '{print $2}' a > x so x might hold the value of say '10' 2)Now, I just want to check to see if... (4 Replies)
Discussion started by: astropi
4 Replies

9. Shell Programming and Scripting

Simple Perl question

Hello, I'm completely new to Perl and I'm just looking for a quick answer to some code I'm trying to come up with. I'm trying to access a website, part of the URL I want the user to be able to define via standard input. As you can see below I'm still trying to get the syntax. ... (2 Replies)
Discussion started by: wxornot
2 Replies

10. UNIX for Dummies Questions & Answers

UNIX File reading question

Is there a script that will automatically access/count the words in each individual file for a program? (Sorry, I'm trying to help my girlfriend who's in computer science out, I know nothing about this. We're having trouble wording this question.) (1 Reply)
Discussion started by: Triple M
1 Replies
VCDXMINFO(1)							   User Commands						      VCDXMINFO(1)

NAME
vcdxminfo - manual page for vcdxminfo 0.7.24 SYNOPSIS
vcdxminfo [OPTION...] DESCRIPTION
-i, --generic-info show generic information -a, --dump-aps dump APS data --relaxed-aps relax APS constraints -o, --output-file=FILE file for XML output -p, --progress show progress -v, --verbose be verbose -q, --quiet show only critical messages --gui enable GUI mode -V, --version display version and copyright information and exit Help options: -?, --help Show this help message --usage Display brief usage message AUTHOR
Written by Herbert Valerio Riedel and Rocky Bernstein. http://www.gnu.org/software/vcdimager/ COPYRIGHT
Copyright (C) 2000-2003 Herbert Valerio Riedel <hvr@gnu.org> 2003 Rocky Bernstein <rocky@panix.com> This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. SEE ALSO
The full documentation for vcdxminfo is maintained as a Texinfo manual. If the info and vcdxminfo programs are properly installed at your site, the command info vcdxminfo should give you access to the complete manual. vcdxminfo 0.7.24 March 2011 VCDXMINFO(1)
All times are GMT -4. The time now is 02:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy