[24367] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6556 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 12 14:06:51 2004

Date: Wed, 12 May 2004 11:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 12 May 2004     Volume: 10 Number: 6556

Today's topics:
    Re: Books online???? (Default)
        grep (chet)
    Re: grep <noreply@gunnar.cc>
    Re: module bad design?) (Olivier Laurent)
    Re: module bad design?) (Sam Holden)
    Re: module bad design?) <gnari@simnet.is>
    Re: module bad design?) <tadmc@augustmail.com>
    Re: module bad design?) <remorse@partners.org>
        Module/recipe to resolve full pathnames? <socyl@987jk.com>
    Re: Module/recipe to resolve full pathnames? <remorse@partners.org>
    Re: Module/recipe to resolve full pathnames? <twhu@lucent.com>
    Re: Module/recipe to resolve full pathnames? <ddunham@redwood.taos.com>
    Re: myfile.cgi?image.gif saved as myfile.cgi in mozilla (Joseph)
        Perl distribution with threads support (Yash)
        Perl PGP (Gilian)
    Re: preferences file (Andres Monroy-Hernandez)
    Re: preferences file <mark.clements@kcl.ac.uk>
    Re: preferences file (Jack)
    Re: Printing multiple Array as multiple column <ewijaya@singnet.com.sg>
    Re: Regular Expression Help? - Newbie Question <vikr@mindspring.com.invalid>
    Re: Regular Expression Help? - Newbie Question <matternc@comcast.net>
        two questions about perl (Charlie)
    Re: two questions about perl (Walter Roberson)
        Unexpected sysread block (Swarna)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 12 May 2004 16:53:09 GMT
From: newuser@newsrouter!.comcast.net (Default)
Subject: Re: Books online????
Message-Id: <c7tkpk$j43$1@newsrouter!.comcast.net>

In article <HxD0GA.9oM@news.boeing.com>,
bxb7668 <bxb7668@somewhere.nocom> wrote:
>
>"Jim Gibson" <jgibson@mail.arc.nasa.gov> wrote in message
>news:070520041215298584%jgibson@mail.arc.nasa.gov...
>> Charlton Wilbur <cwilbur@mithril.chromatico.net> wrote in message
>> news:<87oep1fjfa.fsf@mithril.chromatico.net>...
>> > Seems sensible. I just wish we could take the "F" out. The
>pedantic,
>> > sarcastic manner is a waste of time too, and that's absolutely
>rife on
>> > c.l.p.misc.
>> >
>> > tas
>>
>> Why would you want to remove the word "Fine" from the phrase "Read
>The
>> Fine Manual (RTFM)"?
>
>You forgot the smiley ;-) since the original and commonly accepted
>meaning was a bit cruder than "Fine". I agree with Charlton. I would
>also like the acro to be RTM. Much nicer.
>
>
How about: "Read The Faq and Manual?" Thats how I introduce the term to 
newbies. Only the nor'easters seem to get a bit offended. :-)







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

Date: 12 May 2004 09:02:06 -0700
From: zipper59er@yahoo.com (chet)
Subject: grep
Message-Id: <3988d00.0405120802.252bc16e@posting.google.com>

the following script will parse records out of a log file.

my second grep doesn't find any records when it should
anybody know why (they exist in the file).

-thanx in advance.


#!/usr/bin/perl  

#make te function calls 
parse_lab_share (); 

sub parse_lab_share ()
{
        my @ins;
        my @outs;       
        my @fields;
        my $record; 
        my $login_str;
        my $logout_str;
        my $i;
        
        unless ( open VNTILOG, "./vnti.log" ) 
        {
                die "Cannot open the vector log file: $!";
        }
        @ins =  grep  /VECGI/ 
                        && !/ERROR/ 
                        && !/Error/ 
                        && !/Fragment/, 
                        <VNTILOG>;    
        foreach ( @ins ) 
        {
                @fields = split;        
                if ( $fields[14] eq "in" )      
                {       
                        $login_str =
"$fields[2]-$fields[1]-$fields[5]$fields[3]";
                        $record =
"$fields[23],$login_str,$fields[10],$fields[17]";
                        @outs = grep /$fields[23]/, <VNTILOG>;
                        foreach ( @outs )
                        {
                                @fields = split;        
                                print ( "$fields[23]\n" );      
                        }       
                }       
        }       

        #close the vector log file
        close VNTILOG;
}


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

