[11057] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4657 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 15 04:03:41 1999

Date: Fri, 15 Jan 99 01:00:22 -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           Fri, 15 Jan 1999     Volume: 8 Number: 4657

Today's topics:
    Re: [Q] how to check the existence of ^M in a text file (Ronald J Kimball)
    Re: __DATA__ (Ronald J Kimball)
        A newbie who needs some help <ddowns1@"nospam"telusplanet.net>
    Re: Another newbie problem.  Help <njones@firstquadrant.com>
    Re: Building Dynamic Web Pages <flyfishin@iname.com>
        Different Results With Different Browsers info@gadnet.com
    Re: Different Results With Different Browsers info@gadnet.com
        does globbing remember? <trent@jps.net>
    Re: Dynamic HASHES :-(( (Bart Lateur)
    Re: Help needed with locking <eugene@snailgem.org>
    Re: Help needed with locking (Sam Holden)
    Re: Help needed with locking info@gadnet.com
    Re: Help needed with locking info@gadnet.com
        kwlii: Formatting numbers in Perl ? <kwlii@bigfoot.com>
    Re: logging hits remotely (Aaron P Smith)
    Re: LP eg. 3-2 doesn't work?? - Win32 prob?? (Ronald J Kimball)
    Re: need script or fix to mine <eugene@snailgem.org>
    Re: perl on NT forking problem <markn_nospam_@mincom.com>
    Re: problem with use strict and use FileCache <partha@mihy.mot.com>
    Re: Running Perl Script as cron job : SERIOUS PROBLEM <btate@primary.net>
    Re: Running Perl Script as cron job : SERIOUS PROBLEM ynotssor@my-dejanews.com
        sockets: server-side problem <bench@surfshop.net.ph>
        Treating Strings as FILEHANDLES dmulholl@cs.indiana.edu
    Re: Treating Strings as FILEHANDLES <rick.delaney@home.com>
    Re: Way to measure memory / performance hits of script? <eugene@snailgem.org>
    Re: what would you do? (Larry Rosler)
    Re: what would you do? (Bart Lateur)
    Re: Which Perl reference book? bnelissen@hotmail.com
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Thu, 14 Jan 1999 23:12:16 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: [Q] how to check the existence of ^M in a text file on Unix
Message-Id: <1dln7bh.1oavs5z1scxigeN@bay3-20.quincy.ziplink.net>

Uri Guttman <uri@ibnets.com> wrote:

>   KM> $foundit = $allfile =~ /\cM/;
> 
> much faster with tr/\cM// ;

Nope...  Searching for the first occurence, as with /\cM/, is slightly
faster than counting all occurences, as with tr/\cM//.  You only need to
use tr/\cM// if you actually want to count all the occurences.

tr/X/Y/ is faster than s/X/Y/g, of course.  That's probably what you
were thinking of.

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


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

Date: Thu, 14 Jan 1999 23:12:18 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: __DATA__
Message-Id: <1dln7i0.1mh6q3r1t7apj4N@bay3-20.quincy.ziplink.net>

James B Crigler <james.b.crigler@lmco.com> wrote:

> Though the docs come with perl, it does not follow necessarily that they
> are available to users.  E.g., I have access to the man pages, but to
> get
> the FAQs, I have to on the web.  (Even at that, the version of perl in
> use
> here is 5.003---multiple years out of date.  Unlike my previous job,
> at this employer I don't have admin privileges.)

Ah, but the FAQs are included in the manpages!  They were added with
perl5.004.

With perl5.003, you get 5.003's features, 5.003's bugs, and 5.003's
documentation.

Just one more reason to upgrade, eh?

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


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

Date: Fri, 15 Jan 1999 07:52:55 GMT
From: "Danny Downs" <ddowns1@"nospam"telusplanet.net>
Subject: A newbie who needs some help
Message-Id: <rtCn2.7882$Kg6.57670@news2.telusplanet.net>

I am writing a perl script that would ask you to enter a username and
password then telnet to a mail server and take the value of the username and
the password and enter them once you connect to the mail server.
For example you would enter the username "bob" and the password "bob1". once
a connection to the mail server is made the script would initatate the
'user' command and the 'pass' command using the value that you entered
above. What my problem is is that I can't get the 'user' and the 'pass'
command to type out once I connect to the mail server. Can anyone help me




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

Date: Thu, 14 Jan 1999 19:42:23 -0800
From: Neil Jones <njones@firstquadrant.com>
Subject: Re: Another newbie problem.  Help
Message-Id: <369EB91F.7FDA4A32@firstquadrant.com>

See below.

> --------------------------
> Now for the important 2 questions.
>
> 1-  what convention do I use to call this from the HTML???  I am
> testing this script on a local OmniHTTP server.  What is the
> convention for calling this script.?..
>
> ie. This works <img src="/cgi-bin/visitor.exe">
>

I'd assume <a href="/cgi-bin/visitor.cgi">run the script</a> would do it.

>
> 2- Perhaps this should've been part of question 1, but anyway.
> When calling this script, I want to pass a parameter to it, that being
> the filename I want the info on.  I would obviously have to change the
> Perl script to do this, but how?  All the examples I've seen currently
> are forms, and that's not really what I'm looking for.

I'd further assume <a href="/cgi-bin/visitor.cgi?foo=bar">run the
script</a>
would run visitor.cgi with foo = bar as a parameter.  You should be able
to
use the CGI.pm module to handle the CGI stuff, though I don't know if
it works with OmniHTTP.  It works with Apache, even on Windows.

HTH

Neil





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

Date: Thu, 14 Jan 1999 21:33:10 -0600
From: "rather be fishin'" <flyfishin@iname.com>
Subject: Re: Building Dynamic Web Pages
Message-Id: <77mcoe$38s$1@news3.kcnet.com>

airplanes@altavista.net wrote in message
<772v9q$8qi$1@nnrp1.dejanews.com>...
>Hello!
>  Could anyone help me find a script to create dynamic web pages. I need a
set
>of vari's to be extracted from a database like access. Could someone please
>help me, I'm new to this kind of thing.
>
>Simply, I need to have a script to create pages automaticly from an imput
into
>a database.


Start with Learning Perl, since you are new,  then work with Programming
Perl, then move onto a book discussing CGI using Perl.  Then for great
examples and explanations of code try the Perl Cookbook.

tim m




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

Date: Fri, 15 Jan 1999 11:08:38 GMT
From: info@gadnet.com
Subject: Different Results With Different Browsers
Message-Id: <369f212b.9218694@news.newsguy.com>

I have written a script which works fine under Netscape. You fill in a
form, click on the button and another page comes up. If you do the
same thing with MSIE a blank page comes up. Why are different browsers
treating my script differently? You can see this in action at: 

http://www.gadnet.com/cgi-bin/bpjoin.cgi?new

Drummond


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

Date: Fri, 15 Jan 1999 11:59:43 GMT
From: info@gadnet.com
Subject: Re: Different Results With Different Browsers
Message-Id: <369f2d9c.12398833@news.newsguy.com>

If anyone's interested, I've found the problem. 

The calling form contained the line:
<input type=hidden name=showuser>

The script then did this:

if ($indata{'showuser'})
{
	&showuser;
}

Under Netscape this test worked, but not under MSIE. I have fixed the
problem by changing the input tag to:
<input type=hidden name=showuser value=x>

Drummond

>I have written a script which works fine under Netscape. You fill in a
>form, click on the button and another page comes up. If you do the
>same thing with MSIE a blank page comes up. Why are different browsers
>treating my script differently? You can see this in action at: 
>
>http://www.gadnet.com/cgi-bin/bpjoin.cgi?new
>
>Drummond



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

Date: Fri, 15 Jan 1999 00:02:49 -0800
From: Trent <trent@jps.net>
Subject: does globbing remember?
Message-Id: <369EF629.63B7@jps.net>

Gents/Ladies,

globbing-

I can open a series of text files and place the contents
into an array, but is it possible to recover/identify what
lines came from which original file? I'm thinking a hash,
but then again I'm fairly new at this.


Thanks 

Trent


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

Date: Fri, 15 Jan 1999 08:34:05 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Dynamic HASHES :-((
Message-Id: <369ffb25.3970363@news.skynet.be>

Bart Lateur wrote:

>Stefan Nonneman wrote:
>
>>Is it possible to append data pairs to existing hashes when a key is not
>>found?
>>From the documentation it is not clear to me.
>
>What do you mean?

Oh, wait. Maybe now I get the question.

	$hash{$key}->{$subkey} = $subvalue;

where $hash{$key} didn't exist before. Yup, that works.


    ($\,$,) = ("\n"," | ");
    $hash{key}->{subkey1} = 111;
    $hash{key}->{subkey2} = 222;
    print keys %hash; # key
    print sort keys %{$hash{key}}; # subkey1 | subkey2
    foreach (sort keys %{$hash{key}}) {
	print " * $_ => $hash{key}->{$_}";
	# * subkey1 => 111
	# * subkey2 => 222
    }

	Bart.


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

Date: Thu, 14 Jan 1999 22:17:13 -0500
From: Eugene Sotirescu <eugene@snailgem.org>
Subject: Re: Help needed with locking
Message-Id: <369EB339.EABA5348@snailgem.org>

info@gadnet.com wrote:

> I was hoping for something a little more general (or a little more
> detailed) than the Perl FAQ which I had seen. It doesn't mention any
> kind of semaphore locking, nor the workings of flock. What happens if
> you open a file for reading which is currently held with an flock (2)
> for writing? Will the open work, even if you can't then read the file?
> I am very confused about the concept of applying file level locking
> after opening a file. Is there anywhere where this is explored in
> plain English?
>

AFAIK, Tom Christiansen is the only one in this group who can shed the
light of reason upon the terrible mysteries of Perl flock().
Nevertheless, here's my 2c for your scenario:
if process 1 is granted an flock (FH, LOCK_EX) and then process 2 comes
along to do an flock (FH, LOCK_SH) on the same file, process 2 is not
granted the lock until process 1, the one with the exclusive lock,
releases it (close FH).  I.e. process 2 will have to wait till process 1
finishes (or fails) to write before reading the file.
However, if process 2 opens the file for reading  _without_  requesting
the shared lock, it can read the file without delay, even as it is
written to by process 1.

Sorry can't help more.




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

Date: 15 Jan 1999 04:53:07 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Help needed with locking
Message-Id: <slrn79tidj.j12.sholden@pgrad.cs.usyd.edu.au>

On Thu, 14 Jan 1999 22:17:13 -0500, Eugene Sotirescu <eugene@snailgem.org>
	wrote:
>info@gadnet.com wrote:
>
>> I was hoping for something a little more general (or a little more
>> detailed) than the Perl FAQ which I had seen. It doesn't mention any
>> kind of semaphore locking, nor the workings of flock. What happens if
>> you open a file for reading which is currently held with an flock (2)
>> for writing? Will the open work, even if you can't then read the file?
>> I am very confused about the concept of applying file level locking
>> after opening a file. Is there anywhere where this is explored in
>> plain English?
>>
>
>AFAIK, Tom Christiansen is the only one in this group who can shed the
>light of reason upon the terrible mysteries of Perl flock().
>Nevertheless, here's my 2c for your scenario:
>if process 1 is granted an flock (FH, LOCK_EX) and then process 2 comes
>along to do an flock (FH, LOCK_SH) on the same file, process 2 is not
>granted the lock until process 1, the one with the exclusive lock,
>releases it (close FH).  I.e. process 2 will have to wait till process 1
>finishes (or fails) to write before reading the file.
>However, if process 2 opens the file for reading  _without_  requesting
>the shared lock, it can read the file without delay, even as it is
>written to by process 1.

Which is the only way it can be without OS support for file locking.
Think traffic lights and file locking makes perfect sense. An exclusive
lock causes the lights to go red for every one else. However, there is
nothing actually stopping someone running the red light and causing
problems. However, if every one obeys the red light via LOCK_SH then
all will be well.


-- 
Sam

Of course, in Perl culture, almost nothing is prohibited. My feeling is
that the rest of the world already has plenty of perfectly good
prohibitions, so why invent more?  --Larry Wall


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

Date: Fri, 15 Jan 1999 11:10:04 GMT
From: info@gadnet.com
Subject: Re: Help needed with locking
Message-Id: <369f21d2.9385463@news.newsguy.com>

>Just out of curiosity, I went to the place you recommended:
>
>http://language.perl.com/newdocs/pod/perlfaq5.html#How_can_I_lock_a_file_
>
>This pointed to flock in the perldoc:
>
>http://language.perl.com/newdocs/pod/perlfunc/flock.html
>
>which has the old, wrong example from the Camel book: the mailbox
>appender for BSD that  uses
>flock(MBOX,LOCK_UN);
>
>instead of
>
>close MBOX;
>
>(wasn't it you who said "never, never, never" a short while ago?).


Well that raises a question in itself. Why should one close a file
instead of unlocking it? Makes no sense to me.

Drummond



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

Date: Fri, 15 Jan 1999 12:12:04 GMT
From: info@gadnet.com
Subject: Re: Help needed with locking
Message-Id: <369f2ea6.12664351@news.newsguy.com>

>>What happens if
>> you open a file for reading which is currently held with an flock (2)
>> for writing? Will the open work, even if you can't then read the file?
>
>AFAIK, Tom Christiansen is the only one in this group who can shed the
>light of reason upon the terrible mysteries of Perl flock().
>Nevertheless, here's my 2c for your scenario:
>if process 1 is granted an flock (FH, LOCK_EX) and then process 2 comes
>along to do an flock (FH, LOCK_SH) on the same file, process 2 is not
>granted the lock until process 1, the one with the exclusive lock,
>releases it (close FH).  I.e. process 2 will have to wait till process 1
>finishes (or fails) to write before reading the file.
>However, if process 2 opens the file for reading  _without_  requesting
>the shared lock, it can read the file without delay, even as it is
>written to by process 1.
>
>Sorry can't help more.

My real question concerns the open itself. From what I've seen, using
flock goes something like this:

Open file
lock file
manipulate file
close file

In other words you open a file and then lock it. Two separate steps.
Now if process 1 successfully opens a file in write mode and then
locks it, what happens when process 2 opens the file (in read mode).
We don't need to worry about what happens when Process 2 actually
tries to read, it's the Open that I'm worried about. Does the open
work? Maybe this is just a stupid question, and the answer is: of
course. But the idea of successfully opening locked files worries me.





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

Date: 15 Jan 1999 04:19:57 GMT
From: "kwlii" <kwlii@bigfoot.com>
Subject: kwlii: Formatting numbers in Perl ?
Message-Id: <77mfld$nmq@bgtnsc03.worldnet.att.net>

In COBOL you can create an edit mask for formatting numbers
ie:  28888.00  = $28,888.00 with a PIC $zz,zzz.99

How do you format a number to include the , and the $.

I just have not found a reference to the kind of formatting
in any of the manuals that I have.

Thanks in advance for your help!

Ken
kwlii@bigfoot.com




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

Date: Fri, 15 Jan 1999 00:32:21 -0800
From: asmith@wsindex.com (Aaron P Smith)
Subject: Re: logging hits remotely
Message-Id: <MPG.11089ca33465b38298971d@news.pacifier.com>

[This followup was posted to comp.infosystems.www.misc and a copy was 
sent to the cited author.]

In article <369C8C56.A6AC05DC@processing.net>, michael@processing.net 
says...
> Perl/Web Experts,
> 
> I have a basic web account that allows no CGI access (just a
> form-to-email and a simple counter).  I would like to get stats on who
> is visiting that site.  Is there a way to run the cgi from another
> server and log hits on the basic site?  Please send me any ideas you may
> have, whether backed up by code or not.

Hi Michael,

I maintain a list of counters that provide the type of infomration about 
your visitors that you're looking for. The address to my site is:

http://www.wsindex.com/

I hope this helps,

Aaron
-- 
The Web Service Index
http://www.wsindex.com/


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

Date: Thu, 14 Jan 1999 23:12:20 -0500
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: LP eg. 3-2 doesn't work?? - Win32 prob??
Message-Id: <1dln8if.1xxc4kw1uddoamN@bay3-20.quincy.ziplink.net>

Terry Haroldson <tharoldson@home.com> wrote:

> I suppose it is is the same problem as mentioned by Eric Bohlman today
> re: bugs in the Win32 console routines.  But it's a pain.  Is there
> anything else to do, other than redirect output to a file.

The problem is that the first line of output is lost, when it is printed
after reading input terminated with ^Z.  Thus, output a bozo first line
before the real output.

print "\n";

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


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

Date: Thu, 14 Jan 1999 18:57:23 -0500
From: Eugene Sotirescu <eugene@snailgem.org>
Subject: Re: need script or fix to mine
Message-Id: <369E8463.AC8DD1D3@snailgem.org>



Earl Childers wrote:

> I need a script that will allow the downloading of any filetype (or at elast
> the common ones) on a PC or Mac using Netscape or IE.   Do you know if such
> a thing exists?
>
> Or, I need to find out why some files (e.g. .avi, .mov) open Windows Media
> Player when downloaded with IE, where Netscape handles the download fine by
> presenting me with the "save or open" window to choose from.
>
> I'm aware of the IE but that causes this, from a MS tech note, but I don't
> know the workaround.
>

>
> Really hoping to getting an answer on this!

On a Perl programming newsgroup? Why?





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

Date: Fri, 15 Jan 1999 14:04:26 +0800
From: "Mark Nold" <markn_nospam_@mincom.com>
Subject: Re: perl on NT forking problem
Message-Id: <77mlkv$bnm$1@pithy.mincom.oz.au>

I the function fork() isnt supported in NT Perl. So perhaps what you are
trying to do is also impossible?

See STATUS.TXT

Unsupported process-related routines
====================================

fork()
setpriority()
times()
wait()
waitpid()



Garth Cunningham wrote in message <77jn6v$n3a$1@news.ses.cio.eds.com>...
>I have a perl script which runs fine on our unix system but when trying to
>run it on an NT system I get the following error.
>
>The name specified is not recognised as an internal or external command,
>operable program or batch file.
>
>I run it on NT by doing a
>




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

Date: Fri, 15 Jan 1999 10:12:19 +0530
From: Ramanujam Parthasarathi <partha@mihy.mot.com>
To: Chris Fedde <cfedde@cfedde.corp.infobeat.com>
Subject: Re: problem with use strict and use FileCache
Message-Id: <369EC72B.588A0B96@mihy.mot.com>

Hi,

Always use the directive 'use strict' after importing (literally) all other
packages. So, your use strict should be usually the last one. This way you
need not care if other package modules have 'use(d ) strict' or not.

HTH
-Partha

Chris Fedde wrote:

> The program below generates the following error on my system:
>
>     Can't use string ("sender08.lodo.in.infobeat.com") as a symbol
>     ref while "strict refs" in use at u line 13.
>
> Is there a way to "use FileCache" and "use strict" at the same time?
>
> thanks
> chris





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

Date: Thu, 14 Jan 1999 21:40:58 -0600
From: "Bob Tate" <btate@primary.net>
Subject: Re: Running Perl Script as cron job : SERIOUS PROBLEM
Message-Id: <369ec381.0@news.primary.net>

Why are you using "csh -c"  in your cron job??  I run several Perl cron jobs
and do not make that reference.  Here is a copy of one of my lines from my
cron file.

* * * * * /export/home/fltops/database/email_notify.pl



<jkelly@shannon.tellabs.com> wrote in message
news:77lbpm$c9s$1@nnrp1.dejanews.com...
>Hello,
>
>I am trying to run a perl script as a cron job. The line of the crontab
file
>is shown below
>
>46 17 * * * csh -c "<path>/txt_to_html >& /dev/null"
>
>where txt_to_html is the Perl program.
>
>The command runs OK from the command line but not as a cron job. I have
>looked up this problem in various newsgroups etc. and have tried sourcing
>.cshrc files, .login files, .profile files un the crontab line, setting
>environment variables : everything that is recommended in the newsgroups
>without success. I am not using any Perl libraries / modules. I am using
>Solaris 2.5.1 and perl 5.004. I would be grateful for any help that I could
>get on this problem as it has me well and truly confused !!
>
>Many Thanks,
>John Kelly <jkelly@shannon.tellabs.com>.
>
>-----------== Posted via Deja News, The Discussion Network ==----------
>http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own



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

Date: Fri, 15 Jan 1999 06:40:47 GMT
From: ynotssor@my-dejanews.com
To: jkelly@shannon.tellabs.com
Subject: Re: Running Perl Script as cron job : SERIOUS PROBLEM
Message-Id: <77mnte$hif$1@nnrp1.dejanews.com>

In article http://x11.dejanews.com/getdoc.xp?AN=432589349,
  jkelly@shannon.tellabs.com wrote:

 ...
> 46	17	*	*	* csh -c "<path>/txt_to_html >& /dev/null"
 ...
> I would be grateful for any help that I could get on this problem as
> it has me well and truly confused !!

Hmmmmm, the man page says:

     -c        Execute  the  first  argument   (which   must   be
               present).  Remaining arguments are placed in argv,
               the argument-list variable, and passed directly to
               csh.

Remember that cron is using sh as the shell.

Try:

46 17 * * * csh -c <path>/txt_to_html > /dev/null 2>&1

This directs both standard output and standard error to the bin bucket. Omit
the 2>&1 if you want email of the standard error.

	tony

__________________________________________________________________________
"Yacc" owes much to a most stimulating collection of users, who have
goaded me beyond my inclination, and frequently beyond my ability in
their endless search for "one more feature".  Their irritating
unwillingness to learn how to do things my way has usually led to my
doing things their way; most of the time, they have been right.
                -- S. C. Johnson, "Yacc guide acknowledgements"

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Fri, 15 Jan 1999 15:41:26 +0800
From: "Benjamin" <bench@surfshop.net.ph>
Subject: sockets: server-side problem
Message-Id: <77mred$bv7$1@tempo.news.iphil.net>

How do I handle the escape character "^]" when a client tries to connect to
the
server using "telnet  port#" and types the escape character and at the
prompt
" > quit " ?
After quitting, a 'ps auxw | grep  server'  shows the spawned 'server' is
still there e.g.:

bench    28119   0.0    1.1   2108      1504  p1 S    14:42   0:00 perl
 ./server
bench    28211 83.6  31.7  41192  40584  p1 R    14:43  34:34 perl ./server

If a client connects again using telnet to the port# of the server a new
spawned
"server" is created and when the client quits, the spawned server remains.
Does anyone have an idea on how can I solve this problem?

Thanks.





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

Date: Fri, 15 Jan 1999 04:09:50 GMT
From: dmulholl@cs.indiana.edu
Subject: Treating Strings as FILEHANDLES
Message-Id: <77mf27$agf$1@nnrp1.dejanews.com>

Greetings All,

  I am writing to ask if there is a way I can use a string as
a stream.  The scenario I have is a string that contains newlines
(the string holds the contents of a whole file) and I would like
to process it one line at a time.  I would rather not split it
up into an array (seems unduely memory consuming to have to
copy the data).  Nor open an external shell (performance), so I
*think* open(STRINGHANDLE, "echo $string |") is not an option either.

What would be ideal might be:

  while ( <$string> ) {

   ...some processing...

  }

analagous to "while (<FILEHANDLE>)" whereby $_ is reset to the next
line in the buffer for each new cycle in the loop.

thanks in advance!

  /Daniel


-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Fri, 15 Jan 1999 05:06:24 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Treating Strings as FILEHANDLES
Message-Id: <369ECEA6.BB8A5AC7@home.com>

[posted & mailed]

dmulholl@cs.indiana.edu wrote:
> 
> Greetings All,
> 
>   I am writing to ask if there is a way I can use a string as
> a stream.  The scenario I have is a string that contains newlines
> (the string holds the contents of a whole file) and I would like
> to process it one line at a time.  I would rather not split it
> up into an array (seems unduely memory consuming to have to
> copy the data).

I'm confused.  If the string (scalar) holds the contents of a file, then
why didn't you put the file's data into an array in the first place?

    @array = <FILE>;

And if you're willing to have a whole file in memory at once (in your
scalar) I think you are probably fretting too much about splitting it
into an array as well.

What exactly are you trying to do?  To answer your question, you might
want to look at using tied filehandles, but I doubt it.  

perldoc perltie

-- 
Rick Delaney
rick.delaney@shaw.wave.ca


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

Date: Thu, 14 Jan 1999 19:26:27 -0500
From: Eugene Sotirescu <eugene@snailgem.org>
Subject: Re: Way to measure memory / performance hits of script?
Message-Id: <369E8B33.4DDBB607@snailgem.org>

Daniel Grisinger wrote:

> Eugene Sotirescu <eugene@snailgem.org> writes:
>
> > Andrew M. Langmead wrote:
> <snip list of common errors that lead to slow execution>
> > > And there are a zillion others.

>
> > Maybe not zillions, but here's another big one:
> >
> > combining backreferences with multiple wildcards in regular expressions
>
> That one doesn't really count, though, as it isn't always a mistake.
> There are a lot of problems where need [+*] and backreferences are
> absolutely essential.

You're right, but I thought we were talking about things that can slow your
code down, not necessarilly about mistakes.
If your code reads in a long string and then uses 3 wildcards and a lot of
backtracking to match something making it all take 10 minutes are you making
a mistake?
(You might be able to speed it up with non-greedy matching, for instance:
would it count then? ;---------) )



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

Date: Thu, 14 Jan 1999 21:59:25 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: what would you do?
Message-Id: <MPG.11087919e290752b989991@nntp.hpl.hp.com>

In article <369e5f9c.0@news1.ibm.net>, tavi367@ibm.net says...
> I have 2 possible ways of doing something (Sample A and B below).
> I would like to know which you you use any why.
 ...> 
> Sample A :      chr ( hex $sample )
 ...
> Sample B :      pack ( "c", hex($sample ) )

#!/usr/local/bin/perl -w
use Benchmark;

$sample = 0;

sub Chr  { my $x = chr hex $sample }

sub Pack { my $x = pack 'c', hex $sample }

timethese(1 << (shift || 0), {
    Chr  => sub { &Chr  },
    Pack => sub { &Pack },
});

> 
> 
Benchmark: timing 262144 iterations of Chr, Pack...
       Chr:  3 wallclock secs ( 3.24 usr +  0.00 sys =  3.24 CPU)
      Pack:  4 wallclock secs ( 4.00 usr +  0.00 sys =  4.00 CPU)

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


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

Date: Fri, 15 Jan 1999 08:42:24 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: what would you do?
Message-Id: <36a1ff14.4974062@news.skynet.be>

walter wrote:

>Sample A :      chr ( hex $sample )
>Sample B :      pack ( "c", hex($sample ) )

chr() is new in Perl 5. [B] is how you had to do it in Perl4. Likely
you've seen code that still had it's roots in Perl4.

	Bart.


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

Date: Fri, 15 Jan 1999 06:39:46 GMT
From: bnelissen@hotmail.com
Subject: Re: Which Perl reference book?
Message-Id: <77mnrh$hgp$1@nnrp1.dejanews.com>

In article <x7emoyguar.fsf@home.sysarch.com>,
  Uri Guttman <uri@home.sysarch.com> wrote:
> >>>>> "b" == bnelissen  <bnelissen@hotmail.com> writes:
>
>   b> Programming Perl (2nd Edition)
>   b> The Perl Cookbook
>
>   b> Has anybody compared these two?
>
> they are not comparable.
>
Hi,

Actually I forgot to include "Perl: The Programmer's Companion", which I've
heard is comparable with "Programming Perl (2nd Edition)". Any used this one?

Thanks again,

Bart

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

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 4657
**************************************

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