Error check help

Hi everyone,

I have written a code that takes in two files (containing a set of 
terms) as arguments
  eg: testfile1

CCO:P0000056    cell cycle
CCO:U0000002    cell-cycle process
CCO:P0000308    cell cycle process
CCO:P0000004    regulation of progression through cell cycle
CCO:P0000005    cell cycle checkpoint
CCO:U0000000    cell-cycle entity
CCO:P0000294    regulation of cell cycle

  reads the contents and gets an intersection (common terms) from the 
two file. but the on implementation its throwing me the following errors:

Use of uninitialized value $input_file1 in open at 
get_intersection_terms_from.pl line 9.
readline() on closed filehandle FILEONE at 
get_intersection_terms_from.pl line 11.
Use of uninitialized value $input_file2 in open at 
get_intersection_terms_from.pl line 16.
readline() on closed filehandle FILETWO at 
get_intersection_terms_from.pl line 18.

the code is given below:


#!/usr/local/bin/perl -w

use Carp;
use strict;
use warnings;

# Takes in first argument
my $input_file1 = $_;
open (FILEONE, $input_file1);

my @list1 = <FILEONE>;


# Takes in first argument
my $input_file2 = $_;
open (FILETWO, $input_file2);

my @list2 = <FILETWO>;


# generates an intersection of terms from the first and second arguments
my @intersection_terms;
foreach (@list1)
{
     my $itemlist1 = $_;

     foreach (@list2)
     {
         my $itemlist2 = $_;

         if ($itemlist1 eq $itemlist2)
         {
             push @intersection_terms, $itemlist2;
             print $itemlist2->id();
             print "\t", $itemlist2->name() if (defined $itemlist2->name());
             print "\n";

         }
     }
}

close FILEONE;
close FILETWO;

exit 0;

Could some guide me on this as to where I have gone wrong (I am new to 
programming in perl)?

thanks a lot,

Aravind
0
venkates
6/16/2010 2:30:40 PM
perl.beginners 29345 articles. 3 followers. Follow

3 Replies
378 Views

Similar Articles

[PageSpeed] 28

On Wed, Jun 16, 2010 at 10:30, Aravind Venkatesan <venkates@nt.ntnu.no> wro=
te:
> Hi everyone,
snip
snip
> # Takes in first argument
> my $input_file1 =3D $_;
> open (FILEONE, $input_file1);
>
> my @list1 =3D <FILEONE>;
snip

This does not work.  $_ does not hold the first arguent.  You mean to say

my $input_file1 =3D shift;

or

my $input_file1 =3D $ARGV[0];

This error was complicated by the fact that you are not checking to
see if the open function is successful.  Try this code:

die "invalid number of arguments\n" unless @ARGV =3D=3D 2;

my @list1 =3D do {
    open my $fh, "<", $ARGV[0]
        or die "could not open $ARGV[0]: $!";

    <$fh>;
}; #lexical filehandle will be auto-closed here

my @list2 =3D do {
    open my $fh, "<", $ARGV[1]
        or die "could not open $ARGV[1]: $!";

    <$fh>;
}; #lexical filehandle will be auto-closed here

>
> # Takes in first argument
> my $input_file2 =3D $_;
> open (FILETWO, $input_file2);
>
> my @list2 =3D <FILETWO>;
>
>
> # generates an intersection of terms from the first and second arguments
> my @intersection_terms;
> foreach (@list1)
> {
> =C2=A0 =C2=A0my $itemlist1 =3D $_;
>
> =C2=A0 =C2=A0foreach (@list2)
> =C2=A0 =C2=A0{
> =C2=A0 =C2=A0 =C2=A0 =C2=A0my $itemlist2 =3D $_;
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0if ($itemlist1 eq $itemlist2)
> =C2=A0 =C2=A0 =C2=A0 =C2=A0{
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0push @intersection_terms, $iteml=
ist2;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0print $itemlist2->id();
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0print "\t", $itemlist2->name() i=
f (defined $itemlist2->name());
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0print "\n";
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0}
> =C2=A0 =C2=A0}
> }
>
> close FILEONE;
> close FILETWO;
>
> exit 0;
>
> Could some guide me on this as to where I have gone wrong (I am new to
> programming in perl)?
>
> thanks a lot,
>
> Aravind
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>



