[28183] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9547 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 2 11:06:00 2006

Date: Wed, 2 Aug 2006 08:05:08 -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           Wed, 2 Aug 2006     Volume: 10 Number: 9547

Today's topics:
    Re: Beginner: regex-error? <mol10metal@hotmail.com>
    Re: Beginner: regex-error? <rvtol+news@isolution.nl>
    Re: Beginner: regex-error? <bik.mido@tiscalinet.it>
        executing perl script without .pl extension tweaky@gmail.com
    Re: executing perl script without .pl extension <mritty@gmail.com>
    Re: FAQ 3.27 Where can I learn about object-oriented Pe <mritty@gmail.com>
        file does not begin with '%PDF-'  -  Error when searchi <levbao@gmail.com>
    Re: foreach aliasing, my variables, and visibility in s <bik.mido@tiscalinet.it>
    Re: Heisenbug! was: odd crash in file upload via CGI <msoulier@gmail.com>
    Re: Heisenbug! was: odd crash in file upload via CGI <mritty@gmail.com>
    Re: Heisenbug! was: odd crash in file upload via CGI <msoulier@gmail.com>
        It's test <daegumsoli@naver.com>
    Re: It's test <rvtol+news@isolution.nl>
        Perl hash of hash efficiency. <yekasi@gmail.com>
    Re: Please Help! <tadmc@augustmail.com>
    Re: print command <tadmc@augustmail.com>
    Re: Recursion <mritty@gmail.com>
    Re: Recursion <bik.mido@tiscalinet.it>
    Re: Recursion <mritty@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 2 Aug 2006 03:09:42 -0700
From: "Nick of course" <mol10metal@hotmail.com>
Subject: Re: Beginner: regex-error?
Message-Id: <1154513382.816468.285020@i3g2000cwc.googlegroups.com>


A. Sinan Unur wrote:
> > while ( <DATA> ) {
> >     next unless /^(\d{2}\.\d{2}\.\d{4})/;
> >     print "$1\n" if $1;
> > }
>
> You don't really need the if $1 test, either.
>
In fact it's the unless test that's not really needed, e.g.

while (<DATA>) {
    print "$1\n" if /^(\d{2}\.\d{2}\.\d{4})/;
}

or even...

/^(\d{2}\.\d{2}\.\d{4})/ and print "$1\n" while <DATA>;

but don't do this at home



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

Date: Wed, 2 Aug 2006 12:08:29 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Beginner: regex-error?
Message-Id: <eaq4ks.1ak.1@news.isolution.nl>

Marek Stepanek schreef:

> [...]
> my (@lines);
>
>   while (<DATA>)
>   {
>       chomp;
>       push @lines, $_;
>   }
>
>   foreach my $line (@lines)
>   {
>     my $date = $line =~ /^([\d.]+)/;
>     # why is this regex wrong?
>     # I want to capture the dates: 17.07.2006 ...
>     print "\n$date";
>   }
> [...]

First you only need one line of code to fill @lines:

    @lines = <DATA> ;


But then you still process them one-by-one, so why not just:

  #!/usr/bin/perl
    use warnings ;
    use strict ;

    while (<DATA>)
    {
      print "$1\n" if /^(\d\d[.]\d\d[.]\d{4})\s/ ;
    }

  __DATA__
  17.07.2006    CC mU    58.00

-- 
Affijn, Ruud

"Gewoon is een tijger."




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

Date: 2 Aug 2006 13:38:38 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Beginner: regex-error?
Message-Id: <0931d2hccmsdnphn7nh6d1o5o4lmsu8k9s@4ax.com>

On Tue, 01 Aug 2006 22:42:21 +0200, Marek Stepanek <mstep@t-online.de>
wrote:

>use warnings;
>use strict;

good!

>my (@lines);
>
>
>  while (<DATA>)
>  {
>      chomp;
>      push @lines, $_;
>  }

if you really want to do that... then

  chomp(my @lines=<DATA>);

