[22964] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5184 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 6 03:06:12 2003

Date: Sun, 6 Jul 2003 00:05:10 -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           Sun, 6 Jul 2003     Volume: 10 Number: 5184

Today's topics:
    Re: Alternative to use vars <mgjv@tradingpost.com.au>
    Re: Confused with array and references <abigail@abigail.nl>
    Re: detecting links <grazz@pobox.com>
    Re: dynamic sorting <spam@thecouch.homeip.net>
    Re: How can I analyse jpg file with perl? <nospam@thanksanyway.org>
    Re: How can I analyse jpg file with perl? <newbie@aol.com>
    Re: How can I analyse jpg file with perl? <gamelifes@yahoo.com.cn>
    Re: How can I analyse jpg file with perl? <jurgenex@hotmail.com>
        How do I clone a structure? (John Brock)
    Re: How do I clone a structure? <bdonlan@bd-home-comp.no-ip.org>
    Re: How do I clone a structure? (Tad McClellan)
    Re: naming hash using a variable name. <nanae@perusion.com>
    Re: Need help with Win32::GuiTest and Indigo perl <awingnut@hotmail.com>
        Net::POP3 <levalt@rogers.com>
    Re: Net::POP3 (Jay Tilton)
    Re: Net::POP3 <levalt@rogers.com>
    Re: Net::POP3 <noreply@gunnar.cc>
    Re: ping Tad (Tad McClellan)
    Re: Problem with counter CGI script (Tad McClellan)
    Re: Problems with perlcc <bdonlan@bd-home-comp.no-ip.org>
    Re: Problems with perlcc <mgjv@tradingpost.com.au>
    Re: Regexp constructed from command line arguments. (Tad McClellan)
    Re: script for unrestricted permutation <krahnj@acm.org>
    Re: script for unrestricted permutation <krahnj@acm.org>
    Re: Uri & Tad replies to ARGV/pipe mystery function :) (stu7)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 6 Jul 2003 08:55:30 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Alternative to use vars
Message-Id: <slrnbgelr1.rlm.mgjv@martien.heliotrope.home>

On Sat, 05 Jul 2003 21:24:48 +0200,
	Michele Dondi <bik.mido@tiscalinet.it> wrote:
> On Sat, 5 Jul 2003 10:26:54 +1000, Martien Verbruggen
><mgjv@tradingpost.com.au> wrote:
> 
>>This is what the difference between C<our> and C<use vars> is. C<our>
>>works on lexical scopes, and C<use vars> works on package scope. 
> 
> Hmmm... this seems to be the main issue here. Maybe for a future Perl5
> release a (backwards compatible) mechanism might be devised, by means
> e.g. of a C<package> modifier, that gives a package an implicit
> lexical scope.

You can't do that. Not without major change.

Packages can appear in multiple lexical scopes, and even in multiple
files, simply by using the package keyword.

$ cat Foo.pm
package Foo;
use vars qw/$bar/;
$bar = 3;
1;

$ cat foo.pl
#!/usr/local/bin/perl
use warnings;
use strict;

use Foo;

print "main: $Foo::bar\n";
$Foo::bar = 5;

package Foo;
print "$bar\n";

$ ./foo.pl
main: 3
5

Yes, this is a pathological case, but so are all the cases presented in
this argument. The problem of confusion simply doesn't exist in most of
the code out there.

I tend to think that C<our> is a much better solution than C<use vars>,
because of things like this. There is nothing in foo.pl that indicates
that $bar can be used unqualified. If there had been a C<use vars
'$bar'> in that file in the main package, that would have been very
confusing.

If you need a lexical scope that is different from your file, you use a
block.

Martien
-- 
                        | 
Martien Verbruggen      | Useful Statistic: 75% of the people make up
                        | 3/4 of the population.
                        | 


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

Date: 05 Jul 2003 22:52:38 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Confused with array and references
Message-Id: <slrnbgellm.2cs.abigail@alexandra.abigail.nl>