Date: Wed, 12 May 2004 18:25:11 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: grep
Message-Id: <2gf1j9F1g7urU1@uni-berlin.de>

chet wrote:
> the following script will parse records out of a log file.
> 
> my second grep doesn't find any records when it should

Should it? Which debug efforts have you carried out yourself?

Have you, for instance, considered the implication of the VNTILOG 
filehandle being empty when you apply grep() to it?

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: 12 May 2004 01:23:51 -0700
From: oliderid@yahoo.co.uk (Olivier Laurent)
Subject: Re: module bad design?)
Message-Id: <8d63e22a.0405120023.5d6404af@posting.google.com>

sholden@flexal.cs.usyd.edu.au (Sam Holden) wrote in message news:<slrnca1n3p.qii.sholden@flexal.cs.usyd.edu.au>...

> It is insulting to be asked to do a job a machine can
> do in a millisecond or so.

Well thanks, for Playing the guru teaching the poor mass. But my
problem wasn't your ego, my problem is how to make my first perl
module and having fun while doing it. I'm just asking advices, nobody
forces you to reply.

My problem is why a filename like "./log/test.txt" is transformed into
SCALAR(10CBAA) when it is sent through parse_file->new($filename)

warmings has been disabled because it gave nothing, I played around to
understand what's going on.

I will respect lowercase and stuff like that while I have something
relevant to share with the community. not for a stupid module made by
a complete beginner to learn object oriented coding in perl.



Olivier


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

Date: 12 May 2004 08:29:02 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: module bad design?)
Message-Id: <slrnca3o2e.vg9.sholden@flexal.cs.usyd.edu.au>

On 12 May 2004 01:23:51 -0700, Olivier Laurent <oliderid@yahoo.co.uk> wrote:
> sholden@flexal.cs.usyd.edu.au (Sam Holden) wrote in message news:<slrnca1n3p.qii.sholden@flexal.cs.usyd.edu.au>...
> 
>> It is insulting to be asked to do a job a machine can
>> do in a millisecond or so.
> 
> Well thanks, for Playing the guru teaching the poor mass. But my
> problem wasn't your ego, my problem is how to make my first perl
> module and having fun while doing it. I'm just asking advices, nobody
> forces you to reply.

I gave you advice. I pointed out three problems. One exactly by
line and character, one via the warning perl will
generate (giving the line number and description of the
problem), and one by pointing out an omission.

> 
> My problem is why a filename like "./log/test.txt" is transformed into
> SCALAR(10CBAA) when it is sent through parse_file->new($filename)

And as I said, it isn't because it doesn't. The code you posted does
not generate that output.

The file name isn't "sent through parse_file->new($filename)" since
all the arguments to new() are ignored.

> 
> warmings has been disabled because it gave nothing, I played around to
> understand what's going on.

It pointed out a bug that will make the code not work. 

That seems to be giving something to me.

But to each his own, if you want non-working code then that's 
your business.

-- 
Sam Holden


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

Date: Wed, 12 May 2004 08:52:57 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: module bad design?)
Message-Id: <c7soi8$bo2$1@news.simnet.is>

"Olivier Laurent" <oliderid@yahoo.co.uk> wrote in message
news:8d63e22a.0405120023.5d6404af@posting.google.com...
> sholden@flexal.cs.usyd.edu.au (Sam Holden) wrote in message
news:<slrnca1n3p.qii.sholden@flexal.cs.usyd.edu.au>...
>
> > It is insulting to be asked to do a job a machine can
> > do in a millisecond or so.
>
> Well thanks, for Playing the guru teaching the poor mass. But my
> problem wasn't your ego, my problem is how to make my first perl
> module and having fun while doing it. I'm just asking advices, nobody
> forces you to reply.

[slightly reordered comments]

> warmings has been disabled because it gave nothing, I played around to
> understand what's going on.

you are taking this too personally. when you post a script
because of a problem, and we see no warnings enabled, it is not
worth it for us to look too closely at the code, because we would
have to start by cuttting and pasting your code into an editor,
add the warning, save it and run it , just to see if there are any
warnings. this often seems a bit too much work to do to help
someone who was too lazy to do it himself. now, if you had said
in your OP that 'it ran without warnings when enabled' or some such,
many of us probably would have trusted you on that,

>
> My problem is why a filename like "./log/test.txt" is transformed into
> SCALAR(10CBAA) when it is sent through parse_file->new($filename)

actually your code said:
    my $test= parse_file->new(FILE=>"./log/1fr.txt",AREA=>6);
so you are calling parse_file($some_object_reference);

your main problem is that you do not seem to have grasped how
parameters are picked up by subs.

neither your new() , nor your parse_file seem to do anything
with any arguments sent.

> I will respect lowercase and stuff like that while I have something
> relevant to share with the community. not for a stupid module made by
> a complete beginner to learn object oriented coding in perl.

you were asking for comments

in addition, let me add:
you should declare $a as lexical in parse_file():
    my $a;

did you notice the comment Sam made about the single quotes in the
open() call.

gnari






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

Date: Wed, 12 May 2004 07:55:52 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: module bad design?)
Message-Id: <slrnca47mo.5q9.tadmc@magna.augustmail.com>

Olivier Laurent <oliderid@yahoo.co.uk> wrote:

> But it fails. I receive 


I don't get that when I run your code.

If we cannot duplicate the problem, we probably cannot solve the problem.


> an error "could not open SCALAR(XXXX)";
> it seems that FILE is transformed into a hexadecimal code ?


That is a stringified reference.

Somehow or another (we can't tell because the posted code does not
do what you say it does...) you have a reference to a scalar where
you were probably expecting a scalar itself.


> What is my mistake?


You have multiple mistakes.


> sub new { 
>     my $self = {};
>     $self->{'FILE'} = undef;
>     $self->{AREA} = undef;
>   bless {$self};
          ^     ^
          ^     ^

Those should not be there.

new() does not access any arguments, yet you call it with arguments...


>      my $file = $self->{FILE};
>      my $area = $self->{AREA};


Those will always be undef, since your code never assigns anything
else to them...


>     my @data;
>      my @return_data;
>      open(MYFILE,'$file')|| die "cannot open $file: $!";
                   ^     ^
                   ^     ^

Those should not be there either.



> #     $self->{'var'}= \$file;


Now _there_ is a reference to a scalar.

Was that line uncommented when you saw the SCALAR(XXXX) output?



If you post a short and complete program *that we can run*
that illustrates your problem, we can help you fix it.

If you don't we can't.

Have you seen the Posting Guidelines that are posted here frequently?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Wed, 12 May 2004 09:54:48 -0400
From: Richard Morse <remorse@partners.org>
Subject: Re: module bad design?)
Message-Id: <remorse-F5C704.09544812052004@plato.harvard.edu>

In article <c7soi8$bo2$1@news.simnet.is>, "gnari" <gnari@simnet.is> 
wrote:

> in addition, let me add:
> you should declare $a as lexical in parse_file():
>     my $a;

Actually, isn't this one of those special cases where you want to use a 
different variable name, because $a is involved in sorting?  Or does it 
not count because we're in a different package here?

Ricky

-- 
Pukku


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

Date: Wed, 12 May 2004 13:49:21 +0000 (UTC)
From: kj <socyl@987jk.com>
Subject: Module/recipe to resolve full pathnames?
Message-Id: <c7ta11$ftt$1@reader2.panix.com>




Is there a module (or built-in) that will take an arbitary Unix
filename specification (either absolute or relative) and return
the "canonical" absolute full path to the file?  For example:

  input:  ~jones/../foo/../../bar/./baz//frobozz/
  output: /bar/baz/frobozz

(where, in this case /bar/baz/frobozz is actually a directory).

TIA!

kj

-- 
NOTE: In my address everything before the period is backwards.


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

Date: Wed, 12 May 2004 09:59:29 -0400
From: Richard Morse <remorse@partners.org>
Subject: Re: Module/recipe to resolve full pathnames?
Message-Id: <remorse-B9EB20.09592912052004@plato.harvard.edu>