>  foreach my $line (@lines)
>  {

Oh, but then you *do* iterate over lines, then do so since the
beginning, and avoid, as is usually recommended, to slurp in all of
them:

  while (<DATA>) { #...
>    my $date = $line =~ /^([\d.]+)/;
>    # why is this regex wrong?
>    # I want to capture the dates: 17.07.2006 ...
>    print "\n$date";

my ($date) = $line =~ /^([\d.]+)/;


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 2 Aug 2006 07:24:56 -0700
From: tweaky@gmail.com
Subject: executing perl script without .pl extension
Message-Id: <1154528696.744484.159550@s13g2000cwa.googlegroups.com>

Hey all, I'm doing some testing w/ a WinXP setup (don't ask) and IIS
5.1. Going to test Twiki on it, but I'm having a small issue. I'd like
to run the perl scripts without having to type in the .pl.

Example:

http://www.test.com/script (where script is a perl file at the root of
the public web directory).

I could've sworn I did this on a test environment last week (same
setup), but I can't remember how.

Any suggestions?



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

Date: 2 Aug 2006 07:49:37 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: executing perl script without .pl extension
Message-Id: <1154530177.521559.225190@b28g2000cwb.googlegroups.com>

tweaky@gmail.com wrote:
> Hey all, I'm doing some testing w/ a WinXP setup (don't ask) and IIS
> 5.1. Going to test Twiki on it, but I'm having a small issue. I'd like
> to run the perl scripts without having to type in the .pl.
>
> Example:
>
> http://www.test.com/script (where script is a perl file at the root of
> the public web directory).
>
> I could've sworn I did this on a test environment last week (same
> setup), but I can't remember how.
>
> Any suggestions?

It looks as though you have a webserver configuration issue, not a Perl
issue.  That is, your question has nothing to do with the actual Perl
language.  The files that you want to access by munging their filenames
just happen to contain Perl code.  Therefore, you are not likely to get
the best possible assistance from a group which deals with the Perl
language itself.

I strongly suggest you post your question to a newsgroup or forum that
deals with the configuration of your webserver.

Good luck,
Paul Lalli



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

Date: 2 Aug 2006 05:14:03 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: FAQ 3.27 Where can I learn about object-oriented Perl programming?
Message-Id: <1154520843.071682.53060@m79g2000cwm.googlegroups.com>

PerlFAQ Server wrote:
> --------------------------------------------------------------------
>
> 3.27: Where can I learn about object-oriented Perl programming?
>
>     A good place to start is perltoot, and you can use perlobj, perlboot,
>     perltoot, perltooc, and perlbot for reference.
>
>     A good book on OO on Perl is the "Object-Oriented Perl" by Damian Conway
>     from Manning Publications, or "Learning Perl References, Objects, &
>     Modules" by Randal Schwartz and Tom Phoenix from O'Reilly Media.
>
> --------------------------------------------------------------------

This FAQ should likely be updated with the new title of the Alpaca,
"Intermediate Perl"

Paul Lalli



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

Date: 2 Aug 2006 08:02:11 -0700
From: "lvb" <levbao@gmail.com>
Subject: file does not begin with '%PDF-'  -  Error when searching pdfs on FireFox browser
Message-Id: <1154530931.718852.50660@s13g2000cwa.googlegroups.com>

Hello all:

I have monthly PDFs that I store in a directory and display the 2
latest ones, the rest user can search them by date (mm-yyyy).  Now I
have 2 questions:

First, which one is a better solution, store in a directory or in a
database and retrieve?  It just started so we only have a few PDFs now.
 What happens if latter we add more and more PDFs?

