Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Regular Expressions
This is the forum to discuss the Wrox book Beginning Regular Expressions by Andrew Watt; ISBN: 9780764574894
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Regular Expressions section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 2nd, 2009, 10:39 AM
Registered User
 
Join Date: Sep 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hi

Hi all,

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


Thanks
allenbir
Reply With Quote
  #2 (permalink)  
Old September 2nd, 2009, 11:03 AM
Friend of Wrox
Points: 2,473, Level: 20
Points: 2,473, Level: 20 Points: 2,473, Level: 20 Points: 2,473, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: India
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

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. }
__________________
Om Prakash Pant
Click the "Thanks" button if this post helped you.
Reply With Quote
  #3 (permalink)  
Old September 2nd, 2009, 11:49 AM
Registered User
 
Join Date: Sep 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
  #4 (permalink)  
Old September 2nd, 2009, 12:41 PM
Friend of Wrox
Points: 2,473, Level: 20
Points: 2,473, Level: 20 Points: 2,473, Level: 20 Points: 2,473, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: India
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

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
__________________
Om Prakash Pant
Click the "Thanks" button if this post helped you.
Reply With Quote
  #5 (permalink)  
Old September 4th, 2009, 08:03 AM
Registered User
 
Join Date: Sep 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Thanks

Thank you very much om prakash.
Reply With Quote
  #6 (permalink)  
Old September 4th, 2009, 10:06 AM
Registered User
 
Join Date: Sep 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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
Reply With Quote
  #7 (permalink)  
Old September 9th, 2009, 07:05 AM
Registered User
 
Join Date: Sep 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help

Can any one help me with the above written problem.

Thanks in advance

allenbir
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off



All times are GMT -4. The time now is 12:18 AM.


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