Tassilo v. Parseval (tassilo.parseval@rwth-aachen.de) wrote on MMMDXCV
September MCMXCIII in <URL:news:be763v$8q8$1@nets3.rz.RWTH-Aachen.DE>:
``  
``  I think that round parens generally do construct lists. However, Perl

I think that in general parens *don't* construct lists. *Context* does.
The example quoted below is one of two cases I can think of where parens
do create lists (or list context). There's also the left operand of 'x'
where, depending on context, () make lists.

``  allows to omit the parens when they are not needed (just like one can do
``  away with the $_ with many built-ins). This becomes clearer for those
``  cases where the parens must be used to enforce list context:
``  
``      ($var) = keys %hash;
``      # compared to
``      $var = keys %hash;
``  
``  So you sometimes need parens to force something into list context
``  whereas in the opposite case (when you have the context already), you
``  don't need them. Therefore it's probably better to tackle and explain
``  lists from a context-angle.

Indeed.


Abigail
-- 
 :;$:=~s:
-:;another Perl Hacker
 :;chop
$:;$:=~y
 :;::d;print+Just.
$:;


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

Date: Sun, 06 Jul 2003 01:00:19 GMT
From: Steve Grazzini <grazz@pobox.com>
Subject: Re: detecting links
Message-Id: <DwKNa.4042$19.2625@nwrdny03.gnilink.net>

