[23695] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5902 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 6 06:05:39 2003

Date: Sat, 6 Dec 2003 03:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 6 Dec 2003     Volume: 10 Number: 5902

Today's topics:
    Re: Am I right on Mod_Perl? <kkeller-usenet@wombat.san-francisco.ca.us>
    Re: Am I right on Mod_Perl? <kuujinbo@hotmail.com>
    Re: Can you explain LOCAL, MY and OUR with examples? <Temp@NoSuchDomain.Info>
    Re: Can you explain LOCAL, MY and OUR with examples? <Temp@NoSuchDomain.Info>
    Re: Can you explain LOCAL, MY and OUR with examples? <uri@stemsystems.com>
    Re: Can you explain LOCAL, MY and OUR with examples? <uri@stemsystems.com>
    Re: Can you explain LOCAL, MY and OUR with examples? (Jay Tilton)
    Re: Can you explain LOCAL, MY and OUR with examples? <kuujinbo@hotmail.com>
    Re: Can you explain LOCAL, MY and OUR with examples? <tassilo.parseval@rwth-aachen.de>
    Re: gui in perl <bart.lateur@pandora.be>
    Re: How to open a file from the end and read the last 1 (Anno Siegel)
    Re: How to write to drive A:\ from CGI Perl (William Herrera)
    Re: How to write to drive A:\ from CGI Perl <me@privacy.net>
    Re: How to write to drive A:\ from CGI Perl <asu1@c-o-r-n-e-l-l.edu>
    Re: How to write to drive A:\ from CGI Perl (Jay Tilton)
    Re: Idiom for array index that I'm foreach'ing over? <bik.mido@tiscalinet.it>
        reading binary files (Zoran)
        What is anonymous sub? Why is it better? <Temp@NoSuchDomain.Info>
    Re: What is anonymous sub? Why is it better? <asu1@c-o-r-n-e-l-l.edu>
    Re: What is anonymous sub? Why is it better? <uri@stemsystems.com>
    Re: What is anonymous sub? Why is it better? (Jay Tilton)
    Re: Your code doesn't work <bik.mido@tiscalinet.it>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 5 Dec 2003 22:37:05 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Am I right on Mod_Perl?
Message-Id: <hetrqb.m17.ln@goaway.wombat.san-francisco.ca.us>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

On 2003-12-06, Picker Leon <Temp@NoSuchDomain.Info> wrote:
> After reading the links on perl.apache.org, I have concluded this:
> If I have take care of the globle varible by either make no globle varibles,
> or by clean them each time before I use them and after I use them, I can
> pretty much use the same code of my perl in mod_perl enviroment.

Not necessarily--there is documentation on other mod_perl traps, which
an appropriate google search should find.  Some of these traps can be
subtle, so you should read the docs carefully and decide whether your
code might be susceptible to them.

- --keith

- -- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQE/0XkNhVcNCxZ5ID8RAnsnAJ4msTw9n5giuWC8DrKPVSun4hmrGwCeOf+q
PmwExVv5AwR1lEqmy7zD10U=
=X8Yq
-----END PGP SIGNATURE-----


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

Date: Sat, 06 Dec 2003 16:23:05 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: Am I right on Mod_Perl?
Message-Id: <bqs05i$937$1@pin3.tky.plala.or.jp>

Picker Leon wrote:

> After reading the links on perl.apache.org, I have concluded this:
> If I have take care of the globle varible by either make no globle varibles,
> or by clean them each time before I use them and after I use them, I can
> pretty much use the same code of my perl in mod_perl enviroment.
> 
> Please correct me if I am wrong.
> 

It might be a good idea to start slowly with mod_perl, using the 
Apache::PerlRun handler. It has better performance than plain CGI 
because each child process loads the Perl interpreter once (versus 
loading on each request), but global variables are reiniatilized for 
each request.

HTH -keith



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

Date: Sat, 06 Dec 2003 05:08:55 GMT
From: "Picker Leon" <Temp@NoSuchDomain.Info>
Subject: Re: Can you explain LOCAL, MY and OUR with examples?
Message-Id: <HvdAb.399437$0v4.19909766@bgtnsc04-news.ops.worldnet.att.net>

