[11592] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5192 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Mar 21 17:07:23 1999

Date: Sun, 21 Mar 99 14:00:20 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 21 Mar 1999     Volume: 8 Number: 5192

Today's topics:
        2nd Request, please help Re: newbie: how do I read in b (Joe)
    Re: 2nd Request, please help Re: newbie: how do I read  <gellyfish@btinternet.com>
        Converting an unsigned 16 bit integer to decimal ??  He <randalll@gte.net>
        displaying status. <rahulk@iname.com>
    Re: Forwarding to home directory using Net::FTP <gellyfish@btinternet.com>
        ftp problem (John )
    Re: ftp problem <gellyfish@btinternet.com>
    Re: FTP Recursive Directory Listing <gellyfish@btinternet.com>
    Re: How to find individual undefined array values? (Larry Rosler)
        little file-upload-workshop (Henri Schomdcker)
        My file keeps getting clobbered! <webqueen@bol.net>
    Re: Need a one liner... (Larry Rosler)
    Re: Need a one liner... <uri@home.sysarch.com>
    Re: Q: opening multiple filehandles concurrently? (Larry Rosler)
    Re: Q: opening multiple filehandles concurrently? (brian d foy)
        Reading words from text file dinog@NOSPAMcanada.com
    Re: Reading words from text file <gellyfish@btinternet.com>
    Re: Reading words from text file (Tad McClellan)
    Re: Reading words from text file dinog@NOSPAMcanada.com
        Simple DOS/Win95 originated Perl script not working whe <s.v.kumar@worldnet.att.net>
        using passing delimiter of regexp to sub <zenno22@hotmail.com>
        What isn't getting reset? <bwegman@HiWAAY.net>
    Re: What isn't getting reset? (Ronald J Kimball)
    Re: Win32 Newbie please help <gellyfish@btinternet.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sun, 21 Mar 1999 21:15:05 GMT
From: painter2000@Cybernex.Net (Joe)
Subject: 2nd Request, please help Re: newbie: how do I read in binary file, modify bytes and write out?
Message-Id: <7d3cv8$qvl$1@news.cybernex.net>

I did RTFM, checked the FAQs, the books, dejanews and I cannot find an
answer....anyone? Can PERL do this?

TIA,

Joe
Please read how to change my email address if replying personally - thanks!



painter2000@Cybernex.Net (Joe) wrote:

>I checked FAQ and dejanews and haven't seen this discussed. "Programmin Perl"
>doesn't really explain it.  My goal is to read an MP3 file, analyze the 
>data, then modify it and write it as a new MP3 file. It seems like a simple
>thing to do but HOW DOES ONE DO IT???

>Thanks in advance!

>Joe
>[our email address is 'painter2000@Cybernex.Net' but WITHOUT
> the numbers and with all letters lowercase. Very sorry about
> that but I am trying to avoid all those spammers.]


[our email address is 'painter2000@Cybernex.Net' but WITHOUT
 the numbers and with all letters lowercase. Very sorry about
 that but I am trying to avoid all those spammers.]



------------------------------

Date: 21 Mar 1999 18:57:44 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: 2nd Request, please help Re: newbie: how do I read in binary file, modify bytes and write out?
Message-Id: <7d3ff8$6u6$1@gellyfish.btinternet.com>

On Sun, 21 Mar 1999 21:15:05 GMT Joe wrote:
> I did RTFM, checked the FAQs, the books, dejanews and I cannot find an
> answer....anyone? Can PERL do this?
> 
> painter2000@Cybernex.Net (Joe) wrote:
> 
>>I checked FAQ and dejanews and haven't seen this discussed. "Programmin Perl"
>>doesn't really explain it.  My goal is to read an MP3 file, analyze the 
>>data, then modify it and write it as a new MP3 file. It seems like a simple
>>thing to do but HOW DOES ONE DO IT???
> 

