Re: reading file or pipe

2013-02-08 Thread shawn wilson
On Fri, Feb 8, 2013 at 2:06 AM, Jim Gibson jimsgib...@gmail.com 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?

Re: reading file or pipe

2013-02-08 Thread timothy adigun
Thanks On 8 Feb 2013 07:37, shawn wilson ag4ve...@gmail.com 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-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 @ARGV) {

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 jimsgib...@gmail.com wrote: On Feb 7, 2013, at 10:34 PM, shawn wilson wrote: How do I take in a file or pipe input? What I

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; sub sws {        

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

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 All

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

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 the next

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);

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 = INFILE); @sorted =

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

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 name6 pre2 number6

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

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 would

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 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 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:

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 adding an empty

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/value go away.

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 = FH_D; 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 = FH_D; 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 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 read such

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 = FH_D; foreach $record (@file_list) { And in

Re: Reading File

2002-06-24 Thread Connie Chan
open (FILE, yourfile.txt); my @FD = FILE; 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: Reading File Hi, Let's say I'm

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

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 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 = FH; print $array[-1]; Tor -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail:

RE: Reading File

2002-06-24 Thread Timothy Johnson
. -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 = FILE; close (FILE); my $lastline = $FD[$#FD] Hope this help, Smiley Connie =) - Original Message - From: Karen Liew

Re: Reading File

2002-06-24 Thread Connie Chan
Message - From: David vd Geer Inhuur tbv IPlib [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Monday, June 24, 2002 7:35 PM Subject: Re: Reading File I am try-ing to work something out with seek for you, but just can't find it yet. This is how far I am yet

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 Karen Liew Ying Ping
, 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, with \n) for this test, and have

Re: Reading File

2002-06-24 Thread Connie Chan
: 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 - From: Connie Chan To: Timothy Johnson ; 'Karen Liew Ying Ping ' ; [EMAIL

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, LFCR, and I don't know what uses simply CR as EOL. Macs use just CR. No machine that I know of uses LFCR as a line

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, LFCR, and I don't know what uses simply CR as EOL. Macs use just CR. No machine that I know of uses LFCR as a line terminator. Right,