Second, and it's the problem,  the PDFs are just fine, I can open them
directly on any browser.  However when I search & open it, it throws an
error " file does not begin with '%PDF-' " on Firefox and on some IE
browser (my laptop's IE gives the same error.).  I've done some
research, Adobe gives solution
http://www.adobe.com/support/techdocs/319294.html
But it doesn't satisfy me.  Does anyone know what happens here?  Could
it be my script's problem?   Please see the script below:

if (defined $ins{newsletter_text}) {

  my $letter = "$ins{newsletter_text}.pdf";

  $path_dir = "/www/html/newsletter/";
  opendir(DIRhandle, $path_dir) || die("Cannot open directory");
  @thefiles= readdir(DIRhandle);
  closedir(DIRhandle);

foreach $file (sort @thefiles) {

unless ( ($file eq ".") || ($file eq "..") ) {
  if ($file eq $ins{newsletter_text}) {
     print "location:/newsletter/$ins{newsletter_text}\n\n";
     last;
  }
  elsif ($file =~ /\Q$ins{newsletter_text}\E/i) {
    if ($ins{newsletter_text} =~ m/^\d\d-\d\d\d\d$/) {
      print "location:/newsletter/$letter\n\n";
    } else {
       print "location:/cgi-bin/outdoor.cgi?pg=gov&err=1\n\n";
    }
  }
}
}

Also I realized that when I open the PDF from a link, in the Address
Bar, it shows the path something like '/gl/newsletter/06-2006.pdf'
but when I open it from the search form, it show the path somethink
like '/cgi-bin/gl/newsletter.cgi'

newsletter.cgi proccess the search and redirect to the PDF.  Could it
be that Firefox considers it as a cgi file?

Any ideas, please?

Thanks much in advance.



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

Date: 2 Aug 2006 13:22:18 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: foreach aliasing, my variables, and visibility in sub
Message-Id: <d1s0d25mmevh15nos1v0qmc329hube2sji@4ax.com>

On Tue, 1 Aug 2006 21:27:47 +0100, Ben Morrow
<benmorrow@tiscali.co.uk> wrote:

>> Although that's indeed what both 'perldoc -q closure' and 'perldoc
>> perlref' claim, I regard it as a standard misconception that closures
>> *are* anonymous subs.
>
>And I that a closure is simply a sub with its own scope :). They are

You what? Is the missing verb supposed to be "claim"?

>*not* the same thing: the important property of a closure is that you
>can have *many copies* of the same sub *each with its own scope*.

Well, it could be debatable whether they are *copies* of the *same*
sub or different subs altogether:

  $ perl -le 'print for map { my $v=$_; sub { $v } } 1..3'
  CODE(0x814f180)
  CODE(0x814f240)
  CODE(0x814ff18)

It is largely a matter of interpretation, I guess. As far as the
general CS concept, I don't know... but of course this is a usefulness
of closures. And indeed an important property... however this is far
from being a *defining* one and IMNSH understanding a named sub *is* a
closure around lexical variables defined in the sorrounding scope.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 2 Aug 2006 06:32:25 -0700
From: "msoulier" <msoulier@gmail.com>
Subject: Re: Heisenbug! was: odd crash in file upload via CGI
Message-Id: <1154525545.834060.193620@p79g2000cwp.googlegroups.com>

Paul Lalli wrote:
> 5.8.0 is notoriously buggy.  You use known-buggy software, you
> encounter bugs.  Upgrade.

If you'll check the thread, you'll find that I'm running 5.8.5.

Mike



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

Date: 2 Aug 2006 06:41:10 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Heisenbug! was: odd crash in file upload via CGI
Message-Id: <1154526070.548293.10340@i42g2000cwa.googlegroups.com>


msoulier wrote:
> Paul Lalli wrote:
> > 5.8.0 is notoriously buggy.  You use known-buggy software, you
> > encounter bugs.  Upgrade.
>
> If you'll check the thread, you'll find that I'm running 5.8.5.

If you'll check the paths in the error messages, you'll see you're
using modules from a 5.8.0 installation.

Paul Lalli



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

Date: 2 Aug 2006 07:18:00 -0700
From: "msoulier" <msoulier@gmail.com>
Subject: Re: Heisenbug! was: odd crash in file upload via CGI
Message-Id: <1154528280.245759.130770@p79g2000cwp.googlegroups.com>

Paul Lalli wrote:
> If you'll check the paths in the error messages, you'll see you're
> using modules from a 5.8.0 installation.

Indeed, as packaged by CentOS. Still, the interpreter is 5.8.5, and I
tried a newer CGI::Persistent and it didn't fix the issue. We seem to
be using the latest Persistence::Object::Simple and the latest
Data::Dumper, which is where the error appears to be occurring.

Mike



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

Date: Wed, 2 Aug 2006 22:49:56 +0900
From: "SonJK" <daegumsoli@naver.com>
Subject: It's test
Message-Id: <eaqadl$ksu$1@news2.kornet.net>

Sorry, It's test
I am beginner. 




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

Date: Wed, 2 Aug 2006 15:56:44 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: It's test
Message-Id: <eaqi06.1cc.1@news.isolution.nl>

SonJK schreef:

> Sorry, It's test
> I am beginner.

Such a test fits in test groups only.

You act as if you know that you are doing something that you shouldn't.
Why do it then? Bye.

-- 
Affijn, Ruud

"Gewoon is een tijger."




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

Date: 2 Aug 2006 08:04:44 -0700
From: "tak" <yekasi@gmail.com>
Subject: Perl hash of hash efficiency.
Message-Id: <1154531084.224588.309860@b28g2000cwb.googlegroups.com>

Hi,

I have a script, that loads a txt file, with 240k lines in it to a hash
currently. And when it loads the data to the hash - it becomes slower
and slower when it reaches may be around 150k (probably due to
collision, since perl's hash uses linear chaininig...).

So, i am thinking of implementing it in hash of hash... using the first
letter of these records, and divide them into 26 sub hashes. (Since
these records' first letter are pretty random from A-Z).

So, I tried it, the performance is about the same... why??

The difference between what i had, and what i am doing now is,

Before:
$mainHash{$somekey} = \@values;

After:
my $letter = substr $values, 0 , 1;
$mainHash{$letter}{$somekey} = \@values;

Shouldnt the "after" format helps the memory usage / efficiency by
alot? B/c it lowered the collision by 26 times...???

Thanks,
T



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

Date: Tue, 1 Aug 2006 22:26:44 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Please Help!
Message-Id: <slrned06rk.2kn.tadmc@magna.augustmail.com>

VJDIVINE@gmail.com <VJDIVINE@gmail.com> wrote:

> Subject: Please Help!


I'll bet you would get a lot more help if you put the subject of
your article in the Subject of your article.


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


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

Date: Tue, 1 Aug 2006 22:35:40 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: print command
Message-Id: <slrned07cc.2kn.tadmc@magna.augustmail.com>

ray <ray_lokey7543@yahoo.com> wrote:

> Both of commands are not correct syntactically, 


All of your Perl *is* syntactically correct (though the 2nd
one is semantically incorrect).


> missing something or
> not possible to print the result from a command ?
> 
> perl -pi -e 's/\bbar\b/foo/g' `find . -type f` -print 0| xargs -0


   perl -e 's/\bbar\b/foo/g'

compiles just fine (ie. no syntax errors).


> perl -pi -e -print 0| xargs -0 's/\bbar\b/foo/g' `find . -type f`


   perl -e -print

compiles just fine (ie. no syntax errors).

Negating the return value from print() is likely not what
you were trying for though...


> Please help me.


Please ask shell questions in a shell newsgroup.

Pleading is counter-productive, it has an effect opposite of
what you were likely hoping for.

Have you seen the Posting Guidelines that are posted here frequently?


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


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

Date: 2 Aug 2006 04:05:22 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Recursion
Message-Id: <1154516722.820591.305000@m73g2000cwd.googlegroups.com>

Bernard El-Hagin wrote:
> "Paul Lalli" <mritty@gmail.com> wrote:
>
> > kokolo wrote:
> >> Well, I asked for some help, not for a lecture :" Become a Perl
> >> expert and only then ask a question"
> >
> > For maximum help from this newsgroup, improve your attitude in
> > three ways:
> > 1) Stop being under the impression that anyone here has an
> > obligation to help you, or to give you exactly what you ask for.
>
>
> At no point did the OP claim that anyone here was obligated to help him.
> And his tongue-in-cheek remark about not needing a lecture does not constitute
> the expectation that he'll get exactly what  he asked for.

I did not detect any "tongue-in-cheek"ness in the above quoted
material...

> > 2) Stop rebuking a "lecture".
>
> He didn't. You'd have realised that if you'd taken the time to go beyond
> his smiley-qualified remark and noticed that he not only understood, but
> thanked for the "lecture".

So he did.  You are correct.

> > Lectures are good things.  They
> > teach you.  They instruct you.  They make you a better programmer.
> > If someone offers to tell you why or how you're doing something
> > wrong (whether that 'something' has to do with Perl or with your
> > methodology or with your Usenet postings), thank them.
>
>
> He did. Can't you read?

Again, you're correct.  I didn't bother to read the rest of the post.

> > 3) Get over yourself.
>
>
> This is advice that a *lot* of the regulars should take. Mostly the newer ones.
> You included. This case is a perfect example. You read the first line in the OP's
> response and you thought "this is the perfect opportunity for me to be an arrogant
> ass". And you took it, as you always do. Instead of looking objectively at a post you
> first look for holes you can shoot the OP down for. I have seen you do it many times.