In article <c7ta11$ftt$1@reader2.panix.com>, kj <socyl@987jk.com> 
wrote:

> Is there a module (or built-in) that will take an arbitary Unix
> filename specification (either absolute or relative) and return
> the "canonical" absolute full path to the file?  For example:
> 
>   input:  ~jones/../foo/../../bar/./baz//frobozz/
>   output: /bar/baz/frobozz
> 
> (where, in this case /bar/baz/frobozz is actually a directory).

Try File::Spec (or, more exactly, File::Spec::Unix).

HTH,
Ricky

-- 
Pukku


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

Date: Wed, 12 May 2004 11:17:54 -0400
From: "Tulan W. Hu" <twhu@lucent.com>
Subject: Re: Module/recipe to resolve full pathnames?
Message-Id: <c7tf75$l3t@netnews.proxy.lucent.com>

"kj" <socyl@987jk.com> wrote in message
>
> Is there a module (or built-in) that will take an arbitary Unix
> filename specification (either absolute or relative) and return
> the "canonical" absolute full path to the file?  For example:
>
>   input:  ~jones/../foo/../../bar/./baz//frobozz/
>   output: /bar/baz/frobozz

chdir($input);
$a=`pwd`;




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

Date: Wed, 12 May 2004 16:29:57 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Module/recipe to resolve full pathnames?
Message-Id: <9isoc.7518$Qy5.6757@newssvr27.news.prodigy.com>

kj <socyl@987jk.com> wrote:



> Is there a module (or built-in) that will take an arbitary Unix
> filename specification (either absolute or relative) and return
> the "canonical" absolute full path to the file?  For example:

>   input:  ~jones/../foo/../../bar/./baz//frobozz/
>   output: /bar/baz/frobozz

Do you want this to occur symbolically or by running the filesystem?
Each has disadvantages.

Running the filesystem is usually slower and it assumes you have actual
permissions (and connectivity) to follow along.

Doing that symbolically assumes that none of the components are symlinks
to other locations.  Due to that, the '..' components may not be the
same as the pre-link parent.

"./foo/../bar" does not have to be the same as "./bar".

Because of this, I think File::Spec does things symbolically, but it
then must leave in ".." components.

$ cd /usr/bin
$ perl -e 'use File::Spec; $a = "foo/../bar" ; print File::Spec->rel2abs($a);'
/usr/bin/foo/../bar

-- 
Darren Dunham                                           ddunham@taos.com
Senior Technical Consultant         TAOS            http://www.taos.com/
Got some Dr Pepper?                           San Francisco, CA bay area
         < This line left intentionally blank to confuse you. >


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

Date: 12 May 2004 03:50:25 -0700
From: jcharth@hotmail.com (Joseph)
Subject: Re: myfile.cgi?image.gif saved as myfile.cgi in mozilla?
Message-Id: <2f2b8b0b.0405120250.21d939f5@posting.google.com>

I found this a couple of days ago. 
print "Content-disposition: attachment; filename=$filename\n";
print "Content-type: application/x-download\n\n";

so far it its working in both mozilla and i, with this headers i dont
have to specify file type. thanks for the tips


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

Date: 12 May 2004 07:44:51 -0700
From: yashgt@yahoo.com (Yash)
Subject: Perl distribution with threads support
Message-Id: <5a373b1d.0405120644.2fc646e0@posting.google.com>

Hi,

Can anyone point me to a Perl binary distribution for HP-UX 11i with
support for threads?
The one at http://hpux.connect.org.uk/hppd/hpux/Languages/perl-5.8.3/
has been compiled with threads support.

Thanks


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

Date: 12 May 2004 07:18:00 -0700
From: linux@colsen.org (Gilian)
Subject: Perl PGP
Message-Id: <f325939e.0405120618.5093245f@posting.google.com>

Hello,

I'm working on a Windows 2000 system. I have ActiveState Perl
installed on the machine. Everything is working OK, so far.

Now I need to write a script which will do some routines on a file and
at the end it has to encrypt the file with PGP. I have downloaded the
files from CPAN (Crypt::OpenPGP). Unfortunantly this refuses to be
installed.