--=20
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
0
chas
6/16/2010 3:05:46 PM
At 4:30 PM +0200 6/16/10, Aravind Venkatesan wrote:
>Hi everyone,
>
>I have written a code that takes in two files (containing a set of 
>terms) as arguments
>  eg: testfile1
>
>CCO:P0000056    cell cycle
>CCO:U0000002    cell-cycle process
>CCO:P0000308    cell cycle process
>CCO:P0000004    regulation of progression through cell cycle
>CCO:P0000005    cell cycle checkpoint
>CCO:U0000000    cell-cycle entity
>CCO:P0000294    regulation of cell cycle
>
>  reads the contents and gets an intersection (common terms) from the 
>two file. but the on implementation its throwing me the following 
>errors:
>
>Use of uninitialized value $input_file1 in open at 
>get_intersection_terms_from.pl line 9.
>readline() on closed filehandle FILEONE at 
>get_intersection_terms_from.pl line 11.
>Use of uninitialized value $input_file2 in open at 
>get_intersection_terms_from.pl line 16.
>readline() on closed filehandle FILETWO at 
>get_intersection_terms_from.pl line 18.
>
>the code is given below:
>
>
>#!/usr/local/bin/perl -w
>
>use Carp;
>use strict;
>use warnings;
>
># Takes in first argument
>my $input_file1 = $_;

Command-line arguments are placed in the @ARGV array, not the $_ 
variable. Thus, the above line should be:

my $input_file1 = shift @ARGV;


>open (FILEONE, $input_file1);


You should always check whether the open succeeded, use local 
variables for file handles, and use the 3-argument version of open 
for best results:

open(my $fileone, '<', $input_file1) or die("Can;t open $input_file1: $!);

-- 
Jim Gibson
Jim@Gibson.org
0
jimsgibson
6/16/2010 3:14:39 PM
Thanks a lot for your suggestions, it helped me a lot!! :)

Aravind

On 06/16/2010 05:14 PM, Jim Gibson wrote:
> At 4:30 PM +0200 6/16/10, Aravind Venkatesan wrote:
>> Hi everyone,
>>
>> I have written a code that takes in two files (containing a set of 
>> terms) as arguments
>>  eg: testfile1
>>
>> CCO:P0000056    cell cycle
>> CCO:U0000002    cell-cycle process
>> CCO:P0000308    cell cycle process
>> CCO:P0000004    regulation of progression through cell cycle
>> CCO:P0000005    cell cycle checkpoint
>> CCO:U0000000    cell-cycle entity
>> CCO:P0000294    regulation of cell cycle
>>
>>  reads the contents and gets an intersection (common terms) from the 
>> two file. but the on implementation its throwing me the following 
>> errors:
>>
>> Use of uninitialized value $input_file1 in open at 
>> get_intersection_terms_from.pl line 9.
>> readline() on closed filehandle FILEONE at 
>> get_intersection_terms_from.pl line 11.
>> Use of uninitialized value $input_file2 in open at 
>> get_intersection_terms_from.pl line 16.
>> readline() on closed filehandle FILETWO at 
>> get_intersection_terms_from.pl line 18.
>>
>> the code is given below:
>>
>>
>> #!/usr/local/bin/perl -w
>>
>> use Carp;
>> use strict;
>> use warnings;
>>
>> # Takes in first argument
>> my $input_file1 = $_;
>
> Command-line arguments are placed in the @ARGV array, not the $_ 
> variable. Thus, the above line should be:
>
> my $input_file1 = shift @ARGV;
>
>
>> open (FILEONE, $input_file1);
>
>
> You should always check whether the open succeeded, use local 
> variables for file handles, and use the 3-argument version of open for 
> best results:
>
> open(my $fileone, '<', $input_file1) or die("Can;t open $input_file1: 
> $!);
>

0
venkates
6/16/2010 11:09:15 PM
Reply:

Similar Artilces:

Error error error, help me
Hello, How do I populate a drop down list in asp.net from a database? I have a block of vbscript code that does the server side coding for it. My code is as follows.. <script language="vb" runat="server"> Dim objConn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\data\employee.mdb;") Dim Sql, valEmp As String Dim objDREmp as OleDbDataReader Sub FillEmployeeName(sender As Object, e As System.EventArgs) Sql = "select * from [Employee]" Dim objCommand As Ole...

