[31348] in Perl-Users-Digest
Perl-Users Digest, Issue: 2600 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 17 18:09:54 2009
Date: Thu, 17 Sep 2009 15:09:14 -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, 17 Sep 2009 Volume: 11 Number: 2600
Today's topics:
Re: appending to a file. <rodbass63@gmail.com>
FAQ 4.76 How do I verify a credit card checksum? <brian@theperlreview.com>
FAQ 5.15 How come when I open a file read-write it wipe <brian@theperlreview.com>
FAQ 5.6 How do I make a temporary file name? <brian@theperlreview.com>
Re: How to add Arrays of Arrays to a hash? <WaterLin@ymail.invalid>
Re: How to add Arrays of Arrays to a hash? sln@netherlands.com
Re: How to find the smallest int to a number? <hjp-usenet2@hjp.at>
Re: How to find the smallest int to a number? sln@netherlands.com
Re: How to find the smallest int to a number? <NoSpamPleaseButThisIsValid3@gmx.net>
Re: LV Watch wholesale (paypal payment) (www.brandtrade <antivigilante@pyrabang.com>
matching array element to hash key <cartercc@gmail.com>
Re: matching array element to hash key <tadmc@seesig.invalid>
need to declare/import package variable? <hhr-m@web.de>
Re: need to declare/import package variable? <tadmc@seesig.invalid>
Re: need to declare/import package variable? <hhr-m@web.de>
Re: need to declare/import package variable? <uri@StemSystems.com>
Re: need to declare/import package variable? <tadmc@seesig.invalid>
Re: Underwear supplier (paypal payment)( www.brandtr <antivigilante@pyrabang.com>
Using Perl's Bits 'n Pieces ;-) <RF@NoDen.con>
Re: Using Perl's Bits 'n Pieces ;-) <jimsgibson@gmail.com>
Re: Using Perl's Bits 'n Pieces ;-) <RF@NoDen.con>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 17 Sep 2009 10:39:33 -0700 (PDT)
From: Nene <rodbass63@gmail.com>
Subject: Re: appending to a file.
Message-Id: <eda961e0-f062-4421-ac5d-7e8e748c4f57@d23g2000vbm.googlegroups.com>
On Aug 31, 4:13=A0pm, mer...@stonehenge.com (Randal L. Schwartz) wrote:
> >>>>> "Nene" =3D=3D Nene =A0<rodbas...@gmail.com> writes:
>
> Nene> Greetings, I want to open an apache file and append a line at the b=
ottom
> Nene> of all theListenentries, not the bottom of the file. For example, I
> Nene> want to append once it finds the lastListenentry in the file. For
> Nene> example, the lastListenentry is 'Listen8150', I want to append
> Nene> 'Listen8151' underneathListen8150. From what I read, I might have t=
o
> Nene> use a module, but I'm trying not install modules. Is it possible?
>
> Nene>Listen80Listen5555Listen443Listen7170Listen8002Listen8005
> Nene>Listen8008Listen8009Listen8010Listen8011Listen8013Listen8022
> Nene>Listen8023Listen8024Listen8045Listen8050Listen8051Listen8102
> Nene>Listen8108Listen8155Listen8110Listen8210Listen8211Listen8263
> Nene>Listen8122Listen8145Listen8346Listen8347Listen8147Listen8148
> Nene>Listen8146Listen8150
>
> Use "in-place-edit" mode:
>
> =A0 =A0 my $line_to_insert =3D "Listen8151\n";
>
> =A0 =A0 {
> =A0 =A0 =A0 local @ARGV =3D "/path/to/your/httpd.conf";
> =A0 =A0 =A0 local $^I =3D ".bak"; # appended to the backup copy
>
> =A0 =A0 =A0 while (<>) {
>
> =A0 =A0 =A0 =A0 if ((/^Listen/..!/^Listen/) =3D~ /e/) { # if we're at the=
end of the Listens
> =A0 =A0 =A0 =A0 =A0 $_ =3D $line_to_insert . $_; # prepend the line to th=
e next line
> =A0 =A0 =A0 =A0 }
> =A0 =A0 =A0 =A0 print; # but print whatever we have
> =A0 =A0 =A0 }
>
> =A0 =A0 }
>
> print "Just another Perl hacker,"; # the original
>
> --
> Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 00=
95
> <mer...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
> Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
> Seehttp://methodsandmessages.vox.com/for Smalltalk and Seaside discussion
Mr. Schwartz, this works great, thank you very much.
------------------------------
Date: Thu, 17 Sep 2009 10:00:02 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 4.76 How do I verify a credit card checksum?
Message-Id: <CMnsm.71474$Y83.38463@newsfe21.iad>
This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
4.76: How do I verify a credit card checksum?
Get the "Business::CreditCard" module from CPAN.
--------------------------------------------------------------------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
------------------------------
Date: Thu, 17 Sep 2009 16:00:07 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 5.15 How come when I open a file read-write it wipes it out?
Message-Id: <b2tsm.37137$u76.16025@newsfe10.iad>
This is an excerpt from the latest version perlfaq5.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
5.15: How come when I open a file read-write it wipes it out?
Because you're using something like this, which truncates the file and
*then* gives you read-write access:
open(FH, "+> /path/name"); # WRONG (almost always)
Whoops. You should instead use this, which will fail if the file doesn't
exist.
open(FH, "+< /path/name"); # open for update
Using ">" always clobbers or creates. Using "<" never does either. The
"+" doesn't change this.
Here are examples of many kinds of file opens. Those using sysopen() all
assume
use Fcntl;
To open file for reading:
open(FH, "< $path") || die $!;
sysopen(FH, $path, O_RDONLY) || die $!;
To open file for writing, create new file if needed or else truncate old
file:
open(FH, "> $path") || die $!;
sysopen(FH, $path, O_WRONLY|O_TRUNC|O_CREAT) || die $!;
sysopen(FH, $path, O_WRONLY|O_TRUNC|O_CREAT, 0666) || die $!;
To open file for writing, create new file, file must not exist:
sysopen(FH, $path, O_WRONLY|O_EXCL|O_CREAT) || die $!;
sysopen(FH, $path, O_WRONLY|O_EXCL|O_CREAT, 0666) || die $!;
To open file for appending, create if necessary:
open(FH, ">> $path") || die $!;
sysopen(FH, $path, O_WRONLY|O_APPEND|O_CREAT) || die $!;
sysopen(FH, $path, O_WRONLY|O_APPEND|O_CREAT, 0666) || die $!;
To open file for appending, file must exist:
sysopen(FH, $path, O_WRONLY|O_APPEND) || die $!;
To open file for update, file must exist:
open(FH, "+< $path") || die $!;
sysopen(FH, $path, O_RDWR) || die $!;
To open file for update, create file if necessary:
sysopen(FH, $path, O_RDWR|O_CREAT) || die $!;
sysopen(FH, $path, O_RDWR|O_CREAT, 0666) || die $!;
To open file for update, file must not exist:
sysopen(FH, $path, O_RDWR|O_EXCL|O_CREAT) || die $!;
sysopen(FH, $path, O_RDWR|O_EXCL|O_CREAT, 0666) || die $!;
To open a file without blocking, creating if necessary:
sysopen(FH, "/foo/somefile", O_WRONLY|O_NDELAY|O_CREAT)
or die "can't open /foo/somefile: $!":
Be warned that neither creation nor deletion of files is guaranteed to
be an atomic operation over NFS. That is, two processes might both
successfully create or unlink the same file! Therefore O_EXCL isn't as
exclusive as you might wish.
See also the new perlopentut if you have it (new for 5.6).
--------------------------------------------------------------------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
------------------------------
Date: Thu, 17 Sep 2009 21:59:56 GMT
From: PerlFAQ Server <brian@theperlreview.com>
Subject: FAQ 5.6 How do I make a temporary file name?
Message-Id: <wjysm.180407$O23.171743@newsfe11.iad>
This is an excerpt from the latest version perlfaq5.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .
--------------------------------------------------------------------
5.6: How do I make a temporary file name?
If you don't need to know the name of the file, you can use "open()"
with "undef" in place of the file name. In Perl 5.8 or later, the
"open()" function creates an anonymous temporary file:
open my $tmp, '+>', undef or die $!;
Otherwise, you can use the File::Temp module.
use File::Temp qw/ tempfile tempdir /;
$dir = tempdir( CLEANUP => 1 );
($fh, $filename) = tempfile( DIR => $dir );
# or if you don't need to know the filename
$fh = tempfile( DIR => $dir );
The File::Temp has been a standard module since Perl 5.6.1. If you don't
have a modern enough Perl installed, use the "new_tmpfile" class method
from the IO::File module to get a filehandle opened for reading and
writing. Use it if you don't need to know the file's name:
use IO::File;
$fh = IO::File->new_tmpfile()
or die "Unable to make new temporary file: $!";
If you're committed to creating a temporary file by hand, use the
process ID and/or the current time-value. If you need to have many
temporary files in one process, use a counter:
BEGIN {
use Fcntl;
my $temp_dir = -d '/tmp' ? '/tmp' : $ENV{TMPDIR} || $ENV{TEMP};
my $base_name = sprintf "%s/%d-%d-0000", $temp_dir, $$, time;
sub temp_file {
local *FH;
my $count = 0;
until( defined(fileno(FH)) || $count++ > 100 ) {
$base_name =~ s/-(\d+)$/"-" . (1 + $1)/e;
# O_EXCL is required for security reasons.
sysopen FH, $base_name, O_WRONLY|O_EXCL|O_CREAT;
}
if( defined fileno(FH) ) {
return (*FH, $base_name);
}
else {
return ();
}
}
}
--------------------------------------------------------------------
The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
If you'd like to help maintain the perlfaq, see the details in
perlfaq.pod.
------------------------------
Date: Thu, 17 Sep 2009 12:50:21 +0800
From: Water Lin <WaterLin@ymail.invalid>
Subject: Re: How to add Arrays of Arrays to a hash?
Message-Id: <83k4zyjhte.fsf@ymail.invalid>
Tad J McClellan <tadmc@seesig.invalid> writes:
> Water Lin <WaterLin@ymail.invalid> wrote:
>>
>> I have some arrays of arrays, which is called multidimensional array in
>> other languages. I want to use a hash to index them quickly according to
>> user's command.
>>
>> I am trying to print the first element in each array like this:
>> -------------------
>> my @AoA = (
>> [ "fred", "barney" ],
>> [ "george", "jane", "elroy" ],
>> [ "homer", "marge", "bart" ],
>> );
>>
>> my %index = ("first", @AoA);
>
>
>
> see what you've built for yourself:
>
> use Data::Dumper;
> ...
> print Dumper \%index;
>
>
>> What's the right way to do this?
>
>
> -------------------
> #!/usr/bin/perl
> use warnings;
> use strict;
>
>
> my @AoA = (
> [ "fred", "barney" ],
> [ "george", "jane", "elroy" ],
> [ "homer", "marge", "bart" ],
> );
>
> my %index = ("first", [map {$_->[0]} @AoA] ); # "Make Rule 2" from perlreftut
>
> my @result = @{ $index{"first"} }; "Use Rule 1"from perlreftut
>
> foreach my $current ( @result ) {
> print $current, "\n";
> }
> -------------------
>
>
>> I am not familiar with perl, sorry for that
>
>
> If you hope to use multidimensional arrays in Perl (not perl), then
> you will need to become familiar with Perl (not perl):
>
> perldoc perlreftut
>
> perldoc perldsc
Thanks for you answer, I will pay my time to learn Perl.
--
Water Lin's blog: http://blog.waterlin.org
Email: WaterLin@ymail.com
------------------------------
Date: Thu, 17 Sep 2009 05:15:09 -0700
From: sln@netherlands.com
Subject: Re: How to add Arrays of Arrays to a hash?
Message-Id: <s884b5969p20l77b00v24m2l2o74n9cqdd@4ax.com>
On Thu, 17 Sep 2009 10:31:09 +0800, Water Lin <WaterLin@ymail.invalid> wrote:
>
>I have some arrays of arrays, which is called multidimensional array in
>other languages. I want to use a hash to index them quickly according to
>user's command.
>
>I am trying to print the first element in each array like this:
>-------------------
>my @AoA = (
> [ "fred", "barney" ],
> [ "george", "jane", "elroy" ],
> [ "homer", "marge", "bart" ],
> );
>
>my %index = ("first", @AoA);
>
>my @result = $index{"first"};
>
>foreach my $current ( @result ) {
> print $current->[0];
>}
>-------------------
>
>But the result is just "fred" which means that I can just get the first
>array in my @AoA by using
>--------
>my @result = $index{"first"};
>--------
>
>What's the right way to do this? How can I index many arrays of arrays
>by hash? I am not familiar with perl, sorry for that
Ok, your not familiar with Perl and you want to index many arrays
using a hash. It is not very clear what you mean.
Below is my translation of what I think you said.
-sln
my @AoA = (
[ "fred", "barney", "" ],
[ "george", "jane", "elroy" ],
[ "homer", "marge", "bart" ],
);
my %index = (
'first' => 0,
'second' => 1,
'third' => 2
);
my $user_command = 'first';
for my $current (@AoA) {
print $current->[ $index{$user_command} ] , "\n";
}
# or
for (0 .. $#AoA) {
print $AoA[$_][ $index{$user_command} ] , "\n";
}
------------------------------
Date: Thu, 17 Sep 2009 21:30:12 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: How to find the smallest int to a number?
Message-Id: <slrnhb53i4.1n4.hjp-usenet2@hrunkner.hjp.at>
On 2009-09-16 07:26, Peter Makholm <peter@makholm.net> wrote:
> Water Lin <WaterLin@ymail.invalid> writes:
>
>> I want to find a int which is bigger than $test, but it is also the
>> smallest int to $test. The result should be 5 if $test = 4.34. The
>> result should also be -5 if $test = -5.4.
>
> You're looking for the ceil() function. It is available from the POSIX
> module.
>
> use POSIX qw(ceil);
Not quite. The ceil function returns the smallest integer greater or
equal than the argument. But Water wants the smallest integer greater
than the argument. The floor function can be used to compute that:
#!/usr/bin/perl
use warnings;
use strict;
use POSIX qw(ceil floor);
for (-5.4, -3, 4.34, 5) {
printf("%5.2f %5.2f %5.2f\n", $_, ceil($_), floor($_)+1);
}
__END__
-5.40 -5.00 -5.00
-3.00 -3.00 -2.00
4.34 5.00 5.00
5.00 5.00 6.00
hp
------------------------------
Date: Thu, 17 Sep 2009 13:23:58 -0700
From: sln@netherlands.com
Subject: Re: How to find the smallest int to a number?
Message-Id: <ga65b5l2pmaca1ira3qm7vgve4t31ojl18@4ax.com>
On Thu, 17 Sep 2009 21:30:12 +0200, "Peter J. Holzer" <hjp-usenet2@hjp.at> wrote:
>On 2009-09-16 07:26, Peter Makholm <peter@makholm.net> wrote:
>> Water Lin <WaterLin@ymail.invalid> writes:
>>
>>> I want to find a int which is bigger than $test, but it is also the
>>> smallest int to $test. The result should be 5 if $test = 4.34. The
>>> result should also be -5 if $test = -5.4.
>>
>> You're looking for the ceil() function. It is available from the POSIX
>> module.
>>
>> use POSIX qw(ceil);
>
>Not quite. The ceil function returns the smallest integer greater or
>equal than the argument. But Water wants the smallest integer greater
>than the argument. The floor function can be used to compute that:
>
No, ceil returns the largest integer greater or equal to the fraction.
He mistated, but ceil is what he needs, based on his expected result:
"The result should be 5 if $test = 4.34. The
result should also be -5 if $test = -5.4."
On the number line -5 is greater than -5.5 and 5 is greater than
4.34
if (-5 > -5.4) { print "-5 is greater than -5.4\n" }
-sln
------------------------------
Date: Thu, 17 Sep 2009 23:40:44 +0200
From: Wolf Behrenhoff <NoSpamPleaseButThisIsValid3@gmx.net>
Subject: Re: How to find the smallest int to a number?
Message-Id: <4ab2acde$0$30228$9b4e6d93@newsspool1.arcor-online.net>
sln@netherlands.com schrieb:
>> Not quite. The ceil function returns the smallest integer greater or
>> equal than the argument. But Water wants the smallest integer greater
>> than the argument. The floor function can be used to compute that:
>>
>
> No, ceil returns the largest integer greater or equal to the fraction.
Nonsense. What is - in your opinion - the largest integer?!
The answer is: there is no "largest integer"! Assume n is the largest
integer. Then n+1 is larger. So we have a very simple proof by
contradiction.
ceil returns the SMALLEST integer greater or equal than the argument,
just as Peter Holzer wrote.
Wolf
------------------------------
Date: Thu, 17 Sep 2009 13:39:19 -0700
From: Anti VIgilante <antivigilante@pyrabang.com>
Subject: Re: LV Watch wholesale (paypal payment) (www.brandtrade08.cn )
Message-Id: <4ab29e77$0$89864$815e3792@news.qwest.net>
12345678 wrote:
>
>
>
> Watch
>
> Ebel Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Bape Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Bell&Ross Watch wholesale (paypal payment) (www.brandtrade08.cn )
>
> Breit Ling Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Burberry Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Cartier Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Chopard Watch wholesale (paypal payment) (www.brandtrade08.cn )
> D&G Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Givenchy Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Jacob&Co Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Kappa Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Prada Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Tissot Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Titoni Watch wholesale (paypal payment) (www.brandtrade08.cn )
> U-BOAT Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Zenith Watch wholesale (paypal payment) (www.brandtrade08.cn )
> A.Lange&Sohne Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Audemars Piguet Watch wholesale (paypal payment)
> (www.brandtrade08.cn )
> Baume&Mercier Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Blancpain Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Breguet Watch wholesale (paypal payment) (www.brandtrade08.cn )
> BRM Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Bvlgari Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Chanel Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Concord Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Corum Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Dewitt Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Ferrari Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Franck Muller Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Girard Perregaux Watch
> Glashutte Watch
> Graham Watch wholesale (paypal payment) (www.brandtrade08.cn )
> GUCCI Watch wholesale (paypal payment) (www.brandtrade08.cn )
> GUESS Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Hamilton Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Hermes Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Hublot Watch wholesale (paypal payment) (www.brandtrade08.cn )
> IWC Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Jaeger Le Coultre Watch wholesale (paypal payment)
> (www.brandtrade08.cn )
> Longines Watch wholesale (paypal payment) (www.brandtrade08.cn )
> LV Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Montblanc Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Movado Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Omega Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Oris Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Paket Philippe Watch wholesale (paypal payment)
> (www.brandtrade08.cn )
> Panerai Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Parmigiani Fleurier Watch wholesale (paypal payment)
> (www.brandtrade08.cn )
> Piaget Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Porsche Design Watch wholesale (paypal payment)
> (www.brandtrade08.cn )
> Rolex Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Romain Jerome Titanic-Dna Watch wholesale (paypal payment)
> (www.brandtrade08.cn )
> Tag Heuer Watch wholesale (paypal payment) (www.brandtrade08.cn )
>
> Tudor Watch wholesale (paypal payment) (www.brandtrade08.cn )
> Vach.Constantine Watch wholesale (paypal payment)
> (www.brandtrade08.cn )
>
> Armani Watch wholesale (paypal payment) (www.brandtrade08.cn )
>
> RADO Watch wholesale (paypal payment) (www.brandtrade08.cn )
>
Can you type this in a lisp environment and tell me the results?
(defun see-spot-run (x)
(let (x (+ 1 x))
(print x)
(see-spot-run x)))
(see-spot-run x)
------------------------------
Date: Thu, 17 Sep 2009 13:23:43 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: matching array element to hash key
Message-Id: <de0d8991-e7bc-4f95-9827-4cce8f007979@m20g2000vbp.googlegroups.com>
This is probably a real stupid question, but it's late and I'm running
behind, and quite frankly have run out of mental energy.
I have an array with about 5,000 elements that looks like this:
0002793 0005095 0093350 0134143 0145740 0146854 0150248 0151827
0156424 0161321 0186959 0198460 0218115
I have a four level hash that looks like this:
$hash{$s}{$l}{$h}{$id} = $terms
This has contains about 8,000 discrete elements.
The $id key in the hash either matches an array element or it does
not. I need to write the hash keys and the values to one file if the
$id matches the array element. I need to write the unmatching array
elements to a second file, and the unmatching hash elements to a third
file.
Here's what I'm trying to do:
foreach my $sid (@array)
{
if ($sid == ???)
{
print FIRST qq($s $l $h $id $hash{$s}{$l}{$h}{$id}\n);
delete $hash{$s}{$l}{$h}{$id};
shift @array;
}
}
foreach (@array) { print SECOND qq{$_\n); }
Then, print the remaining hash elements to THIRD
I'm sorry, but for the life of me I can't figure out how to access the
last level of the hash, at least without iterating through the hash.
CC.
------------------------------
Date: Thu, 17 Sep 2009 15:58:29 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: matching array element to hash key
Message-Id: <slrnhb5801.aqm.tadmc@tadmc30.sbcglobal.net>
ccc31807 <cartercc@gmail.com> wrote:
> This is probably a real stupid question, but it's late and I'm running
> behind, and quite frankly have run out of mental energy.
>
> I have an array with about 5,000 elements that looks like this:
> 0002793 0005095 0093350 0134143 0145740 0146854 0150248 0151827
> 0156424 0161321 0186959 0198460 0218115
>
> I have a four level hash that looks like this:
> $hash{$s}{$l}{$h}{$id} = $terms
> This has contains about 8,000 discrete elements.
You have two sets. The elements in the array, and the 4th level keys.
> The $id key in the hash either matches an array element or it does
> not. I need to write the hash keys and the values to one file if the
> $id matches the array element.
Find the intersection of the two sets.
> I need to write the unmatching array
> elements to a second file,
Find the difference between the two sets.
> and the unmatching hash elements to a third
> file.
Find the difference between the two sets in the other direction.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Thu, 17 Sep 2009 16:53:30 +0200
From: Helmut Richter <hhr-m@web.de>
Subject: need to declare/import package variable?
Message-Id: <Pine.LNX.4.64.0909171633580.4944@lxhri01.lrz.lrz-muenchen.de>
It was my understanding that importing variables from packages is only
needed for using them by their unqualified names, but this seems to be
wrong. Here is the source:
There is a module CGI_Fiona.pm starting with the following code:
---- start code example ----
package CGI_Fiona;
use strict;
use vars qw(@ISA @EXPORT);
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(script_begin script_end);
my ($postlude, $included_file);
sub script_begin {
...
$included_file = "/some/filename";
...
}
---- end code example ----
The package is used by a script include_file.pl starting with the follong
code:
---- start code example ----
#! /usr/bin/perl
use strict;
use CGI::Carp qw(fatalsToBrowser);
use Encode;
use lib '/info/www/PERLLIB/';
use CGI_Fiona;
my ($text, $textlength, $outtext);
script_begin();
open (INCLUDED, "<$CGI_Fiona::included_file") || die "unable to open
\"$CGI_Fiona::included_file\": $!\n";
---- end code example ----
Everything compiles fine, but on execution the variable
$CGI_Fiona::included_file has no value inside include_file.pl although
the variable $included_file (which I assumed to be the same variable) has
been set in script_begin() inside CGI_Fiona.pm .
I could try to repair the situation by also exporting the variable with
the same means as the subs, but first I want to understand why this is
necessary. A fully qualified variable should be visible everywhere,
shouldn't it?
--
Helmut Richter
------------------------------
Date: Thu, 17 Sep 2009 10:03:34 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: need to declare/import package variable?
Message-Id: <slrnhb4j6j.6vk.tadmc@tadmc30.sbcglobal.net>
Helmut Richter <hhr-m@web.de> wrote:
> It was my understanding that importing
package
> variables from packages is only
> needed for using them by their unqualified names, but this seems to be
> wrong.
> my ($postlude, $included_file);
^^
^^
> open (INCLUDED, "<$CGI_Fiona::included_file") || die "unable to open
Lexical variables are never visible across file boundaries.
You need to make $included_file a package variable for it to work
like you expect, but that is bad design.
It would be better to leave it as a lexical and provide a getter
function to get its value.
> A fully qualified
package
> variable should be visible everywhere,
> shouldn't it?
A fully qualified package variable should be visible everywhere.
Lexical variables are never visible across file boundaries.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Thu, 17 Sep 2009 17:50:16 +0200
From: Helmut Richter <hhr-m@web.de>
Subject: Re: need to declare/import package variable?
Message-Id: <Pine.LNX.4.64.0909171727400.4944@lxhri01.lrz.lrz-muenchen.de>
On Thu, 17 Sep 2009, Tad J McClellan wrote:
> Lexical variables are never visible across file boundaries.
>
> You need to make $included_file a package variable for it to work
> like you expect, but that is bad design.
Yes, it is bad design. When writing the script, I noticed that it would
*nearly* do what was already in the package's subroutines. It is certainly
better to add the functionality to the package as a new subroutine so that
the script can call this functionality without knowing the package's
internals.
> A fully qualified package variable should be visible everywhere.
>
> Lexical variables are never visible across file boundaries.
There is one thing I have still not understood: Why is the variable with
the name $CGI_Fiona::included_file accepted at all? With "use strict" it
should be rejected because it is nowhere declared.
In any case, thank you very much for your assistance.
--
Helmut Richter
------------------------------
Date: Thu, 17 Sep 2009 12:37:04 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: need to declare/import package variable?
Message-Id: <87hbv1le8f.fsf@quad.sysarch.com>
>>>>> "HR" == Helmut Richter <hhr-m@web.de> writes:
HR> On Thu, 17 Sep 2009, Tad J McClellan wrote:
>> Lexical variables are never visible across file boundaries.
>>
>> A fully qualified package variable should be visible everywhere.
>>
>> Lexical variables are never visible across file boundaries.
HR> There is one thing I have still not understood: Why is the variable with
HR> the name $CGI_Fiona::included_file accepted at all? With "use strict" it
HR> should be rejected because it is nowhere declared.
because that is called a fully qualified package variable. just as tad
said. the :: tells perl you know where this variable is from and because
of that it works with strict. strict only checks simple variable names
and makes sure they are declared (which is always in the current scope
for lexicals). you can declare globals with our or use vars to work with
strict as well.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Thu, 17 Sep 2009 12:06:29 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: need to declare/import package variable?
Message-Id: <slrnhb4qd2.8fm.tadmc@tadmc30.sbcglobal.net>
Helmut Richter <hhr-m@web.de> wrote:
> There is one thing I have still not understood: Why is the variable with
> the name $CGI_Fiona::included_file accepted at all? With "use strict" it
> should be rejected because it is nowhere declared.
Errr, no...
perldoc strict
"strict vars"
This generates a compile‐time error if you access a variable that
wasn’t declared via "our" or "use vars", localized via "my()", or
wasn’t fully qualified.
^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^
That is, "strict vars" requires
EITHER that you declare the variable somehow
OR that you use the fully qualified variable name when you access it.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Thu, 17 Sep 2009 13:38:46 -0700
From: Anti VIgilante <antivigilante@pyrabang.com>
Subject: Re: Underwear supplier (paypal payment)( www.brandtrade08.cn )
Message-Id: <4ab29e56$0$89864$815e3792@news.qwest.net>
12345678 wrote:
> Jeans Wholesale in China Fashion Styles
> Ecko,BBC,Armani,Prada,Evisu,D&G,RMC,Paypal Payment Exempt Freight -
> www.brandtrade08.cn
>
> Jeans supplier (paypal payment)( www.brandtrade08.cn )
> Jean supplier (paypal payment)( www.brandtrade08.cn )
> Roca Wear Jean supplier (paypal payment)( www.brandtrade08.cn )
> ZEN Jean supplier (paypal payment)( www.brandtrade08.cn )
> Artful Dodger Jean supplier (paypal payment)
> ( www.brandtrade08.cn )
> BBC Jean supplier (paypal payment)( www.brandtrade08.cn )
> Cavalli Jean supplier (paypal payment)( www.brandtrade08.cn )
> Laguna Beach Jean Laguna Beach Man supplier (paypal payment)
> ( www.brandtrade08.cn )
> Laguna Beach woman supplier (paypal payment)
> ( www.brandtrade08.cn )
> Prada Jean supplier (paypal payment)( www.brandtrade08.cn )
> RMC Jean supplier (paypal payment)( www.brandtrade08.cn )
> Affliction Jean supplier (paypal payment)( www.brandtrade08.cn )
> Akademiks Jean supplier (paypal payment)( www.brandtrade08.cn )
> Armani Jean supplier (paypal payment)( www.brandtrade08.cn )
> Bape Jean supplier (paypal payment)( www.brandtrade08.cn )
> Black Label Jean supplier (paypal payment)( www.brandtrade08.cn )
> Christian Audigier Jean supplier (paypal payment)
> ( www.brandtrade08.cn )
> Christian Audigier Jean Man supplier (paypal payment)
> ( www.brandtrade08.cn )
> Christian Audigier Jean Women supplier (paypal payment)
> ( www.brandtrade08.cn )
> Coogi Jean supplier (paypal payment)( www.brandtrade08.cn )
> Crown Holder Jean supplier (paypal payment)
> ( www.brandtrade08.cn )
> D&G Jean supplier (paypal payment)( www.brandtrade08.cn )
> Diesel Jean supplier (paypal payment)( www.brandtrade08.cn )
> Ecko Unltd Jean supplier (paypal payment)( www.brandtrade08.cn )
> Ed Hardy Jean supplier (paypal payment)( www.brandtrade08.cn )
> ED Hardy Jean Women supplier (paypal payment)
> ( www.brandtrade08.cn )
> ED Hardy Jean Man supplier (paypal payment)
> ( www.brandtrade08.cn )
> Evisu Jean supplier (paypal payment)( www.brandtrade08.cn )
> G-Star Jean supplier (paypal payment)( www.brandtrade08.cn )
> Gucci Jean supplier (paypal payment)( www.brandtrade08.cn )
> Iceberg Jean supplier (paypal payment)( www.brandtrade08.cn )
> Jack&Jones Jean supplier (paypal payment)( www.brandtrade08.cn )
> Justcavalli Jean supplier (paypal payment)( www.brandtrade08.cn )
> Kanji Jean supplier (paypal payment)( www.brandtrade08.cn )
> LEVI'S Jean supplier (paypal payment)( www.brandtrade08.cn )
> LRG Jean supplier (paypal payment)( www.brandtrade08.cn )
> LV Jean supplier (paypal payment)( www.brandtrade08.cn )
> Rock&Republic Jean supplier (paypal payment)
> ( www.brandtrade08.cn )
> Rock Man Jean supplier (paypal payment)( www.brandtrade08.cn )
> Rock Women Jean supplier (paypal payment)( www.brandtrade08.cn )
> True Relig Jean supplier (paypal payment)( www.brandtrade08.cn )
> True Relig Man Jean supplier (paypal payment)
> ( www.brandtrade08.cn )
> True Relig Women Jean supplier (paypal payment)
> ( www.brandtrade08.cn )
> Versace Jean supplier (paypal payment)( www.brandtrade08.cn )
>
>
> Pants Crown Holder Pants supplier (paypal payment)
> ( www.brandtrade08.cn )
> A&F Pants supplier (paypal payment)( www.brandtrade08.cn )
> A&F Pants Man supplier (paypal payment)( www.brandtrade08.cn )
> A&F Pants Women supplier (paypal payment)( www.brandtrade08.cn )
> Affliction Pants supplier (paypal payment)
> ( www.brandtrade08.cn )
> Bape Pants supplier (paypal payment)( www.brandtrade08.cn )
> BBC Pants supplier (paypal payment)( www.brandtrade08.cn )
> Christian Audigier Pants supplier (paypal payment)
> ( www.brandtrade08.cn )
> Coogi Pants supplier (paypal payment)( www.brandtrade08.cn )
> ED Hardy Pants supplier (paypal payment)( www.brandtrade08.cn )
> ED Hardy Pants Man supplier (paypal payment)
> ( www.brandtrade08.cn )
> ED Hardy Pants Women supplier (paypal payment)
> ( www.brandtrade08.cn )
> Evisu Pants supplier (paypal payment)( www.brandtrade08.cn )
> RMC Pants supplier (paypal payment)( www.brandtrade08.cn )
> Rock&Republic Pants supplier (paypal payment)
> ( www.brandtrade08.cn )
> Underwear supplier (paypal payment)( www.brandtrade08.cn )
>
>
> fashion jeans supplier (paypal payment)( www.brandtrade08.cn )
> denim jeans supplier (paypal payment)( www.brandtrade08.cn )
> men''s jeans
> brand jeans supplier (paypal payment)( www.brandtrade08.cn )
> women jeans'' jeans supplier (paypal payment)
> ( www.brandtrade08.cn )
> branded jeans supplier (paypal payment)( www.brandtrade08.cn )
> designer jeans
> men jeans supplier (paypal payment)( www.brandtrade08.cn )
> blue jeans supplier (paypal payment)( www.brandtrade08.cn )
> Cotton Shirting
> Fashion Shirts Dress Shirts supplier (paypal payment)
> ( www.brandtrade08.cn )
> Casual Shirts Brand Shirts supplier (paypal payment)
> ( www.brandtrade08.cn )
> Long Sleeve Shirt
>
>
> Artful dodger man jeans supplier (paypal payment)
> ( www.brandtrade08.cn )
> BAPE man jeans supplier (paypal payment)( www.brandtrade08.cn )
> BBC man jeans supplier (paypal payment)( www.brandtrade08.cn )
> Christian Audigier man jeans supplier (paypal payment)
> ( www.brandtrade08.cn )
> COOGI man jeans
> Crown Holder man jeans supplier (paypal payment)
> ( www.brandtrade08.cn )
> D&G man jeans
> Diesel man jeans supplier (paypal payment)( www.brandtrade08.cn )
> Ed Hardy women jeans supplier (paypal payment)
> ( www.brandtrade08.cn )
> Ed Hardy man jeans
> Evisu man jeans jeans supplier (paypal payment)
> ( www.brandtrade08.cn )
> G-Star man jeans supplier (paypal payment)( www.brandtrade08.cn )
> Red Monkey man jeans
> ROCK man jeans supplier (paypal payment)
> ( www.brandtrade08.cn )
> ROCK women jeans
> man jeans supplier (paypal payment)( www.brandtrade08.cn )
> True Religion women jeans
> man jeans
>
>
Can you type this in a lisp environment and tell me the results?
(defun see-spot-run (x)
(let (x (+ 1 x))
(print x)
(see-spot-run x)))
(see-spot-run x)
------------------------------
Date: Thu, 17 Sep 2009 11:29:44 -0700
From: RF <RF@NoDen.con>
Subject: Using Perl's Bits 'n Pieces ;-)
Message-Id: <7hfdeqF2t777jU1@mid.individual.net>
Hi Experts,
About 15 years ago I dabbled in Perl and I wrote a few simple programs
but now I have to confess that I am lost.
I have the following instructions for setting up a Perl prog.
"INSTALLATION
To install this module type the following:
perl Makefile.PL
make
make test
make install."
All I have is 3 folders. The top one has about 30 files like About-NLS,
config.guess, count.pl, install.sh, Makefile.in, Makefile.PL.in,
Makefile-xx.in, po2perl.pl, Manifest.SKIP. etc.
The middle subfolder has only two files: ProgName.sxw and groo.pl.
The last subfolder has about 40 files like af.bmo, af.po, de.po,
Makefile.in.in., POTFILES.in, re.po, Rules-quot, sv.po, etc.
I believe some other module or .exe is needed to execute the above
instructions and set up the program.
Help appreciated.
TIA
------------------------------
Date: Thu, 17 Sep 2009 11:53:00 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Using Perl's Bits 'n Pieces ;-)
Message-Id: <170920091153008964%jimsgibson@gmail.com>
In article <7hfdeqF2t777jU1@mid.individual.net>, RF <RF@NoDen.con>
wrote:
> Hi Experts,
>
> About 15 years ago I dabbled in Perl and I wrote a few simple programs
> but now I have to confess that I am lost.
>
> I have the following instructions for setting up a Perl prog.
>
> "INSTALLATION
>
> To install this module type the following:
>
> perl Makefile.PL
> make
> make test
> make install."
>
> All I have is 3 folders. The top one has about 30 files like About-NLS,
> config.guess, count.pl, install.sh, Makefile.in, Makefile.PL.in,
> Makefile-xx.in, po2perl.pl, Manifest.SKIP. etc.
>
> The middle subfolder has only two files: ProgName.sxw and groo.pl.
>
> The last subfolder has about 40 files like af.bmo, af.po, de.po,
> Makefile.in.in., POTFILES.in, re.po, Rules-quot, sv.po, etc.
>
> I believe some other module or .exe is needed to execute the above
> instructions and set up the program.
>
> Help appreciated.
The minimum executables you need are the perl interpreter and a make
utility. Other executables may be required by the installation process,
for example a C compiler if the Perl module contains any C code, but
that depends upon the module. Pure Perl modules should only require
perl and make.
Have you tried the installation commands you listed? What happened?
If you need more help, please post the details of your platform and any
error messages you might be getting.
Thanks and good luck.
--
Jim Gibson
------------------------------
Date: Thu, 17 Sep 2009 13:32:00 -0700
From: RF <RF@NoDen.con>
Subject: Re: Using Perl's Bits 'n Pieces ;-)
Message-Id: <7hfkk1F2sei60U1@mid.individual.net>
Jim Gibson wrote:
> In article <7hfdeqF2t777jU1@mid.individual.net>, RF <RF@NoDen.con>
> wrote:
>
>> Hi Experts,
>>
>> About 15 years ago I dabbled in Perl and I wrote a few simple programs
>> but now I have to confess that I am lost.
>>
>> I have the following instructions for setting up a Perl prog.
>>
>> "INSTALLATION
>>
>> To install this module type the following:
>>
>> perl Makefile.PL
>> make
>> make test
>> make install."
>>
>> All I have is 3 folders. The top one has about 30 files like About-NLS,
>> config.guess, count.pl, install.sh, Makefile.in, Makefile.PL.in,
>> Makefile-xx.in, po2perl.pl, Manifest.SKIP. etc.
>>
>> The middle subfolder has only two files: ProgName.sxw and groo.pl.
>>
>> The last subfolder has about 40 files like af.bmo, af.po, de.po,
>> Makefile.in.in., POTFILES.in, re.po, Rules-quot, sv.po, etc.
>>
>> I believe some other module or .exe is needed to execute the above
>> instructions and set up the program.
>>
>> Help appreciated.
>
> The minimum executables you need are the perl interpreter and a make
> utility. Other executables may be required by the installation process,
> for example a C compiler if the Perl module contains any C code, but
> that depends upon the module. Pure Perl modules should only require
> perl and make.
>
> Have you tried the installation commands you listed? What happened?
>
> If you need more help, please post the details of your platform and any
> error messages you might be getting.
>
> Thanks and good luck.
Thank you Jim for that lightning response.
I did find a few more instructions:
# If you're running Windows 95 or NT with the core Windows distribution
of Perl,
A. DECOMPRESS
When you download the module, make sure it ends in either .tar.gz
or .zip. You can use WinZip (shareware) to decompress and unpack modules.
[I used WinZip and it worked fine]
B. UNPACK
All of the methods in DECOMPRESS will have done this for you.
[I unpacked all the directories and files and copied the complete
structure to a new directory C:\Perlprog]
C. BUILD
Go into the newly-created directory and type:
perl Makefile.PL
[The CMD Prompt I input was: C:\Perlprog>perl Makefile.PL
and the answer was: "'perl' is not recognized as an in operable program
or batch file." I guess another Perl module is required]
dmake
dmake test
Depending on your perl configuration, dmake might not be available.
You might have to substitute whatever perl -V:make says. (Usually, that
will be nmake or make.)
D. INSTALL
While still in that directory, type:
dmake install
[Thanks again for your help]
------------------------------
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 2600
***************************************