Does anyone have experiences with this module? Including installing
it? Also experiences with how you can work with this module (pgp in
perl in general) are welcome!

Regards,
Gilian


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

Date: 11 May 2004 23:53:40 -0700
From: andres@monroy.com (Andres Monroy-Hernandez)
Subject: Re: preferences file
Message-Id: <3591b31a.0405112253.c68932b@posting.google.com>

vomaringo@yahoo.com (Jack) wrote in message news:<682ae665.0405110710.349b317d@posting.google.com>...
> hello,
> 
> have you a good way to examine a preferences file
> with entries like this :
> 
> pref1=short
> pref2=100
> pref3=/tmp/file
> 
> thanks.
> Regards,

You can open the file and parse it. For example:

sub read_preference {
  # this function returns a hashref 
  # with the name-value pairs of the preference file
  my ($file) = @_;
  open(FH, $file) or die "Cannot open $file:$!";
  my %pref; 
  while (<FH>) {
    my ($name, $value) = split /=/; # assuming there are no ='s in the value
    $pref{$name} = $value;
  }
  close (FH);
  return \%pref;
}

-Andrés


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

Date: Wed, 12 May 2004 09:52:54 +0100
From: Mark Clements <mark.clements@kcl.ac.uk>
Subject: Re: preferences file
Message-Id: <40a1e5d1$1@news.kcl.ac.uk>

Andres Monroy-Hernandez wrote:
> vomaringo@yahoo.com (Jack) wrote in message news:<682ae665.0405110710.349b317d@posting.google.com>...
>>have you a good way to examine a preferences file
>>with entries like this :
>>
>>pref1=short

> You can open the file and parse it. For example:
or you can use Config::Properties.

Mark


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

Date: 12 May 2004 06:06:10 -0700
From: vomaringo@yahoo.com (Jack)
Subject: Re: preferences file
Message-Id: <682ae665.0405120506.75e5407a@posting.google.com>

vomaringo@yahoo.com (Jack) wrote in message news:<682ae665.0405110710.349b317d@posting.google.com>...
> hello,
> 
> have you a good way to examine a preferences file
> with entries like this :
> 
> pref1=short
> pref2=100
> pref3=/tmp/file
> 
> thanks.
> Regards,


many thanks.


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

Date: Wed, 12 May 2004 21:19:05 -0000
From: Edward Wijaya <ewijaya@singnet.com.sg>
Subject: Re: Printing multiple Array as multiple column
Message-Id: <opr7wn53c0uj0cst@news.singnet.com.sg>

Hi John,

The array is of the same size.


Regards
Edwawrd


On Tue, 11 May 2004 09:37:13 -0500, John Bokma 
<postmaster@castleamber.com> wrote:

> Edward Wijaya wrote:
>
>> Hi,
>>
>> I have again this array:
>>
>> @array1 = (ab, bc, cd, ...)
>> @array2 = (cc, dd, ee, ...)
>>
>> with: print join("\n", @array), "\n";
>> it does give:
>>
>> ab
>> bc
>> cd
>>
>> Can we extend it to for multiple array?
>>
>> so that it gives:
>>
>> ab  cc
>> bc  dd
>> cd  ee
>>
>>
>> I tried print join ("\n", @array1, @array2), "\n";
>> But of no result.
>
> that prints first array1, then array2 etc...
>
> you must specify more exactly, what if array1 is smaller / bigger than 
> array2?
>
>



-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/


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

Date: Wed, 12 May 2004 07:23:11 GMT
From: Vik Rubenfeld <vikr@mindspring.com.invalid>
Subject: Re: Regular Expression Help? - Newbie Question
Message-Id: <vikr-613AC4.00231112052004@news4.west.earthlink.net>

In article <20040511164109.P25082@dishwasher.cs.rpi.edu>,
 Paul Lalli <ittyspam@yahoo.com> wrote:

> > Did you hear him when he said not to use a regular expression
> > for parsing HTML?
> 
> See, I was afraid of that.  This is what happens when I try to walk the
> line between answering what was asked, and answering what *should have*
> been asked.