What part of this are you having trouble with ?  If it is about the
format of the MPEG file then you are asking in the wrong group.  If it
is simply about how you go about reading and writing a binary file then
perhaps you should consult the documentation again.  The reason that
your question ihas not been answered is that you are not giving anyone
a question to answer.

Yes it is possible to read some binary file with Perl and alter it and
write it out again - you might want to look at sysread, sysread in the
documentation , however the content of that file is irrelevant.  Why dont
you show us what you have tried so far and are having problems with ?

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


------------------------------

Date: Sun, 21 Mar 1999 13:17:49 -0800
From: "Lloyd Randall" <randalll@gte.net>
Subject: Converting an unsigned 16 bit integer to decimal ??  Help pleas
Message-Id: <7d3mhk$d5m$1@news-2.news.gte.net>

#
# Can anyone please tell me how to take a binary, 2 byte field which is
supposed to
# contain a 16 bit Unsigned Integer from a received message and convert it
to decimal???
#
# I am receiving a message via a socket connection from a client, and in the
message that
# I am receiving, there is an Unsigned 16 bit Integer field in byte numbers
7 and 8 that
# is supposed to tell me the complete message length so that I will know if
I have
# received the whole message or not.
#
# This should be pretty easy right???
# Well, not for me... I am really new at this.
#
# Let's say for example that message length number number is:
# Decimal 18260
# Binary  0100011101010100
# Hex     4754
#
# The ASCII Character represented by 47 Hex is "G"
# The ASCII Character represented by 54 Hex is "T"
#
# I have been lead to beleive that Unsigned Integers are stored with the
low-order byte
# before the high-order byte. That is why, in the $buffer= statement below,
I have put
# the ASCII charaters T and G in byte positions 7 and 8 respectively.
(reversed order).
# This is how I anticipate receiving data from another computer into
$buffer.
# I would expect to see the incoming binary as 0101010001000111 if my
reversed byte
# theroy is true.

# There has got to be an easy way to do this with pack and unpack but
unfortunately,
# my feeble brain just doesn't get it......  I have read the books and the
FAQs but
# still I am sooooo confused!!!!  Any help would certainly be very much
appreciated.
# Thanks.


# My stupid way of doing this...


$buffer="xxxxxxTGxxxxxxx";

$seventhbyte=substr($buffer,6,1);
$eighthbyte=substr($buffer,7,1);
$swapedbytes = $eighthbyte.$seventhbyte;

$binary= (join('',unpack('B*',"$swapedbytes")));
print"lenght of Binary in bytes = ",length($binary),"\n";
print"Binary = $binary\n";

                               # I tried this too:
$decimal=pack('B16',$binary);
                               #                              print"Decimal
= $decimal\n";
                               #     it just gives me back the ASCII
Characters "GT"



$sum=0;

if (substr($binary,0,1)  eq "1") {$sum=$sum+32768;}
if (substr($binary,1,1)  eq "1") {$sum=$sum+16384;}
if (substr($binary,2,1)  eq "1") {$sum=$sum+8192;}
if (substr($binary,3,1)  eq "1") {$sum=$sum+4096;}
if (substr($binary,4,1)  eq "1") {$sum=$sum+2048;}
if (substr($binary,5,1)  eq "1") {$sum=$sum+1024;}
if (substr($binary,6,1)  eq "1") {$sum=$sum+512;}
if (substr($binary,7,1)  eq "1") {$sum=$sum+256;}
if (substr($binary,8,1)  eq "1") {$sum=$sum+128;}
if (substr($binary,9,1)  eq "1") {$sum=$sum+64;}
if (substr($binary,10,1) eq "1") {$sum=$sum+32;}
if (substr($binary,11,1) eq "1") {$sum=$sum+16;}
if (substr($binary,12,1) eq "1") {$sum=$sum+8;}
if (substr($binary,13,1) eq "1") {$sum=$sum+4;}
if (substr($binary,14,1) eq "1") {$sum=$sum+2;}
if (substr($binary,15,1) eq "1") {$sum=$sum+1;}
print "Sum = $sum\n";


sleep(10);