HELP!HELP!HELP!HELP!HELP!HELP!
I was using powerbuilder4.0 a month ago I decided that migrate it to PB7.0 When Im using 4.0, in datawindows I was using extra colums additional to stores procedure. I mean that for example; stored proc. returns 4 columns. I was using 2 extra columns to modify something from client. But I cant do the same thing in PB7.0. How can I do that??? please help. Gurcan yucel gyucel@infina.com.tr "I was using 2 extra columns to modify something from client." what does this mean that you added to the result set? If so then just goto the SQL and add a param. Then set the...

Help Help Help Help Help Help
------=_NextPart_000_0074_01C2960E.EBE13A30 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Can someone please help me. I have installed mysql on Unix Solaris and it works fine I have Perl installed previously which is working and with which i have installed other perlmodules before and are working fine. I have also installed DBI and it works fine with the Sybase drivers which i have installed. When i tried to install the Msql-Mysql-modules-1.2219 drivers i get the following error. # make /usr/local/bin/perl -Iblib/arch -Iblib/lib -I/...

Help Help Help me!!!!!!!!!!!!!! Insert data error
Please tell me .Where is error in this code!Thanks  private void Button3_Click(object sender, System.EventArgs e)  {   OleDbConnection myCon=new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source=" + Server.MapPath ( "db/db.mdb"));   string sql="Insert into Student (name,password) Values (@name,@password)";   OleDbCommand myCom=new OleDbCommand( );   myCom.CommandType=CommandType.Text;   myCom.Connection=myCon;   myCom.CommandText=sql;    my...

GWCHeck Error 22 Miscellaneous check errors in database check
Hi! GWCheck logged 2 uncorrectable conditions: "22 Miscellaneous check errors in database check....... 2", that follows above. How should I act to solve that? Thankyou in advance. FM ================================================================================ ===== TASK LOG - 193 (4afb0aa1.ckl) ============================================ ================================================================================ Checking message database msg192.db - 5158912 bytes, 11/11/09 18:02 - Current time 7:02 pm STRUCTURAL VERIFICATION of database TVOE_SA00...

Help Help Help Help
i need to create a crosstab report using Crystal reprot for VS 2003 i face aproblem when i need to order my Fileds by their names my data must be like this Basic Cola Housing Gross Deduction1 Deduction2 Deduction3 Net but when i run my report it give my a not sorted data acutally i have acode field which can i order field using it. but i don't knwo how to do thisSo..................? Select Report tab | |-->Select Record Sort expert Choost the fields you want to sort --Select the corresponding sort direction f...

help help help help
Name: chef mario Email: chefusa_at_pacbell.net Product: Firefox Summary: help help help help Comments: Heard great reports about Firefox!!! Downloaded & installed Firefox !!!! Lost All my very very valuable BOOKMARKS!!! CAN ANYONE HELP!!!!! All bookmarks were in Internet Explorer Did bookmark transfer to Firefox. Seem the Fox eat all m,y bookmarks Need serious help anyone. chef mario Browser Details: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8) Gecko/20051025 Firefox/1.5 ...

Error, Error and more errors
Okay, all I wanted to do was test this app out and it has been a nightmare. 1.) Didn't install the sql database. I had to manually install it. 2.) I get errors when trying to add a picture to an album. "Procedure or function ngUpdatePicture has too many arguments specified" Any ideas? I've gotten more errors than this, but there is no use in bitchin. Are you using the v1.6.1 installer? Also, did you select to install the SQL Server db and give it a valid admin login? What were some of the error messages? Did you have an existing DB from a previous install? ...

Error: Unspecified error
I'm using VS 2005 with VSS 2005. When I try to do a "Get Latest Version" recursive on the project I get this error... Unexpected error encountered. It is recommended that you restart the application as soon as possible. Error: Unspecified error File: vsee\lib\path\cvapipath.cpp Line number: 2459 I can recursively get individual folders but not any of the projects or the solution. I've searched my local machine and the VSS server for that file and it was not found. Thanks. This error lists VS source file, not your source file. I looked into the source file in question and it...