Joe Smith <inwap@inwap.com> wrote:
> In article <be1uub$9dj$1@lore.csc.com>,  <jsowers@csc.com> wrote:
>> I need something equivalent to the '-d' to determine if an 
>> item is a directory.
> 
> Simply test for symlink _before_ testing for directoryness.
>
>         if (-l $item) {
>             (-d _) and print "Symlink to a directory\n";
               ^^^^
This will never be true.

>             (-f _) and print "Symlink to a file\n";
>             (-e _) or  print "Broken symlink; target does not exist\n";
               ^^^^
And this will always be true.

You'll need to do a regular stat() inside the block -- otherwise 
the special _ filehandle will refer to the results of the lstat()
and you know already that the *symlink* exists and is neither
file nor directory.

-- 
Steve


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

Date: Sat, 05 Jul 2003 18:14:41 -0400
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: dynamic sorting
Message-Id: <m5INa.103926$0B.1935367@wagner.videotron.net>

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

ARAVIND wrote:
> hello,
> 
> say i have a variable 
> $temp = "ARAVIND     25     BANGALORE";
> I want just ARAVIND and BANGALORE
> if i do 
> @splitval = split /\d /,$temp;
> then i get
> $splitval[0] = 'ARAVIND     25';
> $splitval[1] = 'BANGALORE';
> 
> i can further split it from $splitval[0] and get only ARAVIND.
> but how to make it one shot....spliting.

Your logical delimiter is whitespace(s), not the number. Use that as the split token:

$temp = "ARAVIND     25     BANGALORE";
@words = split(/\s+/, $temp);
print "First is $words[0] and last is $words[-1]\n";

Or you could do it without the intermediate @words array:

$temp = "ARAVIND     25     BANGALORE";
($first, $last) = (split(/\s+/, $temp))[0,-1];
print "First is $first and last is $last\n";

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE/B03VeS99pGMif6wRAsd5AKDGgo1o9LYa6xO660+k/QAcPBonkgCfRVPh
Jd8JHbCt1rRQrl/NPaBKxas=
=LKhA
-----END PGP SIGNATURE-----



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

Date: Sat, 5 Jul 2003 15:10:56 -0700
From: "Mark" <nospam@thanksanyway.org>
Subject: Re: How can I analyse jpg file with perl?
Message-Id: <BIWdne0K-b5z0ZqiXTWc-w@speakeasy.net>

Let me guess: you want to be able to programmatically create throwaway
accounts on free e-mail services, so you can use them to send spam?




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

Date: Sat, 5 Jul 2003 23:57:47 -0500
From: "Newbie" <newbie@aol.com>
Subject: Re: How can I analyse jpg file with perl?
Message-Id: <vgfb28ca65mva1@corp.supernews.com>

What??

"Mark" <nospam@thanksanyway.org> wrote in message
news:BIWdne0K-b5z0ZqiXTWc-w@speakeasy.net...
> Let me guess: you want to be able to programmatically create throwaway
> accounts on free e-mail services, so you can use them to send spam?
>
>




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

Date: Sun, 6 Jul 2003 13:21:39 +0800
From: "bytewolf" <gamelifes@yahoo.com.cn>
Subject: Re: How can I analyse jpg file with perl?
Message-Id: <be8bn7$n7f$1@mail.cn99.com>

Oh~It's a bad idea...I don't...Sending the rubbish mail should bear legal
responsibility ,I hit spam very much~~
    A few days ago,one of my classmate came to my home and saw I was
"playing" with perl,so,I told he that perl is very strong,then he maked a
jpg file with some words in,and asked me to get this words inside of the jpg
file by using perl,I don't know how to do that,then I asked some friends,and
they advised me to send a "help email" to comp.lang.perl.misc....

"Mark" <nospam@thanksanyway.org> дÈëÓʼþ
news:BIWdne0K-b5z0ZqiXTWc-w@speakeasy.net...
> Let me guess: you want to be able to programmatically create throwaway
> accounts on free e-mail services, so you can use them to send spam?
>
>




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

Date: Sun, 06 Jul 2003 06:02:26 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: How can I analyse jpg file with perl?
Message-Id: <SXONa.31592$n%5.12164@nwrddc02.gnilink.net>

bytewolf wrote:
>>     A few days ago,one of my classmate came to my home and saw I was
> "playing" with perl,so,I told he that perl is very strong,then he
> maked a jpg file with some words in,and asked me to get this words
> inside of the jpg file by using perl,

Ok, let me try to understand what you are asking for.

What are those "words" you are talking about. Are those comments which are
stored in the header of a JPEG file? Then probably one of the modules on
CPAN can extract this information.
JPEG::Comment does the reverse (adds a comment to a JPEG file), but I'm sure
if you search a bit you will find a module that will extract the comment.
Image::Info looks quite promising.

Or are you talking about a bitmap (in JPEG format) which when displayed in a
viewer shows a pattern that is recognized by the human eye as "words".
Extracting those "words" is non-trivial and always a good guess at best. You
will need a character recognition algorithm/program, commonly known as OCR.
I would guess that someone implemented an OCR in Perl already and probably
you can find it on CPAN, too. Did you check there?

jue




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

Date: 5 Jul 2003 17:48:27 -0400
From: jbrock@panix.com (John Brock)
Subject: How do I clone a structure?
Message-Id: <be7h3b$499$1@panix3.panix.com>

Lets say that I have a complicated structure, for example an array
of hash references.  Is there a general way to clone the entire
data structure, no matter how complicated it is, so that copies
are made of all objects and no references in the new structure
point to any objects in the original structure?
-- 
John Brock
jbrock@panix.com



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

Date: Sat, 05 Jul 2003 21:47:41 -0400
From: "bd" <bdonlan@bd-home-comp.no-ip.org>
Subject: Re: How do I clone a structure?
Message-Id: <pan.2003.07.06.01.47.37.552893@bd-home-comp.no-ip.org>

On Sat, 05 Jul 2003 17:48:27 -0400, John Brock wrote:

> Lets say that I have a complicated structure, for example an array
> of hash references.  Is there a general way to clone the entire
> data structure, no matter how complicated it is, so that copies
> are made of all objects and no references in the new structure
> point to any objects in the original structure?

use Data::Dumper;

sub clone {
  local $Data::Dump::Purity = 1;
  my $ref = shift @_;
  my $code = Data::Dumper::Dump([$ref], [qw(new)]);
  eval $code;
  return $new;
}

If it's not a scalar, you need to pass a reference to it, of course.

-- 
Freenet distribution not available
Knocked, you weren't in.
		-- Opportunity



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

Date: Sat, 5 Jul 2003 19:37:23 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How do I clone a structure?
Message-Id: <slrnbgerq3.7mv.tadmc@magna.augustmail.com>

John Brock <jbrock@panix.com> wrote:

> Is there a general way to clone the entire
> data structure


Your Question is Asked Frequently:

   How do I print out or copy a recursive data structure?


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


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

Date: Sat, 5 Jul 2003 22:56:59 +0000 (UTC)
From: Perusion hostmaster <nanae@perusion.com>
Subject: Re: naming hash using a variable name.
Message-Id: <slrnbgelvj.26i.nanae@ns.valuemedia.com>

On Sat, 05 Jul 2003 14:36:33 GMT, Uri Guttman <uri@stemsystems.com> wrote:
>>>>>> "Ph" == Perusion hostmaster <nanae@perusion.com> writes:
> 
>  Ph> 	my $tmp1 = $rand[int rand(scalar(@rand))];
> 
> nither the int nor the scalar are needed there. rand provides scalar
> context to its single argument (single argument means wants a single
> value which is what scalar context is).

I often do this type of thing just because context is not always
foolproof on all versions. Of course, this is because I have been
doing Perl 5 code since 5.001m...

> and indexing also provides
> integer context (ever heard of the 3.14159th slot of an array) to any
> values being used.
> 
> 	my $tmp1 = $rand[rand @rand];
> 
> that is the classic select a random element from an array idiom.

With luck I will remember that next time and flag it as authoritative.
8-)

> 
>  Ph> 	$hash{$tmp1} = {};
> 
> no need to initialize that. autovivification will handle it for you.

I do know that. I am not a big fan of autovivification, and almost
always explicitly instantiate anonymous refs. In fact, I would
like to see:

    use strict qw/no_autovivify/;

>>>>>> "Ph" == Perusion hostmaster <nanae@perusion.com> writes:
> 
> 
>  Ph> 	for(my $i = 0; $i < @ARGV; $i++) {
>  Ph> 		$hash{$tmp1}{$ARGV[$i]} = $i;
>  Ph> 	}
> 
> ewww.
> 
> 	@{$hash{$tmp1}}{@ARGV} = 0 .. $#ARGV ;
> 

Done that way to try and talk to the less-experienced on their 
level.

>  Ph> If you insist on the tired Perl 4 way:
> 
> no, he doesn't insist upon it. you shouldn't even show how symrefs can
> be done. go with your correct instincts and not show it at all.

You are probably right.

-- 
Perusion Hostmaster

"Being against torture ought to be sort of a bipartisan thing."
-- Karl Lehenbauer


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

Date: Sun, 06 Jul 2003 00:11:17 -0400
From: gw1500se <awingnut@hotmail.com>
Subject: Re: Need help with Win32::GuiTest and Indigo perl
Message-Id: <r88fgv8jre2mg1acnmmfkgjlgjahgud531@4ax.com>

On Fri, 4 Jul 2003 19:03:37 +1000, "Sisyphus" <kalinabears@hdc.com.au>
wrote:

>
>"gw1500se" <awingnut@hotmail.com> wrote in message
>>
>> Or at least it fails different. I no longer get the error on the "use"
>> statement. Now I get an error on the "FindWindowLike" statement. Here
>> is what I tried as a test:
>>
>> @windows=FindWindowLike(0;"*","*");
>>
>
>Could that simply be a case of incorrect coding ?
>Perhaps:
>@windows=FindWindowLike(0,"^*","^*");
>

Thanks, that was it. What exactly is the reason for the '^'? In a UNIX
regular expression that is not necessary.


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