Well, half-correct this time.  I read the first line in the OP's
response and thought "this is yet another arrogant poster who thinks
people here should just give him an answer and shut up."

As for my "looking for holes", you may be correct about that too.  I'll
have to evaluate the way I've been looking at posts in this newsgroup
for the past year.  I don't think I started out being this better and
pessimistic about questions posted.  Not sure when that happened.

> > No one *ever* said that asking a question is bad,
>
> The OP never claimed that anyone said asking a question was bad. You're now
> making up crap just so you can spew more of your arrogance at someone who
> is trying to learn? That's pathetic.

The lines of the OPs response that I read insinuated that people here
don't tolerate asking questions from "newbies".  I stand by my response
on that one.

> > or that you need to be an expert before you ask questions.
>
> That was tongue-in-cheek.

Again, I didn't detect the tongue-in-cheek nature of the response.

> He accepted and thanked for the lecture in the same post! Can't you
> read?

Correct again.

> > Questions are encouraged and welcomed.  Badly formed, poorly
> > thought-out questions, on the other hand, are justifiably ignored,
> > flamed, and/or lectured against.  Take the advice your given,
> > write better questions, and you'll do fine.
>
> Where in this thread did anyone say the OP's question was badly formed?
> Or poorly thought-out?

No where.  That was intended to be a generic comment.

