Re: reading file or pipe

2013-02-08 Thread timothy adigun
Thanks On 8 Feb 2013 07:37, "shawn wilson" wrote: > > How do I take in a file or pipe input? Please check this http://perldoc.perl.org/functions/open.html What I want is: > script.pl file.txt > or > cat file.txt | script.pl > > What I'm trying is: > my $logfile; > if (@ARGV and $ARGV[0] =~ /^-.

Re: reading file or pipe

2013-02-08 Thread shawn wilson
> On Fri, Feb 8, 2013 at 2:06 AM, Jim Gibson wrote: >> >> The null filehandle (<>) will read from standard input if @ARGV is empty, >> and from the members of @ARGV, interpreting each scalar as a file name to be >> opened automatically in succession. >> >> Does that do what you want? >> >> Act

Re: reading file or pipe

2013-02-07 Thread shawn wilson
Ah, yeah that'll work. I can just set a count and die "blah" if $count == 0; Didn't think I could do that with a diamond. Thanks On Fri, Feb 8, 2013 at 2:06 AM, Jim Gibson wrote: > > On Feb 7, 2013, at 10:34 PM, shawn wilson wrote: > >> How do I take in a file or pipe input? What I want is: >> s

Re: reading file or pipe

2013-02-07 Thread Jim Gibson
On Feb 7, 2013, at 10:34 PM, shawn wilson wrote: > How do I take in a file or pipe input? What I want is: > script.pl file.txt > or > cat file.txt | script.pl > > What I'm trying is: > my $logfile; > if (@ARGV and $ARGV[0] =~ /^-./) { > open($logfile, '<', $ARGV[0]); > } elsif (-t STDIN and not

reading file or pipe

2013-02-07 Thread shawn wilson
How do I take in a file or pipe input? What I want is: script.pl file.txt or cat file.txt | script.pl What I'm trying is: my $logfile; if (@ARGV and $ARGV[0] =~ /^-./) { open($logfile, '<', $ARGV[0]); } elsif (-t STDIN and not @ARGV) { $logfile = ; } else { doe "no data" } PS - I want to av

Re: Reading file from web into a hash

2010-02-18 Thread Herb
On Feb 16, 8:06 pm, jwkr...@shaw.ca ("John W. Krahn") wrote: > Herb wrote: > > Hi All, > > Hello, > > > I am a perl novice and am having some trouble with formatting a web > > file to put into a hash.  I have the following code: > > > #!/usr/bin/perl -w > > > use LWP::Simple; > > #use strict; > > >

Re: Reading file from web into a hash

2010-02-16 Thread John W. Krahn
Herb wrote: Hi All, Hello, I am a perl novice and am having some trouble with formatting a web file to put into a hash. I have the following code: #!/usr/bin/perl -w use LWP::Simple; #use strict; sub sws { my $file = shift; You should probably pass the filehandle instead of the

Reading file from web into a hash

2010-02-16 Thread Herb
Hi All, I am a perl novice and am having some trouble with formatting a web file to put into a hash. I have the following code: #!/usr/bin/perl -w use LWP::Simple; #use strict; sub sws { my $file = shift; while (!eof(FH)) { $line = ; push @temp

RE: Reading file and changing contents which are not in one line

2009-02-08 Thread Sarsamkar, Paryushan
Thanks ... Thanks, Paryushan -Original Message- From: Rob Dixon [mailto:rob.di...@gmx.com] Sent: Friday, February 06, 2009 9:23 PM To: Perl Beginners Cc: Sarsamkar, Paryushan Subject: Re: Reading file and changing contents which are not in one line Sarsamkar, Paryushan wrote: > Hi

Reading file and changing contents which are not in one line

2009-02-05 Thread Sarsamkar, Paryushan
Hi All, I have one xconf file whose contents are as follows. I actually want to search for a property and change its value. Now what happens in my code is while reading the file, each line is stored in $_ so actually the line in my file is slit up in 2 or more lines, so I can not find the prope

Re: help with reading file script | Help !!

2007-10-19 Thread Chance Ervin
You may want to consider using a mod for the mailer. I usually use Mail::Mailer for a task such as this. use strict; use warnings; Good practice. Chance Ervin Senior Systems Engineer Intelenet Communications NOC 949 784-7911 [EMAIL PROTECTED] On Fri, 19 Oct 2007 14:14:44 -070

Re: help with reading file script | Help !!