------------------------------

Date: Sun, 21 Mar 1999 12:40:08 -0600
From: Rahul K <rahulk@iname.com>
Subject: displaying status.
Message-Id: <36F53D07.B6AA8CBB@iname.com>


Hi,

I am trying to implement something like what you see at
www.metacrawler.com.
If you type a query and hit enter, you will get something like this:

-----snip---------------------------------------
Getting results for query: test

Yahoo!: 10 references returned.
Infoseek: 10 references returned.
Lycos: 8 references returned.
WebCrawler: 10 references returned.
Thunderstone: 10 references returned.
finished sending hits....
-----snip---------------------------------------
and then the page changes to the result.

how can I do that.
Thanks in advance,

-rahul



------------------------------

Date: 21 Mar 1999 17:31:38 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Forwarding to home directory using Net::FTP
Message-Id: <7d3adq$6p4$1@gellyfish.btinternet.com>

On Sun, 21 Mar 1999 16:43:27 GMT "Kevin S (xS)" wrote:
> I honestly think its a problem w/ Net::FTP, because when I got w/ ftp from
> DOS or from Linux it works fine. I think that Net::FTP auto-cwds into the
> root dir regardless of who your logged in as. I'll probably look at the
> perldoc to see if theres a way to stop this.
> 

Not my experience - given :


#!/usr/bin/perl -w

use Net::FTP;

$ftp = Net::FTP->new("localhost");
$ftp->login("gellyfish","********"); # real password commented out
print $ftp->pwd,"\n";
$ftp->quit;


I get :

gellyfish@gellyfish:/home/gellyfish/clpmtest > ftptest.pl
/home/gellyfish
gellyfish@gellyfish:/home/gellyfish/clpmtest > 

So that works.  I will reiterate that it is the server that is doing what
you observe.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


------------------------------

Date: Sun, 21 Mar 1999 18:08:08 GMT
From: John@melon17.freeserve.co.uk (John )
Subject: ftp problem
Message-Id: <36f6354d.23890373@news.freeserve.net>

I get a error message at line 7 in the code below.

The error message says 'can't call method login without
a package or object reference at line 7'.

I would be grateful for any suggestions as to why
the error is occurring.

code is:

------------------------------------------------------------------------

#!/usr/bin/perl

use Net::FTP;
print "connect......\n";
$ftp = Net::FTP->new("mysite.com ");
print "Logging in.........\n";
$ftp->login("userid","password");
print "put file............\n";
$ftp->put("afile");
$ftp->quit;
-----------------------------------

John


------------------------------

Date: 21 Mar 1999 18:48:43 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: ftp problem
Message-Id: <7d3eub$6u1$1@gellyfish.btinternet.com>

On Sun, 21 Mar 1999 18:08:08 GMT John  wrote:
> I get a error message at line 7 in the code below.
> 
> The error message says 'can't call method login without
> a package or object reference at line 7'.
> 
> I would be grateful for any suggestions as to why
> the error is occurring.
> 

Yep it does it for me too ....

gellyfish@gellyfish:/home/gellyfish/clpmtest > ftptest2.pl
Logging in.........
Can't call method "login" on an undefined value at ././ftptest2.pl line 5.

(using your 'myhost.com')

It is because (for some reason) you are not able to connect to the server
that you have tried to connect to.  If you are unsure whether you will be
able to connect then you should check whether your ftp object is defined.

In summary the problem is not with your code or anything to with Net::FTP
it is simply that you are trying to connect to a server that is unavailable
either because you have supplied a bad hostname or there is no network
route to that host at the current time.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


------------------------------

Date: 21 Mar 1999 18:22:15 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: FTP Recursive Directory Listing
Message-Id: <7d3dcn$6rl$1@gellyfish.btinternet.com>

On Sun, 21 Mar 1999 16:41:05 GMT "Kevin S (xS)" wrote:
> I take it alt.perl is frowned upon here. Doesn't matter really. No one every
> responds there.
> 

