[24937] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7187 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 28 14:06:56 2004

Date: Tue, 28 Sep 2004 11:05:12 -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           Tue, 28 Sep 2004     Volume: 10 Number: 7187

Today's topics:
    Re: (was: decode the form information) (Malcolm Dew-Jones)
    Re: (was: decode the form information) <noreply@gunnar.cc>
        (Win32) Timing out a process while reading process' out <mclay@cfdlab.ae.utexas.edu>
        CGI scripts and modular design? (psyshrike)
    Re: CGI scripts and modular design? <noreply@gunnar.cc>
    Re: FileDeletionByDate - Error <nobull@mail.com>
    Re: FileDeletionByDate - Error (Anno Siegel)
        gather/take <dformosa@zeta.org.au>
    Re: gather/take <vetro@online.no>
    Re: gather/take <vetro@online.no>
        How to check size of harddisk? <qjason@starhub.net.sg>
    Re: Loop through scalar? <pinyaj@rpi.edu>
    Re: Mail filtering without procmail using webmail clien (J Cardella)
    Re: Mail filtering without procmail using webmail clien <jvromans@squirrel.nl>
    Re: MD5 of a string ? <warSPAMrenME@NOT.etr-usa.com>
    Re: new commands written in perl <dformosa@zeta.org.au>
    Re: new commands written in perl <dformosa@zeta.org.au>
    Re: Object Oriented Perl : Query <dformosa@zeta.org.au>
    Re: Object Oriented Perl : Query (Anno Siegel)
        Order of subroutines (Aris Xanthos)
    Re: Order of subroutines <josef.moellers@fujitsu-siemens.com>
    Re: Order of subroutines <noreply@gunnar.cc>
    Re: Order of subroutines <mritty@gmail.com>
    Re: Order of subroutines (Aris Xanthos)
    Re: Order of subroutines (Tony Skelding)
    Re: Order of subroutines (Andres Monroy-Hernandez)
    Re: printing array problem <Graham.T.Wood@oracle.com>
    Re: process control <matternc@comcast.net>
    Re: references to filehandle? <matrix_calling@yahoo.dot.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 28 Sep 2004 09:38:56 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: (was: decode the form information)
Message-Id: <415993a0@news.victoria.tc.ca>

Joe Smith (Joe.Smith@inwap.com) wrote:
: Larry wrote:

: > and what do you think about this?
: >         read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

: I think that anyone can crash your server with hardly any effort.
: Have you considered what will happen if CONTENT_LENGTH is 4294967297 ?
: 	-Joe

The same thing that will happen if you use CGI; with the default settings.

(and as far as I've noticed, virtually all scripts and examples use cgi.pm
with the default settings.)



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

Date: Tue, 28 Sep 2004 19:11:42 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: (was: decode the form information)
Message-Id: <2rtkafF1eefroU1@uni-berlin.de>

Malcolm Dew-Jones wrote:
> Joe Smith (Joe.Smith@inwap.com) wrote:
>> Larry wrote:
>>> and what do you think about this?
>>>         read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>> 
>> I think that anyone can crash your server with hardly any effort.
>> Have you considered what will happen if CONTENT_LENGTH is
>> 4294967297 ?
> 
> The same thing that will happen if you use CGI; with the default
> settings.
> 
> (and as far as I've noticed, virtually all scripts and examples use
> cgi.pm with the default settings.)

Very true.

When will the myth in this group, that using CGI.pm makes a big
difference with respect to security, be put to death? Writing secure
CGI scripts requires knowledge about the potential risks and efforts
to address those risks. Whether CGI.pm is used for parsing data or not
has (almost) nothing to do with it.

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


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

Date: Tue, 28 Sep 2004 16:54:58 GMT
From: rtm <mclay@cfdlab.ae.utexas.edu>
Subject: (Win32) Timing out a process while reading process' output?
Message-Id: <pan.2004.09.28.16.54.58.466849@cfdlab.ae.utexas.edu>

I am interested in running a process with a timeout.  Also I'm
interested in analyzing the output of this process.

Under Unix, the solution is described clearly in the Perl Cookbook
"16.10:  Communicating between related processes" and 16.24 "Timing
out an Operation".   Enclosed below is an example showing what I want
to do under Unix.

I need to do this under Windows XP.  As others have pointed out
"alarm" works under 5.8+ and fork sorta works under 5.8+ under
windows.  But the unix example code below just hangs.

So the best thing I have found is Win32::Job.

------------------------------------------------------------------------
#!/usr/bin/env perl
# -*- cperl -*-
BEGIN { $^W = 1; }
use strict;

use Win32::Job;
my $job = Win32::Job->new();

my $r = $job->spawn("z:\t\junk.exe", "junk", {
                                              stdin  => 'NUL', # the NUL device
                                              stdout => 'stdout.log',
                                              stderr => 'stdout.log',
                                             });
$job->run(20);
------------------------------------------------------------------------

The only problem is that I can't see how you read the output while the
process is running when using Win32::Job.  Of course one can write the
output to a file then read it back in after the process is finished.

Is there another way?  Is there another Win32:: something that does
what I want?

Thanks

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


#!/usr/bin/env perl
# -*- cperl -*-
BEGIN { $^W = 1; }
use strict;

use IO::Handle;

pipe(READER, WRITER);

WRITER->autoflush(1);

$SIG{CHLD} = 'IGNORE';
my $pid;
eval
  {
    local $SIG{ALRM} = sub { die "alarm\n" };   # NB: \n required
    alarm 20;

    die "Can't fork: $!" unless defined($pid = fork);
    if ($pid)
      {
        # parent
        close WRITER;
        while(<READER>)
          {
            print "Got: $_";
          }
      }
    else
      {
        close READER;
        open(STDOUT, ">&WRITER");
        exec("junk","","") or die("exec $!");
      }
    alarm 0;
    waitpid($pid,0);
  };

if ($@)
  {
    die unless $@ eq "alarm\n"; # propagate unexpected errors
    print "Tripped Alarm\n";
    kill 9, $pid;
  }

------------------------------------------------------------------------
#include <stdio.h>
#include <math.h>

int main()
{
  int i,j,n;
  double x,y, dx;
  FILE* fp = fopen("junk.log","w");

  n  = 1000000;
  dx = 0.00001;
  x  = 0.0;

  for (j = 0; j < 50; j++)
    {
      for (i = 0; i < n; i++)
        {
          y = sin(x);
          x += dx;
        }
      fprintf(fp,"j: %d\n", j);
      fflush(fp);
      printf("j: %d\n", j);
    }
}



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

Date: 28 Sep 2004 08:41:42 -0700
From: shrike@cyberspace.org (psyshrike)
Subject: CGI scripts and modular design?
Message-Id: <79485f9d.0409280741.340cba6b@posting.google.com>

Howdy, 

I've been poking through some different shopping cart software, trying
to decide which one to use. All of them use piped filehandles or
backticks to handle modularization.

I will be modifying my store with some very custom requirements. It
will be about a dozen modules before it is complete.

My question is, Is there are reason why CGI scripts don't: 

use lib "./lib" ; 

and use modular code instead of backticking everything? My virtual
hosting ISP permits calling locally installed libraries. Is it common
practice for ISP's to not allow this? If I use modular design am I
hurting my portability if I decide to go with another webhosting
service?

I have the hardest darned time sorting through the bazillion scripts
in my cgi-bin. If I can't come up with a reason not to, I am turning
half of them into object libraries, and sticking them in  /cgi-bin/lib

The only reason I can think of for not doing this is executable size.
If memory is quota'd this could be a problem. The quota would have to
be pretty anemic to be a factor though.

Comments? Recomendations? 

Can other folks confirm that they do this too? 

-Thanks in advance 
-Matt


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

Date: Tue, 28 Sep 2004 19:18:52 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: CGI scripts and modular design?
Message-Id: <2rtkntF1dqcleU1@uni-berlin.de>

psyshrike wrote:
> My question is, Is there are reason why CGI scripts don't: 
> 
> use lib "./lib" ; 
> 
> and use modular code instead of backticking everything?

The authors learned Perl 10 years ago?

What you say is of course not true for all CGI scripts. There is no 
reason for you to not apply Perl 5 style and incorporate code via modules.

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


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

Date: Tue, 28 Sep 2004 12:46:55 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: FileDeletionByDate - Error
Message-Id: <cjbin5$gl0$1@sun3.bham.ac.uk>

Anno Siegel wrote:

> What is File::Recurse?

It appears to be an old (and possibly morribund) attempt to fill the 
ecological niche now occupied by File::Finder and File::Find::Rule.

> It is not published on CPAN,

Yes it is.

 > Does its documentation say that it exports a
> function named "recurse"?

No it does not.



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

Date: 28 Sep 2004 12:03:02 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: FileDeletionByDate - Error
Message-Id: <cjbjtm$2bc$1@mamenchi.zrz.TU-Berlin.DE>

Brian McCauley  <nobull@mail.com> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> 
> > What is File::Recurse?
> 
> It appears to be an old (and possibly morribund) attempt to fill the 
> ecological niche now occupied by File::Finder and File::Find::Rule.
> 
> > It is not published on CPAN,
> 
> Yes it is.

Oh.  A CPAN search on cpan.uwinnipeg.ca doesn't find it, but on
search.cpan.org it does...

>  > Does its documentation say that it exports a
> > function named "recurse"?
> 
> No it does not.

Oh well :)

Anno


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

Date: 28 Sep 2004 21:50:45 +1000
From: ? the Platypus {aka David Formosa} <dformosa@zeta.org.au>
Subject: gather/take
Message-Id: <m3wtyed33e.fsf@dformosa.zeta.org.au>


I was reading on googel's archive of the perl6 mailing list abouther
the gather/take construct and I thourt, thats pritty cool its a pitty
that I'm going to have to wait untill perl6 to use it.

Then I thourt, actually with a little mucking about I could implement
it from within perl5.  So I did.

sub gather (&) {
  my $call = shift;
  my @return = ();
  my $package=(caller)[0];

  no strict "refs";

  local *{$package . "::take"} =   sub {
    push @return,@_;
  };

  $call->();

  return @return;
}

Should I wrap a package around this and submit it to CPAN?

-- 
Please excuse my spelling as I suffer from agraphia. See
http://dformosa.zeta.org.au/~dformosa/Spelling.html to find out more.
Free the Memes.


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

Date: Tue, 28 Sep 2004 14:37:47 +0200
From: "Vetle Roeim" <vetro@online.no>
Subject: Re: gather/take
Message-Id: <opse1eo91l3hk3cf@quickfix.opera.com>

On 28 Sep 2004 21:50:45 +1000, ? the Platypus {aka David Formosa}  
<dformosa@zeta.org.au> wrote:

[...]
>
> Should I wrap a package around this and submit it to CPAN?

   Damian Conway has already implemented a module for gather/take.
   <URL:http://search.cpan.org/~dconway/Perl6-Gather-0.04/Gather.pm>


-- 
It's not a bug, it's the future.


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

Date: Tue, 28 Sep 2004 14:44:21 +0200
From: "Vetle Roeim" <vetro@online.no>
Subject: Re: gather/take
Message-Id: <opse1ez7l73hk3cf@quickfix.opera.com>

On 28 Sep 2004 21:50:45 +1000, ? the Platypus {aka David Formosa}  
<dformosa@zeta.org.au> wrote:

>
> I was reading on googel's archive of the perl6 mailing list abouther
> the gather/take construct and I thourt, thats pritty cool its a pitty
> that I'm going to have to wait untill perl6 to use it.
>
> Then I thourt, actually with a little mucking about I could implement
> it from within perl5.  So I did.
>
> sub gather (&) {
>   my $call = shift;
>   my @return = ();
>   my $package=(caller)[0];
>
>   no strict "refs";
>
>   local *{$package . "::take"} =   sub {
>     push @return,@_;
>   };
>
>   $call->();
>
>   return @return;
> }

   Do you have an example on how to use this?


