Re: PERL OSX --- reading a local text file

2003-03-23 Thread Rob Dixon
Scott R. Godin wrote: > Rob Dixon wrote: > > Scott R. Godin wrote: > > > John W. Krahn wrote: > > > > > > > > my %hash = do { local $/; =~ /[^\n,]+/g }; > > > > > > but where's the implicit split of key and value there? forgive me > > > for asking, but I just don't see it. is there some magic goin

Re: PERL OSX --- reading a local text file

2003-03-22 Thread Scott R. Godin
Randal L. Schwartz wrote: >> "Scott" == Scott R Godin <[EMAIL PROTECTED]> writes: > >>> my %hash = map {/\w+/g} >>> >>> :-) > > Scott> grin away. This shortcut deserves to be in the perldocs > Scott> somewhere. I wish I'd seen this before. > > The problem is that it is very intolerant of

Re: PERL OSX --- reading a local text file

2003-03-22 Thread Scott R. Godin
Rob Dixon wrote: > Scott R. Godin wrote: >> John W. Krahn wrote: >> > >> > Yes, there is. :-) >> > >> > my %hash = do { local $/; =~ /[^\n,]+/g }; >> >> Holy Handgrenades, Batman! >> >> but where's the implicit split of key and value there? forgive me for >> asking, but I just don't see it. is t

Re: PERL OSX --- reading a local text file

2003-03-19 Thread John W. Krahn
David Gilden wrote: > > Thanks for all of the help, > > Here is what I am currently going with: > > my $prices = '../paul_s/data/prices.txt'; > > open (FH,$prices) || die "could not open $prices $!"; > > while( ) { > s/^\s*(.+)\s*$/$1/; # clean the front of each line > next if /^\s*$/;

Re: PERL OSX --- reading a local text file

2003-03-19 Thread Randal L. Schwartz
> "Scott" == Scott R Godin <[EMAIL PROTECTED]> writes: >> my %hash = map {/\w+/g} >> >> :-) Scott> grin away. This shortcut deserves to be in the perldocs Scott> somewhere. I wish I'd seen this before. The problem is that it is very intolerant of mis-formatted data. If I had a line that h

Re: PERL OSX --- reading a local text file

2003-03-19 Thread Rob Dixon
Scott R. Godin wrote: > John W. Krahn wrote: > > > > Yes, there is. :-) > > > > my %hash = do { local $/; =~ /[^\n,]+/g }; > > Holy Handgrenades, Batman! > > but where's the implicit split of key and value there? forgive me for > asking, but I just don't see it. is there some magic going on here?

Re: PERL OSX --- reading a local text file

2003-03-19 Thread Sudarshan Raghavan
On Tue, 18 Mar 2003, Scott R. Godin wrote: > John W. Krahn wrote: > > > David Gilden wrote: > >> > >> OK, one problem is solved, which was the path to the data file. > >> I know there is a simple way to read in a file like the following: > >> > >> apple,2 > >> banana,4 > >> kiwi,1 > >> > >> an

Re: PERL OSX --- reading a local text file

2003-03-19 Thread Scott R. Godin
Rob Dixon wrote: > John W. Krahn wrote: >> David Gilden wrote: >> > >> > OK, one problem is solved, which was the path to the data file. >> > I know there is a simple way to read in a file like the following: >> > >> > apple,2 >> > banana,4 >> > kiwi,1 >> > >> > and produce a HASH. The code below

Re: PERL OSX --- reading a local text file

2003-03-19 Thread Scott R. Godin
John W. Krahn wrote: > David Gilden wrote: >> >> OK, one problem is solved, which was the path to the data file. >> I know there is a simple way to read in a file like the following: >> >> apple,2 >> banana,4 >> kiwi,1 >> >> and produce a HASH. The code below works I get the feeling there is a

Re: PERL OSX --- reading a local text file

