Sponsored Content
Top Forums Shell Programming and Scripting Problem in perl program in printing all the entries Post 302651843 by pludi on Wednesday 6th of June 2012 08:59:10 AM
Old 06-06-2012
For readability, here's a formatted and numbered version:
Code:
  1 #!/usr/bin/perl
  2 $/ = "\n\n";
  3 open( DATA, 'mutationsonly.txt' );
  4
  5 # or die("Could not open mutationsonly file.");
  6 open( MYOUTPUT, ">newmutations.txt" );
  7
  8 # or die ("could not open newmutations file.");
  9 my @records = <DATA>;
 10 close(MYOUTPUT);
 11 close(DATA);
 12 foreach my $record (@records) {
 13     chomp;
 14     my $find = /^\*FIELD\*\sAV$/;
 15     if ( $record =~ m/ $find / ) {
 16         print "$record";
 17     }
 18 }

My guess is that in line 14 you're trying to assign a regular expression to a variable, and use that in the match below. To do that, you'd have to use the qr// construct, and it would be much more efficient to do that outside the loop, instead of each time again.

Other than that, you can probably do the same thing with a simple grep {}, eg
Code:
#!/usr/bin/perl
#$/ = "\n\n";
open( DATA, 'mutationsonly.txt' );

# or die("Could not open mutationsonly file.");
open( MYOUTPUT, ">newmutations.txt" );

# or die ("could not open newmutations file.");
my @records = <DATA>;
close(MYOUTPUT);
close(DATA);
print grep { /^\*FIELD\*\sAV$/ } @records;

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl printing error

Hi Scripting Gurus, I am new bee in perl, and trying to write a script which must print the free disk space availability of C and E drives. Please advice. Here is the script snippet and expected output: #!/usr/bin/perl use CGI qw/:html3 :standard/; $spaceuselog =... (4 Replies)
Discussion started by: ccsaviour
4 Replies

2. Shell Programming and Scripting

Problem using mailx instead of mail in perl program

I have a perl program that uses the mail program to send emails. It works fine but because I want to change the return address on the emails to be different I need to use mailx with the "-r" option. the problem is when I change this line to use mailx I no longer recieve "any" emails. This works... (1 Reply)
Discussion started by: kieranfoley
1 Replies

3. Shell Programming and Scripting

[Perl] Printing - Scalars

Hey Guys, I have some weird problem with printing scalars ... When I'm executing script both are printing in terminal ... But only one is printed to the file ? I don't know whats going on .. :) Btw .. I'm noobie :) took me lots of time to put this simple script together :) Thank you... (3 Replies)
Discussion started by: NDxiak
3 Replies

4. Shell Programming and Scripting

Printing between 2 matches with Perl

Can we please modify this perl one-liner to print lines between pattern1 and pattern2 in a file? Currently it prints lines till pattern2. (4 Replies)
Discussion started by: anand_bh
4 Replies

5. Homework & Coursework Questions

Calling compiled C program with Perl program

Long story short: I'm working inside of a Unix SSH under a bash shell. I have to code a C program that generates a random number. Then I have to call the compiled C program with a Perl program to run the C program 20 times and put all the generated random #s into a text file, then print that text... (1 Reply)
Discussion started by: jdkirby
1 Replies

6. Shell Programming and Scripting

help with perl database printing

Hey guys i am using perl and trying to pull a list of books from a database and then populate the list in a separate TT2 file. When the list is generated there should be 39 book names. When I do the foreach statement in my tt2 below, the first statement gives me 39 Array(random number) and the... (1 Reply)
Discussion started by: Joey12
1 Replies

7. Shell Programming and Scripting

Need help in Perl Script for printing next line

I got multiple of documents in which i have to extract a line coming after a ID..The scenario is Customer ID: none VT : 002/89 Customer ID: Yes VT: 001/89 Customer ID: none VT: 006/85 Customer ID: Yes VT: 003/56 I have to extract the id which is coming after YES..The output... (7 Replies)
Discussion started by: rajkrishna89
7 Replies

8. Shell Programming and Scripting

Creating Printing Program in bash

HI I am trying to create a bash script to print whatever i type in It has to have these below to define the size of the label and what size to print the text N q609 A100,10,0,5,2,2,N," " P1 It has to be sent to below > /dev/usblp0 So what it has to be is Written... (12 Replies)
Discussion started by: bganse
12 Replies

9. Shell Programming and Scripting

count number of entries perl program or Unix script

Hi I have a file with number of entries name 1 123 name 1 345 name 1 65346 name2 3243 name2 24234 name 2 234234 so on ......... how to count total number of entries for name 1 and name2...and so on Please guide. (1 Reply)
Discussion started by: manigrover
1 Replies

10. Shell Programming and Scripting

Perl program get a response before the program quits

I created a program, so a kid can practice there math on it. It dispenses varies math problems and the kid must input an answer. I also want it to grade the work they have done, but I can't find the best place for it to print out the grade. I have: if ( $response =~ m/^/ ) { $user_wants_to_quit... (1 Reply)
Discussion started by: germany1517
1 Replies
DlfStream(3pm)						  LogReport's Lire Documentation					    DlfStream(3pm)

NAME
Lire::DlfStream - Interface to DLF data stream SYNOPSIS
use Lire::DlfStore; my $store = Lire::DlfStore->open( "mystore" ); my $dlf_stream = $store->open_dlf_stream( "www", "r" ); print "Data begins on ", scalar localtime $dlf_stream->start_time(), " "; print "Data ends on ", scalar localtime $dlf_stream->end_time(), " "; while ( my $dlf = $dlf_stream->read_dlf() ) { ... } DESCRIPTION
This object encapsulates DLF stream. name Returns the schema's name of the DlfStream. mode() Returns the mode in which the DlfStream was opened. sort_spec() Returns the sort specification that is set on the stream. close() This method should be called when the Lire::DlfStream isn't needed anymore, otherwise the same DlfStream cannot be opened until then. nrecords() Returs the number of DLF records in the stream. start_time() Returns the timestamp of the oldest DLF record in the stream in seconds since the epoch. end_time() Returns the timestamp of the newest DLF record in the stream in seconds since the epoch. read_dlf() Returns an hash reference containing the next DLF record in the stream. It returns undef once the end of the stream is reached. This method will throw an exception if the DlfStream isn't open in 'r' mode or if there is an error reading the DLF record. read_dlf_aref() Returns the next DLF record in the stream as an array reference. The fields are in the order specified by the schema. This method will throw an exception if the DlfStream isn't open in 'r' mode or if there is an error reading the DLF record. write_dlf( $dlf, [ $link_ids ] ) Writes the fields contained in the hash ref $dlf to the DLF stream. This method will throw an exception if there is an error writing the DLF record or if the stream isn't opened in 'w' mode. The $link_ids parameter is used when the stream's schema is a Lire::DerivedSchema. It should be an array reference containing the DLF ids of the records which are linked to this record. clean( [ $time ] ) This method will remove all DLF records older than $time. It $time is omitted, all Dlf records will be removed. Lire 2.1.1 2006-07-23 DlfStream(3pm)
All times are GMT -4. The time now is 07:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy