[25494] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7738 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 4 18:05:40 2005

Date: Fri, 4 Feb 2005 15:05:14 -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           Fri, 4 Feb 2005     Volume: 10 Number: 7738

Today's topics:
    Re: "Best" Practices (WAS: Equality of hashref objects) <shawn.corey@sympatico.ca>
    Re: [perl-python] get web page programatically <matternc@comcast.net>
    Re: [perl-python] get web page programatically <noreply@gunnar.cc>
    Re: a very bad question (and getting OT) <dha@panix.com>
    Re: a very bad question (and getting OT) <cavac@grumpfzotz.org>
    Re: Array reference not consistently interpolating <evillen@innocent.com>
        Can't get perl to find .pm in my own private directory <m_p_v_13@yahoo.com>
        Can't use an undefined value as a HASH reference <nospam@sbcglobal.net>
    Re: Can't use an undefined value as a HASH reference <nospam@sbcglobal.net>
    Re: Equality of hashref objects <please_post@nomail.edu>
    Re: Equality of hashref objects <please_post@nomail.edu>
        Foreign characters in filenames, revisited <szpara_ga@tlen.pl>
    Re: Foreign characters in filenames, revisited <shawn.corey@sympatico.ca>
    Re: Free perl obfuscation service <cavac@grumpfzotz.org>
    Re: Google Groups posters, please read <mjl69mjl69@myaccmyacc.net>
    Re: in line editing <perl@my-header.org>
        perl style: can I combine two steps into one? <miknrene@drizzle.com>
    Re: perl style: can I combine two steps into one? <mritty@gmail.com>
    Re: perl style: can I combine two steps into one? <postmaster@castleamber.com>
    Re: perl style: can I combine two steps into one? <mjl69mjl69@myaccmyacc.net>
    Re: perl style: can I combine two steps into one? <miknrene@drizzle.com>
    Re: perl style: can I combine two steps into one? <postmaster@castleamber.com>
    Re: Problem serving a PDF <cavac@grumpfzotz.org>
        ran into previously declared variables with Inline::C <tom.coceano@ulticom.com>
    Re: Regular expression woes <gwagner@agricoreunited.com>
    Re: Regular expression woes (News)
    Re: Regular expression woes (IFR LIT MET\)
    Re: Regular expression woes <exjxw.hannivoort@interxnl.net>
    Re: why the variable become local? <1usa@llenroc.ude.invalid>
    Re: why the variable become local? <news@chaos-net.de>
    Re: why the variable become local? <1usa@llenroc.ude.invalid>
    Re: www::mechanize $mech->select <mritty@gmail.com>
    Re: XML & Perl - Error codefixer@gmail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 04 Feb 2005 15:36:27 -0500
From: Shawn Corey <shawn.corey@sympatico.ca>
Subject: Re: "Best" Practices (WAS: Equality of hashref objects)
Message-Id: <T0RMd.4478$lw4.935367@news20.bellglobal.com>

bill wrote:
 ...
> 
> BEGIN {                         # private subs
                                     ^^^^^^^
What on Earth for? If these subs are useful inside the file, they are 
useful outside the file. Stop reading books on programming and hack more 
Perl.

    --- Shawn


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

Date: Fri, 04 Feb 2005 16:39:24 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: [perl-python] get web page programatically
Message-Id: <AKidnUp1n6ATdp7fRVn-jA@comcast.com>

Xah Lee wrote:

<snip>

Just the standard warnings for any novices unfamiliar with Mr. Lee.
Mr. Lee's posts are regularly riddled with severe errors (I found
the assertion that LWP::Simple and LWP::UserAgent aren't part of
the standard base perl install a particularly amusing one in this 
particular post).  Please be advised that you should get your
perl information from accurate sources.  http://learn.perl.org
is an excellent place to start, with pointers to excellent Perl
books and even some readable for free online (notably Beginning
Perl).
-- 
             Christopher Mattern

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


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

Date: Fri, 04 Feb 2005 22:41:29 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: [perl-python] get web page programatically
Message-Id: <36i90rF50rp9lU1@individual.net>

Chris Mattern wrote:
> Just the standard warnings for any novices unfamiliar with Mr. Lee. 
> Mr. Lee's posts are regularly riddled with severe errors

Concur.

> (I found the assertion that LWP::Simple and LWP::UserAgent aren't
> part of the standard base perl install a particularly amusing one in
> this particular post).

I'm not sure about that, though. I thought that libwww-perl was not a
core package.

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


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

Date: Fri, 4 Feb 2005 20:13:41 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: a very bad question (and getting OT)
Message-Id: <slrnd07lrl.leu.dha@panix2.panix.com>

On 2005-02-03, Chris Mattern <matternc@comcast.net> wrote:
> Well, yes, that's what an oxymoron is, you know.
> Like "Large medium", "jumbo shrimp", or "military
> intelligence".

I've always been fond of "postal service".

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
In the silence that followed, Homer was heard to mutter,
"Mmmm... context- dependent semantics..."
	- Darrin Edwards in c.l.p.m.


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

Date: Fri, 04 Feb 2005 23:25:06 +0100
From: Rene Schickbauer <cavac@grumpfzotz.org>
Subject: Re: a very bad question (and getting OT)
Message-Id: <4902339.ekg9MuZB9R@gandalf.grumpfzotz.org>

David H. Adler wrote:

> On 2005-02-03, Chris Mattern <matternc@comcast.net> wrote:
>> Well, yes, that's what an oxymoron is, you know.
>> Like "Large medium", "jumbo shrimp", or "military
>> intelligence".
> 
> I've always been fond of "postal service".

I favour "trusted computing"...

LLAP & LG
Rene


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