> Do you just have an "arrogant ass" template that you post every time you see
> a beginner's post? It seems that way.

No, I generally make it up as I go.

> > You should start by reading the Posting Guidelines for this group.
>
> The OP's post clearly stated his problem and provided working (although bad)
> code. Didn't you even read the post you're so troubled by?

Nope.   I did not.  I f***ed up in this thread, and you have called me
on it, quite deservingly.  I apologize to the OP, profusely.  I was out
of line in my responses.

Bernard, thank you for having the guts to tell an ass when he's being
an ass.  I appreciate it.  Seriously.

Paul Lalli



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

Date: 2 Aug 2006 13:30:07 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Recursion
Message-Id: <0131d2tgsm1nims5780o2bvrbq3iv0jdeb@4ax.com>

On Wed, 2 Aug 2006 09:47:06 +0200, "Bernard El-Hagin"
<bernard.el-haginDODGE_THIS@lido-tech.net> wrote:

>The usefulness of this group has become questionable at best. The likes of you have made it so. 
>Most questions asked here are rejected immediately because they don't conform to *every* 
>*single* *fucking* *point* in the guidelines, even if they are perfectly clear. The only ones left 
>are so simple, they can be answered with a perldoc reference. It's pathetic. In fact, I think I need 
>to take a loooong break from this place. I'll miss the *true* wisdom of Tad, Anno, Abigail, Randal 
>and some others, but this new bunch of regulars, who have no clue, but make up for it in 
>arrogance are ruining even their input for me.

Although I *partly* agree with some of your remarks, and specifically
that the OP of this particular thread has been bashed more than
necessary, I think that you should acknowledge that some of the "new
regulars", including the person you're replying to, do also provide
precious help...


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 2 Aug 2006 04:44:04 -0700
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Recursion
Message-Id: <1154519044.173379.222380@s13g2000cwa.googlegroups.com>

Paul Lalli wrote:
> I don't think I started out being this better and
> pessimistic about questions posted.

Well there's an unfortunate typo if I ever saw one.  "bitter", not
"better".

Paul Lalli



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

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


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