HELP HELP HELP
Hi again: Just tested my first test and proceeded to test and install a second time. This time I let the server run the update after registering with Novell. However, upon reboot the server was dorked as it could not read my /usr and /var partitions (fstab was bad). Now here is what changed between my first the second build: I added a separate partition for /usr, that is all. I could really use a hand here. If I can't trust the update mechanism ...... Chris. Chris wrote: > Hi again: Just tested my first test and proceeded to test > and install a second...

errors errors errors..
Name: harun Email: harunbjk1903hrnatgmaildotcom Product: Firefox Summary: errors errors errors.. Comments: first of all when i launch firefox (3) i cant enter websites via writing.. for example when I type "google" and then press ctrl and enter, it crashes.. and i take lots of error reports. firefox 2 was better.. see you again , harun Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; tr; rv:1.9) Gecko/2008052906 Firefox/3.0 From URL: http://hendrix.mozilla.org/ ...

help help help
Name: bryon Email: bryonbattampabaydotrrdotcom Product: Thunderbird Summary: help help help Comments: why can't i go into the address book and create a new contact with all the information. the screen does not scroll down to the phone numbers section to allow me to enter it, this is with a few of the application that wont allow me to scroll down and finish inserting information needed. please help Browser Details: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9 ...

Error checking and error handling
ASA Gurus: ** ASA Version 7.03** I am only checking for SQLSTATE value. Do I need to check for SQLCODE as well? Is it possible to have SQLCODE=0 but SQLSTATE<>00000 ? Is SQLSTATE good enough to debug the error from error_log table? Should I check for @@error instead? hard to to debug later? What's the best way to check for SQL errors in a loop for Update and Insert statements? What's the best way to get the error text in ASA 7.03 so that I could save the text into error_log table? (ASA 8.x has a built in funcion) I have included a sample proc for i...

error on PB check in/check out
Getting the following message on both check in and check out using native PB source control: 'Check in(out) of library entry failed. Probable library file I/O error. Continue?' Does anyone know what causes this and how it can be corrected? Using PB 6.5 Thanks Most likely, somebody is running the source that you are checking in/out... Or regenning it. Good luck, Terry [TeamSybase] and Sequel the techno-kitten On Tue, 1 Jul 2003 17:33:41 -0400, Philip_Salgannik wrote: >Most likely, somebody is running the source that you are checking in/out... ...

Web resources about - Error check help - perl.beginners

Pilot error - Wikipedia, the free encyclopedia
Pilot error (sometimes called cockpit error ) is a term used to describe the cause of an accident involving an airworthy aircraft where the pilot ...

VW says emissions cheating was not a one-time error
The German carmaker's chairman says the decision by employees to cheat on emissions tests was made more than a decade ago after they realised ...

Eliminating errors secret to Western Sydney Wanderers' win streak: Mitch Nichols
Western Sydney Wanderers star Mitch Nichols believes his side's ascension to the top of the A-League is down to getting rid of the fatal errors ...

Is This The Biggest Bluebook Error Of Them All?
Who deserves credit (or blame) for the authoritative (and often criticized) legal citation manual?

Another Major NYT Error
... public Facebook postings about her feelings about jihad; it wrapped that contention into what reads as a condemnation of the U.S. anti-terrorism ...

10 continuity errors in popular movies that somehow made it to the final cut
... that suddenly appears on a different side of the room or a character that isn't quite in the right spot from one shot to the next, these errors ...

Yield Curve and Spreads: Fed's Real Policy Error in Pictures; What's Next?
... 1998-2015 (Year-End Values) Bubbles of Increasing Amplitude Over Time In the above chart, my statement " Fed's Real Policy Error is to Encourage ...

Transportation secretary: Red Line train may have left station unmanned due to ‘operator error’
Officials are investigating a case of ‘operator error’ that may have allowed an unmanned Red Line train to leave Braintree Station Thursday morning. ...

Operator Error ‘Primary Focus’ Of Runaway Red Line Train Investigation
... BOSTON (CBS) — MBTA officials say the investigation into the runaway Red Line train Thursday morning is focused primarily on operator error. ...

The worst error a Chinese journo can make?
Four staff at China News Service have been suspended after a report about Xi Jinping's speech mistakenly referred to his resignation.

Resources last updated: 12/19/2015 2:57:31 PM