Date: 4 Feb 2005 12:54:39 -0800
From: "evillen@innocent.com" <evillen@innocent.com>
Subject: Re: Array reference not consistently interpolating
Message-Id: <1107550479.190379.245880@f14g2000cwb.googlegroups.com>


A. Sinan Unur wrote:
> "evillen@innocent.com" <evillen@innocent.com> wrote in
> news:1107540162.829506.302140@z14g2000cwz.googlegroups.com:
>
> > Hi
> >
> > I am trying to pass an array reference to a subroutine but get the
> > error:
> >
> > "Not an ARRAY reference at array_ref_test.txt line 14."
> >
> > I have slimmed down my code so don't worry about why I'm using an
> > array reference. The reference is getting correctly interpolated at
> > some point as line 12 reports:
> >
> > "$key is: CONN_UMP_3MM_SMT"
> >
> > Thanks for any ideas!
> > Len
> >
> > ## Please remove line numbers!
>
> Yeah, thanks ... And with an exclamation point at the end. There is
no
> point in posting line numbers. It makes it harder than necessary to
copy
> and paste your code in an editor.
>
> If you want to draw our attention to a line, you can put a comment
> _above_ it (not in the right margin, because those comments have an
> annoying tendency to run off the end of the line).
>
> > ###########
> > 1 #! perl -w
>
> use warnings;
>
> is better because it allows you to selectively disable warnings.
>
> > 2 use strict;
> >
> > 4 my (%symbols_and_data, $key);
>
> Always declare your vairables in the smallest applicable scope. What
is
> $key doing here? What is %symbols_and_data doing here? You only use
them
> in the body of the sub.
>
> > 5 my @symbol_data = ("CONN_UMP_3MM_SMT", "sym.req:0554",
> > "lib.name:conn_ump_3mm_smt", "height:3.00mm",
"used:01ATiss1/Whitney
> > RF", "rev:2,NJH,26/05/04");
>
> Properly formatting your code would give you an advantage when you
are
> asking for others' help. It is like saying "I respect your time". Not

> properly formatting your code is then tantamount to spitting in the
faces
> of the people whose help you are asking. Just thought I would point
that
> out.
>
> > 7 &hash_sym(@symbol_data, $key);
> >
> > 9 sub hash_sym{
> > 10     $symbols_and_data{$_[0]} = \@_[0]; #create new Hash key
> > "reference" 11     foreach $key (keys %symbols_and_data){
>
> See what I meen by comments wrapping?
>
> I do not know what 'create new Hash Key "reference"' means. It seems
like
> what you are trying to do is to insert a key into %symbols_and_data
hash
> whose value is a reference to a hash formed using the elements of
> @symbol_data. I have come up with something based on that
interpretation.
>
> > 12          print "\$key is: $key\n"
> > 13          };
> > 14     print "Elements in this hash key are: ".join(', ',
> > @{$symbols_and_data{$_[0]}})."\n";
>
> I am speechless in the face of this join call. Is there any reason
why
> you don't use Data::Dumper?
>
> C:\Documents> cat s__t.pl
> #! perl
>
> use strict;
> use warnings;
>
> use Data::Dumper;
>
> my @symbol_data = (
>      'CONN_UMP_3MM_SMT',
>      'sym.req:0554',
>      'lib.name:conn_ump_3mm_smt',
>      'height:3.00mm',
>      'used:01ATiss1/WhitneyRF',
>      'rev:2,NJH,26/05/04',
> );
>
>
> my %symbols_and_data;
>
> print Dumper hash_sym(\%symbols_and_data, @symbol_data);
>
> sub hash_sym {
>     my $h = shift;
>     $h->{$_[0]} = { @_ };
> }
>
> __END__
>
> C:\Documents> perl s__t.pl
> $VAR1 = {
>           'used:01ATiss1/WhitneyRF' => 'rev:2,NJH,26/05/04',
>           'CONN_UMP_3MM_SMT' => 'sym.req:0554',
>           'lib.name:conn_ump_3mm_smt' => 'height:3.00mm'
>         };
>
> Sinan

Hi Sinan

I would like to thank you both for your excellent advice - which I
shall shortly investigate, and also for the great pleasure it gave me
to read you venting your spleen upon me.

I guess I should have added that this is my first Perl prog, indeed it
is my first programming at all in the last five years... be patient
with the newbs ;-)

Thanks
Len



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

Date: 4 Feb 2005 14:06:21 -0800
From: "m_p_v_13" <m_p_v_13@yahoo.com>
Subject: Can't get perl to find .pm in my own private directory
Message-Id: <1107554781.556485.186710@f14g2000cwb.googlegroups.com>

How do I add to the search paths for .pm modules in my local
environment?

I am running on AIX with perl5 (revision 5.0 version 6 subversion 0)
I have some perl programs and .pm modules installed in my own private
directories (not in /usr/opt/perl5/....).  I have one perl program
calling a second perl program which requires the private modules. I
don't want to change the code in either of these programs, but want the
private modules found.

Useing the perl -I<path> option on starting the first doesent seem to
pass this environment to the second perl program.

I tried setting PERL5PATH, PERLPATH, PERL5LIB, PERLLIB without success.
The documentation seems to indicate that one of these should work.

Putting the modules in ./ does work (./ is in @INC) but I wanted to
locate the modules in a different place.

*** I just tried one more thing, before sending this post, and it seems
to work so far.  Setting PERL5OPT=-I<myprivatepath> does seem to work!

Is this the best I can do.  Any gotchas.

Thanks in advance,
Michael



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

Date: Fri, 04 Feb 2005 21:54:49 GMT
From: Josh McAdams <nospam@sbcglobal.net>
Subject: Can't use an undefined value as a HASH reference
Message-Id: <JaSMd.18067$2e7.14457@newssvr12.news.prodigy.com>

In the example below, I am using Data::Dumper to print the data 
structure for the hash, %h, and then using eval to process the data 
structure back into a hash-reference that I dereference into a hash and 
print the keys.

This first example works fine:

<code>
perl -MData::Dumper -e 'print join "\n", keys %{eval(`perl 
-MData::Dumper -e "print Dumper(\\\%h)"`)}'
</code>

This second example, with the strict pragma turned on causes and error 
message "Can't use an undefined value as a HASH reference"

<code type="broken">
perl -MData::Dumper -e 'print join "\n", keys %{eval(`perl 
-MData::Dumper -Mstrict -e "print Dumper(\\\%h)"`)}'
</code>

In reality, this section of code is part of a larger script and to 
suppress the error, I use "no strict 'vars'" in the block of code that 
creates the hash.  However, I don't like doing that.  Is there a way to 
have this code work with strict?

Thanks,
Josh



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

Date: Fri, 04 Feb 2005 21:56:57 GMT
From: Josh McAdams <nospam@sbcglobal.net>
Subject: Re: Can't use an undefined value as a HASH reference
Message-Id: <4203EFA9.9070605@sbcglobal.net>

Josh McAdams wrote:

> In the example below, I am using Data::Dumper to print the data 
> structure for the hash, %h, and then using eval to process the data 
> structure back into a hash-reference that I dereference into a hash and 
> print the keys.
> 
> This first example works fine:
> 
> <code>
> perl -MData::Dumper -e 'print join "\n", keys %{eval(`perl 
> -MData::Dumper -e "print Dumper(\\\%h)"`)}'
> </code>
> 
> This second example, with the strict pragma turned on causes and error 
> message "Can't use an undefined value as a HASH reference"
> 
> <code type="broken">
> perl -MData::Dumper -e 'print join "\n", keys %{eval(`perl 
> -MData::Dumper -Mstrict -e "print Dumper(\\\%h)"`)}'
> </code>
> 
> In reality, this section of code is part of a larger script and to 
> suppress the error, I use "no strict 'vars'" in the block of code that 
> creates the hash.  However, I don't like doing that.  Is there a way to 
> have this code work with strict?
> 
> Thanks,
> Josh
> 

Oops, the second code block really was broken, try this instead:

<code type="broken">
perl -MData::Dumper -Mstrict -e 'print join "\n", keys %{eval(`perl 
-MData::Dumper -e "print Dumper(\\\%h)"`)}'
</code>


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

Date: Fri, 4 Feb 2005 21:44:50 +0000 (UTC)
From: bill <please_post@nomail.edu>
Subject: Re: Equality of hashref objects
Message-Id: <cu0qch$l0m$1@reader2.panix.com>

In <1107543811.374991.63530@l41g2000cwc.googlegroups.com> "nobull@mail.com" <nobull@mail.com> writes:

>bill wrote:

>> I have a class that is implemented as a hashref, and furthermore,
>> the values for the corresponding hash are always scalars.  I want
>> a sub to test for equality between any two instances of this class,
>> defined roughly as "two instances $x and $y are equal if $x->{
>> $field } and $y->{ $field } are equal for all instance fields
>> $field".  I took a crack at this function, but it is so *ugly* that
>> I'm sure there must be a better way.  I give my version below for
>> your mocking pleasure.  Any pointers to a better implementation
>> would be much appreciated.

>Data::Compare

>>       if (2 == grep $_is_numeric($_), @vals) {
>>         return 0 unless $vals[0] == $vals[1];
>>       }
>>       else {
>>         return 0 unless $vals[0] eq $vals[1];
>>       }

>>   $_is_numeric = sub {
>>     use warnings 'all', FATAL => 'numeric';
>>     return defined eval { $_[0] == 0 };
>>   };

>This has the effect of treating the strings '0' and '0000000000' as the
>same.  Is that what you wanted?

Yes, that was the intent.

>What you you percieve as the problem
>if you just use eq all the time?


In this application it is far more likely for a "numeric" field to
hold, say, '1.0' in one instance and '1.00' in another, than it is
for a "string" field to hold a value for which $_is_numeric would
return true.  In fact, I am debating whether to change

         return 0 unless $vals[0] == $vals[1];

to

         return 0 unless abs($vals[0], $vals[1]) < $EPSILON;

for some tiny $EPSILON.

bill


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

Date: Fri, 4 Feb 2005 21:45:44 +0000 (UTC)
From: bill <please_post@nomail.edu>
Subject: Re: Equality of hashref objects
Message-Id: <cu0qe8$l0m$2@reader2.panix.com>




Thanks for the suggestions!

bill


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

Date: 4 Feb 2005 12:17:29 -0800
From: "P" <szpara_ga@tlen.pl>
Subject: Foreign characters in filenames, revisited
Message-Id: <1107548249.510212.161740@z14g2000cwz.googlegroups.com>

Hi,

  Thanks to your help I have learned how to open files which have
filenames containing foreign characters (like umlauts). I now have
a different, although slightly related problem. I am reading text
from a file. This file is a list of other files, each of which I have
to open for reading. I do something like this:

while (<>) {
  # $_ contains one filename
  chomp;

  open ( IN, $_ ) or die $!;

  # do stuff with the opened file
  close(IN);
}


This is fine as long as the filename to be opened doesn't contain
foreign characters. It doesn't open such files. For example, if $_
is


"Todo El Ano.log"

then the open() will fail even though the file clearly exists. It has
no problems whatsoever with any filenames containing "normal"
characters.

Is there any way to properly open these kinds of files when getting
their names from a text file?

-- 
Thank you,
Jenny



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

Date: Fri, 04 Feb 2005 15:43:00 -0500
From: Shawn Corey <shawn.corey@sympatico.ca>
Subject: Re: Foreign characters in filenames, revisited
Message-Id: <97RMd.4481$lw4.936399@news20.bellglobal.com>

P wrote:
> Hi,
> 
>   Thanks to your help I have learned how to open files which have
> filenames containing foreign characters (like umlauts). I now have
> a different, although slightly related problem. I am reading text
> from a file. This file is a list of other files, each of which I have
> to open for reading. I do something like this:
> 
> while (<>) {
>   # $_ contains one filename
>   chomp;
> 
>   open ( IN, $_ ) or die $!;
> 
>   # do stuff with the opened file
>   close(IN);
> }
> 
> 
> This is fine as long as the filename to be opened doesn't contain
> foreign characters. It doesn't open such files. For example, if $_
> is
> 
> 
> "Todo El Ano.log"
> 
> then the open() will fail even though the file clearly exists. It has
> no problems whatsoever with any filenames containing "normal"
> characters.
> 
> Is there any way to properly open these kinds of files when getting
> their names from a text file?
> 

Your problem is not with the filename but in the way it is read. You 
have to change the way STDIN is read. Since I don't know what system 
you're using I can tell exactly what is needed but if the filenames were 
in UTF-8, then before the 'while(<>)...' use:

binmode(STDIN,':utf8');
while(<>) {
 ...


    --- Shawn


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

Date: Fri, 04 Feb 2005 23:11:55 +0100
From: Rene Schickbauer <cavac@grumpfzotz.org>
Subject: Re: Free perl obfuscation service
Message-Id: <1147000.MLuG2v1EOG@gandalf.grumpfzotz.org>

Liraz.Siri@gmail.com wrote:

> Perl readability keeping you up at night? Worried someone else might
> one day understand your spaghetti code? Say no more! Your job security
> woes are over!

Nice try, but all i get is
---
#!/usr/bin/perl
while(<>){tr/A-Za-z/n-za-mN-ZA-M/;print;}
---

from
---
#!/usr/bin/perl

while (<>)
{
    tr/A-Za-z/n-za-mN-ZA-M/;
    print;
}
---

Ok, maybe it'll do better on longer programs, so let's try to obfuscate a
more complicated one:

---
#!/usr/bin/perl

use strict;
use warnings;

{
    # Generate MD5 sums

    print "Generating MD5-Sums\n";

    my @flist = `ls *.php4 *.dx1 *.tmpl`;

    open(my $ofile, ">", "md5.crc") or die("Can't open md5.crc for
writing");

    foreach my $fname (@flist) {
        chomp $fname;
        next if($fname =~ /md5.crc/);
        my $sum = `md5sum $fname`;
        chomp $sum;
        my @parts = split(" ", $sum);
        $sum = $parts[0];
        print "$fname|$sum\n";
        print $ofile "$fname|$sum\n" or die("Can't write to md5.crc");
    }

    close $ofile or die("Can't close md5.crc after write");
}
---

and i get 

---
#!/usr/bin/perl
use strict;use warnings;{print
"\x47\x65\x6e\x65\x72\x61\x74\x69\x6e\x67\x20\x4d\x44\x35\x2d\x53\x75\x6d\x73\x0a";my
@OO=`ls *.php4 *.dx1 *.tmpl`;open(my
$OO000,"\x3e","\x6d\x64\x35\x2e\x63\x72\x63")or
die("\x43\x61\x6e\x27\x74\x20\x6f\x70\x65\x6e\x20\x6d\x64\x35\x2e\x63\x72\x63\x20\x66\x6f\x72\x20\x77\x72\x69\x74\x69\x6e\x67");foreach
my $OO0(@OO){chomp $OO0;next if($OO0=~ /md5.crc/);my $OO0O0=`md5sum
$OO0`;chomp $OO0O0;my @OO00O=split("\x20",$OO0O0);$OO0O0=$OO00O[0];print
"$OO0\x7c$OO0O0\x0a";print $OO000 "$OO0\x7c$OO0O0\x0a" or
die("\x43\x61\x6e\x27\x74\x20\x77\x72\x69\x74\x65\x20\x74\x6f\x20\x6d\x64\x35\x2e\x63\x72\x63");}close
$OO000 or
die("\x43\x61\x6e\x27\x74\x20\x63\x6c\x6f\x73\x65\x20\x6d\x64\x35\x2e\x63\x72\x63\x20\x61\x66\x74\x65\x72\x20\x77\x72\x69\x74\x65");}
---
(Above example may be broken by my newsclient)

And it's still running (although i haven't checked the resulting file).

Of course, the "damage" the obfuscater made seems to be reversible without 
too much effort - lacking of course comments after reversing the
obfuscation...

You might also work a bit on interchanging hex-code with octal and unchanged
ascii.

Of course, obfuscation is nice. But the *real* art of writing code no-one
can re-use is documented here:
<http://mindprod.com/unmain.html> "How to write unmaintainable code"

LLAP & LG
Rene


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

Date: 4 Feb 2005 19:37:18 GMT
From: mjl69 <mjl69mjl69@myaccmyacc.net>
Subject: Re: Google Groups posters, please read
Message-Id: <36i17eF50aqdhU1@individual.net>



> I tried a current version of rn but found it to be a little complex,
> like learning vi from scratch.  I tried writing my own Perl solution,
> which was great at reading the new posts as they came in, but I found
> that writing a decent interface for following threads was too much for
> me.
> 
> Thanks for any suggestions.
> 
> wana

I wrote a fairly simple set of scripts that use Net:NNTP to post my message.  If I am replying, I cut and past from Google.
Do 'Show Options' and then 'Show Original' and cut & paste the message to file 'in.news'.  Then this script to format:

#!c:/perl/bin/perl.exe

use strict;
use warnings;

my ($mid, $ref, $ng, $sub) = ('','','','');
my @bod;
open my $in, '<', './in.news';
my $fr = 'mjl69 <mjl69mjl69@myaccmyacc.net>';
while (<$in>)
{
	if (/^message.*?id:\s*(.*)/i) {$mid = $1}
	if (/^references:\s*(.*)/i) {$ref = $1}
	if (/^newsgroups:\s*(.*)/i) {$ng = $1}
	if (/^subject:\s*(.*)/i) {$sub = $1}
	#if (not /^\S+:\s*.*/i) {push @bod, $_}
	last if /^\s*$/;
}
push @bod, $_ while (<$in>);
close $in;
if ($mid)
{
	if ($sub !~ /re:/i) {$sub = 'Re: '.$sub}
	$ref = $ref.' '.$mid;
	s/^(.*)/> $1/ for @bod;
}
unshift @bod, "References: $ref\n\n\n";
unshift @bod, "Subject: $sub\n";
unshift @bod, "Newsgroups: $ng\n";
unshift @bod, "From: $fr\n";
die "error: no subject" if not $sub;
open $in, '>', './in.news';
print $in $_ for @bod;

and then this script to send after editing 'in.news' with my response:

#!c:/perl/bin/perl.exe

use strict;
use warnings;
use Net::NNTP;

my $nntp = Net::NNTP->new("your.news.server");
$nntp->authinfo ( 'xxxx','xxxx'); 
my ($mid, $ref, $ng, $sub) = ('','','','');
my @bod;
open my $in, '<', './in.news';
my @out = <$in>;
print "success!\n" if $nntp->post(@out);

$nntp->quit;

I'm sure there are a million better ways to do it, but it works for me.

mjl


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

Date: Fri, 04 Feb 2005 20:32:03 +0100
From: Matija Papec <perl@my-header.org>
Subject: Re: in line editing
Message-Id: <aaj701t1jg0v73pael5hrc0453fh8216jl@4ax.com>

X-Ftn-To: Eric Schwartz 

Eric Schwartz <emschwar@fc.hp.com> wrote:
>I've never inveigled against reading the FAQ, and the answer is a
>correct one, to be sure, but it's inadequate, if you ask me (nobody
>did).  

True.


-- 
Matija


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

Date: Fri, 04 Feb 2005 11:21:05 -0800
From: Michael Slass <miknrene@drizzle.com>
Subject: perl style: can I combine two steps into one?
Message-Id: <m3is582kta.fsf@eric.rossnet.com>

I have a hash where the keys are strings and the values are integers.
I wanted to produce a report of the name/value pairs, sorted by the
integers in descending order.

I came up with this:

,----
| #!/usr/bin/perl -w
| use strict;
| 
| my %hack_count;
| my @report;
|
| # read in ssh attempts from /var/log/messages*
| while (<>)
|   {
|     if (/sshd.+rhost=(\S+)/)
|       {
|         ++$hack_count{$1};
|       }
|   }
|
| # create a list of (count, ip) cells, sorted by count 
| my ($ip, $count);
| while (($ip, $count) = each %hack_count)
|   {
|     push @report, [$count, $ip];
|   }
| 
| foreach (sort { $b->[0] <=> $a->[0]; } @report) {
|      printf("%-50s\t%4d\n", $_->[1], $_->[0]);
|     }
`----

Is there a way to combine the "each" and "push" statements so I don't
need the intermediate variables $ip and $count?  The order of the
variables in the anonymous lists is not important; I just put the
numerical value first since I figured I'd remember to sort on the
first element of the anonymous lists.

Thanks.

-- 
Mike Slass


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

Date: Fri, 04 Feb 2005 19:31:24 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: perl style: can I combine two steps into one?
Message-Id: <g4QMd.6109$ya6.1689@trndny01>

"Michael Slass" <miknrene@drizzle.com> wrote in message
news:m3is582kta.fsf@eric.rossnet.com...
> I have a hash where the keys are strings and the values are integers.
> I wanted to produce a report of the name/value pairs, sorted by the
> integers in descending order.
>
> I came up with this:
<snip>
> | # create a list of (count, ip) cells, sorted by count
> | my ($ip, $count);
> | while (($ip, $count) = each %hack_count)
> |   {
> |     push @report, [$count, $ip];
> |   }
<snip>

> Is there a way to combine the "each" and "push" statements so I don't
> need the intermediate variables $ip and $count?

my @report = map {[$hack_count{$_}, $_]} keys %hack_count;
# OR . . .
my @report;
push @report, [$hack_count{$_}, $_] for keys %hack_count;

Of course, these are both still using an intermediate variable of $_.
That may or may not be 'good enough' for you.

Paul Lalli



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

Date: 4 Feb 2005 19:32:40 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: perl style: can I combine two steps into one?
Message-Id: <Xns95F389C846DCCcastleamber@130.133.1.4>

Michael Slass wrote:

> I have a hash where the keys are strings and the values are integers.
> I wanted to produce a report of the name/value pairs, sorted by the
> integers in descending order.
> 
> I came up with this:
> 
> ,----
>| #!/usr/bin/perl -w

drop the -w and

use warnings;

>| # read in ssh attempts from /var/log/messages*
>| while (<>)
>|   {
>|     if (/sshd.+rhost=(\S+)/)
>|       {
>|         ++$hack_count{$1};

I recommend using $hack_count{$1}++;

[ sorting ]

printf "%-50s\t%4d\n", $_, $hack_count{ $_ }
    for sort { $hack_count{ $b }<=>$hack_count{ $a } } keys %hack_count;


-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


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

Date: 4 Feb 2005 20:07:53 GMT
From: mjl69 <mjl69mjl69@myaccmyacc.net>
Subject: Re: perl style: can I combine two steps into one?
Message-Id: <36i30pF51ruunU1@individual.net>


> I have a hash where the keys are strings and the values are integers.
> I wanted to produce a report of the name/value pairs, sorted by the
> integers in descending order.
> 
> I came up with this:
> 
> ,----
> | #!/usr/bin/perl -w
> | use strict;
> | 
> | my %hack_count;
> | my @report;
> |
> | # read in ssh attempts from /var/log/messages*
> | while (<>)
> |   {
> |     if (/sshd.+rhost=(\S+)/)
> |       {
> |         ++$hack_count{$1};
> |       }
> |   }
> |
> | # create a list of (count, ip) cells, sorted by count 
> | my ($ip, $count);
> | while (($ip, $count) = each %hack_count)
> |   {
> |     push @report, [$count, $ip];
> |   }
> | 
> | foreach (sort { $b->[0] <=> $a->[0]; } @report) {
> |      printf("%-50s\t%4d\n", $_->[1], $_->[0]);
> |     }
> `----
> 
> Is there a way to combine the "each" and "push" statements so I don't
> need the intermediate variables $ip and $count?  The order of the
> variables in the anonymous lists is not important; I just put the
> numerical value first since I figured I'd remember to sort on the
> first element of the anonymous lists.
> 
> Thanks.
> 
> -- 
> Mike Slass
> 
> 

@report = map {[$_->[1], $_->[0]]}sort {$b->[0] <=> $a->[0]} map {[$hack_count{$_}, $_]} keys %hack_count;



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

Date: Fri, 04 Feb 2005 13:09:37 -0800
From: Michael Slass <miknrene@drizzle.com>
Subject: Re: perl style: can I combine two steps into one?
Message-Id: <m3ekfw2fse.fsf@eric.rossnet.com>

"Paul Lalli" <mritty@gmail.com> writes:

>"Michael Slass" <miknrene@drizzle.com> wrote in message
>news:m3is582kta.fsf@eric.rossnet.com...
>> I have a hash where the keys are strings and the values are integers.
>> I wanted to produce a report of the name/value pairs, sorted by the
>> integers in descending order.
>>
>> I came up with this:
><snip>
>> | # create a list of (count, ip) cells, sorted by count
>> | my ($ip, $count);
>> | while (($ip, $count) = each %hack_count)
>> |   {
>> |     push @report, [$count, $ip];
>> |   }
><snip>
>
>> Is there a way to combine the "each" and "push" statements so I don't
>> need the intermediate variables $ip and $count?
>
>my @report = map {[$hack_count{$_}, $_]} keys %hack_count;
># OR . . .
>my @report;
>push @report, [$hack_count{$_}, $_] for keys %hack_count;
>
>Of course, these are both still using an intermediate variable of $_.
>That may or may not be 'good enough' for you.
>
>Paul Lalli
>

Ahh.. didn't know about map.  That's perfect, thank you.  I'll read
the docs about it.

-- 
Mike Slass


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

Date: 4 Feb 2005 21:52:50 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: perl style: can I combine two steps into one?
Message-Id: <Xns95F3A18B2FD51castleamber@130.133.1.4>

mjl69 wrote:

[ snip ]

my @report =

    map { [ $_->[ 1 ], $_->[ 0 ] ] }
    sort { $b->[ 0 ] <=> $a->[ 0 ] }
    map { [ $hack_count{ $_ }, $_ ] }
    keys %hack_count; 

Amazing how things can become more readable by careful reformating :-D

-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


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

Date: Fri, 04 Feb 2005 22:46:27 +0100
From: Rene Schickbauer <cavac@grumpfzotz.org>
Subject: Re: Problem serving a PDF
Message-Id: <1955006.PLlTB0YvJ3@gandalf.grumpfzotz.org>

DMB wrote:

> I have a Perl script that serves a PDF on a Unix server and it works
> perfectly.  The same script on Windows is not working.  Can someone
> tell me what obvious mistake I'm overlooking?
> 
> #!c:/Perl/bin/Perl.exe
> 
> print "Cache-control: no-cache\n";
     ^^^^^^^^^^^^^^^^^^^^^

This does NOT work very well with IE (haven't really checked the rest of
your script because the above line will surely make trouble on IE6).

I had some problems with that, both serving from PHP and Perl.

The reason seems to be that IE downloads the file, deletes it from the Cache
and simultaniously calls Acroread.

The problem depends on client *and* server timing.

Here's the Header-generating code i used in a PHP project (converting it to
perl is up to the user):

---

// Send special headers
// See http://at.php.net/en/session_cache_limiter for details
//header("Pragma: no-cache"); <-- Bug in IE triggers deletion of temporary
// file before opening

header("Content-Type: application/pdf");
$pdfid = "$filename-$timestamp.pdf";
header("Content-Disposition: inline; filename=$pdfid");
//header("Accept-Ranges: bytes");
//header("Expires: 0");
//header("Cache-Control: private");

---

If left the comments in to show what is and what isn't working. Make sure
the filename always changes. I did this by adding a timestamp to the
filename.

LLAP & LG
Rene


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

Date: Fri, 04 Feb 2005 16:32:40 -0500
From: "sipreglab" <tom.coceano@ulticom.com>
Subject: ran into previously declared variables with Inline::C
Message-Id: <eb241391febd0ee2a0d59d81e4875f36@localhost.talkaboutprogramming.com>

I am learning the Inline::C module.  I am trying to use an external library
and I find that there are declarations in the header files for this library
that are also used in handy.h

In file included from /export/home/omni/include/architecture.h:14,
                 from /export/home/omni/include/Ft.h:77,
                 from useOmniFt_pl_2a86.xs:6:
/export/home/omni/include/arch_lnx.h:199: redefinition of `U8'
/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE/handy.h:131: `U8'
previously declared here
/export/home/omni/include/arch_lnx.h:201: redefinition of `U16'
/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE/handy.h:133: `U16'
previously declared here
/export/home/omni/include/arch_lnx.h:207: conflicting types for `U32'
/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE/handy.h:135: previous
declaration of `U32'

Now I realize these types (U8, U16, U32) appear in the
/usr/lib/perl5/5.8.0/ExtUtils/typemap file.

How can I resolve this?  I would rather not alter any of these files.  I
was hoping there was a way within Inline configuration, etc. I could do
this.

Any help would be appreciated!




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

Date: Fri, 04 Feb 2005 19:21:34 GMT
From: "Grant Wagner" <gwagner@agricoreunited.com>
Subject: Re: Regular expression woes
Message-Id: <2XPMd.177$3d3.762@news2.mts.net>

"Dietmar Meier" <usereplytoinstead@innoline-systemtechnik.de> wrote in 
message news:36hoasF52jhqlU1@individual.net...
> Rasto Levrinc wrote:
>
>>> What I'm really after is to contain the logic entirely within
>>> the regular expression.
>
>> You can do it with a zero-width negative look-ahead assertion in 
>> perl.
>>
>> $string=~/^(?!http)/
>
> Some JavaScript implementations implement regular expressions but
> don't implement look-ahead assertions. Here you would need
>
> /^([^h]ttp.*|h[^t]tp.*|ht[^t]p|htt[^p].*|.{0,3})$/.test(string)

Why do people insist on doing things the hardest way possible. Test for 
the condition you don't want, then negate it.

if (!/^http/i.test(some_string)) { ... }

By the way, this is pretty much the same solution already provided for 
Perl:

if ($some_string !~ /^http/) { ... }

(although I chose to make it case-insensitive, since the protocol in a 
URI isn't case-sensitive, it could be upper, lower or mixed case)

-- 
Grant Wagner <gwagner@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq 




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

Date: 4 Feb 2005 11:55:53 -0800
From: "Mark (News)" <news@mail.adsl4less.com>
Subject: Re: Regular expression woes
Message-Id: <1107546953.505390.30830@f14g2000cwb.googlegroups.com>

"Why do people insist on doing things the hardest way possible."? Well,
as I said in an earlier post, I wanted to do the whole thing within a
regex rather than resorting to the shell. Mainly because, crazy as it
sounds, it's a fun intellectual exercise. :-) And anyway, if I always
take the path of least resistance, I'll never learn, right? (But I
guess that's OT.)



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

Date: Fri, 4 Feb 2005 16:14:46 -0500
From: "Richards Noah \(IFR LIT MET\)" <Noah.Richards@infineon.com>
Subject: Re: Regular expression woes
Message-Id: <cu0ok7$snr$1@athen03.muc.infineon.com>

"Evertjan." <exjxw.hannivoort@interxnl.net> wrote in message
news:Xns95F3C5F131A46eejj99@194.109.133.29...
> Dietmar Meier wrote on 04 feb 2005 in comp.lang.javascript:
>
> > Evertjan. wrote:
> >
> >>> /^([^h]ttp.*|h[^t]tp.*|ht[^t]p|htt[^p].*|.{0,3})$/.test(string)
> >
> >> [The $ cannot be right, I think.]
> >
> > For what value of string do you think, the "$" would lead to the
> > wrong result?
>
> "xttp://" should return true
> "http://" should return false
>
> Yes, you are right here.
>
> >> r = /^(([^h]...)|(.[^t]..)|(..[^t].)|(...[^p]))/.test(s)
> >
> > This would not match strings with 3 or less characters.
>
> Yes, you are right again.
>
> Let me try:
>
> r = /^(([^h]...)|(.[^t]..)|(..[^t].)|(...[^p])|(.{0,3}$))/.test(s)
>
> [I could loose some () but I like them for clarity
>

None of those regular expressions will work.  For example, you regexp will
not match against "this string", since it differs in 4 places in the first 4
characters.

You cannot negate a string by negating each character.  If you really wanted
to do it in that way, you would have to negate all possible combinations of
letters in "http".  So, just for fun, it would look something like this
(newlines added for clarity):

/^(
    ([^h][^t][^t][^p])|

    (h[^t][^t][^p])|
    ([^h]t[^t][^p])|
    ([^h][^t]t[^p])|
    ([^h][^t][^t]p)|

    (ht[^t][^p])|
    (h[^t]t[^p])|
    (h[^t][^t]p)|
    ([^h]tt[^p])|
    ([^h]t[^t]p)|
    ([^h][^t]tp)|

    (htt[^p])|
    (ht[^t]p)|
    (h[^t]tp)|
    ([^h]ttp)

    )|(.{0,3}$)/

The moral of this story: "negating" a string in regular expressions is very,
very ugly (without negative look ahead).  Your best bet, as many others have
mentioned, is to do something akin to perl's !~, i.e. match against ^http,
and consider matches to be, well, not matches.




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

Date: 04 Feb 2005 21:47:23 GMT
From: "Evertjan." <exjxw.hannivoort@interxnl.net>
Subject: Re: Regular expression woes
Message-Id: <Xns95F3E7D7DF08Ceejj99@194.109.133.29>

Richards Noah (IFR LIT MET) wrote on 04 feb 2005 in
comp.lang.javascript: 

>> r = /^(([^h]...)|(.[^t]..)|(..[^t].)|(...[^p])|(.{0,3}$))/.test(s)
>>
>> [I could loose some () but I like them for clarity
>>
> 
> None of those regular expressions will work.  For example, you regexp
> will not match against "this string", since it differs in 4 places in
> the first 4 characters.
> 

s = "this string"
r = /^(([^h]...)|(.[^t]..)|(..[^t].)|(...[^p])|(.{0,3}$))/.test(s)
alert(r)

shows: true as per OQ. 

So what is the problem?

Please show a string that does not work.

-- 
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)



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

Date: 4 Feb 2005 19:13:22 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: why the variable become local?
Message-Id: <Xns95F390AEDCDCDasu1cornelledu@132.236.56.8>

ai2003lian@yahoo.com wrote in news:1107540859.281482.203830
@l41g2000cwc.googlegroups.com:

> # Some settings
> 
> $idx = 0;
> $next_arg = $ARGV[idx];
> if(!$next_arg){
>         printUsage();
>         exit;
> }

print_usage() unless @ARGV;

 
> while($next_arg){
>         if($next_arg == "-h"){

You can replace this whole craziness with:

#!/usr/local/bin/perl

use strict;
use warnings;

use constant USAGE =><<USAGE
Usage: download_zip_file -h <ftp server> -u <user name> -p <password>
USAGE
    ;


die USAGE unless @ARGV;

my %args = @ARGV;

die USAGE unless(
    defined $args{-h}
        and defined $args{-u}
        and defined $args{-p}
);

login_to_ftp_server_and_download(\%args) 
    or die "Error logging on to $args{-h} for $args{-u}\n";

sub login_to_ftp_server_and_download {
    return;
}

__END__

or use one of the modules available on CPAN:

http://search.cpan.org/modlist/Option_Parameter_Config_Processing

Sinan


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

Date: Fri, 4 Feb 2005 22:57:57 +0100
From: Martin Kissner <news@chaos-net.de>
Subject: Re: why the variable become local?
Message-Id: <slrnd07rv5.cjq.news@maki.homeunix.net>

A. Sinan Unur wrote :
> ai2003lian@yahoo.com wrote in news:1107540859.281482.203830
> @l41g2000cwc.googlegroups.com:
>
>> if(!$next_arg){
>>         printUsage();
>>         exit;
>> }
>
> print_usage() unless @ARGV;

Just for my own understanding:
Shouldn't that be:

print_usage() and exit unless @ARGV;

Regards
Martin

-- 
perl -e 'print 7.74.117.115.116.11.32.13.97.110.111.116.104.101.114.11
 .32.13.112.101.114.108.11.32.13.104.97.99.107.101.114.10.7'


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

Date: Fri, 04 Feb 2005 21:59:50 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: why the variable become local?
Message-Id: <Xns95F3ACF338641asu1cornelledu@127.0.0.1>

Martin Kissner <news@chaos-net.de> wrote in 
news:slrnd07rv5.cjq.news@maki.homeunix.net:

> A. Sinan Unur wrote :
>> ai2003lian@yahoo.com wrote in news:1107540859.281482.203830
>> @l41g2000cwc.googlegroups.com:
>>
>>> if(!$next_arg){
>>>         printUsage();
>>>         exit;
>>> }
>>
>> print_usage() unless @ARGV;
> 
> Just for my own understanding:
> Shouldn't that be:
> 
> print_usage() and exit unless @ARGV;

Of course ... Thanks for catching that.

Sinan.


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

Date: Fri, 04 Feb 2005 19:20:15 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: www::mechanize $mech->select
Message-Id: <PVPMd.6301$t46.4511@trndny04>

"Ralf Schaa" <schaa@geo.uni-koeln.de> wrote in message
news:36hj7fF513lo6U1@individual.net...
> according the document there is a method 'select' in the
www::mechanize
> package

You probably mean the WWW::Mechanize package.  Case matters.

>, trying the following i get an error mesage:
>
> $mech->form(0);
> $mech->select("var select", 17);
>
> Error: Can't locate object method "select" via package WWW::Mechanize
>
> could someone tell me what is going on here ?

What version of WWW::Mechanize are you using?  To find out, print the
variable
$WWW::Mechanize::VERSION

The latest on CPAN appears to be 1.10   If your version is less than
that, consider upgrading.  If not, please post a *short* but *complete*
script that demonstrates this error.

Paul Lalli



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

Date: 4 Feb 2005 11:36:03 -0800
From: codefixer@gmail.com
Subject: Re: XML & Perl - Error
Message-Id: <1107545763.210358.183210@l41g2000cwc.googlegroups.com>


nobull@mail.com wrote:
> Sherm Pendley wrote:
> > codefixer@gmail.com wrote:
> >
> > > I am getting an error when I use  use XML::LibXML(); in my .pl
> file.
> > ...
> > > Binary build 808 provided by ActiveState Corp.
> > > http://www.ActiveState.com
> > >
> > > I was wondering if I have to upgrade or how do I get the required
> > > pm(perl module).
> >
> > XML::LibXML isn't part of the core Perl distribution, so you'll
> > have to install it separately. Go to the URL you listed above
> > and follow their instructions for obtaining and installing a
> > compiled and packaged PPM of the module.
>
> Really, their website says they don't have PPMs.
>
> For pointers to other PPM respositoies or how to build XML::LibXML
> yourself on Win32 see numerous previous threads on this subject.

 Like which ones ?? I did find LibXML on their webpage
"http://ppm.activestate.com/BuildStatus/5.6-X.html"
But when I do serach on their Perl Package Manager(ppm prompt) I don't
get that package. So what's going on here ?

Any other compatible packages ?

Thanks



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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 7738
***************************************


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