Can you explain this code:

  my $input = $_[0];
  local $matchkey = $_[1]; # must use local instead of my to be used in
callback

  local @output = (); # must use local instead of my to be used in callback

  sub callback {
     my($tag, %attr) = @_;
     if ($tag eq $matchkey) {push(@output, values %attr);};
     return;
  }
  my $p = HTML::LinkExtor->new(\&callback);
  $p->parse($input);


Why do I have to use local here? If I just use my @output, should callback
have access @output, because callback is in the same scope with my @output?
I tried using my, but records messed up totally.
And I don't know why use my for $input but local for $matchkey.



> Picker Leon wrote:
> > I read the perldoc -f local, my our, but would like to know what exactly
is
> > "eval", because without knowing "eval" I can not understand LOCAL, MY,
OUR
> > clearly. I got some ideas what those are, but very confused what
difference
> > they have.
> >
> > Anyone can give me an example script which will act differently with MY,
> > LOCAL and OUR?
> >
> > Thank you.
> >
> >
>
> perldoc -f local directs you to read perlsub. So do a:
>
> pelrdoc perlsub
>
> from your shell. The examples/explanations are *very* good and include
> code snippets. In particular, read the sections:
>
> 1. Private Variables via my()
> 2. Temporary Values via local()
> 3. When to Still Use local()
>
> Then do a 'perldoc -f our' for an explanation of our.
>
> If you don't understand a particular section of perlsub, please ask.
> Someone will help.
>
> HTH - keith
>




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

Date: Sat, 06 Dec 2003 05:14:44 GMT
From: "Picker Leon" <Temp@NoSuchDomain.Info>
Subject: Re: Can you explain LOCAL, MY and OUR with examples?
Message-Id: <8BdAb.399463$0v4.19910545@bgtnsc04-news.ops.worldnet.att.net>


"Picker Leon" <Temp@NoSuchDomain.Info> дÈëÓʼþ
news:HvdAb.399437$0v4.19909766@bgtnsc04-news.ops.worldnet.att.net...
> Can you explain this code:
>
>   my $input = $_[0];
>   local $matchkey = $_[1]; # must use local instead of my to be used in
> callback
>
>   local @output = (); # must use local instead of my to be used in
callback
>
>   sub callback {
>      my($tag, %attr) = @_;
>      if ($tag eq $matchkey) {push(@output, values %attr);};
>      return;
>   }
>   my $p = HTML::LinkExtor->new(\&callback);
>   $p->parse($input);
>
>
> Why do I have to use local here? If I just use my @output, should callback
> have access @output, because callback is in the same scope with my
@output?
> I tried using my, but records messed up totally.
> And I don't know why use my for $input but local for $matchkey.
>
>

Here is a similar example to above, but both my and local work the same:
local $temp=1;

sub printtemp {
print  $temp;
$temp++;
}

&printtemp;
&printtemp;
&printtemp;
&printtemp;

both my or local will give me 1234, why here local and my are the same but
in the above example, only local works not my.




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

Date: Sat, 06 Dec 2003 05:21:51 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Can you explain LOCAL, MY and OUR with examples?
Message-Id: <x7zne6ttao.fsf@mail.sysarch.com>

>>>>> "PL" == Picker Leon <Temp@NoSuchDomain.Info> writes:

  PL> Can you explain this code:
  PL>   my $input = $_[0];
  PL>   local $matchkey = $_[1]; # must use local instead of my to be used in
  PL> callback

  PL>   local @output = (); # must use local instead of my to be used in callback


that makes NO sense at all.

  PL>   sub callback {
  PL>      my($tag, %attr) = @_;
  PL>      if ($tag eq $matchkey) {push(@output, values %attr);};
  PL>      return;
  PL>   }
  PL>   my $p = HTML::LinkExtor->new(\&callback);
  PL>   $p->parse($input);


  PL> Why do I have to use local here? If I just use my @output, should
  PL> callback have access @output, because callback is in the same
  PL> scope with my @output?  I tried using my, but records messed up
  PL> totally.  And I don't know why use my for $input but local for
  PL> $matchkey.

there is NO need for local in callbacks. callbacks can be closure or
have code refs which have access to lexicals. local there is dumb,
useless and misleading.