Yep,  All I'm concerned about is getting the crap response back into this
group.  There is no reason for an 'alt.perl' excpet for people who would
rather not be told to read the documentation ...

> Also do you have any advice on how to determine if an item is a dir or a
> file. When I do a $ftp->dir it gives me the following
> 
> dr-xr-xr-x 3 0 1 512 Mar 30 1994 usr
> 
> I know I can just split the string and go from there but a lot cpu usage
> there especially if I did it for more than one ftp per session. Any know any
> other ideas?
> 

No that is about the only option open to you - I would split the returned
rows and if the first field begins with 'd' push the last field into an array
(prepending the PWD ) and then cd to each directory thus discovered in turn.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


------------------------------

Date: Sun, 21 Mar 1999 08:12:04 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: How to find individual undefined array values?
Message-Id: <MPG.115eba2ecb41964c9897a0@nntp.hpl.hp.com>

In article <36f6d62d.1302216@news.skynet.be> on Sun, 21 Mar 1999 
12:40:50 GMT, Bart Lateur <bart.lateur@skynet.be >says...
> David wrote:
 ... 
> >How do I find out if any other array element is undefined.
> 
> Urm... if you what you really want, is to replace the undefined entries
> with 0, then this is one way:
> 
> 	@zeropadded = map { $_ || 0 } @array;

Well, all right, provided you don't mind replacing the null string "" by 
0.  'undefined' ne 'null'.  FALSE has three flavors in Perl.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personl/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Sun, 21 Mar 1999 19:16:13 GMT
From: hschomae@rz-online.de (Henri Schomdcker)
Subject: little file-upload-workshop
Message-Id: <36f544e4.30315312@news.rhein-zeitung.de>

Hi folks,

if someone is interested in a little workshop how to handle
file-uploads with CGI.pm, take a look at my personal pages:

http://home.rhein-zeitung.de/~hschomae/microtry/

Hope it helps a little bit,

Henri


------------------------------

Date: Sun, 21 Mar 1999 15:55:37 -0500
From: sara starre <webqueen@bol.net>
Subject: My file keeps getting clobbered!
Message-Id: <36F55CC9.CD67CA85@bol.net>

I have a textfile that numerous users update through perl print
statements and copy() commands. The file is about 10k lines.

About 3 times a day it  turns 100 to 2000 lines into one giant line,
which in vi looks like screenfuls of NULL chars I guess. The lines
appear to be garbled too- if I insert CR every 80 chars there seems to
be some lines missing and others shortened.

I tried adding flock (exclusive) during updates- no improvement. I tried
replacing system calls (to cp) with copy(f1,f2). I tried checking the
length of each line that I print to the file. None of these remedies
made any difference.

I dont know what else to try. Has anyone any idea of why this would be
happening? I'm all ears! Any similar experience/remedy would be most
appreciated.

:)







------------------------------

Date: Sun, 21 Mar 1999 07:08:52 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Need a one liner...
Message-Id: <MPG.115eab59f204715f98979f@nntp.hpl.hp.com>

[Posted and a courtesy copy sent.]

In article <x7k8wcazd9.fsf@home.sysarch.com> on 20 Mar 1999 11:40:18 -
0500, Uri Guttman <uri@home.sysarch.com >says...
 ... 
> a rarely used feature of the scalar range op .. is its return value. it
> returns the line number in the true range. this is actually the value
> used by the surrounding conditional. as a bonus trick, the last line is
> in floating notation with a trailing 'e0' this allows for a test of the
> last line which matteched the ending tag.
> 
> so a common idiom i use in parsing text is
> 
> 	if ( $range_line = /foo/ .. /bar/ ) {
> 
> 		next if $range_line == 1 || $range_line ~= /e/ ;
> 
> 		.....
> 	}
> 
> sometime other work has to be done at the boundaries of a range.
> 
> and here is a oneline that does it (tested):
> 
> perl -ne 'print if (/^S/../^E/) =~ /(?=^\d+$)(?!^1$)|e/'
> 
> the regex is doing both boolean tests. the first part looks ahead for
> all digits and looks ahead for not a single 1, the second part just
> looks for the /e/.
> 
> 
> scalar range needs to be used more. i rarely see it mentioned in this group.
> 
> have fun kiddies,

