[28474] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9838 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 12 14:10:18 2006

Date: Thu, 12 Oct 2006 11:10:09 -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           Thu, 12 Oct 2006     Volume: 10 Number: 9838

Today's topics:
        Perl scoping questions <cdalten@gmail.com>
    Re: Perl scoping questions <David.Squire@no.spam.from.here.au>
    Re: Perl scoping questions <january.weiner@gmail.com>
    Re: Perl scoping questions <tadmc@augustmail.com>
    Re: Perl scoping questions <David.Squire@no.spam.from.here.au>
    Re: Perl scoping questions <hjp-usenet2@hjp.at>
    Re: Perl scoping questions (reading news)
        Perl trainer needed in The Netherlands <mjm1802@gmail.com>
    Re: Perl trainer needed in The Netherlands <john@castleamber.com>
    Re: QUERY_STRING parsing and '$value =~ tr/+/ /;' treat <ynl@nsparks.net>
    Re: QUERY_STRING parsing and '$value =~ tr/+/ /;' treat <ynl@nsparks.net>
    Re: Running scripts on the Exceed (Chris Mattern)
    Re: Sorting and moving files to dir for DVD burn (at)
    Re: Standard output problem (Chris Mattern)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 12 Oct 2006 06:24:46 -0700
From: "grocery_stocker" <cdalten@gmail.com>
Subject: Perl scoping questions
Message-Id: <1160659486.058458.324960@m73g2000cwd.googlegroups.com>

Given

#!/usr/bin/perl

 $x = 1000;

 sub g() {
     $x=1;
     print "$x\n";
 }

 g();

 print "$x\n";

 produces
 $./bi.pl
 1
 1


 How can $x in g modify $x=1000 (which is global) when the variable
isn't passed by reference (or pointers)? To do the same thing in C, I
would do like the following:

 include <stdio.h>

 int x = 1000;

 int g (int *p) {
     *p=1;
     printf("%d\n",*p);
     return 0;
 }

 int main(void) {

     g(&x);
     printf("%d\n",x);

     return 0;
 }

 $gcc -Wshadow -Wall bi.c -o bi
 $./bi
 1
 1


 Maybe I'm overcomplicating this, but the only thing I can think of is
that
 is somehow related to x's symbol table. Ie the on that holds $x,@x,%x.

Chad



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

Date: Thu, 12 Oct 2006 14:40:18 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: Perl scoping questions
Message-Id: <eglgk3$prc$1@gemini.csx.cam.ac.uk>

grocery_stocker wrote:
> Given
> 
> #!/usr/bin/perl
> 
>  $x = 1000;
> 
>  sub g() {
>      $x=1;
>      print "$x\n";
>  }
> 
>  g();
> 
>  print "$x\n";
> 
>  produces
>  $./bi.pl
>  1
>  1

Yep. The $x in your sub g() is the same one you (implicitly declared
and) initialized as a global above the sub.

You need to indicate that variables are lexically scoped by declaring
them with the "my" keyword, e.g.

----

#!/usr/bin/perl

use strict;
use warnings;

 my $x = 1000;

 sub g() {
     my $x=1;
     print "$x\n";
 }

 g();

 print "$x\n";

----

Note also the "use strict;" and "use warnings;" lines I have added. You
should *always* develop with these pragmas in place. In particular, "use
strict;" might have helped you in this case (by enforcing variable
declaration, and perhaps prompting the thought that it had only been
done once).


DS


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

Date: Thu, 12 Oct 2006 15:31:54 +0200 (CEST)
From: January Weiner <january.weiner@gmail.com>
Subject: Re: Perl scoping questions
Message-Id: <eglg4a$sas$1@sagnix.uni-muenster.de>

grocery_stocker <cdalten@gmail.com> wrote:

>  How can $x in g modify $x=1000 (which is global) when the variable
> isn't passed by reference (or pointers)? 

I think if you add this line after the first line of your script:
use strict ;

and modify your program until it works, you will find that the behaviour it
is not really different from C.

j.

-- 


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

Date: Thu, 12 Oct 2006 08:44:53 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Perl scoping questions
Message-Id: <slrneishml.4cc.tadmc@magna.augustmail.com>

grocery_stocker <cdalten@gmail.com> wrote:

> Subject: Perl scoping questions


See:

   "Coping with Scoping":

      http://perl.plover.com/FAQs/Namespaces.html


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


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

Date: Thu, 12 Oct 2006 15:07:13 +0100
From: David Squire <David.Squire@no.spam.from.here.au>
Subject: Re: Perl scoping questions
Message-Id: <egli6h$t3n$1@gemini.csx.cam.ac.uk>

grocery_stocker wrote:
> Given
> 
> #!/usr/bin/perl
> 
>  $x = 1000;
> 
>  sub g() {
>      $x=1;
>      print "$x\n";
>  }
> 
>  g();
> 
>  print "$x\n";
> 
>  produces
>  $./bi.pl
>  1
>  1
> 
> 
>  How can $x in g modify $x=1000 (which is global) when the variable
> isn't passed by reference (or pointers)? To do the same thing in C, I
> would do like the following:
> 
>  include <stdio.h>
> 
>  int x = 1000;
> 
>  int g (int *p) {
>      *p=1;
>      printf("%d\n",*p);
>      return 0;
>  }
> 
>  int main(void) {
> 
>      g(&x);
>      printf("%d\n",x);
> 
>      return 0;
>  }
> 
>  $gcc -Wshadow -Wall bi.c -o bi
>  $./bi
>  1
>  1
> 

 ... but you don't need to. The C equivalent to your Perl above is:

----

#include <stdio.h>

int x = 1000;

void g() {
	x = 1;
	printf("%d\n", x);
}

int main(char *argv, int argc) {

	g();
	printf("%d\n", x);

}

----

 ... which produces exactly the same result as the Perl script, for
exactly the same reasons.


DS


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

Date: Thu, 12 Oct 2006 16:15:54 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Perl scoping questions
Message-Id: <slrneisjgq.57s.hjp-usenet2@yoyo.hjp.at>

On 2006-10-12 13:24, grocery_stocker <cdalten@gmail.com> wrote:
> Given
>
> #!/usr/bin/perl
>
>  $x = 1000;
>
>  sub g() {
>      $x=1;
>      print "$x\n";
>  }
>
>  g();
>
>  print "$x\n";
>
>  produces
>  $./bi.pl
>  1
>  1
>
>
>  How can $x in g modify $x=1000 (which is global) when the variable
> isn't passed by reference (or pointers)?

You just gave the answer yourself: Because it is global.

> To do the same thing in C, I would do like the following:

You might do it this way, but it works exactly the same as in perl:



#include <stdio.h>

int x = 1000;

 int g (void) {
     x=1;
     printf("%d\n", x);
     return 0;
 }

 int main(void) {

     g();
     printf("%d\n",x);

     return 0;
 }

% gcc -Wshadow -Wall foo.c -o foo
% ./foo
1
1

	hp


-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


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

Date: Thu, 12 Oct 2006 15:29:24 GMT
From: "Mumia W. (reading news)" <paduille.4059.mumia.w@earthlink.net>
Subject: Re: Perl scoping questions
Message-Id: <obtXg.8227$Y24.6526@newsread4.news.pas.earthlink.net>

On 10/12/2006 08:24 AM, grocery_stocker wrote:
> Given
> 
> #!/usr/bin/perl
> 
>  $x = 1000;
> 
>  sub g() {
>      $x=1;
>      print "$x\n";
>  }
> 
>  g();
> 
>  print "$x\n";
> 
>  produces
>  $./bi.pl
>  1
>  1
> 
> 
>  How can $x in g modify $x=1000 (which is global) when the variable
> isn't passed by reference (or pointers)? To do the same thing in C, I
> would do like the following:
> 