and you still haven't said what is confusing you about my and
local. have you read the relevant docs? have you read the web pages that
were mentioned?

where did that code come from?

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Sat, 06 Dec 2003 05:23:06 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Can you explain LOCAL, MY and OUR with examples?
Message-Id: <x7wu9att8l.fsf@mail.sysarch.com>

>>>>> "PL" == Picker Leon <Temp@NoSuchDomain.Info> writes:


  PL> Here is a similar example to above, but both my and local work the same:
  PL> local $temp=1;

  PL> sub printtemp {
  PL> print  $temp;
  PL> $temp++;
  PL> }

  PL> &printtemp;
  PL> &printtemp;
  PL> &printtemp;
  PL> &printtemp;

  PL> both my or local will give me 1234, why here local and my are the
  PL> same but in the above example, only local works not my.

huh? i see only one example. you claim to have two. and you are not
asking intelligent questions. don't use local as you have no clue about
it so why are you asking about it?

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Sat, 06 Dec 2003 05:52:55 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Can you explain LOCAL, MY and OUR with examples?
Message-Id: <3fd16a5b.134042009@news.erols.com>

[Please don't top-post replies.  Please trim reply-quoted material to the
minimum necessary to establish context.]

"Picker Leon" <Temp@NoSuchDomain.Info> wrote:

: Can you explain this code:
:
:   my $input = $_[0];
:   local $matchkey = $_[1]; # must use local instead of my to be used in
: callback

Be aware of how your news client handles word-wrapping.

:   local @output = (); # must use local instead of my to be used in callback
: 
:   sub callback {
:      my($tag, %attr) = @_;
:      if ($tag eq $matchkey) {push(@output, values %attr);};
:      return;
:   }
:   my $p = HTML::LinkExtor->new(\&callback);
:   $p->parse($input);
: 
: Why do I have to use local here?
:
: If I just use my @output, should callback
: have access @output, because callback is in the same scope with my @output?
:
: I tried using my, but records messed up totally.
: And I don't know why use my for $input but local for $matchkey.

For what's shown, there's no reason to use local() instead of my().  

local() _might_ make sense if the code shown is inside a subroutine that is
being called recursively, but that seems unlikely.

Where did you get this code?  Is there more to it?



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

Date: Sat, 06 Dec 2003 15:58:00 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: Can you explain LOCAL, MY and OUR with examples?
Message-Id: <bqrumh$6va$1@pin3.tky.plala.or.jp>

Picker Leon wrote:
> "Picker Leon" <Temp@NoSuchDomain.Info> дÈëÓʼþ
> news:HvdAb.399437$0v4.19909766@bgtnsc04-news.ops.worldnet.att.net...
> 
>>Can you explain this code:
>>
>>  my $input = $_[0];
>>  local $matchkey = $_[1]; # must use local instead of my to be used in
>>callback
>>
>>  local @output = (); # must use local instead of my to be used in
> 
> callback
> 
>>  sub callback {
>>     my($tag, %attr) = @_;
>>     if ($tag eq $matchkey) {push(@output, values %attr);};
>>     return;
>>  }
>>  my $p = HTML::LinkExtor->new(\&callback);
>>  $p->parse($input);
>>
>>
>>Why do I have to use local here? If I just use my @output, should callback
>>have access @output, because callback is in the same scope with my
> 
> @output?
> 
>>I tried using my, but records messed up totally.
>>And I don't know why use my for $input but local for $matchkey.

I'm not sure where you got that code from, but why not use the complete 
example from the HTML::LinkExtor docs? And you'll notice that local is 
nowhere to be found. In other words, you *don't* need to use local for 
the example above.

> Here is a similar example to above, but both my and local work the same:
> local $temp=1;
> 
> sub printtemp {
> print  $temp;
> $temp++;
> }
> 
> &printtemp;
> &printtemp;
> &printtemp;
> &printtemp;
> 
> both my or local will give me 1234, why here local and my are the same but
> in the above example, only local works not my.

Did you read the sections mentioned in the previous post regading my and 
local? Or any of the links given by the others? In the example above, 
you're not using local the way its supposed to be used. That's why you 
get the same results, whether you use a my declaration or a local 
declaration for $temp.

Here's a direct (relavant) quote from perlsub:

"WARNING: In general, you should be using my instead of local, because 
it's faster and safer. Exceptions to this include the global punctuation 
variables, global filehandles and formats, and direct manipulation of 
the Perl symbol table itself. local is mostly used when the current 
value of a variable must be visible to called subroutines."

As has been pointed out by others, its hard to help you if you don't 
explain *exactly* what it is you don't understand/are trying to 
accomplish - the subject of your post asks about local, my, and our, but 
you have also made a reference to eval, and you have used 
HTML::LinkExtor in another example.

keith



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

Date: 6 Dec 2003 08:36:31 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Can you explain LOCAL, MY and OUR with examples?
Message-Id: <bqs4ef$6np$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Picker Leon:

> Can you explain this code:
> 
>   my $input = $_[0];
>   local $matchkey = $_[1]; # must use local instead of my to be used in
> callback
> 
>   local @output = (); # must use local instead of my to be used in callback
> 
>   sub callback {
>      my($tag, %attr) = @_;
>      if ($tag eq $matchkey) {push(@output, values %attr);};
>      return;
>   }
>   my $p = HTML::LinkExtor->new(\&callback);
>   $p->parse($input);
> 
> 
> Why do I have to use local here? If I just use my @output, should callback
> have access @output, because callback is in the same scope with my @output?
> I tried using my, but records messed up totally.
> And I don't know why use my for $input but local for $matchkey.

In the above code, there is no need for using local().

First thing that can be said about local(), is that only deals with
package variables. Package variables are those that live in a package
(=namespace) and can be qualified:

    package Test;
    $var = "foobar";
    package main;
    print $var;         # $var is undef here because it is $main::var

versus

    package Test;
    $var = "foobar";
    package main;
    print $Test::var;   # prints foobar
    
Compare this with

    package Test;
    my $var = "foobar";
    package main;
    print $Test::var;   # prints nothing
    print $var;         # prints foobar

So variables declared with my() are visible only in the enclosing block
or - in case their is no block - throughout the whole file.

local() can now be used to give a package variable temporarily a new
value:

    $var = "old value";     # this is a package variable!
    {
        local $var = "new value";
        print $var, "\n";
    }
    print $var, "\n";
    __END__
    new value
    old value

The previous value is restored when leaving the block in which the
variable was localized.

my() on the other hand doesn't do anything to the value of a variable.
It is used to create _new_ lexical variables. local() on the other hand
does not create variables, it simply gives them a new value. The reason
why local() and my() are often mentioned in the same context is
historical. Perl4 did not have lexical variables, there were only
package ones. So it was impossible to write

    sub function {
        my ($var1, $var2) = @_;
        ...
    }

instead one had to use global variables inside a function. That's why it
was common to use

    sub function {
        local ($var1, $var2) = @_;
        ...
    }

in order to make sure that you did not accidently overwrite $var1 and
$var2 elsewhere in your program. 

This problem no longer exists with lexical variables because they only
exist in the block in which they were declared:

    package main;
    {
        my $var = "foobar";
    }
    print $var;     # tries to print $main::var

The above will additionally give a fatal error when 'use strict' is in
effect because global variables either have to be declared using our()
or 'use vars'. So our() and 'use vars' are to package variables roughty
what my() is for lexicals. I say 'roughly' because our() the vars pragma
aren't quite the same. our() adds some odd scoping semantics (similar to
those of my()) to package variables. But I suggest you forget about
that. It's more than obscure.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Sat, 06 Dec 2003 09:27:36 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: gui in perl
Message-Id: <p783tv0eelgdol7k3fq145ur392hsb3cot@4ax.com>

Matt Garrish wrote:

>It's not about complexity, but the speed at which you can toss a gui
>together.

Take a look at The GUI Loft, not for Tk, but for Win32::GUI on Win32. As
easy as VB, which means, a lot easier than VC++ (IMO)

	<http://www.bahnhof.se/~johanl/perl/Loft/>

-- 
	Bart.


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

Date: 6 Dec 2003 09:49:01 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to open a file from the end and read the last 100 lines
Message-Id: <bqs8md$hfo$1@mamenchi.zrz.TU-Berlin.DE>