[...]
-- 
It's not a bug, it's the future.


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

Date: Wed, 29 Sep 2004 02:05:32 +0800
From: Jason Quek <qjason@starhub.net.sg>
Subject: How to check size of harddisk?
Message-Id: <1s9jl09ohl16egnj3b9h8aedd9uuib88eo@4ax.com>

Hi

How can I use Perl to check the size of the harddisk and the amount of
space left?

Any help would be appreciated.

Regards,




Jason Q.


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

Date: Tue, 28 Sep 2004 11:55:04 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: Loop through scalar?
Message-Id: <Pine.SGI.3.96.1040928115438.20567B-100000@vcmr-64.server.rpi.edu>

On 28 Sep 2004, Anno Siegel wrote:

>Jason Kinkade <jkinkade@datashelter.net> wrote in comp.lang.perl.misc:
>> I have a scalar/variable ($var) that looks like:
>> 
>> Line1
>> Line2
>> Line3
>> Line4
>> etc.
>> 
>> Theres obviously a new line after each Line#.  I would like to loop
>> through this variable line by line with something like
>> 
>> foreach ($var)
>> {
>>    print "Current Line: $_";
>> }
>> 
>> This reads the entire $var in.  I want it line by line instead.
>
>It prints it out.  No reading here.

Jason meant the foreach loop "reads" all of $var as one element; he had
hoped it would split it on newlines.

--
Jeff "japhy" Pinyan         %  How can we ever be the sold short or
RPI Acacia Brother #734     %  the cheated, we who for every service
  Senior Dean, Fall 2004    %  have long ago been overpaid?
RPI Corporation Secretary   %
http://japhy.perlmonk.org/  %    -- Meister Eckhart




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

Date: 28 Sep 2004 06:29:44 -0700
From: dronf@pobox.com (J Cardella)
Subject: Re: Mail filtering without procmail using webmail client
Message-Id: <b9eabb98.0409280529.2723a15d@posting.google.com>

Mark Clements <mark.clements@kcl.ac.uk> wrote in message news:<41584a23$1@news.kcl.ac.uk>...
> J Cardella wrote:
> > Greetings --
> > 
> > Is there any alternative to procmail available?
> <snip>
> This has nothing to do with perl. However...

Sorry, my reasoning was I am a fairly competent in Perl, so I would
write my own parser, but if anyone knew of something more readily
available I could use or mod, that's what I would do. I should have
phrased this " Are there any Perl alternatives to Procmail available."

CPAN has a couple solutions, but I think hosting policy negates me
using them.

Basically I need something in Perl which can run with the permissions
I have, without many bells and whistles (i.e. installed packages).


> 
> > 
> > Any mail gurus out there who can help? Searching the newsgroup
> > archives for "webamil without procmail" yeilds nothing.
> I'm not surprised...... However, there are a number of alternatives to 
> procmail. You can set up filters in Imp (which is what I assume you mean 
> by Horde), or there are a number of programs that will run on the server 
> eg sieve or maildrop, but plugging these into the MTA is dependent on 
> the MTA itself and the hosting policy.
> 
> Mark

I've looked into Imp (you are correct with your Horde assumption) but
I think it only allows delivery to a script, not to a file. I have not
seen sieve or maildrop, I'll look into those now.

Thanks for your time,
Joel


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

Date: Tue, 28 Sep 2004 19:04:06 +0200
From: Johan Vromans <jvromans@squirrel.nl>
Subject: Re: Mail filtering without procmail using webmail client
Message-Id: <41599986$0$124$e4fe514c@dreader19.news.xs4all.nl>

dronf@pobox.com (J Cardella) writes:

> I should have
> phrased this " Are there any Perl alternatives to Procmail available."

Mail::Procmail ?
http://search.cpan.org/~jv/Mail-Procmail

-- Johan


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