Date: Sun, 06 Jul 2003 02:46:26 GMT
From: "Lev Altshuler" <levalt@rogers.com>
Subject: Net::POP3
Message-Id: <64MNa.70818$x4o.46663@news04.bloor.is.net.cable.rogers.com>

Hi,

I am trying to count email messages in the mailbox and read their headers.
In case that there are some messages on the POP3 server and
they haven't yet got to the Inbox, I get a number of messages.
As soon as they have been in the Inbox, I get '0E0' as a number of messages.
Does anyone know what feature of Net::POP3 I am not aware of, or
where did I screw up in the code?

use Net::POP3;

my $server = "pop.bloor.phub.net.cable.rogers.com";
my $pop3 = Net::POP3->new($server, Timeout => 10, Debug =>1);
die "Couldn't log on to server" unless $pop3;

my $user = "levalt\@rogers.com";
my $password = "password";
my $num_Messages = $pop3->login($user, $password);
print "$num_Messages\n";





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

Date: Sun, 06 Jul 2003 03:13:24 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Net::POP3
Message-Id: <3f07934f.126178557@news.erols.com>

[comp.lang.perl removed from list of newsgroups.  Don't post to dead
groups.]

"Lev Altshuler" <levalt@rogers.com> wrote:

: I am trying to count email messages in the mailbox and read their headers.
: In case that there are some messages on the POP3 server and
: they haven't yet got to the Inbox, I get a number of messages.
: As soon as they have been in the Inbox, I get '0E0' as a number of messages.
: Does anyone know what feature of Net::POP3 I am not aware of, or
: where did I screw up in the code?

0E0 evaluates to zero in numeric context, but evaluates to true in
boolean context.

Just like the Net::POP3 documentation says.



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

Date: Sun, 06 Jul 2003 03:26:56 GMT
From: "Lev Altshuler" <levalt@rogers.com>
Subject: Re: Net::POP3
Message-Id: <4GMNa.70962$x4o.34496@news04.bloor.is.net.cable.rogers.com>


"Jay Tilton" <tiltonj@erols.com> wrote in message
news:3f07934f.126178557@news.erols.com...
> [comp.lang.perl removed from list of newsgroups.  Don't post to dead
> groups.]
>
> "Lev Altshuler" <levalt@rogers.com> wrote:
>
> : I am trying to count email messages in the mailbox and read their
headers.
> : In case that there are some messages on the POP3 server and
> : they haven't yet got to the Inbox, I get a number of messages.
> : As soon as they have been in the Inbox, I get '0E0' as a number of
messages.
> : Does anyone know what feature of Net::POP3 I am not aware of, or
> : where did I screw up in the code?
>
> 0E0 evaluates to zero in numeric context, but evaluates to true in
> boolean context.
>
> Just like the Net::POP3 documentation says.
>

The point is that there is a number of messages in my Inbox, and
 $pop3->login($user, $password);
 is evaluated to 0E0 which is zero.




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

Date: Sun, 06 Jul 2003 05:47:15 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Net::POP3
Message-Id: <be865c$1eq3u$1@ID-184292.news.dfncis.de>

Lev Altshuler wrote:
> The point is that there is a number of messages in my Inbox, and
>  $pop3->login($user, $password);
>  is evaluated to 0E0 which is zero.

You said in your first message: "In case that there are some messages 
on the POP3 server and they haven't yet got to the Inbox ..."
Obviously you distinguish between "POP3 server" and "Inbox". Are you 
talking about the "Inbox" in Outlook Express or something, and if so, 
what has that to do with Net::POP3...?

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



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

Date: Sat, 5 Jul 2003 19:22:08 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: ping Tad
Message-Id: <slrnbgeqtg.7mv.tadmc@magna.augustmail.com>

noViagraHere <requests@zipperpulls.com> wrote:

> Subject: Re: ping Tad


Please put the subject of your article in the Subject of your article.

Your article is about making a CGI request.

Your article is not about Tad.


> Thank you so much for your help but I don't think you understood my
> question. 