Lighten up you guys! The question that should have been asked depends in 
part on information that's available to me and not yet necessarily to 
you. The application in question is a weblog. I've personally entered 
each of the <b></b> codes which are to be removed. They're all done the 
same way. The question I asked was sufficient to the actual situation to 
which I was applying it.


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

Date: Wed, 12 May 2004 11:19:15 -0400
From: Chris Mattern <matternc@comcast.net>
Subject: Re: Regular Expression Help? - Newbie Question
Message-Id: <cdWdnaflmJ7o3T_dRVn-gw@comcast.com>

Vik Rubenfeld wrote:

> In article <20040511164109.P25082@dishwasher.cs.rpi.edu>,
>  Paul Lalli <ittyspam@yahoo.com> wrote:
> 
>> > Did you hear him when he said not to use a regular expression
>> > for parsing HTML?
>> 
>> See, I was afraid of that.  This is what happens when I try to walk the
>> line between answering what was asked, and answering what *should have*
>> been asked.
> 
> Lighten up you guys! The question that should have been asked depends in
> part on information that's available to me and not yet necessarily to
> you. The application in question is a weblog. I've personally entered
> each of the <b></b> codes which are to be removed. They're all done the
> same way. The question I asked was sufficient to the actual situation to
> which I was applying it.

The deal here is that many of the people replying to your question code
perl for a living.  They have seen far too much perl code that tries
to make shortcuts in interpreting HTML by making assumptions about it--
and having that code break when it is suddenly subjected to HTML that
doesn't conform to those assumptions.  Such bugs are often hard to 
dig out.  As a result, they're (rightfully, IMHO) allergic to code
that assumes anything about HTML input other than that it *is* legal
HTML.  And considering the amount of broken HTML out there that survives
because browsers are willing to render it, even that is sometimes 
assuming too much...
-- 
             Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"


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

Date: 11 May 2004 23:44:15 -0700
From: cji_work@yahoo.com (Charlie)
Subject: two questions about perl
Message-Id: <1dc70d61.0405112244.6df39b7e@posting.google.com>

Hi folks, 
I have created some test cases which are written in perl and used to
test some web applications. And I have two issues here about PERL,
1. Let's say in one of my single test case, following events happening
   User::Place_an_order()
   Manager::approveOrder()
   Approver::approveOrder()
   Manger::giveConfirmation()
Each event is being called in a seperate function. The question that I
have is how can I calculate the seconds being used for each function
call? I do not want the timing is that acculate, but simple, and easy
to use.

2. I want to simulate multiple transactions running at the same time
to check the time consuming. The way that I am doing now is by using
the Thread. I am just a beginner for the Thread, and the code that I
am using now is :
"
 ...
thread1 = Thread->new(\&eachSession);
thread2 = Thread->new(\&eachSession);
$_->join foreach($thread1, $thread2);
 ...
"
My feeling is it is not  scalable, if one thread is broken somewhere,
the whole running will be dead. And it does not make sense to me, as
if I need to have 100 transactions, I need to create 100 threads and
have them joined together.
So any comments? Good module I may use ? 


thanks a lot 


CJ


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

Date: 12 May 2004 07:39:02 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: two questions about perl
Message-Id: <c7skam$ecc$1@canopus.cc.umanitoba.ca>

In article <1dc70d61.0405112244.6df39b7e@posting.google.com>,
Charlie <cji_work@yahoo.com> wrote:
:1. Let's say in one of my single test case, following events happening
:   User::Place_an_order()
:   Manager::approveOrder()
:   Approver::approveOrder()
:   Manger::giveConfirmation()
:Each event is being called in a seperate function. The question that I
:have is how can I calculate the seconds being used for each function
:call? I do not want the timing is that acculate, but simple, and easy
:to use.

my $starttime = time();
Manager::approveOrder()
my $endtime = time();
my $elapsed_time = $endtime - $starttime.

I also suggest you check out the Devel::DProf module from CPAN.


:2. I want to simulate multiple transactions running at the same time
:to check the time consuming. The way that I am doing now is by using
:the Thread. I am just a beginner for the Thread, and the code that I
:am using now is :

:thread1 = Thread->new(\&eachSession);
:thread2 = Thread->new(\&eachSession);
:$_->join foreach($thread1, $thread2);

