p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   BOOK: Beginning Regular Expressions (http://p2p.wrox.com/book-beginning-regular-expressions-157/)
-   -   Hi (http://p2p.wrox.com/book-beginning-regular-expressions/76013-hi.html)

allenbir September 2nd, 2009 11:39 AM

Hi
 
Hi all,

I am new to perl and I do not know how to open file with @argv.


Thanks
allenbir

om_prakash September 2nd, 2009 12:03 PM

Please check the following URL:
http://perldoc.perl.org/functions/open.html

Code:

  1. # process argument list of files along with any includes

  2.     foreach $file (@ARGV) {

  3.         process($file, 'fh00');

  4.     }

  5.     sub process {

  6.         my($filename, $input) = @_;

  7.         $input++;                # this is a string increment

  8.         unless (open($input, $filename)) {

  9.             print STDERR "Can't open $filename: $!\n";

  10.             return;

  11.         }



allenbir September 2nd, 2009 12:49 PM

Thanks om prakash

suppose I have a file 1.txt how can I open it with argv could you plz tell me I am new to perl.

Thanks

allen

om_prakash September 2nd, 2009 01:41 PM

Example:1
Code:

$str = <MYDATA>;
use strict;
open(MYDATA, "1.txt") or
  die("Error: cannot open file 'data.txt'\n");
my $line;
my $lnum = 1;
while( $line = <MYDATA> ){
  chomp($line);
  print "$lnum: $line\n";
  $lnum++;
}
close MYDATA;

Example:2
Code:

@lines = <MYDATA>;
open(MYDATA, $ARGV[0]) or die("Error: cannot open file '$ARGV[0]'\n");

More Examples:
http://ist.marshall.edu/ist334/perl_fio.html

allenbir September 4th, 2009 09:03 AM

Thanks
 
Thank you very much om prakash.

allenbir September 4th, 2009 11:06 AM

HI
 
Hi,

I have a 2 files like

File 1 has entries like this
PF00912
PF00913
PF00914
PF00915
PF00916
..
..

File2

>128UP_DROME |==============================================| P32234.2 368 a.a.
MMR_HSR1 1 ______________ (9407) PF01926.15 GTPase of unknown function 65-176
TGS 1 _________ (2078) PF02824.13 TGS domain 292-366

>12KD_FRAAN |=====================================| Q05349.1 111 a.a.
Auxin_repressed 1 __________________________________ (61) PF05564.4 Dormancy/auxin associated protein 7-110

>12S1_ARATH |================================================| P15455.2 472 a.a.
Cupin_1 2 _______________ _______________ (1556) PF00190.14 Cupin 41-199 295-444

>12S2_ARATH |==============================================| P15456.2 455 a.a.
Cupin_1 2 ________________ _______________ (1556) PF00190.14 Cupin 35-192 282-431

>12S_PROFR |===============================================| Q8GBW6.3 611 a.a.
Carboxyl_trans 1 ______________________________________ (2491) PF01039.14 Carboxyl transferase domain 34-522

>13S1_FAGES |================================================| O23878.1 565 a.a.
Cupin_1 2 __________________ ____________ (1556) PF00190.14 Cupin 49-275 390-539

Problem is that I need to take one entry at a time from File1 , i.e PF00912 and match it with the File 2 in such a way that , if it found match then it should do the following ,

1. Take one entry from the file1 say like PF00912 and look it into file2.
2. Take only that enteries that starts from > to next > in file 2 that has PF00912 in it.
3. In file 2 look for the position after this |=====|, say like this P32234 (in file2) take this name and store it.
4. Look for PF* entries and numbers like 65-176 (can be any) in that same P32234 and then classify accordingly

a. if no. of PF* (1 only) and 65-176 (1 only any number) put P32234 into bin1 and

b. if no. PF* (more than 1) and 65-176 (1 only) for each PF* put P32234 into bin2 and

c. if no. PF* (1 only) and 65-176 (more than 1 times) put P32234
or no. if PF* (more than 1) and 65-176 (more than 1) put P32234 put them into bin3

d. if no. PF* (1 only) and 65-176 (more than 5) put them in bin 4

* note 65-176 can be any number.

5. At final we need to count the number of entries in each bin.

Thanks in advance

allen

allenbir September 9th, 2009 08:05 AM

Help
 
Can any one help me with the above written problem.

Thanks in advance

allenbir


All times are GMT -4. The time now is 07:17 PM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
2013 John Wiley & Sons, Inc.