Sara <genericax@hotmail.com> wrote in comp.lang.perl.misc:
> rui.vilao@rocketmail.com (Rui Vilao) wrote in message
> news:<385a715f.0312041004.71e2d777@posting.google.com>...
> > Greetings, 
> > 
> > I am writing some Perl script to check some patterns errors in an
> > alert log (Oracle alert log).  The file can't get quite large.
> > Therefore I would like write a Perl script that runs every day via at
> > and opens the file from the end to read the last 100 lines. How can I
> > do this?
> > Any help/suggestion is highly appreciated. 
> > 
> > Thanks in advance for your help, 
> > 
> > Kind Regards, 
> > 
> > Rui Vilao
> 
> 
> Good Day Rui:
> 
> There are some modules in CPAN that would be useful - but it's more
> fun to roll your own!  You DO say that the file CAN'T get quite large,
> which is curious because my logs DO get quite large here on thie RH8
> server. But if it's small why not just:
> 
>    die "I hate MONDAYS!\n" unless open F, 'log';
>    my @l = <F>;
>    close F;
>    @l = splice @l, @l-100;
> 
> and botta bing you have your last 100 lines! 

 ...except when the file has fewer than 100 lines, in which case a fatal
run-time error results.  Uri's File::ReadBackwards deals correctly with
that case.

This is a good demonstration why "rolling your own" is a bad idea, even
if the problem looks trivial.

Anno


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

Date: Sat, 06 Dec 2003 05:51:28 GMT
From: posting.account@lynxview.com (William Herrera)
Subject: Re: How to write to drive A:\ from CGI Perl
Message-Id: <3fd16d4b.191373485@news2.news.adelphia.net>

On 5 Dec 2003 20:34:14 -0800, canle@lecan.com (Cle) wrote:

>Hi!
>
>Please show me how to write an output.txt file from CGI perl sript to
>drive A or C?
>I could access drive A by HTML codes, and I know how to write to a
>file from CGI Perl script. However, a Perl book shown the same thing
>for CGI Perl script that doesn't work.

What operating system is the script in question running upon? Can you run the
script from a command line session on the server and get it to write to the
directory or drive you want? Are there read/write restrictions on the CGI
script's disk writing privileges?

You need to post the script in question here (not just a web page location--if
the server is configured properly, most CGI scripts can only be run as CGI, not
viewed from the internet side here).


---
Use the domain skylightview (dot) com for the reply address instead.


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

Date: Sat, 6 Dec 2003 18:53:57 +1300
From: "Tintin" <me@privacy.net>
Subject: Re: How to write to drive A:\ from CGI Perl
Message-Id: <bqrqvd$264s8i$1@ID-172104.news.uni-berlin.de>


"Cle" <canle@lecan.com> wrote in message
news:8a21e493.0312052034.4fc49519@posting.google.com...
> Hi!
>
> Please show me how to write an output.txt file from CGI perl sript to
> drive A or C?
> I could access drive A by HTML codes, and I know how to write to a
> file from CGI Perl script. However, a Perl book shown the same thing
> for CGI Perl script that doesn't work.
>
> The path from my website:
>
> http://www.mywebsite.com/cgi-bin/cgiwrap/myName/MyFile.pl

open FILE, ">C:/some/path/output.txt" or die "Can not open
C:/some/path/output.txt $!\n";

Change C: to whatever drive is appropriate.




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

Date: 6 Dec 2003 06:01:24 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: How to write to drive A:\ from CGI Perl
Message-Id: <Xns9449A69CCD3Fasu1cornelledu@132.236.56.8>

canle@lecan.com (Cle) wrote in news:8a21e493.0312052034.4fc49519
@posting.google.com:

> Hi!
> 
> Please show me how to write an output.txt file from CGI perl sript to
> drive A or C?

Easy:

#! C:/Perl/bin/perl.exe -T

use strict;
use warnings;

my $fn = 'output.txt';
open(AFILE, ">", $fn) or die "Cannot open $fn: $!\n";
print AFILE 'Output';
close(AFILE) or die "Cannot close $fn: $!\n";
__END__


This will create the file output.txt on the server's A: drive provided 
you remembered to put a floppy in there.

> I could access drive A by HTML codes, 

Interesting ...

> and I know how to write to a file from CGI Perl script. 

good ...