:My feeling is it is not  scalable, if one thread is broken somewhere,
:the whole running will be dead.

Depends what you mean by 'broken' and 'will be dead'. Each thread
will start running as you Thread->new it, and the question becomes whether
you need to get results from the thread back to the spawning routine,
and whether you want notification as the thread finishes. Each thread
*naturually* dies when the invoked procedure (&eachSession() in your case)
finishes through any mechanism short of major internal perl corruption.
As far as perl is concerned, there is no difference between a thread
terminating because it has run out of things to do, and the thread
terminating because (for example) it tried to divide by 0.

The join foreach that you show will have the effect of holding up
the main thread waiting for $thread1 to finish, and not doing anything
else in the main thread until it does (even if it infinite loops...).
When the end of $thread1 is detected, the main thread would then look
for the end of $thread2; if $thread2 had already terminated before
$thread1 did, then the result (return value) of $thread2 will be
immediately available, and if $thread2 had not yet finished, then
the main thread would wait for it.


:And it does not make sense to me, as
:if I need to have 100 transactions, I need to create 100 threads and
:have them joined together.

I think you have misunderstood 'join'. You do not use 'join'
to place a thread into execution. You only use 'join' to get back
the results of a thread when it has finished (waiting until it -has-
finished if necessary.) If you do not -need- the results of the thread,
you can use

$thread1 = Thread->new(\&eachSession);
$thread1->detach();


I note, by the way, that you are using the 'Thread' module, which
implies 5005threads . 

          Finally, note that there are many known serious problems
          with the 5005threads, one of the least of which is that
          regular expression match variables like $1 are not
          threadsafe, that is, they easily get corrupted by competing
          threads.  Other problems include more insidious data
          corruption and mysterious crashes.  You are seriously urged
          to use ithreads instead.

If you can use perl5.8, you are much better off using threads->new
(or threads->create) instead of Thread->new : much more stable!


Creating 100 threads does not really emulate a load equivilent to 100
simultaneous accesses. Each time you create a new ithread, the entire
set of variables of the calling thread is duplicated. That can end up
using a *lot* of memory unless you plan very carefully. For example,
if you build a big hash table first, the entire hash table will be
duplicated (unless it is marked as being sharable.)

At an operating system level, threads are intended to be "lightweight",
less expensive to create than processes -- but 100 actual users would
be 100 actual processes (unless you are using mod_perl perhaps.) In
theory, 100 actual processes should be harder on the system; in
practice, ithreads are still very expensive to create, and 100 threads
is probably more expensive than 100 processes (especially if your perl
is compiled to use a shared libperl library instead of as one big
program.)

If you expect 100 users simultaneously, then your code will need
good resource locking to ensure that (for example) one newly placed
order does not overwrite another. The way you impliment that locking
is going to differ noticably between the case of running 100
threads and the case of running 100 different processes. In turn,
the way you lock is going to make a difference to the timing.
First you have to get the code -right- with respect to locking;
only -then- should you be considering fine-tuning the code for
efficiency.
-- 
What is "The Ultimate Meme"? Would it, like Monty Python's
"The World's Funniest Joke", lead to the deaths of everyone who
encountered it? Ideas *have* lead to the destruction of entire cultures.
   -- A Child's Garden Of Memes


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

Date: 12 May 2004 06:01:16 -0700
From: lathaswarna@yahoo.com (Swarna)
Subject: Unexpected sysread block
Message-Id: <13be9173.0405120501.31d43ae2@posting.google.com>

When I execute test1.pl, test2.pl is blocking. 

Any ideas as to why the sysread is not returning immediately.

Thanks
Swarna



########## test1.pl #########
#!perl

open (FD, "|-", "perl test2.pl");
sleep (100);


###########  test2.pl ##########

#!perl

my $buffer;

while (1) {

 print STDERR "before sysread \n";
 $bytes = sysread(STDIN, $buffer, 524288) || last;
 die "undef bytes \n" unless defined $bytes;
 print STDERR "after sysread \n";
 
}
print STDERR "last statement\n";


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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.

#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 V10 Issue 6556
***************************************


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