[23627] in Perl-Users-Digest
Perl-Users Digest, Issue: 5834 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 20 09:05:52 2003
Date: Thu, 20 Nov 2003 06:05:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 20 Nov 2003 Volume: 10 Number: 5834
Today's topics:
apache cgi can't open file <"jg"@opencity. com>
Re: apache cgi can't open file <jtoth@acm.org>
Re: bit sequence match <eddhig22@yahoo.com>
Re: bit sequence match (Jay Tilton)
Re: comments on JAPH? <ThomasKratz@REMOVEwebCAPS.de>
Comments on parsing solution. (Prabh)
Re: Comments: locking variables <mb@uq.net.au.invalid>
Re: Comments: locking variables <mb@uq.net.au.invalid>
Re: Fastest Perl Interpreter <reg1-at-hatless-dot-com@nospam.net>
Re: god im a noob <noreply@gunnar.cc>
Re: god im a noob (Tad McClellan)
Re: god im a noob <HelgiBriem_1@hotmail.com>
How to pass DBI handle into module <roman@sky.lviv.ua>
Re: How to pass DBI handle into module <ben.liddicott@comodogroup.com>
Re: Image::Magick memory leak question (William Herrera)
Re: Inserting the same thing multi times into array. <spikeywan@bigfoot.com.delete.this.bit>
Re: Inserting the same thing multi times into array. <REMOVEsdnCAPS@comcast.net>
Re: Inserting the same thing multi times into array. <spikeywan@bigfoot.com.delete.this.bit>
Re: Mail Spool Truncation (Anno Siegel)
Re: Match and cut regex? <abigail@abigail.nl>
Re: Need some help... <abigail@abigail.nl>
Re: perldoc installation <abigail@abigail.nl>
Please direct me to a help page (dn_perl@hotmail.com)
Re: Please direct me to a help page (Tad McClellan)
Re: Protecting Source code of a perl script (Aqua)
Re: Protecting Source code of a perl script <abigail@abigail.nl>
Re: RegEx problem <ben.liddicott@comodogroup.com>
Sorting an array <bob@vdpcorp.com>
Re: Sorting an array <ak+usenet@freeshell.org>
Re: Sorting an array <notspam@spamfree.dud>
Re: test please ignore <REMOVEsdnCAPS@comcast.net>
Re: test please ignore <abigail@abigail.nl>
Re: trying to grep a $line for $line...any ideas? (Aqua)
Re: trying to grep a $line for $line...any ideas? <tore@aursand.no>
Re: trying to grep a $line for $line...any ideas? (Sam Holden)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 20 Nov 2003 08:30:00 -0500
From: jcs <"jg"@opencity. com>
Subject: apache cgi can't open file
Message-Id: <bpiems$ga3$2@reader2.panix.com>
Sorry if this shouldn't be here - it's peripherally a perl question.
SuSE 8.2
apache-2.0.48
'seems' to be installed and running. Returns hello page
Konqueror
http://127.0.0.1/cgi-bin/perl.cgi
returns "hello world" fine but won't open 'log'
error_log
[Wed Nov 19 12:25:13 2003] [error] [client 127.0.0.1] Premature end of
script headers: perl.cgi
[Wed Nov 19 12:25:13 2003] [error] [client 127.0.0.1] can't open log at
/usr/local/apache2/cgi-bin/perl.cgi line 7.
log is cgi-bin/log
permissions have been changed.
runs from command line.
#!/usr/bin/perl
use SDBM_File;
use Fcntl;
use strict;
open (LOG, "+>>log") or die "can't open log";
print LOG "log\n";
close LOG;
print "Content-type: text/html\n\n";
print "<HTML>HELLO<BR>WORLD</HTML>";
print "</HTML>";
------------------------------
Date: Thu, 20 Nov 2003 13:44:28 +0000 (UTC)
From: Jim Toth <jtoth@acm.org>
Subject: Re: apache cgi can't open file
Message-Id: <slrnbrph9s.git.jtoth@baka.acw.vcu.edu>
In article <bpiems$ga3$2@reader2.panix.com>, jcs wrote:
[snip]
> [Wed Nov 19 12:25:13 2003] [error] [client 127.0.0.1] Premature end of
> script headers: perl.cgi
> [Wed Nov 19 12:25:13 2003] [error] [client 127.0.0.1] can't open log at
> /usr/local/apache2/cgi-bin/perl.cgi line 7.
[snip]
Have it use the $! variable so that it will tell you more
about why it can't open the file:
> #!/usr/bin/perl
>
> use SDBM_File;
> use Fcntl;
> use strict;
>
> open (LOG, "+>>log") or die "can't open log";
open (LOG, "+>>log") or die "can't open log: $!";
> print LOG "log\n";
> close LOG;
>
> print "Content-type: text/html\n\n";
> print "<HTML>HELLO<BR>WORLD</HTML>";
> print "</HTML>";
--
Jim Toth
jtoth@acm.org
------------------------------
Date: Thu, 20 Nov 2003 21:22:34 +1100
From: Edo <eddhig22@yahoo.com>
Subject: Re: bit sequence match
Message-Id: <3FBC95EA.8010608@yahoo.com>
Jay Tilton wrote:
> Edo <eddhig22@yahoo.com> wrote:
>
> : what I wanted to do is sort the hash at the time or once it's been created.
>
> The Tie::IxHash module is a convenient way to have this.
> See "How can I always keep my hash sorted?" in perlfaq4.
>
too many important points I realy want to understand with out missing
much here, so one point at the time. first using Tie::IxHash in this case.
the fist point is in the code below, after adding the line (use
Tie::IxHash), and the hash I want to sort is not a hash but an anynomuse
hash_ref that is being pushed to @results, how can I utalize the module
in this case? the man page does not mention it.
plus my %h1 = Tie::IxHash->new in the first hash is not doing good,
error is being generated when prog is run.
>
> : and an equal number of values starting form 1st to number of items in
> : @v1 from sorted %h2 in another array @v2
>
> There's already the %match hash. Getting the values from it would be
> just like getting the values from %h1.
no, I don't want the match but rather 5 values starting from the first
record in %h2, to feed to a sub, then another 5 values starting from the
second record in %h2 to feed to the sub and ... each group of values
from %h2 is being put in @v2 and feed to sub sim(\@v1, \@v2)
the sim returns a number from 0 to 1
------------------------------
Date: Thu, 20 Nov 2003 11:37:47 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: bit sequence match
Message-Id: <3fbc9ae6.221692334@news.erols.com>
Edo <eddhig22@yahoo.com> wrote:
: too many important points I realy want to understand with out missing
: much here, so one point at the time. first using Tie::IxHash in this case.
: the fist point is in the code below, after adding the line (use
: Tie::IxHash), and the hash I want to sort is not a hash but an anynomuse
: hash_ref that is being pushed to @results, how can I utalize the module
: in this case? the man page does not mention it.
The easy way would be to create a real, named hash that is tied to the
Tie::IxHash class, then push a reference to that hash onto @results.
E.g.
tie my %match, 'Tie::IxHash';
%match = map { $_ => $h2{$_} } @k2[ $-[0] .. $-[0]+@k1-1 ];
push @results, \%match;
: plus my %h1 = Tie::IxHash->new in the first hash is not doing good,
: error is being generated when prog is run.
The "Tie::IxHash->new" syntax creates and returns a Tie::IxHash object,
which is useful when you need to use some of its more exotic methods.
You probably don't need those methods.
To have a hash that simply keeps elements in the order in which they
were added, Perl's tie() function is enough.
tie my %h1, 'Tie::IxHash';
%h1 = ( ... );
: no, I don't want the match but rather 5 values starting from the first
: record in %h2, to feed to a sub, then another 5 values starting from the
: second record in %h2 to feed to the sub and ... each group of values
: from %h2 is being put in @v2 and feed to sub sim(\@v1, \@v2)
Now I understand.
We've seen array slices and hash slices. Now we get to see a list
slice. It looks almost just like an array slice.
for( 0 .. keys(%h2) - 5 ) {
my @v2 = @h2{ (keys %h2)[ $_ .. $_+4 ] };
sim( \@v1, \@v2 );
}
The "keys(%h2)" in the first line is in scalar context, so it returns
the number of keys in %h2.
the "(keys %h2)" in the second line is in list context, so it returns a
list of all keys in %h2. Since %h2 is tied to the Tie::IxHash class,
that list of keys will already be sorted. The list slicing is done by
the square brackets.
The "@h2{ ... }" is a hash slice, which you are already familiar with.
------------------------------
Date: Thu, 20 Nov 2003 10:46:35 +0100
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: comments on JAPH?
Message-Id: <3fbc8e35.0@juno.wiesbaden.netsurf.de>
Michele Dondi wrote:
>>
>>Using ARGV would be an alternative (and the above problem would vanish).
>>I just found out that you can't paste the lines via STDIN (always tested
>>with a file :-( ). The DATA filehandle seems to be missing. I have to look
>>that up.
>
>
> Huh?!?
'Huh?!?' to what? :-)
Ok I'll try to be clearer.
1. I am moving through the comment on the right side of the JAPH with
'seek' and 'getc'. Therefore I need to know how many bytes the line
endings consist of, to get the right offset. Just pulling everything into
an array and parsing that would be easier.
2. I just realized (never thought about it before), that when you paste
the code to the perl interpreter via STDIN, you won't get anything from
the DATA filehandle. I don't know if and - if yes - how I can get at the
code when it comes in via STDIN.
Better?
Thomas
--
open STDIN,"<&DATA";$=+=14;$%=50;while($_=(seek( #J~.> a>n~>>e~.......>r.
STDIN,$:*$=+$,+$%,0),getc)){/\./&&last;/\w| /&&( #.u.t.^..oP..r.>h>a~.e..
print,$_=$~);/~/&&++$:;/\^/&&--$:;/>/&&++$,;/</ #.>s^~h<t< ..~. ...c.^..
&&--$,;$:%=4;$,%=23;$~=$_;++$i==1?++$,:_;}__END__#....>>e>r^..>l^...>k^..
------------------------------
Date: 20 Nov 2003 06:00:09 -0800
From: Prab_kar@hotmail.com (Prabh)
Subject: Comments on parsing solution.
Message-Id: <e7774537.0311200600.462e5e15@posting.google.com>
Hello all,
This is about grepping, regexps and parsing data.
I do have a solution, but I was wondering if anyone could direct me to
a more efficient one.
I have a log file of the following format, which contains info. on a
series of files after a process.
===============================
File1: Info. on File1
File2: Info. on File2
File1: Info. on File1
File3: Info. on File3
File1: Info. on File1
and so on...
===============================
I want to display the output as...
============================
n1 lines of info on File1
n2 lines of info on File2
n3 lines of info on File3
============================
This is what I came up with, but when the input log file is of
gigantic proportions, the parsing takes a lot of time, could anyone
recommend a better solution, please?
#!/usr/local/bin/perl
#======================
#====================
# Foo.txt is the log
#--------------------
open(FDL,"Foo.txt") ;
chomp(@arr = <FDL> ) ;
close(FDL) ;
#===============================
# Get all the files in the log
#-------------------------------
undef @files ;
foreach $line ( @arr ) {
push(@files,(split(/\:/,$line))[0]) ;
}
#==========================================
# Sort the files, find the uniq files.
# Foreach such file, grep the original log
# for all occurrences and count.
#------------------------------------------
foreach $file ( &uniq(sort @files ) ) {
undef $info ;
$info = grep {/^$file\:/} @arr ;
printf "$info lines of info on $file\n";
}
#=============================
# subroutine to do Unixy-uniq
#-----------------------------
sub uniq {
@uniq = @_ ;
#=======================================================
# Foreach array element , compare with its predecessor.
# If yes, its already present and splice.
#-------------------------------------------------------
for ( $i = 1; $i < @uniq ; $i++ ) {
if ( @uniq[$i] eq @uniq[$i-1] ) {
splice( @uniq,$i-1,1 ) ;
$i--;
}
}
return @uniq ;
}
Thanks,
Prab
------------------------------
Date: Thu, 20 Nov 2003 15:06:45 +1000
From: Matthew Braid <mb@uq.net.au.invalid>
Subject: Re: Comments: locking variables
Message-Id: <bphi56$iea$1@bunyip.cc.uq.edu.au>
Jay Tilton wrote:
> Matthew Braid <mb@uq.net.au.invalid> wrote:
>
> : I need to lock down some keys in a blessed hash so that they cannot be
> : directly altered (eg through $self->{key} = "whatever").
>
> The lock_keys() function in the Hash::Util module is perfectly suited.
>
Hmm, seems nice, but there is one little problem. I can't lock a single
key - I have to lock them all.
So I can't make a hash where keys can be created at will, but key
'AltUID' is both undeletable and readonly... and looking at the code
this isn't an oversight - its just not possible (the whole hash keyset
has to be set as readonly).
Not such a huge problem - I just have to make sure my code knows all the
keys its ever going to need (or do some in-sub unlocking/relocking).
Thanks for the info. Up until now I didn't know about the *::Util packages.
MB
------------------------------
Date: Thu, 20 Nov 2003 15:14:28 +1000
From: Matthew Braid <mb@uq.net.au.invalid>
Subject: Re: Comments: locking variables
Message-Id: <bphijk$emm$1@bunyip.cc.uq.edu.au>
Matthew Braid wrote:
> Jay Tilton wrote:
>
>> Matthew Braid <mb@uq.net.au.invalid> wrote:
>>
>> : I need to lock down some keys in a blessed hash so that they cannot
>> be : directly altered (eg through $self->{key} = "whatever").
>>
>> The lock_keys() function in the Hash::Util module is perfectly suited.
>>
>
> Hmm, seems nice, but there is one little problem. I can't lock a single
> key - I have to lock them all.
>
> So I can't make a hash where keys can be created at will, but key
> 'AltUID' is both undeletable and readonly... and looking at the code
> this isn't an oversight - its just not possible (the whole hash keyset
> has to be set as readonly).
>
> Not such a huge problem - I just have to make sure my code knows all the
> keys its ever going to need (or do some in-sub unlocking/relocking).
>
> Thanks for the info. Up until now I didn't know about the *::Util packages.
>
> MB
>
Duh.
Or don't actually lock $self, but lock $self->{Protected}, which is
itself a hashref.
Obviously my brain moves slower than my fingers :)
MB
------------------------------
Date: Thu, 20 Nov 2003 13:41:22 GMT
From: Steve Koppelman <reg1-at-hatless-dot-com@nospam.net>
Subject: Re: Fastest Perl Interpreter
Message-Id: <6w3vb.196198$275.727719@attbi_s53>
Michael J. Astrauskas wrote:
> William Herrera wrote:
>> On Sat, 25 Oct 2003 15:34:51 -0700, "Michael J. Astrauskas"
>> <trevie@cox.net>
>> wrote:
>
> It'll basically be a front end NNTP server. Network I/O will be intense.
> About 300 copies of the script will be running at any time.
NNTP? Sounds like a strange contest. Is this a coding contest or a
contest contest? SMTP, POP, IMAP, HTTP and maybe an IM protocol I can
see, but NNTP, huh? All right. Are there even 300 regular users of NNTP
left? :) Okay, okay. No matter.
Regardless of what protocol you're building this out of, "running 300
copies of the script" simultaneously is an incredibly bad idea. Doing so
with an interpreted language like Perl, Python, Tcl, VBScript, LISP,
whatever will certainly need heavy duty hardwarte, but not for the
actual work of your script. The CPU and memory and probably the disks
too will all be occupied initializing and tearing down all those
interpreters. The actual meat of what your script does will use only a
tiny fraction of the resources, and you'll need many times the memory
and CPU than you would otherwise.
Perl is fine for what you want to do, but you want to do it
*multithreaded*, with one instance of the script running per box as a
daemon. That ought to be plenty fast given adequate hardware, and your
choice of CPU architecture, compiler and compiler optimizations should
be mostly irrelevant. Throw an adequate number of MIPS at it focus more
on writing properly optimized Perl and making sure your disk and network
I/O are adequate.
If you or someone else insists on implementing this with hundreds of
separate processes, then it's hard to imagine a worse design decision
than spawning hundreds of interpreters simultaneously with tens or
hundreds of thousands of launches and teardowns per day. If you want
separate processes, you should be using C/C++ or something else that
compiles to tight binaries, period.
Splitting hairs over Opterons vs. Xeons vs. supercooled Athlons or
mastodons is pointless. You should have hardware capable of handling
your largest realistically-projected traffic spikes with a good amount
of headroom remaining, period. You can do it with Celerons if you really
want to: just pick hardware that gives you the SPECmarks, the I/O and
the uptime you need at a good price. If you're running it on one box
rather than load-balancing a few smaller ones, and have nothing
"collecting" requests during downtime, then redundant and/or
hot-swappable components (especially disk and power supplies) become
more important. Trying to get a "perfect fit" with little or no headroom
is completely wrong.
Indeed, if availability is critical, you should either design the system
to be load balanced across 1..n machines with no single point of
failure, or you should be holding your contest over a protocol that can
store-and-forward gracefully, unlike private NNTP. With something like
HTTP you can load-balance straightforwardly and run a few smaller and
more disposable servers instead of one big high-availability one. With
an email-based contest, on the other hand, you can have dumb
store-and-forward MX hosts specified in DNS that will catch inbound
entries and pass them along automatically in the event of downtime on
your "collector", effectively offloading the job of inbound-message
fault tolerance to your ISP.
>> OTOH, if your app is really CPU bound, not network bound, maybe you
>> should not
>> use Perl. Use something compiled.
>
> Sadly, it's for a contest and the language and script are not of my choice.
------------------------------
Date: Thu, 20 Nov 2003 06:02:55 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: god im a noob
Message-Id: <bphidl$1obsjf$1@ID-184292.news.uni-berlin.de>
Tad McClellan wrote:
> Default@User011011101101.net wrote:
>> This nntp isnt very good, perhaps there is a perl bbs?
>
> You know that is the fault of your ISP and not of clp.misc don't
> you?
>
> Switch to an ISP with a better news feed.
Or try an independent news service, such as:
http://news.individual.net/
(I do recommend them.)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 20 Nov 2003 05:48:57 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: god im a noob
Message-Id: <slrnbrpah9.2lu.tadmc@magna.augustmail.com>
Default@IO_Error_1011101.xyz <Default@IO_Error_1011101.xyz> wrote:
> From: Default@IO_Error_1011101.xyz
Please pick one posting address and stick with it.
Thank you.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 20 Nov 2003 12:34:53 +0000
From: Helgi Briem <HelgiBriem_1@hotmail.com>
Subject: Re: god im a noob
Message-Id: <06dprvsfueof8l6png6qjg620h6676pmv5@4ax.com>
On Wed, 19 Nov 2003 20:38:48 -0600, tadmc@augustmail.com (Tad
McClellan) wrote:
>Default@User011011101101.net <Default@User011011101101.net> wrote:
>>> Default@User011011101101.net wrote:
>>> Please put the main topic of your post in the Subject field.
>> ok, sry bout that..
> ^^^ ^^^^
>Please don't use cutsie spelling either, it is inconsiderate
>of those whose first language is not English.
And even to those whose first language is.
------------------------------
Date: Thu, 20 Nov 2003 11:59:10 +0200
From: "Roman Khutkyy" <roman@sky.lviv.ua>
Subject: How to pass DBI handle into module
Message-Id: <bpi2vh$2kv8$1@news.uar.net>
Hi,
i'm trying to collect some modules in one project main.pl, each uses DBI
connection to the same databse but with different querries. Is it possible
to set connection to database once? Now i have to declare 'use DBI' in
main.pl . Then i make new connection
> $query*=$dbh*->prepare(***),
and disconnect the query in each module. But error_log exist the string:
>Database handle destroyed without explicit disconnect.
When i make DBI handle $dbh in main.pl, and try to make new query in module
i get the message:
> Can't call method "prepare" on an undefined value
Can anybody help?
------------------------------
Date: Thu, 20 Nov 2003 10:18:24 -0000
From: "Ben Liddicott" <ben.liddicott@comodogroup.com>
Subject: Re: How to pass DBI handle into module
Message-Id: <bpi4e7$vto$1@kylie.comodogroup.com>
Hi Roman,
Can I suggest first, that Perl will give you useful comments if you "use
strict" and "use warnings".
Secondly, as a matter of personal style, I prefer to pass the $dbh database
handle around as a parameter, or make it an attribute of your objects.
Beyond that, you haven't quoted enough of your perl for me to really see
what is going on, but it is certainly possible to make the database
connection once.
Cheers,
Ben Liddicott
"Roman Khutkyy" <roman@sky.lviv.ua> wrote in message
news:bpi2vh$2kv8$1@news.uar.net...
> Hi,
> i'm trying to collect some modules in one project main.pl, each uses DBI
> connection to the same databse but with different querries. Is it possible
> to set connection to database once?
(...)
> Can anybody help?
------------------------------
Date: Thu, 20 Nov 2003 05:27:33 GMT
From: posting.account@lynxview.com (William Herrera)
Subject: Re: Image::Magick memory leak question
Message-Id: <3fbc4f37.145998938@news2.news.adelphia.net>
On Wed, 19 Nov 2003 19:57:31 +0000 (UTC), Stan Brown <stanb@panix.com> wrote:
>
>BTW, adding @$image = ();, right before the undef $image; call seems to
>have drasticly lowered the ammount of memory that it's leaking.
>
>Does that make any sens at all? I would hhave thoughtthat the undef would
>have deleted all parts of the $image object. Am I wrong?
>
With some module objects, who knows? You are undefining a reference to the
object, which cetainly frees the object (the array) if there are no other
references to it. However, it may be that the object's code keeps some hidden
reference to instances of itself (circular?) which then preserves all the
elements in the array when you undefine it. When you instead set the array
contents to none, you dereference and destroy all the actual elements in the
array. So the amount of leak is limited to just the empty array object's memory
usage alone, probably a much smaller leak.. I hope this makes sense. In any
case, I suggest considering saving required states, exiting, and re-running
the script itself periodically, to keep any remaining leakiness under control.
---
Use the domain skylightview (dot) com for the reply address instead.
------------------------------
Date: Thu, 20 Nov 2003 10:08:08 -0000
From: "Richard S Beckett" <spikeywan@bigfoot.com.delete.this.bit>
Subject: Re: Inserting the same thing multi times into array.
Message-Id: <bpi3t8$cvf$1@newshost.mot.com>
> It is, however, worth pointing out that if you were inserting
> reference to anonymous things rather than strings then you probably
> would want map().
>
> splice @array, 2, 0, map [], 1..7; # DWIM - refs to 7 empty arrays
> splice @array, 2, 0, ([]) x 7; # !DWIM - 7 refs to one empty array
Hmmm. Getting a bit over my head, now. What's the difference?
Basically what I'm doing, is parsing a text file into an Excel spreadsheet.
I take a line, and use split to get the array. Because of the nature of the
line, it contains data for the first 2 columns, then nothing for the next 7,
then data for several after that. So just to make life easier when writing
to excel, I wanted to insert 7 empty elements into the array.
--
R.
GPLRank +79.699
------------------------------
Date: Thu, 20 Nov 2003 06:39:53 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Inserting the same thing multi times into array.
Message-Id: <Xns94394E1B33C0Bsdn.comcast@216.196.97.136>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
"Richard S Beckett" <spikeywan@bigfoot.com.delete.this.bit> wrote in
news:bpi3t8$cvf$1@newshost.mot.com:
>> It is, however, worth pointing out that if you were inserting
>> reference to anonymous things rather than strings then you probably
>> would want map().
>>
>> splice @array, 2, 0, map [], 1..7; # DWIM - refs to 7 empty arrays
>> splice @array, 2, 0, ([]) x 7; # !DWIM - 7 refs to one empty
>> array
>
> Hmmm. Getting a bit over my head, now. What's the difference?
The first creates a new array reference seven times, then sticks those
seven distinct array references into @array.
The second creates a new array reference, duplicates that ONE array
reference seven times, and sticks those copies into @array.
In the first case, you'll have seven independent values. In the second
case, you'll have seven references to the SAME array ref -- if you assign
to one of them, you're assigning to *all* of them.
Similarly,
@r = map rand, 1..7;
will insert seven different random numbers into @r, while
@r = (rand) x 7;
will insert one random number into @r seven times.
- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBP7y2RmPeouIeTNHoEQIQ4QCg3nKxyBR9JJmdfnMukCee87jPmDoAoKHp
Uowwz8xZPRd4G25fEeigUh72
=2lUh
-----END PGP SIGNATURE-----
------------------------------
Date: Thu, 20 Nov 2003 13:30:32 -0000
From: "Richard S Beckett" <spikeywan@bigfoot.com.delete.this.bit>
Subject: Re: Inserting the same thing multi times into array.
Message-Id: <bpifol$3r$1@newshost.mot.com>
> >> splice @array, 2, 0, map [], 1..7; # DWIM - refs to 7 empty arrays
> >> splice @array, 2, 0, ([]) x 7; # !DWIM - 7 refs to one empty
> >> array
> The first creates a new array reference seven times, then sticks those
> seven distinct array references into @array.
>
> The second creates a new array reference, duplicates that ONE array
> reference seven times, and sticks those copies into @array.
>
> In the first case, you'll have seven independent values. In the second
> case, you'll have seven references to the SAME array ref -- if you assign
> to one of them, you're assigning to *all* of them.
>
> Similarly,
>
> @r = map rand, 1..7;
>
> will insert seven different random numbers into @r, while
>
> @r = (rand) x 7;
>
> will insert one random number into @r seven times.
Ah! Thanks Eric. That's well worth knowing.
--
R.
GPLRank +79.699
------------------------------
Date: 20 Nov 2003 13:17:07 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Mail Spool Truncation
Message-Id: <bpiesj$uk$1@mamenchi.zrz.TU-Berlin.DE>
Mike Hunter <mhunter@uclink.berkeley.edu> wrote in comp.lang.perl.misc:
> Hey everybody,
>
> I'm looking to write a script that truncates a certain mailbox to a reasonable
> size, in case I get a flood of messages to it. Before I go and write a script
> to do this, is there a cpan package I'm missing? Mail::Spool doesn't seem to
> do it.
Try the Email::* family of modules. Email::Simple plus one or two
support modules should do.
Anno
------------------------------
Date: 20 Nov 2003 13:14:20 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Match and cut regex?
Message-Id: <slrnbrpfhc.772.abigail@alexandra.abigail.nl>
Bryan (bryan@akanta.com) wrote on MMMDCCXXXI September MCMXCIII in
<URL:news:j0xub.6699$9q7.54480104@newssvr21.news.prodigy.com>:
}} If I have a 'cut' phrase:
}} my $cut = "ABBCCCD";
}}
}} and a 'sentence':
}} my $sentence = "ALSSDJOOASABBCCCDUUSIIASDLLLPP";
}}
}} What regex do I use to match the ABBCCCD and then chop off everything
}} after it?
$_ = "ALSSDJOOASABBCCCDUUSIIASDLLLPP";
/ABBCCCD/g;
$_ = (split /\G/) [0];
print;
__END__
ALSSDJOOASABBCCCD
Abigail
--
$_ = "\nrekcaH lreP rehtona tsuJ"; my $chop; $chop = sub {print chop; $chop};
$chop -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
-> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
------------------------------
Date: 20 Nov 2003 13:17:09 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Need some help...
Message-Id: <slrnbrpfml.772.abigail@alexandra.abigail.nl>
warpman (warpman999@netscape.net) wrote on MMMDCCXXXII September MCMXCIII
in <URL:news:99977611.0311191052.3c1f5ff1@posting.google.com>:
;; I need some help. I'm new to perl and I have borrow the following code.
I suggest you return the borrowed code and write something better.
Abigail
--
perl -wle 'eval {die [[qq [Just another Perl Hacker]]]};; print
${${${@}}[$#{@{${@}}}]}[$#{${@{${@}}}[$#{@{${@}}}]}]'
------------------------------
Date: 20 Nov 2003 13:23:30 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: perldoc installation
Message-Id: <slrnbrpg2h.772.abigail@alexandra.abigail.nl>
Tintin (me@privacy.net) wrote on MMMDCCXXXI September MCMXCIII in
<URL:news:bpcsc8$1mnm7e$1@ID-172104.news.uni-berlin.de>:
\\ This is just a comment/observation about people who reply that if perldoc
\\ isn't on the system, then your Perl installation is broken/defective.
\\
\\ Well, that maybe one interpretation, but keep in mind that Perl as included
\\ on later releases of Solaris doesn't include the Perl documentation. This
\\ may well also apply for other similar OS's.
Are you sure? I've never heard Alan Burlison say anything like that
on p5p, and he's the guy responsible for including perl in Solaris.
I never heard anything like this on p5p.
Unfortunally, I don't have access to a SUN system at the moment.
Abigail
--
A perl rose: perl -e '@}>-`-,-`-%-'
------------------------------
Date: 20 Nov 2003 04:38:37 -0800
From: dn_perl@hotmail.com (dn_perl@hotmail.com)
Subject: Please direct me to a help page
Message-Id: <97314b5b.0311200438.5ffa4655@posting.google.com>
While going through perl FAqs on www.perldoc.com and www.perl.com,
I came across a patch of code which users are advised to avoid.
It goes something like :
while(1) {
construct $filename here
if (-e $filename) {
last ;
}
else {
open FH ">$filename" ;
}
}
I was curious and wanted to revisit the page later. But I haven't
been able to locate this page of do's and dont's. Please help.
------------------------------
Date: Thu, 20 Nov 2003 07:17:47 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Please direct me to a help page
Message-Id: <slrnbrpfnr.3it.tadmc@magna.augustmail.com>
dn_perl@hotmail.com <dn_perl@hotmail.com> wrote:
> While going through perl FAqs on www.perldoc.com and www.perl.com,
> I came across a patch of code which users are advised to avoid.
Do you remember what the reason was for avoiding it?
> It goes something like :
^^^^^^^^^^^^^^
That isn't good enough for computer programming, a tiny detail
can change the whole complexion of what is happening.
So we can't help with whatever it was that you saw in the docs,
only with the code that was actually posted.
> while(1) {
> construct $filename here
> if (-e $filename) {
> last ;
> }
> else {
> open FH ">$filename" ;
> }
> }
I see at least 3 things wrong with that code.
1) There is a race, it won't work reliably in a multitasking environment.
2) It does not check the return value from open(), which could
lead to an infinite loop.
3) The code that follows might be able to use FH (if the open()
succeeded) or it might not be able to use FH (if the file
existed or if the open() failed).
> I was curious and wanted to revisit the page later. But I haven't
> been able to locate this page of do's and dont's. Please help.
Maybe you were looking at perltrap.pod ?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 19 Nov 2003 21:54:29 -0800
From: junk@dlink.org (Aqua)
Subject: Re: Protecting Source code of a perl script
Message-Id: <55d7995c.0311192154.132eb55b@posting.google.com>
Senthilraja <senthil.raja@adcc.alcatel.be> wrote in message news:<3FBB1913.2CF04140@adcc.alcatel.be>...
> I've written a perl script for a high security application and hence I
> want to protect the source code of the perl script, even from the
> administrator of the application.
>
> Is there any way to convert the perl script source into some sort of exe
> or binary file, without affecting the functioning of the script?
>
> TIA.
> regards,
> Senthil.
I dont know what platform r u in. If it is windows you can try perlex.
Regards
Dominic
Perl Consulting http://www.dlink.org/perl
------------------------------
Date: 20 Nov 2003 13:35:42 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Protecting Source code of a perl script
Message-Id: <slrnbrpgpe.772.abigail@alexandra.abigail.nl>
Senthilraja (senthil.raja@adcc.alcatel.be) wrote on MMMDCCXXXII September
MCMXCIII in <URL:news:3FBB1913.2CF04140@adcc.alcatel.be>:
\\ I've written a perl script for a high security application and hence I
\\ want to protect the source code of the perl script, even from the
\\ administrator of the application.
I fail to follow this logic. If it's really secure, there's no need to
hide the source.
Now, if you mean "I want to pretent I can write secure code, but I can't,
and I hope my customers don't see my mistakes by 'hiding' the source code",
I could imagine your plea.
\\ Is there any way to convert the perl script source into some sort of exe
\\ or binary file, without affecting the functioning of the script?
I suggest 'chmod 000 super_secret_program'.
Abigail
--
A perl rose: perl -e '@}-`-,-`-%-'
------------------------------
Date: Thu, 20 Nov 2003 10:23:29 -0000
From: "Ben Liddicott" <ben.liddicott@comodogroup.com>
Subject: Re: RegEx problem
Message-Id: <bpi4nr$gk$1@kylie.comodogroup.com>
Hi Gunnar,
"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:bpgraa$1nef93$1@ID-184292.news.uni-berlin.de...
> Ben Liddicott wrote:
> > Then you can say
> > if($fields{2} == 307){
> > my $whatIWantToKnow = $fields{1107};
> > }
>
> Uhmm.. What would the point be with all that, when you can simply do
>
> $line =~ /1107=([^,]+)/;
> print $1;
If he wants to use more than two or three of the fields, I'd recommend going
to the general case would make the code easier to write and understand. It
may still be slower, of course.
As a matter of personal style, I'd do it for even one field, and optimize if
it proved too slow.
Cheers,
Ben Liddicott
------------------------------
Date: Thu, 20 Nov 2003 13:22:08 GMT
From: "Bob Van Der Ploeg" <bob@vdpcorp.com>
Subject: Sorting an array
Message-Id: <4e3vb.18616$KI4.16851@twister.tampabay.rr.com>
How can I get perl to sort an array based on the second value inthe array?
example
@array=(201,1,635,4,987,3,407,2);
^ ^ ^ ^
Result I want is (201,1,407,2,987,3,635,4);
Would this be easier to sort if it were a multi-demsional array?
@array=([201,1],[635,4],[987,3],[407,2])
If so how do I sort a multi-demensional array?
Thanks,
Bob
------------------------------
Date: Thu, 20 Nov 2003 13:51:30 +0000 (UTC)
From: Andreas Kahari <ak+usenet@freeshell.org>
Subject: Re: Sorting an array
Message-Id: <slrnbrphn1.4eo.ak+usenet@otaku.freeshell.org>
In article <4e3vb.18616$KI4.16851@twister.tampabay.rr.com>, Bob Van Der Ploeg wrote:
> How can I get perl to sort an array based on the second value inthe array?
> example
>
> @array=(201,1,635,4,987,3,407,2);
> ^ ^ ^ ^
>
> Result I want is (201,1,407,2,987,3,635,4);
>
> Would this be easier to sort if it were a multi-demsional array?
>
> @array=([201,1],[635,4],[987,3],[407,2])
Yes it would be. If they are to be kept in pairs, then keep
them in pairs.
> If so how do I sort a multi-demensional array?
my @sorted = sort { $a->[1] <=> $b->[1] } @array;
Swap $a and $b if you want them sorted in the oher direction.
Replace [1] with [0] if you want to sort on the first value of
each pair.
Read the documentation about the sort function.
--
Andreas Kähäri
------------------------------
Date: Thu, 20 Nov 2003 14:00:13 GMT
From: Sean O'Dwyer <notspam@spamfree.dud>
Subject: Re: Sorting an array
Message-Id: <notspam-F4CDDB.09001420112003@nycmny-nntp-rdr-03-ge0.rdc-nyc.rr.com>
In article <4e3vb.18616$KI4.16851@twister.tampabay.rr.com>,
"Bob Van Der Ploeg" <bob@vdpcorp.com> wrote:
> How can I get perl to sort an array based on the second value inthe array?
> example
> @array=(201,1,635,4,987,3,407,2);
> Result I want is (201,1,407,2,987,3,635,4);
How about splitting the array's two parts into a hash...
$hashname{$secondnumber} = $firstnumber;
@sorted = sort(keys(%hashname));
foreach $num (@sorted) {print $num." = ".$hashname{$num};}
...this would work if you only had one occurrence of each second number
in @array. There's probably a more efficient way, but that's what occurs
to me at my level of skill.
Sean
------------------------------
Date: Thu, 20 Nov 2003 06:29:12 -0600
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: test please ignore
Message-Id: <Xns94394C4BBA466sdn.comcast@216.196.97.136>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Default@User011011101101.xyz wrote in news:9_Uub.37471$hB5.6243
@nwrdny02.gnilink.net:
> posts not showing up.. is nntp usually slow like this?
>
It varies based on your server.
For your information, there are test groups (eg alt.test) which exist for
the sole purpose of being a place where you can post test messages. I
suggest you continue your testing there, rather than any specific non-test
newsgroup.
- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBP7yzxmPeouIeTNHoEQIaEACg41OmP4ntt46G4nfBH7LkCWY/qjoAn04d
rtk4/jJmfbZdbg7V0hzGmm5F
=SgTf
-----END PGP SIGNATURE-----
------------------------------
Date: 20 Nov 2003 13:40:41 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: test please ignore
Message-Id: <slrnbrph2p.772.abigail@alexandra.abigail.nl>
Default@User011011101101.net (Default@User011011101101.net) wrote on
MMMDCCXXXIII September MCMXCIII in <URL:news:8NWub.37848$hB5.1619@nwrdny02.gnilink.net>:
`` shrug, dont be a douchebag.
*PLONK*
Abigail
--
:$:=~s:$":Just$&another$&:;$:=~s:
:Perl$"Hacker$&:;chop$:;print$:#:
------------------------------
Date: 19 Nov 2003 22:47:18 -0800
From: junk@dlink.org (Aqua)
Subject: Re: trying to grep a $line for $line...any ideas?
Message-Id: <55d7995c.0311192247.670e3659@posting.google.com>
sholden@flexal.cs.usyd.edu.au (Sam Holden) wrote in message > foreach my $line1 (<INPUT>) {
> my $boolean_found = 0;
> foreach my $line2 (@needles) {
> if (index($line1, $line2) != -1) {
> $boolean_found = 1;
> }
> }
> if ($boolean_found == 0) {
> # do some stuff with $line1
> }
> }
>
> close INPUT;
>
> The only "tricky" bit how to express L2 in L1, using index seems reasonable
> to me, though you could also use a regex.
In the above exampe you can further simpilify/remove the second loop
with "grep" function.
REgards
Dominic
Perl Consulting http://www.dlink.org/perl
------------------------------
Date: Thu, 20 Nov 2003 08:25:04 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: trying to grep a $line for $line...any ideas?
Message-Id: <pan.2003.11.20.07.11.31.788026@aursand.no>
On Thu, 20 Nov 2003 03:02:42 +0000, Joshua Sparks wrote:
> for each line L1 in INPUT
> boolean_found <- false
> for each line L2 in INPUT2
> if L2 in L1
> boolean_found <- true
> endif
> end
> end
Better yet, read the contents of INPUT2 into an array, and then grep for
each line of INPUT;
while my $line ( <INPUT> ) {
my @matches = grep { $line =~ m,$_, } @input2;
}
--
Tore Aursand <tore@aursand.no>
------------------------------
Date: 20 Nov 2003 10:42:30 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: trying to grep a $line for $line...any ideas?
Message-Id: <slrnbrp6km.ndj.sholden@flexal.cs.usyd.edu.au>
On 19 Nov 2003 22:47:18 -0800, Aqua <junk@dlink.org> wrote:
> sholden@flexal.cs.usyd.edu.au (Sam Holden) wrote in message > foreach my $line1 (<INPUT>) {
>> my $boolean_found = 0;
>> foreach my $line2 (@needles) {
>> if (index($line1, $line2) != -1) {
>> $boolean_found = 1;
>> }
>> }
>> if ($boolean_found == 0) {
>> # do some stuff with $line1
>> }
>> }
>>
>> close INPUT;
>>
>> The only "tricky" bit how to express L2 in L1, using index seems reasonable
>> to me, though you could also use a regex.
>
> In the above exampe you can further simpilify/remove the second loop
> with "grep" function.
It could be, but I was following the pseudo code line for line.
And when I did optimise further down, I added a last, which I prefer
over grep since it stops searching as soon as a match is found instead
of doing a bunch of useless comparisons.
Of course I introduced grep at the very end, anyway.
--
Sam Holden
------------------------------
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 5834
***************************************