> However, a Perl book shown the same thing for CGI Perl 
> script that doesn't work.

So?

> The path from my website:
> 
> http://www.mywebsite.com/cgi-bin/cgiwrap/myName/MyFile.pl

Hmmm ... http://www.mywebsite.com/ redirects to www.cesmarketing.com and 
the link above does not work. What are you trying to do?

If you are under the illusion that you can write a CGI script that can 
create a file on a floppy disk in the computer of a visitor to your site, 
I would ask if you should be programming CGI scripts at all.

-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


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

Date: Sat, 06 Dec 2003 06:04:23 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: How to write to drive A:\ from CGI Perl
Message-Id: <3fd16f1c.135260009@news.erols.com>

canle@lecan.com (Cle) wrote:

: Please show me how to write an output.txt file from CGI perl sript to
: drive A or C?

From Perl's perspective, it's just like writing any file.  The only
difference is that the filename would include a fully-specced path with the
drive name.

    open FOO, '>', 'A:/thefile' or die $!;

: I could access drive A by HTML codes,

Why do you believe that has anything to do with opening a file with Perl?

: and I know how to write to a file from CGI Perl script.

Then you have the Perl part of the problem under control.  The way to
specify the location of the file is OS-dependent.

: However, a Perl book shown the same thing
: for CGI Perl script that doesn't work.

Saying "doesn't work" is a waste of time.  Show the program, say what you
expect it to do, and say what it really does.

: The path from my website:
: 
: http://www.mywebsite.com/cgi-bin/cgiwrap/myName/MyFile.pl

What does that have to do with anything?



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

Date: 6 Dec 2003 08:37:21 GMT
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Idiom for array index that I'm foreach'ing over?
Message-Id: <2j8gtvsemtr0ffi5u485e8n3710ti4b4ld@4ax.com>

On Fri, 5 Dec 2003 08:57:39 +0000 (UTC), "Bernard El-Hagin"
<bernard.el-haginDODGE_THIS@lido-tech.net> wrote:

>Michele Dondi <bik.mido@tiscalinet.it> wrote in 
>news:36evsvsojg2b2riqrs42hrjdeg0qbq23dd@4ax.com:
>> 
>>>>         $i ++;                                            # hi Abigail
>>              ^
[snip]
>> I *think* it is because of that space. And I can't believe it: it...
>> it really works!
>
>What's so unbelievable about it?

Hmmm... maybe that I didn't think it was possible?!?


On 5 Dec 2003 11:02:11 GMT, "Tassilo v. Parseval"
<tassilo.parseval@rwth-aachen.de> wrote:

>Well, you can do funny things in Perl, particularly with whitespaces:
>
>    ethan@ethan:~$ perl
>    $
>    # comment
>    bla
>
>
>    = 5
>    ;
>
>    print $bla;
>    __END__
>    5

I didn't expect this to be possible either. Funny!

The trick doesn't always work, anyway:

  # perl -le 'print $i ++ for 1..3'
  syntax error at -e line 1, near "++ for "
  Execution of -e aborted due to compilation errors.

  # perl -le 'print($i ++) for 1..3'
  syntax error at -e line 1, near "++ for "
  Execution of -e aborted due to compilation errors.

  # perl -le 'print +($i ++) for 1..3'
  0
  1
  2

  # perl -le 'print do{$i ++} for 1..3'
  0
  1
  2

Could you please be so kind and explain me what perl understands in
the respective cases? In particular I am not puzzled by the fact that
the first one fails and the last one succeeds, but I can't understand
why the second one does not.

As a side (minor) note, by the examples above one sees that even if
the postfix form of the auto increment operator should *increment* the
variable after returning its value, in practice it *modifies* its
value before returning it:

  # perl -le "print $i; print $i++"
  
  0

I checked perldoc perlop and read the magic bit about the
auto-increment operator with strings, but I don't think it applies
here. Also, it doesn't treat explicitly of the case of undefined
variables.


Michele
-- 
# This prints: Just another Perl hacker,
seek DATA,15,0 and  print   q... <DATA>;
__END__


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

Date: Sat, 06 Dec 2003 10:54:33 GMT
From: Zoran.Marinkovic@post.rwth-aachen.de (Zoran)
Subject: reading binary files
Message-Id: <3fd1b263.172576@news.rwth-aachen.de>