OK, Uri, I'll try to have fun.

The following is quoted from perlop:

"The final sequence number in a range has the string ``E0'' appended to 
it, which doesn't affect its numeric value, but gives you something to 
search for if you want to exclude the endpoint."

'E0' ne 'e0'

The '|e' part of your test doesn't work.  But it isn't needed anyhow, 
because the final sequence number ending in 'E0' is ruled out by the 
first look-ahead ^\d+$ .

Now lets have fun with this:

 		next if $range_line == 1 || $range_line ~= /e/ ;

This also tests for 'e', so it doesn't work (even if the non-operator 
'~=' is replaced by '=~' :-).

Golly gee, that *was* fun!  :-)

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personl/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: 21 Mar 1999 14:53:31 -0500
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: Need a one liner...
Message-Id: <x7hfrebow4.fsf@home.sysarch.com>

>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:

  >> perl -ne 'print if (/^S/../^E/) =~ /(?=^\d+$)(?!^1$)|e/'
  >> 
  >> the regex is doing both boolean tests. the first part looks ahead for
  >> all digits and looks ahead for not a single 1, the second part just
  >> looks for the /e/.

  LR> 'E0' ne 'e0'

  LR> The '|e' part of your test doesn't work.  But it isn't needed anyhow, 
  LR> because the final sequence number ending in 'E0' is ruled out by the 
  LR> first look-ahead ^\d+$ .

  LR> Now lets have fun with this:

  LR>  		next if $range_line == 1 || $range_line ~= /e/ ;

  LR> This also tests for 'e', so it doesn't work (even if the non-operator 
  LR> '~=' is replaced by '=~' :-).

  LR> Golly gee, that *was* fun!  :-)

hey larry,

the one liner worked for the reasons you stated. i removed the |e and it
works fine so it is a better solution. i didn't look at my old working
code when i wrote it so i forgot about the E vs. e bit. the next line was
not tested nor from my old working code, so it was posted as caveat
coder.

but the describing the use of the scalar range op and its return value
are still valid as they are greatly underused and under covered in this
group.

BTW, your reply was not fun for me :-(

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


------------------------------

Date: Sun, 21 Mar 1999 08:18:56 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Q: opening multiple filehandles concurrently?
Message-Id: <MPG.115ebbceff50845b9897a1@nntp.hpl.hp.com>

In article <1dozudt.1dsb1bg1ppmrnfN@[207.60.170.22]> on Sun, 21 Mar 1999 
02:11:05 -0500, Ronald J Kimball <rjk@linguist.dartmouth.edu >says...
> Larry Rosler <lr@hpl.hp.com> wrote:
> > > > Is it possible to have more than one filehandle open concurrently?
> > > 
> > > yes.  you even start off with a couple open already :)
> > 
> > New definition of 'a couple' -- three?  I thought that was a 'crowd'.
> > ;-)
> 
> Not a new definition.  'couple' can mean 'an indefinite small number' or
> 'few' in addition to 'two'.

A new one on me.  Fourth definition in my dictionary:  'Informal.  A 
few, several:  "a couple of days"'.  Funny.  I always thought that that 
phrase meant "the day after tomorrow".  (Every other sense of 'couple' 
in that dictionary is explicitly "two".)

It's nice to learn some English here, as well as some Perl.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personl/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: Sun, 21 Mar 1999 16:57:59 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Q: opening multiple filehandles concurrently?
Message-Id: <comdog-ya02408000R2103991657590001@news.panix.com>

In article <MPG.115ebbceff50845b9897a1@nntp.hpl.hp.com>, lr@hpl.hp.com (Larry Rosler) posted:

> A new one on me.  Fourth definition in my dictionary:  'Informal.  A 
> few, several:  "a couple of days"'.  Funny.  I always thought that that 
> phrase meant "the day after tomorrow".  (Every other sense of 'couple' 
> in that dictionary is explicitly "two".)
> 
> It's nice to learn some English here, as well as some Perl.

i think this informal defintion is right in line with Larry's theme
in the State of the Onion address:  English is a mess, and so is Perl,
but then so is the problem space. ;)

-- 
brian d foy                    
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>


------------------------------

Date: Sun, 21 Mar 1999 18:07:18 GMT
From: dinog@NOSPAMcanada.com
Subject: Reading words from text file
Message-Id: <36F55E9C.FA751D9E@NOSPAMcanada.com>

Newbie here.  I'd like to open a text file and read in the text word by
word that would be delineated by spaces.  I've opened a file ok, but
reading in words, I still haven't found anything that would help.
read() does a read of size bytes not by word.  From my understanding,
perl is good at file manipulations so I can't imagine there isn't an
easy way to do this.  Any ideas?

TIA,
dg



------------------------------

Date: 21 Mar 1999 19:14:04 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Reading words from text file
Message-Id: <7d3gds$6uc$1@gellyfish.btinternet.com>

In comp.lang.perl.misc dinog@nospamcanada.com wrote:
> Newbie here.  I'd like to open a text file and read in the text word by
> word that would be delineated by spaces.  I've opened a file ok, but
> reading in words, I still haven't found anything that would help.

No reading in word by word is not very easy to achieve - you will need
to read a line at a time and the split that line into words (however you
might define words ).

Of course beyond this is it is difficult to comment further because you
dont say what you want to do with words after you have this list.

BTW comp.lang.perl is a dead group - its fallen off its perch and is pushing
up camels ... and I dont think this is appropriate to modules either ...

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


------------------------------

Date: Sun, 21 Mar 1999 08:52:19 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Reading words from text file
Message-Id: <jit2d7.os3.ln@magna.metronet.com>


[ comp.lang.perl is a non-group. It is not there. It is not here.
  It is not anywhere. It was deleted a few _years_ ago...

  No module stuff here.

  Newsgroups and Followup-To trimmed.
]



dinog@NOSPAMcanada.com wrote:

[snip text, it is included as data below]


   Read by lines, then break up each line into words:

-----------------------
#!/usr/bin/perl -w
use strict;

while (<DATA>) {
   chomp;
   foreach my $word ( split ) {

      print "$word\n";   # do something with the word
   }
}

__DATA__
Newbie here.  I'd like to open a text file and read in the text word by
word that would be delineated by spaces.  I've opened a file ok, but
reading in words, I still haven't found anything that would help.
read() does a read of size bytes not by word.  From my understanding,
perl is good at file manipulations so I can't imagine there isn't an
easy way to do this.  Any ideas?
-----------------------


   This "loses" information about the discarded whitespace though...


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: Sun, 21 Mar 1999 20:27:50 GMT
From: dinog@NOSPAMcanada.com
Subject: Re: Reading words from text file
Message-Id: <36F57F8C.51EC625C@NOSPAMcanada.com>

Thanks for the quick response.

I've gotten what you've said to work: read in the input file line by line and
splitting it up into an array of words defined by whitespaces.  What I'm trying to
do is compare 2 arrays of words: each created from file.  One file contains the
master list of words while the second file contains words I'd like to check. If
the second file contains words not in the master file, I'd like to add them to the
master file.  Can you think of an efficient way to do this?  Loading up the master
file words into a trie data struct would be ideal but I haven't found any packages
with tries implemented.  Any thoughts?

Another quesiton:  Is there a quick way to remove unwanted elements from a file?
eg. like substitute all periods with a space?

TIA,
dg

Jonathan Stowe wrote:

> In comp.lang.perl.misc dinog@nospamcanada.com wrote:
> > Newbie here.  I'd like to open a text file and read in the text word by
> > word that would be delineated by spaces.  I've opened a file ok, but
> > reading in words, I still haven't found anything that would help.
>
> No reading in word by word is not very easy to achieve - you will need
> to read a line at a time and the split that line into words (however you
> might define words ).
>
> Of course beyond this is it is difficult to comment further because you
> dont say what you want to do with words after you have this list.
>
> BTW comp.lang.perl is a dead group - its fallen off its perch and is pushing
> up camels ... and I dont think this is appropriate to modules either ...
>
> /J\
> --
> Jonathan Stowe <jns@btinternet.com>
> Some of your questions answered:
> <URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
> Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>



------------------------------

Date: 21 Mar 1999 17:12:54 GMT
From: "Suresh Visuvasakumar" <s.v.kumar@worldnet.att.net>
Subject: Simple DOS/Win95 originated Perl script not working when loaded in the UNIX Server
Message-Id: <7d39am$lls@bgtnsc01.worldnet.att.net>

I didn't see my original message so I am reposting

Suresh

Suresh Visuvasakumar wrote in message ...
>Please help!!!!!!!!!!!!!!!!
>
>I am so much frustrated a very simple script is not working when loaded in
>the Unix server.
>
>Originally the script (hello.pl) was created in DOS/Win95. The same script
>works when my ISP loaded after creating it in his Unix machine.
>I know that Unix ignores DOS carage return or newlines.  Is this one
>creating the problem. I am new to Perl and so far worked only in Dos Win32
>machines.
>
>I wrote a Perl script (inout.pl) to remove white space and insert an
newline
>\n at the end of each line but it doesn't help either.
>Any help is appreciated.
>
>-------- INOUT.PL Script -------------
>#!/usr/local/bin/perl
>#
>###########################################
># A program to remove white space in DOS file
># and to insert newline.
>############################################
>#
># open input file
>#
>$input = <STDIN>;
>chop($input);
>unless (open(INFILE, "$input")) {
>die ("Cannot open input file: \n" );
>}
>#
># open output file
>#
>$output = <STDIN>;
>chop($output);
>unless (open(OUTFILE, ">$output")) {            # to append replace > with
>>>
>die ("Cannot open output file: \n" );
>}
>#
># do copy
>#
>$line = <INFILE>;
>while ($line ne "") {
>#next line is commented to test the other line , uncomment to remove white
>space
>#$line =~ s/^\s+|\s+$//g; # remove white space
>$line =~ s/\n\r$/\n/;    # convert \n\r to \n
>$line = "$line\n";       # insert \n at end of each line
>print OUTFILE ($line);
>$line = <INFILE>;
>}
>
>
>-------- END of INOUT.PL Script -------------
>
>
>
>
>




------------------------------

Date: Sun, 21 Mar 1999 22:16:04 +0100
From: Zenno <zenno22@hotmail.com>
Subject: using passing delimiter of regexp to sub
Message-Id: <36F56138.62D8CA01@hotmail.com>

Hi all


How can I pass a char to a function and use that char as a delimiter in
a regexp?

I have a file with words separated by a character. this may be a space,
a '|' symbol or by any other char. Therefore I pass the delimiter as the
last argument in the function call.
Tthe function should return a list containing lists in which each word
is an element.

I tried it like this:

@LoL = get_FileText_LOL($aFilePath.'|'); # read the file in a LoL