Date: Tue, 28 Sep 2004 08:13:37 -0600
From: Warren Young <warSPAMrenME@NOT.etr-usa.com>
Subject: Re: MD5 of a string ?
Message-Id: <kke6d.1$xC4.2026@news.uswest.net>

vp wrote:
> How to get MD5 of a string in Perl please.

Digest::MD5


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

Date: 28 Sep 2004 21:33:02 +1000
From: ? the Platypus {aka David Formosa} <dformosa@zeta.org.au>
Subject: Re: new commands written in perl
Message-Id: <m31xgmeihd.fsf@dformosa.zeta.org.au>

Ted Zlatanov <tzz@lifelogs.com> writes:

[...]

> Sometimes the shell is not a good choice for trivial operations
> (e.g. `cat' is a pretty redundant program when you use a shell).

cat file1 file2 file3 > file4

-- 
Please excuse my spelling as I suffer from agraphia. See
http://dformosa.zeta.org.au/~dformosa/Spelling.html to find out more.
Free the Memes.


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

Date: 28 Sep 2004 21:57:43 +1000
From: ? the Platypus {aka David Formosa} <dformosa@zeta.org.au>
Subject: Re: new commands written in perl
Message-Id: <m3r7omd2rs.fsf@dformosa.zeta.org.au>

"Paul Lalli" <mritty@gmail.com> writes:

[...]

> Because -w is a global switch.  Once you use it, you can't refine it.
> 
> use warnings; on the other hand, is a lexical pragma.  You can turn it
> off for certain sections of the code if you need to.  For example:
> 
> use warnings;
> print "Here I am!\n";
> my $str = "23foo";
> my $num;
> {
>     no warnings 'numeric';
>     $num = $str + 3;
> }

Are you sure?

[dformosa@dformosa perl]$ perl -v                                               
This is perl, v5.8.0 built for i586-linux-thread-multi-64all-ld

Copyright 1987-2002, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'.  If you have access to the
Internet, point your browser at http://www.perl.com/, the Perl Home Page.

[dformosa@dformosa perl]$ cat test.pl
#!/usr/local/bin/perl -w


print "Here I am!\n";
my $str = "23foo";
my $num;
{
    no warnings 'numeric';
    $num = $str + 3;
}
[dformosa@dformosa perl]$ perl -w test.pl
Here I am!
[dformosa@dformosa perl]$ exit


-- 
Please excuse my spelling as I suffer from agraphia. See
http://dformosa.zeta.org.au/~dformosa/Spelling.html to find out more.
Free the Memes.


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

Date: 28 Sep 2004 22:19:05 +1000
From: ? the Platypus {aka David Formosa} <dformosa@zeta.org.au>
Subject: Re: Object Oriented Perl : Query
Message-Id: <m3mzzad1s6.fsf@dformosa.zeta.org.au>

pjacklam@online.no (Peter J. Acklam) writes:

[...]

> Users all to often do things they have no business of doing.  :-)
> 
> I think that *all* inappropriate or incorrect usage should display
> a descriptive error message.

Isn't it the unix philosophy (and in turn perl's) to not forbid
inapproprate usage or "incorrect" usage for fear that it would also
prevent people from doing something brillent.

-- 
Please excuse my spelling as I suffer from agraphia. See
http://dformosa.zeta.org.au/~dformosa/Spelling.html to find out more.
Free the Memes.


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

Date: 28 Sep 2004 13:01:39 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Object Oriented Perl : Query
Message-Id: <cjbnbj$60t$1@mamenchi.zrz.TU-Berlin.DE>

? the Platypus {aka David Formosa}  <dformosa@zeta.org.au> wrote in comp.lang.perl.misc:
> pjacklam@online.no (Peter J. Acklam) writes:
> 
> [...]
> 
> > Users all to often do things they have no business of doing.  :-)
> > 
> > I think that *all* inappropriate or incorrect usage should display
> > a descriptive error message.
> 
> Isn't it the unix philosophy (and in turn perl's) to not forbid
> inapproprate usage or "incorrect" usage for fear that it would also
> prevent people from doing something brillent.

Un-planned for, un-thought of usage is what shouldn't be prohibited.
Inappropriate and incorrect usage (as in calling a class method through
an object) isn't going to get you anywhere.  No philosophy will change
that.

Anno


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

Date: 28 Sep 2004 03:58:58 -0700
From: Aris.Xanthos@ling.unil.ch (Aris Xanthos)
Subject: Order of subroutines
Message-Id: <b3b0e6f5.0409280258.51e7d232@posting.google.com>

Hi,

I have a problem with the order of subroutines
and I couldn't find help about that in books or
online.

Could someone tell me why this code works fine:

------------------
 #!/usr/bin/perl

 Function1();

 sub Function1() {
   Function2( 'arg' );
 }

 sub Function2() {
   my ( $arg ) = @_;
 }

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

and not this one:

------------------
 #!/usr/bin/perl

 Function1();

 sub Function2() {
   my ( $arg ) = @_;
 }

 sub Function1() {
   Function2( 'arg' );
 }

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

which yields the following error message:

Too many arguments for main::Function2 at 
D:\Developpement\Perl\test.pl line 10, near "'arg' )"
Execution of D:\Developpement\Perl\test.pl 
aborted due to compilation errors.

I have this problem in the framework of a rather 
long (tk) script (about 2'000 lines so far), and the
calls to various subroutines are getting too intricate 
for me to find an order that works (besides, it is not
a satisfying solution).

I hope this does not duplicate a previous post.

Aris Xanthos


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

Date: Tue, 28 Sep 2004 13:17:39 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Order of subroutines
Message-Id: <cjbh1v$nne$1@nntp.fujitsu-siemens.com>

Aris Xanthos wrote:
> Hi,
>=20
> I have a problem with the order of subroutines
> and I couldn't find help about that in books or
> online.
>=20
> Could someone tell me why this code works fine:
>=20
> ------------------
>  #!/usr/bin/perl
>=20
>  Function1();
>=20
>  sub Function1() {
>    Function2( 'arg' );
>  }
>=20
>  sub Function2() {
>    my ( $arg ) =3D @_;
>  }
>=20
> ------------------
>=20
> and not this one:
>=20
> ------------------
>  #!/usr/bin/perl
>=20
>  Function1();
>=20
>  sub Function2() {
>    my ( $arg ) =3D @_;
>  }
>=20
>  sub Function1() {
>    Function2( 'arg' );
>  }
>=20
> ------------------
>=20
> which yields the following error message:
>=20
> Too many arguments for main::Function2 at=20
> D:\Developpement\Perl\test.pl line 10, near "'arg' )"
> Execution of D:\Developpement\Perl\test.pl=20
> aborted due to compilation errors.

It's as it says:
In the first case, the compiler cannot know how much arguments Function2 =

accepts, because the prototype of Function2 happens after the call, so=20
it assumes 1 argument is OK. In the second case, it can determine that=20
Functon2 does not accept any arguments, so it complains.
If you change the definition of Function 2 to

sub Function2($)

the compiler will know that it accepts a single argument and will be=20
satisfied. If you change it to

sub Function2

the compiler will know that you don't care and will be satisfied.

HTH,

Josef

--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett



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

Date: Tue, 28 Sep 2004 13:37:22 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Order of subroutines
Message-Id: <2rt0ncF1d3espU1@uni-berlin.de>

Aris Xanthos wrote:
> I have a problem with the order of subroutines
> and I couldn't find help about that in books or
> online.
> 
> Could someone tell me why this code works fine:
> 
> ------------------
>  #!/usr/bin/perl

     use strict;
     use warnings;

and let Perl hint you about possible problems.

>  Function1();
> 
>  sub Function1() {
----------------^^

Why are you using prototypes? If you don't know, you shouldn't do that.

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


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

Date: Tue, 28 Sep 2004 13:45:45 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Order of subroutines
Message-Id: <dWd6d.2748$OX.50@trndny07>

"Aris Xanthos" <Aris.Xanthos@ling.unil.ch> wrote in message
news:b3b0e6f5.0409280258.51e7d232@posting.google.com...
> Hi,
>
> I have a problem with the order of subroutines
> and I couldn't find help about that in books or
> online.
>
> Could someone tell me why this code works fine:
>
> ------------------
>  #!/usr/bin/perl
>
>  Function1();
>
>  sub Function1() {
>    Function2( 'arg' );
>  }
>
>  sub Function2() {
>    my ( $arg ) = @_;
>  }

If you had warnings enabled, you would see that while this code 'works',
it certainly doesn't work 'fine'.  Indeed, that warning message would
help you to understand why the second snippet doesn't work at all.

Please ask the Perl interpreter for help before asking thousands of
people on the internet for help.

Paul Lalli

> and not this one:
> ------------------
>  #!/usr/bin/perl
>
>  Function1();
>
>  sub Function2() {
>    my ( $arg ) = @_;
>  }
>
>  sub Function1() {
>    Function2( 'arg' );
>  }
>




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

Date: 28 Sep 2004 06:46:15 -0700
From: Aris.Xanthos@ling.unil.ch (Aris Xanthos)
Subject: Re: Order of subroutines
Message-Id: <b3b0e6f5.0409280546.595dc484@posting.google.com>

Actually a solution to my problem can be found in this post:

http://groups.google.ch/groups?selm=tpomat2ucah5f0%40corp.supernews.com&output=gplain

Sorry, I should have searched more.

AX


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

Date: 28 Sep 2004 07:13:09 -0700
From: tony@skelding.co.uk (Tony Skelding)
Subject: Re: Order of subroutines
Message-Id: <a78026a1.0409280613.f330b36@posting.google.com>

Aris.Xanthos@ling.unil.ch (Aris Xanthos) wrote in message news:<b3b0e6f5.0409280258.51e7d232@posting.google.com>...
> Hi,
> 
> I have a problem with the order of subroutines
> and I couldn't find help about that in books or
> online.
> 
> Could someone tell me why this code works fine:
> 
> ------------------
>  #!/usr/bin/perl
> 
>  Function1();
> 
>  sub Function1() {
>    Function2( 'arg' );
>  }
> 
>  sub Function2() {
>    my ( $arg ) = @_;
>  }
> 
> ------------------
> 
> and not this one:
> 
> ------------------
>  #!/usr/bin/perl
> 
>  Function1();
> 
>  sub Function2() {
>    my ( $arg ) = @_;
>  }
> 
>  sub Function1() {
>    Function2( 'arg' );
>  }
> 
> ------------------
> 
> which yields the following error message:
> 
> Too many arguments for main::Function2 at 
> D:\Developpement\Perl\test.pl line 10, near "'arg' )"
> Execution of D:\Developpement\Perl\test.pl 
> aborted due to compilation errors.
> 
> I have this problem in the framework of a rather 
> long (tk) script (about 2'000 lines so far), and the
> calls to various subroutines are getting too intricate 
> for me to find an order that works (besides, it is not
> a satisfying solution).
> 
> I hope this does not duplicate a previous post.
> 
> Aris Xanthos

You probably don't realise that you are defining a prototype for
Function2, i.e.

sub Function2() {
 ...

says that the function should expect no parameters.  Leave the () off
and it will be unprototyped.

The reason the first example works OK is that the prototype for
Function2 has not been compiled at the time that Function1 is
compiled.


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

Date: 28 Sep 2004 09:56:12 -0700
From: andres@monroy.com (Andres Monroy-Hernandez)
Subject: Re: Order of subroutines
Message-Id: <3591b31a.0409280856.148d85e9@posting.google.com>

Try not using empty prototypes. Your code would be cleaner if you had:

Function1();
sub Function2 {
    my ( $arg ) = @_;
}
sub Function1 {
    Function2('arg');
}

It seems that there is no need for prototypes. 

---
-Andres Monroy-Hernandez


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

Date: Tue, 28 Sep 2004 11:32:12 +0100
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: printing array problem
Message-Id: <41593DAC.1F7B61B5@oracle.com>

Anno Siegel wrote:
> 
> Graham Wood  <Graham.T.Wood@oracle.com> wrote in comp.lang.perl.misc:
> > Mark Day wrote:
> 
> [...]
> 
> > > @array = qq(1 2 3 4 5 6 7 8 9 10 11 12 baker's dozen);
> >
> > Your problem is that you're using qq which will surround the contents of
> > the parenthesis with double quotes rather than qw which will surround
> > each word in the parenthesis with double quotes.
> 
> That is wrong.  "qw()" treats the whole string as single quoted,
> then splits the result on whitespace.


Oh.  Thanks

Graham

> 
> Anno


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

Date: Tue, 28 Sep 2004 11:12:24 -0400
From: Chris Mattern <matternc@comcast.net>
Subject: Re: process control
Message-Id: <gtidnbpEQ_rE4sTcRVn-vQ@comcast.com>

Matt wrote:

> I am having a process control problem with one of my Perl scripts.
> Basically, I have a couple lines at the beginning of my script that are of
> the form:
> 
> system("export path1"); #Note path1 and path2 are just dummy strings here
> system("export path2");

Before I read any further:  Both these lines change the environment of
the process you spawn with the system() (which then promptly exits).
Neither changes the environment of your perl program in any way 
whatsoever.
> 
> system("catutil -i file1 -o file2");
> 
> The problem I am having is that I don't want to execute the catutil
> command
> until the exports are done above.  From what I read, I thought a system
> command would pause until the process was done, but it doesn't appear to
> work that way in this case.  I'm thinking this might be because the
> exports are shell commands?

You've lost me.  The above system()s run the export command, which 
finishes and control does return to your perl program.  As I stated, 
this doesn't change the environment of the perl program in the 
slightest, but that has nothing to do with the exports not being 
"done", it has to do with the fact that system() can't change the
environment of your perl program.
> 
> Anyway, what I did as a workaround seems to work. What I did was take the
> exports out of the perl program and create an executable file that had the
> following lines:
> 
> export path1
> export path2
> perlfile.pl

Yes, that would work.  Now the exports are happening in a process that is
the *parent* of the perl program, not a process that is the *child* of 
the perl program.
> 
> This works, but now I have a shell wrapper doing some things before
> calling
> the perl program.  Is there a way to get this to work without the shell
> wrapper (i.e. self contained in the perl program).
> 
> Thank you so much in advance for your help.

You've lost me again, I'm afraid.  Do these variables have a value before
you call the perl program?  If so, you must export them before you call
the perl program, or those variables never make it to the program, let
alone your system() statement.  Otherwise, you want to use the %ENV hash.
Setting an environment variable in %ENV automatically exports it.

-- 
             Christopher Mattern

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


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

Date: Tue, 28 Sep 2004 20:01:46 +0530
From: Abhinav <matrix_calling@yahoo.dot.com>
Subject: Re: references to filehandle?
Message-Id: <ZLe6d.41$4V.141@news.oracle.com>

Michele Dondi wrote:
> On 27 Sep 2004 13:41:22 GMT, "A. Sinan Unur"
> <usa1@llenroc.ude.invalid> wrote:
> 
> 
>>>      open my $fh, '>', $m or
>>>        die "Can't write to `$m': $!\n";
> 
> [snip]
> 
>>>Hope there are no more typos left,
>>
>>Strictly speaking, not a typo, but I am going to suggest dropping the \n 
> 
>>from the error message. 
> 
> Hehe! Opinions tend to vary here... IMHO the user should not be
> interested in the additional info that omitting \n supplies, and I
> find that generally this is the case. Well in this case, he/she may be
> interested in the line of input that triggered it, but hopefully
> knowing "which $m" is the guilty one should be enough. OTOH you should
> have noticed that my code contained also a \n-less warn() because in
> that case it seemed to mo more meaningful to do so...
> 

That was interesting behaviour(for me..). Where can I find more about this ?

Regards
Abhinav


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

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


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