2003-03-18 Thread David Gilden
Thanks for all of the help, Here is what I am currently going with: my $prices = '../paul_s/data/prices.txt'; open (FH,$prices) || die "could not open $prices $!"; while( ) { s/^\s*(.+)\s*$/$1/; # clean the front of each line next if /^\s*$/; # skip blank lines my ( $k, $v ) = sp

Re: PERL OSX --- reading a local text file

2003-03-18 Thread Rob Dixon
John W. Krahn wrote: > David Gilden wrote: > > > > OK, one problem is solved, which was the path to the data file. > > I know there is a simple way to read in a file like the following: > > > > apple,2 > > banana,4 > > kiwi,1 > > > > and produce a HASH. The code below works I get the feeling there

Re: PERL OSX --- reading a local text file

2003-03-18 Thread John W. Krahn
David Gilden wrote: > > OK, one problem is solved, which was the path to the data file. > I know there is a simple way to read in a file like the following: > > apple,2 > banana,4 > kiwi,1 > > and produce a HASH. The code below works I get the feeling there is a more > compact way to accomplish

Re: PERL OSX --- reading a local text file

2003-03-18 Thread Scott R. Godin
David Gilden wrote: > OK, one problem is solved, which was the path to the data file. > > I know there is a simple way to read in a file like the following: > > apple,2 > banana,4 > kiwi,1 > > > and produce a HASH. The code below works I get the feeling there is a more > compact way to accompl

RE: PERL OSX - reading a local text file with white space

2003-03-18 Thread Wagner, David --- Senior Programmer Analyst --- WGO
David Gilden wrote: > Thanks Dave for the while loop, > > I need to protect against blank lines and spurious white space that > could show up in the data. No doubt the file will edited in Note pad > (on widows 98), and I want to put the data in to the hash in a clean > format. and since the this

RE: PERL OSX - reading a local text file with white space

2003-03-18 Thread David Gilden
Thanks Dave for the while loop, I need to protect against blank lines and spurious white space that could show up in the data. No doubt the file will edited in Note pad (on widows 98), and I want to put the data in to the hash in a clean format. and since the this is basically a price list nam

RE: PERL OSX --- reading a local text file

2003-03-18 Thread David Olbersen
rt San Diego, CA 92127 1-858-676-2277 x2152 > -Original Message- > From: David Gilden [mailto:[EMAIL PROTECTED] > Sent: Tuesday, March 18, 2003 10:56 AM > To: [EMAIL PROTECTED] > Subject: Re: PERL OSX --- reading a local text file > > > OK, one problem is solved,

Re: PERL OSX --- reading a local text file

2003-03-18 Thread David Gilden
OK, one problem is solved, which was the path to the data file. I know there is a simple way to read in a file like the following: apple,2 banana,4 kiwi,1 and produce a HASH. The code below works I get the feeling there is a more compact way to accomplish this. --- #!/usr/bin/perl -w use

Re: PERL OSX --- reading a local text file

2003-03-18 Thread Michael Weber
What do you get if you run this script? #!/usr/bin/perl -w use strict; my $data = "data.txt"; print `ls -l $data`; __END__ -Michael >>> David Gilden <[EMAIL PROTECTED]> 03/18/03 10:36AM >>> > But what directory were you in when you ran the program? That's a lot > more important than where

Re: PERL OSX --- reading a local text file

2003-03-18 Thread Randal L. Schwartz
> "David" == David Gilden <[EMAIL PROTECTED]> writes: >> But what directory were you in when you ran the program? That's a lot >> more important than where the program is. David> /Users/dowda/Desktop/tmp test/read-prices.pl David> OSX Jaguar, G4 Right. When you ran the program, were you

Re: PERL OSX --- reading a local text file

2003-03-18 Thread Rob Dixon
David Gilden wrote: > > But what directory were you in when you ran the program? That's a > > lot > > more important than where the program is. > > > /Users/dowda/Desktop/tmp test/read-prices.pl > > OSX Jaguar, G4 Try adding use Cwd; print cwd, "\n"; just before your open, to make sure

Re: PERL OSX --- reading a local text file

2003-03-18 Thread David Gilden
> But what directory were you in when you ran the program? That's a lot > more important than where the program is. /Users/dowda/Desktop/tmp test/read-prices.pl OSX Jaguar, G4 Randal L. Schwartz <[EMAIL PROTECTED]>, > The following message is a courtesy copy of an article > that has been p

Re: PERL OSX --- reading a local text file

2003-03-18 Thread Randal L. Schwartz
> "David" == David Gilden <[EMAIL PROTECTED]> writes: David> Hi List, David> Any reason why this dies? error: " could not open data.txt No such file or directory" --> The file and script reside in the same directory!!! But what directory were you in when you ran the program? That's a lo

PERL OSX --- reading a local text file

2003-03-18 Thread David Gilden
Hi List, Any reason why this dies? error: " could not open data.txt No such file or directory" -->The file and script reside in the same directory!!! #!/usr/bin/perl -w use strict; my $data = "data.txt"; open (FH,$data) || die "could not open $data $!"; local $/; my $tmp = ; my @tmp =