sub get_FileText_LOL {
 my($file) = @_;
 my($delimiter) = pop(@_);
 my(@LoL) = ();

 open(FILEHANDLE, "<$file") || &file_open_error("can\'t read open file
$file $!\n");
 foreach $line(<FILEHANDLE>) {
  @tmp = split(/$delimiter/,$line); #The words in this file are
separated by a "|" symbol.

print $tmp[0];

  push(@LoL, [@tmp]);
 }

 close (FILEHANDLE);
 return @LoL;
}

The "print $tmp[0];" statement in te sub body prints out the first
_char_, not the first _word_ which is what I want.

How can I have it print out the word?

Thanks,

Marc
zmbakker@xs4all.nl



------------------------------

Date: Sun, 21 Mar 1999 12:13:57 -0600
From: Barry Wegman <bwegman@HiWAAY.net>
Subject: What isn't getting reset?
Message-Id: <3aBaWa8c#GA.211@pet.hiwaay.net>

$s = "This is a test of the American Broadcasting Service."
@matches = ($s =~ /([tT]\S{1,})/);  ## NOTE: Not done globally!
print "Matched: ", join(", ", @matches), "\n";
@matches = ($s =~ /([tT]\S{1,})/g);
print "Matched: ", join(", ", @matches), "\n";
@matches = ($s =~ /([tT]\S{1,})/g);
print "Matched: ", join(", ", @matches), "\n";

Forgive my newbie question, but the above code produces the
following output, which I don't understand.  Can someone please
explain it to me?  (Please E-mail me a copy of any responses.)

Matched: This
Matched: test, the, ting
Matched: This, test, the, ting

Clearly, something is not getting reset between the first and
second matches.  Otherwise, the second and third matches would
be the same.  Their code is identical.  The first match is NOT
global.  What isn't being reset?  And how can I reset it?


------------------------------

Date: Sun, 21 Mar 1999 14:41:34 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: What isn't getting reset?
Message-Id: <1dp0tzu.fttz5w1i3dtzwN@p111.block2.tc6.state.ma.tiac.com>

[posted and mailed]

Barry Wegman <bwegman@HiWAAY.net> wrote:

> $s = "This is a test of the American Broadcasting Service."
> @matches = ($s =~ /([tT]\S{1,})/);  ## NOTE: Not done globally!
> print "Matched: ", join(", ", @matches), "\n";
> @matches = ($s =~ /([tT]\S{1,})/g);
> print "Matched: ", join(", ", @matches), "\n";
> @matches = ($s =~ /([tT]\S{1,})/g);
> print "Matched: ", join(", ", @matches), "\n";
> 
> Forgive my newbie question, but the above code produces the
> following output, which I don't understand.  Can someone please
> explain it to me?  (Please E-mail me a copy of any responses.)
> 
> Matched: This
> Matched: test, the, ting
> Matched: This, test, the, ting
> 
> Clearly, something is not getting reset between the first and
> second matches.  Otherwise, the second and third matches would
> be the same.  Their code is identical.  The first match is NOT
> global.  What isn't being reset?  And how can I reset it?

What version of Perl are you using?


Matched: This
Matched: This, test, the, ting
Matched: This, test, the, ting


~> perl -v

This is perl, version 5.004_04 built for IP32-irix

 ...


This is likely a bug in earlier versions of Perl which has now been
fixed.


-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


------------------------------

Date: 21 Mar 1999 18:33:03 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Win32 Newbie please help
Message-Id: <7d3e0v$6ro$1@gellyfish.btinternet.com>

On Sun, 21 Mar 1999 13:40:17 GMT Mike Kirkby wrote:
> I have installed perl, -v gives the following:
> This is perl, version 5.004_02
> 
> when I try to makefile for any module,
> using the command:
> 
> perl -w makefile.pl
> 
> I get a file created called "makefile" in the same directory
> 
> If I then run :
> 
> perl -w makefile
> 
> I get:
> Backslash found where operator expected at makefile line 56, near "blib\"

Er, yes. thats because you are trying to run a Makefile with Perl.

You need some 'make' utility to process a makefile - 'dmake' was (I seem
to recall) distributed with the 5.00402 distribution.  So what you have to
do is

C:\whatever> dmake

After having created the makefile from Makefile.PL.

*However*  the 5.00402 distribution is no longer the most current available
for Win32.  If you download and install the ActiveState distribution from

<http://www.activestate.com/ActivePerl/>

The everything is a zip - all of the supported modules can be installed
via the Perl Package Manager (PPM) without the need for any deviousness
however this relies on modules having been packaged for this platform.

/J\

-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


------------------------------

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 5192
**************************************

home help back first fref pref prev next nref lref last post