Hello, 
I have problems with unpacking binary data(win98,activestate perl).
The procedure is very simple:
1.Packing ascii data as binary data.
2.Unpacking binary data.
3.Printing the output.

This is my input file:
0.1 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 
0.2 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.1 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
1.5 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
2.1 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
2.3 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
2.5 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
3.1 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0
3.2 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 
3.5 11 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0

This is the output:
0.1 0 0 0 0 0 0 0 0 0 0 0 0 0
0.2 0 0 0 0 0 0 0 0 0 0 0 0 0
1.1 0 0 0 0 0 0 0 0 0 0 0 0 0
1.5 0 0 0 0 0 0 0 0 0 0 0 0 0
2.1 0 0 0 0 0 0 0 0 0 0 0 0 0
2.3 0 0 0 0 0 0 0 0 0 0 0 0 0
2.5 0 0 0 0 0 0 0 0 0 0 0 0 0
3.1 0 0 0 0 0 0 0 0 0 0 0 0 0
3.2 0 0 0 0 0 0 0 0 0 0 0 0 0
3.5 0 0 0 0 0 0 0 0 0 0 0 0 0

As you can see only the first numbers are correct.Maybe I am making
mistakes ,when I try to pack the data in a special format 
  @var= pack ("d I d11",$buf);  .


This is the code:
______________________________________________________
print "\n ******************************\n";

open (B ,"< stats.dat") or die "failed opening stats.dat \n";
open (C ,"> bin.dat") or die "failed creating bin.dat \n";

while (my $buf = <B>) 
{
chomp $buf;
@var2 = pack("d I d11",$buf);
print C "@var2\n";
}
close(C);
close(B);

open (B ,"< bin.dat") or die "failed opening bin.dat \n";
open (C ,"> asc.dat") or die "failed opening asc.dat \n";

binmode(B);

while ($buf2=<B>)
#while (read B,$buf2,102) 
{
chomp $buf2;
@var = unpack("d I d11",$buf2);
print C "@var\n";
print " @var\n";
}
close(C);
close(B);

print " Operation done\n";
print " ******************************\n";
__________________________________________________









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

Date: Sat, 06 Dec 2003 05:38:17 GMT
From: "Picker Leon" <Temp@NoSuchDomain.Info>
Subject: What is anonymous sub? Why is it better?
Message-Id: <dXdAb.399569$0v4.19913464@bgtnsc04-news.ops.worldnet.att.net>

From perlsub

To declare subroutines:

    sub NAME;                     # A "forward" declaration.
    sub NAME(PROTO);              #  ditto, but with prototypes
    sub NAME : ATTRS;             #  with attributes
    sub NAME(PROTO) : ATTRS;      #  with attributes and prototypes    sub
NAME BLOCK                # A declaration and a definition.
    sub NAME(PROTO) BLOCK         #  ditto, but with prototypes
    sub NAME : ATTRS BLOCK        #  with attributes
    sub NAME(PROTO) : ATTRS BLOCK #  with prototypes and attributesTo define
an anonymous subroutine at runtime:

    $subref = sub BLOCK;                 # no proto
    $subref = sub (PROTO) BLOCK;         # with proto
    $subref = sub : ATTRS BLOCK;         # with attributes
    $subref = sub (PROTO) : ATTRS BLOCK; # with proto and attributesIt looks
to me that anonymous sub is better just as in file handle, using $FILE is
always better than FILE. right?




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

Date: 6 Dec 2003 05:51:12 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: What is anonymous sub? Why is it better?
Message-Id: <Xns94498AF13F85asu1cornelledu@132.236.56.8>

"Picker Leon" <Temp@NoSuchDomain.Info> wrote in
news:dXdAb.399569$0v4.19913464@bgtnsc04-news.ops.worldnet.att.net: 

> looks to me that anonymous sub is better just as in file handle, using 
> $FILE is always better than FILE. right?

Huh? You might want to get a book and try learning things from the ground 
up instead of reading random bits and pieces of documentation and then 
throwing our way every little question that pops into your mind.

http://www.catb.org/~esr/faqs/smart-questions.html

Sinan.



-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


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