Please rephrase the question. You just modified the variable without it 
being passed by reference (and pointers don't exist in perl).

>  include <stdio.h>
> 
>  int x = 1000;
> 
>  int g (int *p) {
>      *p=1;
>      printf("%d\n",*p);
>      return 0;
>  }
> 
>  int main(void) {
> 
>      g(&x);
>      printf("%d\n",x);
> 
>      return 0;
>  }
> 
>  $gcc -Wshadow -Wall bi.c -o bi
>  $./bi
>  1
>  1
> 
> 
>  Maybe I'm overcomplicating this, but the only thing I can think of is
> that
>  is somehow related to x's symbol table. Ie the on that holds $x,@x,%x.
> 
> Chad
> 

Your original bi.pl seems to do what you want it to. If you are 
confused, read "perldoc perlreftut"


-- 
Mumia W.
paduille.4059.mumia.w@earthlink.net
This is a temporary e-mail to help me catch some s-p*á/m.


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

Date: 12 Oct 2006 08:21:27 -0700
From: "marcel" <mjm1802@gmail.com>
Subject: Perl trainer needed in The Netherlands
Message-Id: <1160666487.436387.75260@b28g2000cwb.googlegroups.com>

Hi,

Due to illness of our own trainer we are looking for someone to teach
the course: Perl Programming on October 16, 17 and 18th in our
classroom near Utrecht. Can be dutch or english spoken.

You can find the course outline on:
http://www.twice.nl/vis/infosheet.asp?id=1497

Interested. Please send an email to mjm1802@gmail.com

TIA,

Marcel



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

Date: 12 Oct 2006 17:35:48 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Perl trainer needed in The Netherlands
Message-Id: <Xns985A80239F5F8castleamber@130.133.1.4>

"marcel" <mjm1802@gmail.com> wrote:

> Hi,
> 
> Due to illness of our own trainer we are looking for someone to teach
> the course: Perl Programming on October 16, 17 and 18th in our
> classroom near Utrecht. Can be dutch or english spoken.

Meh :-( Currently living in Mexico.

It's good to be in Utrecht... (The Boegies at the start of a live concert)


-- 
John                Experienced Perl programmer: http://castleamber.com/

          Perl help, tutorials, and examples: http://johnbokma.com/perl/


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

Date: Thu, 12 Oct 2006 18:28:48 +0200
From: Yohan N Leder <ynl@nsparks.net>
Subject: Re: QUERY_STRING parsing and '$value =~ tr/+/ /;' treatment
Message-Id: <MPG.1f988ba2cdb5d1169898e3@news.tiscali.fr>

In article <slrneilg82.l3i.hjp-usenet2@yoyo.hjp.at>, hjp-usenet2@hjp.at 
says...
> It doesn't. Why should it? It is perfectly possiblt to parse
> $ENV{'QUERY_STRING'} without modifying it. Even if you want to use
> "destructive" operators like tr///, you can always apply them to a copy:
> 
> $value= $ENV{'QUERY_STRING'};
> $value =~ tr/+/ /;
> 

Yes, it's always possible to take an alternative way. But my question 
was about something supposed to work with usual manner (w/ CGI.pm or 
usual parsing), for the purpose to be able to copy/paste my piece of 
code in a third parties (others developers) scripts

> BTW, I just noticed that the manual doesn't describe query_string()
> correctly:
> 
>        You can also retrieve the unprocessed query string with
>        query_string():
> 
> While CGI does leave $ENV{'QUERY_STRING'} unprocessed, query_string()
> returns a changed version in the case of old isindex-style queries:
> 
> "aa+bb" is converted into "keywords=aa;keywords=bb".
> 

Well, so this thread has been useful :)


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

Date: Thu, 12 Oct 2006 18:31:08 +0200
From: Yohan N Leder <ynl@nsparks.net>
Subject: Re: QUERY_STRING parsing and '$value =~ tr/+/ /;' treatment
Message-Id: <MPG.1f988c3869bd6ea09898e4@news.tiscali.fr>

In article <MPG.1f9357423e6924799898df@news.tiscali.fr>, ynl@nsparks.net 
says...
> Parsing $ENV{'QUERY_STRING'} w/o CGI.pm, it's usual to see code treating 
> extracted values with a "$value =~ tr/+/ /;" for 'unwebification' of the 
> '+' signs.
> 
> But, this kind of treatment will corrupt any QUERY_STRING content which 
> is not simple text (for example, I've done test on base64 data).
> 
> So, how does CGI.pm handle this ? How does it differenciates 
> QUERY_STRING content's values which has to be 'not treated' (e.g. like a 
> base64 encoded image) from the one which has to be 'treated' (e.g. like 
> a simple text) ?
> 

Just found that it exists base64 variant which works around this problem 
: see http://en.wikipedia.org/wiki/Base64

Were we can read (quote) : "Using a URL-encoder on standard Base64, 
however, is inconvenient as it will translate the '+' and '/' characters 
into special '%XX' hexadecimal sequences ('+' = '%2B' and '/' = '%2F'). 
When this is later used with database storage or across heterogeneous 
systems, they will themselves choke on the '%' character generated by 
URL-encoders (because the '%' character is also used in ANSI SQL as a 
wildcard).

For this reason, a modified Base64 for URL variant exists, where no 
padding '=' will be used, and the '+' and '/' characters of standard 
Base64 are respectively replaced by '*' and '-', so that using URL 
encoders/decoders is no longer necessary and has no impact on the length 
of the encoded value, leaving the same encoded form intact for use in 
relational databases, web forms, and object identifiers in general."

Solved !


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

Date: Thu, 12 Oct 2006 15:43:00 -0000
From: syscjm@sumire.eng.sun.com (Chris Mattern)
Subject: Re: Running scripts on the Exceed
Message-Id: <12isok44v2mm108@corp.supernews.com>

In article <1160628987.950622.252770@h48g2000cwc.googlegroups.com>, EZP wrote:
>when i'm running the script (above) through my windows cmd, the window
>is stuck.
>

What script?  Above what?  I don't see anything.

Please quote sufficient content so that people can know what you're talking
about.

-- 
             Christopher Mattern

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


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

Date: Thu, 12 Oct 2006 09:10:15 -0400
From: at <"romorris(at)"@bellsouth.net>
Subject: Re: Sorting and moving files to dir for DVD burn
Message-Id: <R4rXg.42875$8s6.34556@bignews4.bellsouth.net>

Michele Dondi wrote:
> On 11 Oct 2006 19:27:27 -0700, "romorris@bellsouth.net"
> <romorris@bellsouth.net> wrote:
>
>   
>> Im sure someone done this, probally for MP3's, and knows how to do it
>> in such a simple fashion with perl, so I have to ask this:
>>
>> I have a quite few files (~230), all different sizes ( 2megs~200megs )
>> all in one directory. All files are compressed(.Z).
>>
>> What I want to do is somehow sort and move these into seperate
>> directories filling each as close to 4 gigs as possible. This way I can
>>     
>
> Notoriously, this is a mathematically hard problem, precisely the
> "knapsack problem". However for more pointers you may look into the
> following PM thread:
>
> http://perlmonks.org/?node_id=546968
>
> which BTW has some "suspiscious" similarities with this message
> itself...
>
>
> HTH,
> Michele
>   
Michele;
  "suspicious similarities" is Right! I guess there are actually others 
looking for the same thing. Funny thing was after wading though messages 
about "file splitting" I had found a handful of other similar requests, 
all with no answers, or going in the wrong direction.

 Thanks for this link. This is exactly what I'm trying to do, but too 
bad I don't know more about Perl.

The link also gives better search terms than I was using, lets see where 
I can go from there.

thanks!

-Rob


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

Date: Thu, 12 Oct 2006 15:47:36 -0000
From: syscjm@sumire.eng.sun.com (Chris Mattern)
Subject: Re: Standard output problem
Message-Id: <12isoso8bmltg68@corp.supernews.com>

In article <1160598910.311902.207580@h48g2000cwc.googlegroups.com>, 
wesphillips@gmail.com wrote:
>I have a perl script, it is very basic:
>
>#!/usr/bin/perl -w
>#test.pl
>print "test\n";
>
>
>The test.pl file is executable (permissions are 755). If I run this
>script like this:
>perl ./test.pl
>
>I get the expected output, but if I run it like this:
>
>./test.pl
>
>I don't get anything at all. I have induced errors into the script to
>see if I get the error messages, but I still get nothing. If I run the
>script with the errors by explicitly calling perl, I see the error
>output like I expect to. I have a second script in the same directory
>that DOES work when called directly, so I don't know what could be
>wrong. I have also changed the first line so that it looks like this:
>
>#!/usr/bin/perly -w
>
>and I get the expected error from bash stating that it cannot find the
>interpreter called "perly"
>
>Any ideas?
>

Start out by making your command line the exact same as your #!.  What do
you get when you try:

/usr/bin/perl -w ./test.pl

?

-- 
             Christopher Mattern

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


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

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


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