[29554] in Perl-Users-Digest
Perl-Users Digest, Issue: 798 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 26 21:09:44 2007
Date: Sun, 26 Aug 2007 18:09: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 Sun, 26 Aug 2007 Volume: 11 Number: 798
Today's topics:
Re: best practice ... requires <ced@blv-sam-01.ca.boeing.com>
Re: best practice ... requires <hillmw@charter.net>
Re: best practice ... requires <noreply@gunnar.cc>
Re: great and better hash eval anno4000@radom.zrz.tu-berlin.de
Re: Help: How to change PATH variable by array? <paduille.4061.mumia.w+nospam@earthlink.net>
Re: Program Dies after 60 or so Iterations of Loop <hal@thresholddigital.com>
Re: Program Dies after 60 or so Iterations of Loop <hal@thresholddigital.com>
Re: Program Dies after 60 or so Iterations of Loop <hal@thresholddigital.com>
Re: Why can't I access an Array like this? <rkb@i.frys.com>
Re: Why can't I access an Array like this? <rkb@i.frys.com>
Re: Why can't I access an Array like this? <1usa@llenroc.ude.invalid>
Re: Why can't I access an Array like this? <hjp-usenet2@hjp.at>
Re: Why can't I access an Array like this? <bik.mido@tiscalinet.it>
Re: Why can't I access an Array like this? <bik.mido@tiscalinet.it>
Re: Why can't I access an Array like this? <bill@ts1000.us>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 26 Aug 2007 12:53:58 -0700
From: "comp.llang.perl.moderated" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: best practice ... requires
Message-Id: <1188158038.618541.184430@i13g2000prf.googlegroups.com>
On Aug 23, 6:39 pm, mike <hil...@charter.net> wrote:
> i'm having trouble with variables
>
> I have a main cgi script ... lets call it main.cgi
>
> In main.cgi i have some other perl scripts that have subroutines
>
> #!/usr/bin/perl -w
> #
> # name of this program is: main.cgi
> #
>
> use CGI;
> use Cwd; #used to get the current working directory
> $filebase = cwd;
>
> #requires here
> require "$filebase/some.lib";
> require "$filebase/a.pl";
> require "$filebase/b.pl";
> require "$filebase/c.pl";
>
> my $x = &do this;
>
> So the question is:
> 1) if i dont use a subroutine that is in some.lib here in main.cgi but
> in a.pl is it better to remove the require from main.cgi and put it in
> a.pl?
Yes, clearer IMO to put the require in a.pl since
the subroutine's used there and not in main.cgi.
> 2) can my require in main.cgi be global since the vars in some.lib are
> used in a.pl, b.pl, and c.pl?
>
Yes, as already noted, package variables defined
earlier in some.lib can be used later downstream if fully qualified.
This applies to subroutines as well.
The package qualifier can be omitted only if
the definitions are in package 'main'. But,
polluting main from files pulled in via require
isn't a good idea.
--
Charles DeRykus
------------------------------
Date: Sun, 26 Aug 2007 16:52:32 -0700
From: mike <hillmw@charter.net>
Subject: Re: best practice ... requires
Message-Id: <1188172352.917943.31780@r34g2000hsd.googlegroups.com>
Ok, so i decided to use packages.
my scripts would look something like:
#!/usr/bin/perl -w
#
# name of this program is: main.cgi
#
use CGI;
use pkg_a;
use pkg_b;
my $x = &pkg_a::do_this();
#!/usr/bin/perl -w
#
# name of this program is: pkg_a.pm
#
package pkg_a;
sub do_this()
{
&pkg_b::do_that();
}
so you can see that my package is nested and I am now wondering how
correctly to do this. You can see that I am calling a package from
inside a package. I dont know if that is legal or not.
I am getting this error message: Illegal character in prototype
I dont know if it because the packages are nested or if i have some
other problem.
Thanks
------------------------------
Date: Mon, 27 Aug 2007 02:59:38 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: best practice ... requires
Message-Id: <5jelvtF3tmvocU1@mid.individual.net>
mike wrote:
> Ok, so i decided to use packages.
>
> my scripts would look something like:
>
> #!/usr/bin/perl -w
> #
> # name of this program is: main.cgi
> #
> use CGI;
> use pkg_a;
> use pkg_b;
> my $x = &pkg_a::do_this();
>
> #!/usr/bin/perl -w
> #
> # name of this program is: pkg_a.pm
> #
> package pkg_a;
>
> sub do_this()
-------------^^
Skip those parentheses (i.e. don't bother with prototypes)
> {
> &pkg_b::do_that();
> }
>
> so you can see that my package is nested and I am now wondering how
> correctly to do this. You can see that I am calling a package from
> inside a package. I dont know if that is legal or not.
You have already been told that it works.
> I am getting this error message: Illegal character in prototype
See above.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 26 Aug 2007 18:45:14 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: great and better hash eval
Message-Id: <5je01qF3tv8j3U1@mid.dfncis.de>
john swilting <john.swilting@wanadoo.fr> wrote in comp.lang.perl.misc:
> anno4000@radom.zrz.tu-berlin.de wrote:
>
> > john swilting <john.swilting@wanadoo.fr> wrote in comp.lang.perl.misc:
> >> I do not understand .i start the deboguor ,is the file test.dat is well
> >> execute.in the file main.pl the loop while does not seem to function
> >> correctly. one only value is returned to me before keys. it appears
> >> infinite
> >>
> ##########################################################################
> >> #main.pl
> >>
> ##########################################################################
> >> #!/usr/bin/perl
> >>
> >> require "ouvre_fichier.pl";
> >> $f = "test.dat";
> >> %fh = ouvre_fichier($f);;
> >> while(( $clef,$valeur) = each %fh){
>
> #update code
> print "$clef => $valeur";
> # keys %fh;
> #assuming not infinite loop
> > What is the call to "keys %fh" for? It does nothing useful but messes
> > up the iteration.
> >
> >> }
> >
> > The call to "keys %fh" resets the iterator that controls the behavior
> > of "each". Instead of giving you the next key/value pair it gives you
> > the first one again. That leads to the endless loop you're observing.
> > Remove the line, then the loop will work as expected.
> >
> >> ########################################################################
> >> #ouvre_fichier.pl
> >> ########################################################################
> >> !/usr/bin/perl
> >> sub ouvre_fichier {
> >> open ($F, $_[0]) || die "impossible d ouvrir le fichier : $!";
> >> while($ligne =<$F>){
> >> $str.= $ligne;
> >> }
> >> eval $str;
> >> }
> >> $f = 'test.dat';
> >> while(1){
> >> eval {
> >> ouvre_fichier($f);#si ouvre fichier echoue, le programme ne se termine
> >> pas };##et à mon avis c la dernier veleur utliser
> >> last unless $@; #pas d erreur on sort de la boucle
> >> print "$f est absent. entrez un nouveau nom de fichier $f";
> >> chomp ($f = <STDIN>);
> >> }
> >>
> >> 1
> >> #######################################################################
> >> #test.dat
> >> #######################################################################
> >> $Conf{XferMethod} = 'rsync';
> >> $Conf{XferLogLevel} = '1';
> >> $Conf{RSyncShareName} = '___1___';
> >> $Conf{ClientNameAlias} = '___2___';
> >
> > From your usage the function ouvre_fichie() is supposed to set up
> > a hash. As far as I can see without running it, it returns the
> > single value "___2___", in an incredibly convoluted manner.
> >
> > Anno
> I do not understand .
Indeed.
> ok any more while infinite. now only a key is turned
> over, ___ 2___. at the time of eval of test.dat the last value used it is
> my hash I think?. ouvre_fichier should return the hach in entirety.
Then you must make it do that.
Your function ouvre_fichier() is way off the mark. It evaluates
a piece of Perl code read from test.dat. That code assigns some values
to a hash names %Conf (which is never used again). As a side effect,
it returns the last values assigned which happens to be "___2___".
The statement "%fh = ouvre_fichier($f)" makes this the only key of the
hash %h, with an undefined value.
To make the function ouvre_fichier() return the right kind of data,
change the format of test.dat to contain one blank-separated key/value
pair per line. Then use Perl's split function to retrieve the
key/value pairs and return them collectively. Putting the data
in the __DATA__ section of ouvre_fichier.pl, this is how it might
look (untested):
sub ouvre_fichier {
my @coll;
push @coll, split while <DATA>;
return @coll;
}
__DATA__
XferMethod rsync
XferLogLevel 1
RSyncShareName ___1___
ClientNameAlias ___2___
Anno
------------------------------
Date: Sun, 26 Aug 2007 12:53:26 -0500
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: Help: How to change PATH variable by array?
Message-Id: <13d47telt5vri15@corp.supernews.com>
On 08/26/2007 08:08 AM, Amy Lee wrote:
> Hi,
>
> I make a Perl script to add a path in PATH variable of the .bash_profile.
> Just like
>
> PATH=/usr/java/jdk1.5.0_09/bin:$HOME/perl:$HOME/shell:$PATH:$HOME/bin
>
> to be
>
> PATH=/usr/local/vice:/usr/java/jdk1.5.0_09/bin:$HOME/perl:$HOME/shell:$PATH:$HOME/bin
>
> There's my code:
> $ADD="/usr/local/vice"
> foreach $FILE (@ARGV)
> {
> open $IN, '<', $FILE;
> while (<$IN>)
> {
> if (/PATH=/)
> {
> chomp;
> s/PATH=/;
This does not compile. This is not your real program. We cannot debug an
imaginary program.
> my @PATH=s/:/ /;
Why are you using the s/// operator in place of the split() function?
> unshift @PATH, $ADD;
> print $_;
> }
> }
> close $IN;
> }
>
> But when I run this script, it still displays
>
> /usr/java/jdk1.5.0_09/bin $HOME/perl $HOME/shell $PATH $HOME/bin
>
> Could you tell me how to solve this problem?
>
> Thank very much~
>
> Regards,
>
> Amy Lee
Technically, this looks like it should be a one-liner, but here is a
three-liner.
use strict;
use warnings;
while (<>) {
s/(?<=^PATH=)/\/usr\/local\/miami\/vice:/;
}
__UNTESTED__
------------------------------
Date: Sun, 26 Aug 2007 20:11:02 -0400
From: Hal Vaughan <hal@thresholddigital.com>
Subject: Re: Program Dies after 60 or so Iterations of Loop
Message-Id: <ceudnYlMo90Ii0_bnZ2dnUVZ_t-gnZ2d@comcast.com>
Peter J. Holzer wrote:
> On 2007-08-26 01:07, Hal Vaughan <hal@thresholddigital.com> wrote:
>> I found the old time radio shows a the Interet Archives, so I wrote a
>> program to scan the shows, then the episodes and let me list the ones I
>> wanted to download. The program then goes through the list of files and
>> downloads each file (most are MP3, some are Ogg). Files are at least a
>> few
>> megabytes in length. The problem is that after about 60 or so downloads
>> (it varies), my computer (running Linux, Ubuntu Fiesty Fawn) slows down
>> for about 30 minutes (not an exaggeration), then the program stops with
>> a "Killed!" statement.
>
> That sounds like you are exhausting virtual memory. When the total
> memory used by all processes approaches the sum of RAM and swap space,
> the system spends more and more time to finding yet another piece of
> memory it doesn't need immediately and could reuse. If you are unlucky,
> the system becomes completely unresponsive. However, most of the time
> the system just gives up at some point and kills a process (hopefully
> the one which caused this sorry state).
>
> Run "top" in a second window to confirm this.
I figured it was a virtual memory and swap issue as well, but I figured I'm
best just saying the symptoms instead of assuming because I find that there
is often an aspect I don't know about.
I had problems with running top. There was a slight slow down, then
suddenly a big one and it took forever to change to the Konsole window, so
I switched to my server, which always has an ssh connection open to my
workstation for cases like this and tried running top. By the the time it
came up in Konsole or ssh, the Perl program was already terminated and not
showing and the system was cleaning up.
>> #Download the file with WWW::Mechanize
>> #Isn't $data reinitialized each loop? Could old copies not be cleared
>> #by garbage collector?
>> $data = getpage($url);
>
> $data is reinitialized, but WWW::Mechanize may cache downloaded
> documents. I vaguely remember that this has been discussed here before
> and that there is a way to turn this off even though perldoc
> WWW::Mechanize doesn't seem to mention it. Google should find it.
I found it by Googling for "Perl mechanize memory." I tried several
different phrases, but they didn't help until I tried that one. Here's the
trick. I was creating Mech like this:
------------------------------
Date: Sun, 26 Aug 2007 20:14:53 -0400
From: Hal Vaughan <hal@thresholddigital.com>
Subject: Re: Program Dies after 60 or so Iterations of Loop
Message-Id: <ceudnYhMo93mik_bnZ2dnUVZ_t_inZ2d@comcast.com>
I hit the wrong key and sent by mistake. Response continued below:
Hal Vaughan wrote:
> Peter J. Holzer wrote:
>
>> On 2007-08-26 01:07, Hal Vaughan <hal@thresholddigital.com> wrote:
>>> I found the old time radio shows a the Interet Archives, so I wrote a
>>> program to scan the shows, then the episodes and let me list the ones I
>>> wanted to download. The program then goes through the list of files and
>>> downloads each file (most are MP3, some are Ogg). Files are at least a
>>> few
>>> megabytes in length. The problem is that after about 60 or so downloads
>>> (it varies), my computer (running Linux, Ubuntu Fiesty Fawn) slows down
>>> for about 30 minutes (not an exaggeration), then the program stops with
>>> a "Killed!" statement.
>>
>> That sounds like you are exhausting virtual memory. When the total
>> memory used by all processes approaches the sum of RAM and swap space,
>> the system spends more and more time to finding yet another piece of
>> memory it doesn't need immediately and could reuse. If you are unlucky,
>> the system becomes completely unresponsive. However, most of the time
>> the system just gives up at some point and kills a process (hopefully
>> the one which caused this sorry state).
>>
>> Run "top" in a second window to confirm this.
>
> I figured it was a virtual memory and swap issue as well, but I figured
> I'm best just saying the symptoms instead of assuming because I find that
> there is often an aspect I don't know about.
>
> I had problems with running top. There was a slight slow down, then
> suddenly a big one and it took forever to change to the Konsole window, so
> I switched to my server, which always has an ssh connection open to my
> workstation for cases like this and tried running top. By the the time it
> came up in Konsole or ssh, the Perl program was already terminated and not
> showing and the system was cleaning up.
>
>>> #Download the file with WWW::Mechanize
>>> #Isn't $data reinitialized each loop? Could old copies not be cleared
>>> #by garbage collector?
>>> $data = getpage($url);
>>
>> $data is reinitialized, but WWW::Mechanize may cache downloaded
>> documents. I vaguely remember that this has been discussed here before
>> and that there is a way to turn this off even though perldoc
>> WWW::Mechanize doesn't seem to mention it. Google should find it.
>
> I found it by Googling for "Perl mechanize memory." I tried several
> different phrases, but they didn't help until I tried that one. Here's
> the
> trick. I was creating Mech like this:
$mech = WWW::Mechanize->new;
By default, Mech caches all the pages (or binary files) it downloads in
memory. I changed it to this:
$mech = WWW::Mechanize->new(stack_depth => 3);
If the stack_depth is set to 0, it'll cache all pages (the default). I
experimented and got VERY slow downloads with a stack_depth of 1 (it
doesn't make sense why, but I don't know what else that effects), so I
experimented. Maybe it was just chance that when I changed it from 1 to 3
it worked, but I'm going to leave it there until it finishes it's current
batch of files before testing it to be sure the speed is the same with a
value of 1.
Thanks! I had never imagined it was an issue with the module. I still tend
to think I've missed something. I'm self-taught and I eem to constantly
find new holes in what I've learned as I keep going.
Hal
------------------------------
Date: Sun, 26 Aug 2007 20:15:28 -0400
From: Hal Vaughan <hal@thresholddigital.com>
Subject: Re: Program Dies after 60 or so Iterations of Loop
Message-Id: <ceudnYtMo90Dik_bnZ2dnUVZ_t_inZ2d@comcast.com>
Sisyphus wrote:
>
> "Hal Vaughan" <hal@thresholddigital.com> wrote in message
> news:i-KdnWQuLpP_T03bnZ2dneKdnZydnZ2d@comcast.com...
> .
> .
>> .... then the program stops with
>> a "Killed!" statement.
>
> That's not something that would be coming from perl (afaik).
> Sounds more like something that the OS is doing.
>
> Does your ISP impose any limits that may be coming into play ?
It's the Mech module. Se the other branch of the thread.
Thanks for the help!
Hal
------------------------------
Date: Sun, 26 Aug 2007 12:12:55 -0700
From: Ron Bergin <rkb@i.frys.com>
Subject: Re: Why can't I access an Array like this?
Message-Id: <1188155575.905119.104730@i13g2000prf.googlegroups.com>
On Aug 26, 10:51 am, Michele Dondi <bik.m...@tiscalinet.it> wrote:
> On Sun, 26 Aug 2007 09:34:28 -0700, Ron Bergin <r...@i.frys.com> wrote:
> >Since you're working with a hash, why not simply iterate over it with
> >"each"?
>
> >foreach my $key ( sort keys %in ) {
> > print "$key = $in{$key}\n";
> >}
>
> Just a minor nitpick: you're *not* "iterating over it with C<each>",
> but iterating overt its *keys* with C<foreach>.
>
> Michele
> --
> {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
> (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
> .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
> 256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
Ya, I changed my thought pattern while I was writing. I guess I
should proof read before hitting the send key.
------------------------------
Date: Sun, 26 Aug 2007 12:28:59 -0700
From: Ron Bergin <rkb@i.frys.com>
Subject: Re: Why can't I access an Array like this?
Message-Id: <1188156539.209232.128310@z24g2000prh.googlegroups.com>
On Aug 26, 9:45 am, Bill H <b...@ts1000.us> wrote:
> > > Here is a simple working example of what I am trying to do:
>
> > > $in{'TEST0001'} = "Hello 0001";
> > > $in{'TEST0002'} = "Hello 0002";
> > > $in{'TEST0003'} = "Hello 0003";
> > > $in{'TEST0004'} = "Hello 0004";
>
> > > for($i = 1;$i < 5;$i++)
> > > {
> > > $a = substr("0000".$i,-4);
> > > print "TEST$a = $in{'TEST$a'}\n";
> > > }
>
> > --
> > --------------------http://NewsReader.Com/--------------------
> > Usenet Newsgroup Service $9.95/Month 30GB- Hide quoted text -
>
> > - Show quoted text -
>
> Xho,
>
> I knew there was some way of doing it Thanks for pointing out using
> the qq construct!
>
> Ron,
>
> I use the keys hash alot, but for this usage I needed to do it
> differently. Basically what the processor is doing is reading in form
> values and all I know about the form values is that there are 10
> fields that start with different words and end in ???? where ???? is
> 0001 - 9999. I also know how many groups of these values there are so
> I have to do a for loop to read in the values for each group based on
> the starting word and a counter, checking that some of the groups
> aren't empty etc.
>
> Bill H
The substr approach isn't going to work as expected when you have
varying amounts of leading zeros. I can't say for sure without seeing
your actual data, but you'd either want to use the sprintf approach
like I've shown, or use a regex to capture the digits.
Something like this:
foreach my $key ( sort keys %in ) {
if ( $key =~ /\D(\d{4})$/ ) {
print "$key = $in{$key}\n";
}
}
------------------------------
Date: Sun, 26 Aug 2007 20:04:33 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Why can't I access an Array like this?
Message-Id: <Xns9998A3822D80Dasu1cornelledu@127.0.0.1>
Michele Dondi <bik.mido@tiscalinet.it> wrote in
news:t3f3d3145p67gs2a0r35ec3ap1pj1ud3m7@4ax.com:
> On Sun, 26 Aug 2007 08:39:07 -0700, Bill H <bill@ts1000.us> wrote:
>
>>$in{'TEST0001'} = "Hello 0001";
>>$in{'TEST0002'} = "Hello 0002";
>>$in{'TEST0003'} = "Hello 0003";
>>$in{'TEST0004'} = "Hello 0004";
>>
>>
>>for($i = 1;$i < 5;$i++)
>>{
>> $a = substr("0000".$i,-4);
>
> Why this substr() madness? What's wrong with sprintf()?
Maybe he wants to be able to make it to the front page of the Daily WTF.
(I know, it is "Worse than Failure" now, but I prefer the former name).
>> print "TEST$a = $in{'TEST$a'}\n";
>>}
>>
>>for($i = 1;$i < 5;$i++)
>>{
>> $a = substr("0000".$i,-4);
>> $b = "TEST$a";
>> print "$b = $in{$b}\n";
>>}
>
> How 'bout
>
> $in{"$TEST$_"} = "$Hello $_" for '0001'..'0004'; # ?
There is a philosophical issue here. Assuming he is implementing a
sparse data structure using hashes (and that's why he is not using
arrays despite the fact that his keys are integers), a simple name
change would make all the interpolation completely and utterly
unnecessary as well as making *ALL* of his code much more readable:
my %test;
$test{ $_ } = "Hello $_" for '0001' .. '0004';
print "$test{0003}\n";
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>
------------------------------
Date: Sun, 26 Aug 2007 23:12:48 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Why can't I access an Array like this?
Message-Id: <slrnfd3r6g.ahd.hjp-usenet2@zeno.hjp.at>
On 2007-08-26 15:39, Bill H <bill@ts1000.us> wrote:
> for($i = 1;$i < 5;$i++)
> {
> $a = substr("0000".$i,-4);
> print "TEST$a = $in{'TEST$a'}\n";
> }
>
> for($i = 1;$i < 5;$i++)
> {
> $a = substr("0000".$i,-4);
> $b = "TEST$a";
> print "$b = $in{$b}\n";
> }
>
>
> The 1st for loop doesnt work as expected, but the second does.
[...]
> I am not sure why I need to go to the extra step of assigning a
> variable (in this case $b) to access the data.
You don't. There is another difference between your two loops. Look more
closely.
hp
--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | hjp@hjp.at |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
------------------------------
Date: Mon, 27 Aug 2007 00:07:45 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Why can't I access an Array like this?
Message-Id: <2bu3d356bvr42h583vbks18r8b8l9adcj5@4ax.com>
On Sun, 26 Aug 2007 12:12:55 -0700, Ron Bergin <rkb@i.frys.com> wrote:
>On Aug 26, 10:51 am, Michele Dondi <bik.m...@tiscalinet.it> wrote:
[sniè]
>> Just a minor nitpick: you're *not* "iterating over it with C<each>",
>> but iterating overt its *keys* with C<foreach>.
^
^
>Ya, I changed my thought pattern while I was writing. I guess I
>should proof read before hitting the send key.
/me too. Except that I do. But I still fail! ;-)
(For what can I smile on a day like this...</sidenote>)
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Mon, 27 Aug 2007 00:09:09 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Why can't I access an Array like this?
Message-Id: <teu3d3tvgnco2a7n27apembkjkgicvbip6@4ax.com>
On Sun, 26 Aug 2007 20:04:33 GMT, "A. Sinan Unur"
<1usa@llenroc.ude.invalid> wrote:
>Maybe he wants to be able to make it to the front page of the Daily WTF.
>
>(I know, it is "Worse than Failure" now, but I prefer the former name).
I didn't know it had changed.
>There is a philosophical issue here. Assuming he is implementing a
>sparse data structure using hashes (and that's why he is not using
>arrays despite the fact that his keys are integers), a simple name
>change would make all the interpolation completely and utterly
>unnecessary as well as making *ALL* of his code much more readable:
>
>my %test;
>$test{ $_ } = "Hello $_" for '0001' .. '0004';
>
>print "$test{0003}\n";
Indeed!
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Sun, 26 Aug 2007 17:43:03 -0700
From: Bill H <bill@ts1000.us>
Subject: Re: Why can't I access an Array like this?
Message-Id: <1188175383.166812.89070@19g2000hsx.googlegroups.com>
On Aug 26, 4:04 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
> Michele Dondi <bik.m...@tiscalinet.it> wrote innews:t3f3d3145p67gs2a0r35ec3ap1pj1ud3m7@4ax.com:
>
> > On Sun, 26 Aug 2007 08:39:07 -0700, Bill H <b...@ts1000.us> wrote:
>
> >>$in{'TEST0001'} = "Hello 0001";
> >>$in{'TEST0002'} = "Hello 0002";
> >>$in{'TEST0003'} = "Hello 0003";
> >>$in{'TEST0004'} = "Hello 0004";
>
> >>for($i = 1;$i < 5;$i++)
> >>{
> >> $a = substr("0000".$i,-4);
>
> > Why this substr() madness? What's wrong with sprintf()?
>
> Maybe he wants to be able to make it to the front page of the Daily WTF.
>
> (I know, it is "Worse than Failure" now, but I prefer the former name).
>
> >> print "TEST$a = $in{'TEST$a'}\n";
> >>}
>
> >>for($i = 1;$i < 5;$i++)
> >>{
> >> $a = substr("0000".$i,-4);
> >> $b = "TEST$a";
> >> print "$b = $in{$b}\n";
> >>}
>
> > How 'bout
>
> > $in{"$TEST$_"} = "$Hello $_" for '0001'..'0004'; # ?
>
> There is a philosophical issue here. Assuming he is implementing a
> sparse data structure using hashes (and that's why he is not using
> arrays despite the fact that his keys are integers), a simple name
> change would make all the interpolation completely and utterly
> unnecessary as well as making *ALL* of his code much more readable:
>
> my %test;
> $test{ $_ } = "Hello $_" for '0001' .. '0004';
>
> print "$test{0003}\n";
>
> Sinan
>
> --
> A. Sinan Unur <1...@llenroc.ude.invalid>
> (remove .invalid and reverse each component for email address)
> clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>
Sinan
It never occured to me to use sprintf, substr has always worked for
me, but now that you mention it I may just start using it.
As for the reason I wanted to use it the way I posted is that I have a
web form that starts out with
fields:
SNAME0001, SPASS0001, FRONT0001, BACK0001, TITLE0001, COPY0001,
TOC0001, FOR0001, ACK0001, CHAP0001 and the person using the form can
add / remove groups of fields (these 10 fields all ending with the
same numbers). I add and remove the fields dynamically in the perl
script to the web page, so I only know the starting letters of the
field (ie SNAME, SPASS, FRONT etc) and how many groups are on the
page. So I have to work my way through the groups of fields using a
for loop (hence the need for the 0001 - ????) to build the page.
Bill H
------------------------------
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 V11 Issue 798
**************************************