Date: Sat, 06 Dec 2003 05:51:48 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: What is anonymous sub? Why is it better?
Message-Id: <x7k75atrwr.fsf@mail.sysarch.com>

>>>>> "PL" == Picker Leon <Temp@NoSuchDomain.Info> writes:

  PL> to me that anonymous sub is better just as in file handle, using
  PL> $FILE is always better than FILE. right?

why are you asking all these odd questions when you haven't shown skill
in basic perl yet?

ever heard of closures?

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Sat, 06 Dec 2003 06:13:55 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: What is anonymous sub? Why is it better?
Message-Id: <3fd17234.136051509@news.erols.com>

"Picker Leon" <Temp@NoSuchDomain.Info> wrote:

: to me that anonymous sub is better 

Anonymous subs are useful.
Named subs are also useful.

Saying one is better than the other depends entirely on what you plan on
doing with the sub.

: just as in file handle, using $FILE is always better than FILE. right?

That's just baffling.  Those two have nothing to do with each other.



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

Date: 6 Dec 2003 08:37:20 GMT
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Your code doesn't work
Message-Id: <6g8ftvkb9q6ml41fd8gfjbrln2l7bm2n3q@4ax.com>

On Fri, 05 Dec 2003 11:42:16 +0100, Colossus
<colossus_NOSPAM_@freemail.it> wrote:

>Michele Dondi wrote:
>
>> As I wrote in my other post, please quote correctly. I had to check
>> Gunnar Hjalmarsson's own post above to see what you consider a "very
>> difficult explanation"... and only now I realize that I gave you the
>> very same advice (but the 'perldoc -q' one is probably more
>> effective)!
>
>Did it cost you so much checking Gunnar Hjalmarsson's own post above ?
>If so have a vitamin cure !

It did not cost me much. Not just as much as to require a vitamin
cure! Definitely more than finding the correct quotation directly in
your post, period.

Also, in this case I must admit it was not a major concern, but in
other contexts it may well become one! So, just accept this as an
advice: try to quote correctly, always!

Last, due to the nature of propagation of messages in usenet, I may
have never received Gunnar's post. If posted here, then your message
is to be considered of general interest and not a private one, so it
must be of easy access, in terms of content, to anyone.

>> However your claim is plainly false: the perldoc entry you were
>> pointed to definitely is *not* "an explanation on how to sort an array
>> of more fields", either difficult or not. It's the full documentation
>> of the sort() function
>
>The documentation of something does not include explanations ? If it is
>not so why do you waste your time pointing out useless specifications ?

The documentation of something generally *does* include explanations.
This is not relevant and does *not* contradict what I wrote.

The documentation of sort() indeed *does* include explanations!
However it is *not* "an explanation on how to sort an array of more
fields", which was *your* claim, and since you deleted it from
quotations, I'm pasting it here again:

  What you call suitable is a very difficult
  explanation on how to sort an array of more fields.

Hence my comment: no, it is *not*, period!

And my time (and FWIW Gunnar's) was not wasted pointing out that
reference because it is far from being a collection of "useless
specifications". But then, if you have any evidence that makes you
*think* this is not the case, why don't you expose it?

>>and certainly it is clear enough as to give
>> you an idea on how to sort an array "of more fields".
>
>Bah, matter of opinion, to me is not clear. it is really incredible
>how many messages this thread is composed of. I made a mistake
>in posting the expected output ok, I apologized, but still trolls keep on
>replying. It is not the case of arising such a flame, this means in the
>Internet language to be a troll.

I don't think so. I guess you're more probable to be considered a
troll: it's a matter of opinion too. And opinions are made by the
people who take part to a discussion. But that is not the point: I,
for one, do not think you are a troll. You have been arrogant though,
without there being any reason, IMHO.

However the non-flame content left here is: "what is not clear in the
pieces of documentation you were pointed to?", provided you're still
interested. Are you?!?


PS: I (have to) read news offline; this circumstance may contribute to
the "keeping on replying" effect, I hope you can understand me. Since
you actually apologized, I won't add anything that is not Perl-related
in subsequent follow-ups.


Ciao,
Michele
-- 
# This prints: Just another Perl hacker,
seek DATA,15,0 and  print   q... <DATA>;
__END__


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

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.  

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


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