2007-10-19 Thread Tom Phoenix
On 10/19/07, Juan B <[EMAIL PROTECTED]> wrote: > I need a script to read /var/log messages and each > time it sees a line with the word "IDS" it will send > the whole line via mail to the administrator > #!/usr/local/bin/perl > > $file = '/var/log/messages'; # Name the file > open(INFO,

help with reading file script | Help !!

2007-10-19 Thread Juan B
Hi all !! im really new to perl so please bare with me and help.. I need a script to read /var/log messages and each time it sees a line with the word "IDS" it will send the whole line via mail to the administrator of the IDS, here is an example of such a line: Oct 19 15:40:30 172.31.0.254 %PIX-4

Re: new for reading file containing multiple records

2006-01-08 Thread chen li
Hi Shawn, Thanks for the detailed explanations. But Edward(see one of posts in my thread) tells me to try Bio::SeqIO from www.bioperl.org. After I try I think it is what I really need. Once again thank you so much for the help. Li __

Re: new for reading file containing multiple records

2006-01-08 Thread Shawn Corey
chen li wrote: You are 50% right. This method is not correct for the first record(which actually contains ">' only) but it is correct for the last record(and others in between). I want to edit the file first and try to delete the first ">" in this big file. I browse Programming Perl and Perl

Re: new for reading file containing multiple records

2006-01-07 Thread chen li
Hi Tom, Thanks for the reply. > Although it's tempting to set $/ to "\n>" for the > file format you > describe, that's probably not correct for the first > or last record in > your file. You are 50% right. This method is not correct for the first record(which actually contains ">' only) but it

Re: new for reading file containing multiple records

2006-01-06 Thread Wijaya Edward
q() ) { push @seqs, $seq->seq(); } #end while return [EMAIL PROTECTED]; } Hope that helps. Regards, Edward WIJAYA - Original Message - From: chen li <[EMAIL PROTECTED]> Date: Saturday, January 7, 2006 9:27 am Subject: Re: new for reading file containing multiple records >

Re: new for reading file containing multiple records

2006-01-06 Thread chen li
Hi Shawn, I use the your code to do the job: #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $filename='sequence.fasta'; open (DATA,$filename) or die; {local $/ = '>'; while( ){ print Dumper \$_; } } exit; And I get the following output: $VAR1 = \'>'; $VAR1 =

Re: new for reading file containing multiple records

2006-01-06 Thread Tom Phoenix
On 1/5/06, chen li <[EMAIL PROTECTED]> wrote: > Each record starts with ">". I want to read each > record once at a time.I hear about a special variable > call $/ might do the job but not sure how to use it. The perlvar manpage documents $/ and all of Perl's other special variables. In particular,

Re: new for reading file containing multiple records

2006-01-06 Thread Shawn Corey
chen li wrote: Each record starts with ">". I want to read each record once at a time.I hear about a special variable call $/ might do the job but not sure how to use it. I wonder if anyone could help me out. See `perldoc perlvar` and search for INPUT_RECORD_SEPARATOR. Here is a simple script

Re: new for reading file containing multiple records

2006-01-06 Thread John Doe
chen li am Freitag, 6. Januar 2006 11.27: > Hi Xicheng, Hi Chen > Thanks. I search the list before I post the question > but I can't find similar topics. Could you please tell > me some ealier posts? Also I try to use your code to > read a very small file containing only these two > records. Here

Re: new for reading file containing multiple records

2006-01-06 Thread chen li
> Word wrapping possibly mangled the example records, > could you please > upload a handful of them in a file somewhere? > > -- fxn Hi, I am just a newbie. What is word wrapping? Is it a perl module or something else? Thanks, Li

Re: new for reading file containing multiple records

2006-01-06 Thread chen li
Hi Xicheng, Thanks. I search the list before I post the question but I can't find similar topics. Could you please tell me some ealier posts? Also I try to use your code to read a very small file containing only these two records. Here is what I got: This is record 1. This is sequence: This is re

Re: new for reading file containing multiple records

2006-01-06 Thread Xavier Noria
On Jan 6, 2006, at 4:12, chen li wrote: Hi all, I have a big file (2.7G) containing multiple records in this format: gi|618748|dbj|D21618.1| MUS74F01 mouse embryonal carcinoma cell line F9 Mus mus culus cDNA clone 74F01, mRNA sequence GCTGCCTCGACGATCTTCGCTTGCNTCCTCGCTCGCTGTCCCGTTGTCCTAGCCCGCC

new for reading file containing multiple records

2006-01-05 Thread chen li
Hi all, I have a big file (2.7G) containing multiple records in this format: >gi|618748|dbj|D21618.1| MUS74F01 mouse embryonal carcinoma cell line F9 Mus mus culus cDNA clone 74F01, mRNA sequence GCTGCCTCGACGATCTTCGCTTGCNTCCTCGCTCGCTGTCCCGTTGTCCTAGCCCGCCGCCGCCCGCTGAGCTTGTCTTT ACCCTGCTTGCAGACATGGC

Re: Reading File & grep according item 5 and sorting

2004-03-10 Thread Bjorn Van Blanckenberg
On 7-mrt-04, at 00:00, R. Joseph Newton wrote: Bjorn Van Blanckenberg wrote: On 3-mrt-04, at 09:56, R. Joseph Newton wrote: I understand how the code works It reads the file end split every line according to the tabs and then sorts everything. For returning the info it looks at colomn 5 (1-base

Re: Reading File & grep according item 5 and sorting

2004-03-06 Thread R. Joseph Newton
Bjorn Van Blanckenberg wrote: > On 3-mrt-04, at 09:56, R. Joseph Newton wrote: > > > I understand how the code works > > It reads the file end split every line according to the tabs and then > sorts everything. > For returning the info it looks at colomn 5 (1-based indexing) and if > colomn 5 of t

Re: Reading File & grep according item 5 and sorting

2004-03-04 Thread Bjorn Van Blanckenberg
On 3-mrt-04, at 09:56, R. Joseph Newton wrote: Bjorn Van Blanckenberg wrote: #!/usr/bin/perl use strict; use Getopt::Long; GetOptions(\my %opt, 'filepath=s'); my $filepath = (%opt->{'filepath'}); my @fields = (); my @sorted = (); my $lastbit = 1; my @bits = (); open(INFILE,$filepath); chomp(

Re: Reading File & grep according item 5 and sorting

2004-03-03 Thread R. Joseph Newton
Bjorn Van Blanckenberg wrote: > > #!/usr/bin/perl > > use strict; > use Getopt::Long; > > GetOptions(\my %opt, 'filepath=s'); > > my $filepath = (%opt->{'filepath'}); > > my @fields = (); > my @sorted = (); > my $lastbit = 1; > my @bits = (); > > open(INFILE,$filepath); > > chomp(@fields = ); > >

Re: Reading File & grep according item 5 and sorting

2004-03-02 Thread John W. Krahn
Bjorn Van Blanckenberg wrote: > > On 28-feb-04, at 20:32, R. Joseph Newton wrote: > > > Bjorn Van Blanckenberg wrote: > > > >> let say that the file contains these items (every item is seperated > >> with a tab) > >> > >> one title3 state3 name3 pre number3 > >> dip title6 state6 na

Re: Reading File & grep according item 5 and sorting

2004-03-02 Thread Bjorn Van Blanckenberg
On 28-feb-04, at 20:32, R. Joseph Newton wrote: Bjorn Van Blanckenberg wrote: let say that the file contains these items (every item is seperated with a tab) ... one title3 state3 name3 pre number3 dip title6 state6 name6 pre2 number6 So what changes have you made in the code t

Re: Reading File & grep according item 5 and sorting

2004-02-28 Thread R. Joseph Newton
Bjorn Van Blanckenberg wrote: > let say that the file contains these items (every item is seperated > with a tab) > ... > > one title3 state3 name3 pre number3 > dip title6 state6 name6 pre2 number6 > So what changes have you made in the code to reflect this diffeence in speci

Reading File & grep according item 5 and sorting

2004-02-25 Thread Bjorn Van Blanckenberg
let say that the file contains these items (every item is seperated with a tab) one title state name testing number two title2 state2 name2 final number2 one title3 state3 name3 pre number3 four title4 state4 name4 tesing2 number4 six title5 state5 name5 t

RE: reading file into hash?

2003-06-24 Thread Dan Muey
> Dan Muey said: > > >> my %codes_hash = (); > > > > Change this to my %codes_hash; > > the = () is adding an empty key/value > > Are you sure? I assumed (I know I know one shouldn't assume ;p) that since I've had the same issue and once I changed my %hash = (); to my %hash; the empty key/valu

RE: reading file into hash?

2003-06-24 Thread Dan Muey
> Yah - that didn't work. It still would have needed the chomp; > Then it must be getting added from the a blank line (IE ^\n$ or somilar) in the file. > Tim > > Paul Johnson wrote: > > Dan Muey said: > > > > > >>>my %codes_hash = (); > >> > >>Change this to my %codes_hash; > >>the = () is

Re: reading file into hash?

2003-06-24 Thread Tim McGeary
Yah - that didn't work. It still would have needed the chomp; Tim Paul Johnson wrote: Dan Muey said: my %codes_hash = (); Change this to my %codes_hash; the = () is adding an empty key/value Are you sure? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMA

RE: reading file into hash?

2003-06-24 Thread Paul Johnson
Dan Muey said: >> my %codes_hash = (); > > Change this to my %codes_hash; > the = () is adding an empty key/value Are you sure? -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

RE: reading file into hash?

2003-06-24 Thread Dan Muey
> This works great, except when I do: > > for (keys %codes_hash) { > print "$_|$codes_hash{$_}\n"; > } > > for my own confirmation, I'm getting a blank line in the > printout. I re-checked my config file and made sure there > was not an extra blank line at the end of the file. Do you >

Re: reading file into hash?

2003-06-24 Thread Sudarshan Raghavan
Tim McGeary wrote: This works great, except when I do: for (keys %codes_hash) { print "$_|$codes_hash{$_}\n"; } for my own confirmation, I'm getting a blank line in the printout. I re-checked my config file and made sure there was not an extra blank line at the end of the file. Do you have

Re: reading file into hash?

2003-06-24 Thread Tim McGeary
This works great, except when I do: for (keys %codes_hash) { print "$_|$codes_hash{$_}\n"; } for my own confirmation, I'm getting a blank line in the printout. I re-checked my config file and made sure there was not an extra blank line at the end of the file. Do you have any ideas why it woul

Re: reading file into hash?

2003-06-23 Thread Steve Grazzini
On Mon, Jun 23, 2003 at 01:39:49PM -0700, Madhu Reddy wrote: A little unasked-for code review :-) > my %alpha_hash = (); > open(FH_D,"$d_list") || die "File opening $d_list\n"; ^ ^ You don't need to quote the variable. > @file_list = ; > foreach $record (@file_list) { And in

Re: reading file into hash?

2003-06-23 Thread John W. Krahn
Tim McGeary wrote: > > I'm still very green to perl, so please forgive this possibly stupid > question. > > I want to setup a configuration file to have a list of alpha codes > delimiter and a unique number that will match the code e.g. > > PACT | 23 > PART | 24 > etc > > How is the best way to

Re: reading file into hash?

2003-06-23 Thread Madhu Reddy
This will do ... alpha_hash is u r hash... - my %alpha_hash = (); open(FH_D,"$d_list") || die "File opening $d_list\n"; @file_list = ; foreach $record (@file_list) { @t_array = split(/\|/, $record); $alpha_hash{$t_array[0]} = $t_array[1]; } close(FH_D); --- Tim

Re: reading file into hash?

2003-06-23 Thread Madhu Reddy
This will do ... alpha_hash is u r hash... - my %alpha_hash = (); open(FH_D,"$d_list") || die "File opening $d_list\n"; @file_list = ; foreach $record (@file_list) { @t_array = split(/\|/, $record); $alpha_hash{$t_array[0]} = $t_array[1]; } close(FH_D); --- Tim

reading file into hash?

2003-06-23 Thread Tim McGeary
I'm still very green to perl, so please forgive this possibly stupid question. I want to setup a configuration file to have a list of alpha codes delimiter and a unique number that will match the code e.g. PACT | 23 PART | 24 etc How is the best way to read such a file into my program (hash ?)

Re: Reading File

2002-06-24 Thread Connie Chan
onnie Chan" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Tuesday, June 25, 2002 12:34 PM Subject: Re: Reading File Hi Connie, what's your $PrevEOL? did you declare it somewhere? sorry i'm still a very beginning beginner in PERL thanks. - Original Message

Re: Reading File

2002-06-24 Thread Karen Liew Ying Ping
lib Sent: Tuesday, June 25, 2002 12:51 AM Subject: Re: Reading File Hi everybody, I've done a dummy test, and finalized that David's method is the Goal Method, that's really Really Very Great !!! I've made a 50MB Text file ( Fixed length, 1001 char per line

RE: Reading File

2002-06-24 Thread Shishir K. Singh
>Hi everybody, >I've done a dummy test, and finalized that David's method is the >Goal Method, that's really Really Very Great !!! >I've made a 50MB Text file ( Fixed length, 1001 char per line, with \n) >for this test, and have the following results : > SCRIPT 1 # Suggested by Johnson

Re: Reading File

2002-06-24 Thread Connie Chan
e, mine one will surely halt the system (WinMe). Wish you have a nice day, Smiley Connie =) - Original Message - From: "David vd Geer Inhuur tbv IPlib" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Monday, J

RE: Reading File

2002-06-24 Thread Timothy Johnson
to memory. -Original Message- From: Connie Chan To: Karen Liew Ying Ping; [EMAIL PROTECTED] Sent: 6/24/02 3:20 AM Subject: Re: Reading File open (FILE, "yourfile.txt"); my @FD = ; close (FILE); my $lastline = $FD[$#FD] Hope this help, Smiley Connie =) - Original Message - Fr

Re: Reading File

2002-06-24 Thread Tor Hildrum
> could puting the entire file into an aray then i think there is a function to > get the number of elements... then just use that to know what the last > element would be? my @array = ; print "$array[-1]"; Tor -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EM

Re: Reading File

2002-06-24 Thread WyvernGod
could puting the entire file into an aray then i think there is a function to get the number of elements... then just use that to know what the last element would be? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: Reading File

2002-06-24 Thread David vd Geer Inhuur tbv IPlib
Hi, I added one. The seek didn't work. I don't have the ReadBackwards, but at least some timeing results : Benchmark: timing 1 iterations of complete, frk, pop... complete: 21 wallclock secs (16.93 usr + 0.80 sys = 17.73 CPU) @ 564.02/s (n=1) frk: 83 wallclock secs ( 1.34 usr

Re: Reading File

2002-06-24 Thread David vd Geer Inhuur tbv IPlib
txt"); > my @FD = ; > close (FILE); > > my $lastline = $FD[$#FD] > > Hope this help, > Smiley Connie =) > > > - Original Message - > From: "Karen Liew Ying Ping" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Monda

Re: Reading File

2002-06-24 Thread John W. Krahn
Karen Liew Ying Ping wrote: > > Hi, Hello, > Let's say I'm opening a file. > How do I read the last line of the file? > is there any function in doing so? use File::ReadBackwards; my $bw = File::ReadBackwards->new( $file ) or die "Cannot read $file: $!"; my $last_line = $bw->readline; # OR

Re: Reading File

2002-06-24 Thread Connie Chan
open (FILE, "yourfile.txt"); my @FD = ; close (FILE); my $lastline = $FD[$#FD] Hope this help, Smiley Connie =) - Original Message - From: "Karen Liew Ying Ping" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, June 24, 2002 6:05 PM Subject: R

Reading File

2002-06-24 Thread Karen Liew Ying Ping
Hi, Let's say I'm opening a file. How do I read the last line of the file? is there any function in doing so? Thanks.

Re: Reading file line by line regardless of type of end-of-line?

2001-08-05 Thread Mel Matsuoka
At 07:11 AM 08/04/2001 -0700, Arthur Klassen wrote: >[EMAIL PROTECTED] wrote: >> >> > Michael Fowler <[EMAIL PROTECTED]> said: >> >> > You left out the Macintosh EOL sequence, , and I don't know >> > what uses simply as EOL. >> >> Macs use just . No machine that I know of uses as a line >> t

Re: Reading file line by line regardless of type of end-of-line?

2001-08-05 Thread Arthur Klassen
[EMAIL PROTECTED] wrote: > > > Michael Fowler <[EMAIL PROTECTED]> said: > > > You left out the Macintosh EOL sequence, , and I don't know > > what uses simply as EOL. > > Macs use just . No machine that I know of uses as a line > terminator. I don't know this from experience, but I remember

Re: Reading file line by line regardless of type of end-of-line?

2001-08-03 Thread Michael Fowler
On Fri, Aug 03, 2001 at 01:40:30PM -0700, [EMAIL PROTECTED] wrote: > > Michael Fowler <[EMAIL PROTECTED]> said: > > > You left out the Macintosh EOL sequence, , and I don't know what > > uses simply as EOL. > > Macs use just . No machine that I know of uses as a line > terminator. Right, th

RE: Reading file line by line regardless of type of end-of-line?

2001-08-03 Thread Steve Howard
unless ($_ eq ''); } Like I said, ugly, but it will work and give you a consistent file format to work with in the second loop Steve -Original Message- From: Sherlock Holmes [mailto:[EMAIL PROTECTED]] Sent: Friday, August 03, 2001 7:33 AM To: [EMAIL PROTECTED] Sub

Reading file line by line regardless of type of end-of-line?

2001-08-03 Thread Sherlock Holmes
I would like to create a perl script that reads lines from an ascii file, but that reads them regardless of whichever of the three variants (, or ) is actually in use as end-of-line, *without* knowing beforehand which is the case. The script should run on many systems (so installing a special