I think you don't understand my answer.  :-)


> file1.cgi is called from a third party by sending variables to the script,
> ie. http://file1.cgi?parameters=list


How the first program is invoked is irrelevant.


> from
> within file1.cgi calls http://file2.cgi?parameters=list


You don't "call" CGI programs, you make a "request".

The LWP module can make your Perl program "look like" a browser.

   use LWP::Simple;
   my $answer_from_file2 = get 'http://file2.cgi?parameters=list';


LWP::Simple is fine for short GET requests, I recommended UserAgent
because it can be used for GET _and_ for POST requests.


> I need to know how to add code within file1.cgi to determine what
> http://file2.cgi?parameters=list returned,


And now you know.


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


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

Date: Sat, 5 Jul 2003 21:08:43 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Problem with counter CGI script
Message-Id: <slrnbgf15b.7mv.tadmc@magna.augustmail.com>

T Stewart <tstewart66@hotmail.com> wrote:
> 
> I downloaded a free counter 


I may be worth precisely what you paid for it. Perhaps even less...


> CGI from http://www.htmlgoodies.com/ and
> it works fine on my server with one exception.


You should contact the author of the code if you have discovered a bug.

Were they not responsive?


> It has a feature where if someone else is detected using it without
> permission, you can create a .LOCK file in the counter directory that
> will always cause it to return 0 to the caller.
> 
> But I'm finding it will create the .LOCK file after the first call,
> causing subsequent calls to return 0.
> 
> Here is where it goes to increment the counter:
> 
> sub incrementCount {
>   if (&lockFile == 1) {
        ^
        ^
>     $count = "0";
               ^ ^
               ^ ^

That coding style tells me a lot about the quality of the code.

     if ( lockFile() ) {
       $count = 0;

or, better yet:

   $count = 0 if lockFile();


Using the ampersand means something that programmers seldom mean,
see perlsub.pod for what happens when the function is called
in that "zero cost" code.

Why stringify something that is cleary _meant_ to be a number?


> sub lockFile {
>   $lockCount = 0;
>   while (-f "$counterFile.lock") { 
               ^^^^^^^^^^^^
>     if ($lockCount > $lockWait) {
                       ^^^^^^^^^
>       $count = 0;
        ^^^^^^

That sure is a lot of global variables...

And now we switch back to _not_ stringifying $count's value?

Were there multiple authors of this code, or just one person
switching styles back and forth?



>   open(LOCK,">$counterFile.lock") || die("Can't open
> $counterFile.lock: $!\n");
>   return 0;
> }
> 
> Shouldn't this just check for a LOCK file, not create one?


I think there are probably two "lock" files here, and which
is which has been confused.

The code in lockFile() appears to be implementing file locking,
this has nothing to do with the "return zero" feature you
described above.



> &ReadParse;


People that don't use a module for CGI parameters are on their own.

Good luck.


>       open(CNTRFILE,">$counterFile");


You should always, yes *always*, check the return value from open():

   open(CNTRFILE,">$counterFile") or die "could not open '$counterFile' $!";


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


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

Date: Sat, 05 Jul 2003 17:59:46 -0400
From: "bd" <bdonlan@bd-home-comp.no-ip.org>
Subject: Re: Problems with perlcc
Message-Id: <pan.2003.07.05.21.59.46.335035@bd-home-comp.no-ip.org>

On Sat, 05 Jul 2003 21:14:41 +0200, Dennis Hueckelheim wrote:

> 
> "bd" <bdonlan@bd-home-comp.no-ip.org> wrote
>>
>> If you're using Apache, you can use mod_perl to compile your scripts only
>> once. As for the source viewing problem, this would be something to take
>> up with your hosting provider.
>>
> 
> The problem is, that the people who don't should see the sources have access
> as root, so I can't use different rights.

Then they could probably get your compiled binary, put it in a debugger,
and use B::Deparse on it anyway, if they really wanted to.


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

Date: Sun, 6 Jul 2003 09:00:24 +1000
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Problems with perlcc
Message-Id: <slrnbgem48.rlm.mgjv@martien.heliotrope.home>

On Sat, 5 Jul 2003 15:49:36 +0200,
	Dennis Hueckelheim <dennis.hueckelheim@issdh.com> wrote:
> 
> "Sisyphus" <kalinabears@hdc.com.au> wrote
>>
>> If you really *must* use perlcc then you're probably on your own :-)
> 
> No, I don't *must* use perlcc. I only want to compile my sources, because
> the program would run faster, wouldn't it?

Unlikely. It may be marginally faster, but then again, it may not.

>                                            A second reason s, that the other
> webmaster's on my server can't read the sources.

You need to read the Perl FAQ, section 3. Both of these issues are
addressed in there.

Martien
-- 
                        | 
Martien Verbruggen      | System Administration is a dirty job, but
                        | someone said I had to do it.
                        | 


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

Date: Sat, 5 Jul 2003 19:33:48 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Regexp constructed from command line arguments.
Message-Id: <slrnbgerjc.7mv.tadmc@magna.augustmail.com>

ddtl <this.is.invalid@yahoo.com> wrote:


> $a=~s/([\d]{2})/0\1/g;


You should always enable warnings when developing Perl code!

$a (and $b) are poor choices of variable names, they are used
by sort() too, values could get mangled...

The pattern would be easier to read and understand if written as:

   $x =~ s/(\d\d)/0$1/g;



> print "$a";


See the Perl FAQ:

   What's wrong with always quoting "$vars"?


> What is another problem here?


You only get one round of interpolation, and you are using it to
fetch the value from the hash. You'd need an additional round
to interpolate it yet again.


> But why it is so - 


Because if you had:

   $_ = '$100.00';
   s/(\$1)/$1/g;

and Perl kept doing rounds of interpolation until there was
nothing left to interpolate, it would never finish.  :-)

So it only does one round.

The solution to your problem can be found in the Perl FAQ:

   How can I expand variables in text strings?


> containing regexp?


The variable you are speaking of DOES NOT contain a regex.

The replacement string is a (double quotish) _string_, not a regex.


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


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

Date: Sun, 06 Jul 2003 05:30:45 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: script for unrestricted permutation
Message-Id: <3F07B400.6BA2DD6E@acm.org>

Jay Tilton wrote:
> 
> charley@pulsenet.com (Chris Charley) wrote:
> 
> : I solved this permutation by modeling it on an odometer.
> 
> Nice analogy.
> 
> : #!/usr/bin/perl
> : use strict;
> : use warnings;
> :
> : my $group = 4;
> : my @perms = perm($group, "red", "green", "blue");
> :
> : for my $i (0..$#perms) {
> :     for my $j (0..$group-1) {
> :         print "$perms[$i][$j] ";
> :     }
> :     print "\n";
> : }
> : sub perm {
> :     my $groupings = shift @_;
> :     my @elements = @_;
> :     my @odometer = (0) x $groupings;
> :     my @perms;
> :     while ( 1 ) {
> :         push @perms, [ @elements[@odometer] ];
> :         my $wheel= 0;
> :         $odometer[$wheel] = ($odometer[$wheel] + 1) % @elements;
> :
> :         while ($odometer[$wheel] == 0 && ++$wheel< @odometer) {
> :             $odometer[$wheel] = ($odometer[$wheel] + 1) % @elements;
> :         }
> :         return @perms if $wheel == @odometer;
> :     }
> : }
> 
> I like the principle, but the implementation feels a little too
> fiddly.
> 
> How about instead of monitoring $wheel and bailing out when it indexes
> a nonexistent @odometer element, just add another element to
> @odometer.  Ignore its value in the permutation, but bail out when it
> increments.  Program flow simplifies itself a lot.
> 
>     print "@$_\n" for perm(4, "red", "green", "blue");
>     sub perm {
>         my($groupings, @elems) = @_;
>         my @odometer = (0) x ($groupings+1);
>         my @perms;
>         until( $odometer[-1] ) {
>             push @perms, [ @elems[ @odometer[0..$groupings-1] ] ];
>             for( @odometer ) {
>                 $_++;
>                 last if $_ %= @elems;
>             }
>         }
>         return @perms;
>     }


This looks a bit simpler.  :-)

my $group = 4;
my @elements = qw/ red green blue /;

for ( 0 .. ( @elements ** $group ) - 1 ) {
    my @odometer;
    do { unshift @odometer, $_ % @elements } while $_ = int( $_ / @elements );
    @odometer = ( (0) x $group, @odometer )[ map -$_, reverse 1 .. $group ];
    print "@{[ map $elements[$_], @odometer ]}\n";
    }



John
-- 
use Perl;
program
fulfillment


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

Date: Sun, 06 Jul 2003 06:11:44 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: script for unrestricted permutation
Message-Id: <3F07BD9F.BAA5B427@acm.org>

"John W. Krahn" wrote:
> 
> This looks a bit simpler.  :-)
> 
> my $group = 4;
> my @elements = qw/ red green blue /;
> 
> for ( 0 .. ( @elements ** $group ) - 1 ) {
>     my @odometer;
>     do { unshift @odometer, $_ % @elements } while $_ = int( $_ / @elements );
>     @odometer = ( (0) x $group, @odometer )[ map -$_, reverse 1 .. $group ];
>     print "@{[ map $elements[$_], @odometer ]}\n";
>     }


Or a bit simpler.  :-)

my $group = 4;
my @elements = qw/ red green blue /;

for ( 0 .. ( @elements ** $group ) - 1 ) {
    my @odometer;
    do { unshift @odometer, $_ % @elements } while $_ = int( $_ / @elements );
    print "@{[ map $elements[$_], (0) x ($group - @odometer), @odometer ]}\n";
    }



John
-- 
use Perl;
program
fulfillment


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

Date: 5 Jul 2003 16:58:00 -0700
From: stuseven@hotmail.com (stu7)
Subject: Re: Uri & Tad replies to ARGV/pipe mystery function :)
Message-Id: <d7dd90b0.0307051558.15c60825@posting.google.com>

 ...after GolbinGiblet on dalnet #perl either lied, joked, 
 or was typing in the middle of a fantasy, to me, regarding 
 a supposed perl function... and, after I inquired to this 
 very newsgroup about the amazing new function...

Uri Guttman <uri@stemsystems.com> 

 ...agreed I had been lied to...
  ...felt I needed to go back to computer school...
   ...and, that purchasing a good Perl book would be useful to me.

   Uri - I guess, since this pipe/ARGV fh function or operation, 
 or whatever, doesn't even exist in Perl - at least not as it was 
 described to me - I could expect some exhasperation from anyone who
 knew it didn't... somehow, however, I feel you and Tad took my 
 question much too personally.

Tad McClellan <tadmc@augustmail.com>
 
  ...began by calling my question "incoherent", immediately letting 
 himself off the hook :)
   ...more than with my inquiry, seemed very concerned with points I 
 wasn't even aware had been raised - a sure sign something wasn't 
 right...
     ...finally, after arguing that InterProcess Communication would
 never allow what I was describing, offered to show me how to do
 whatever it might be I was trying to do, but not what I had asked
 about originally(?)... a very nice offer.

     To both Uri and Tad, thanks again for trying.  I do feel 
 obligated to say, after both of you pointed out the utter 
 impossibility of my strictly innocent inquiry, that in no way, 
 did I intend to upset either of you with this apparently 
 unanswerable question.  
     I hope both of you recover successfully. 

     A third poster did seem to understand what I was getting at...
 and answered as well as could be expected... I still felt a simple
 "no, it can't be done", or, "yes, this is how to do that", reply
 would have been sufficient.


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

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


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