[25118] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7368 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 6 11:05:43 2004

Date: Sat, 6 Nov 2004 08:05:10 -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           Sat, 6 Nov 2004     Volume: 10 Number: 7368

Today's topics:
    Re: an original perldoc viewer <postmaster@castleamber.com>
    Re: an original perldoc viewer <ioneabu@yahoo.com>
    Re: an original perldoc viewer <ioneabu@yahoo.com>
    Re: an original perldoc viewer <ioneabu@yahoo.com>
    Re: an original perldoc viewer <tadmc@augustmail.com>
    Re: Check POP3 E-mail (krakle)
    Re: Check POP3 E-mail (krakle)
    Re: Common file operations (Seymour J.)
    Re: EOF issue <usenet@morrow.me.uk>
        FAQ 4.13: How do I find the current century or millenni <comdog@panix.com>
    Re: Finding consecutive lines <bik.mido@tiscalinet.it>
        Hash ref problem in Plucene::Simple (while searching a  <ewijaya@singnet.com.sg.removethis>
    Re: Hash ref problem in Plucene::Simple (while searchin <tadmc@augustmail.com>
    Re: Lexical file handles <uri@stemsystems.com>
    Re: Lexical file handles <nobull@mail.com>
    Re: map()'s BLOCK [was: "Re: Q: re Inline and Benchmark (Anno Siegel)
        matching all perldoc names but no more <ioneabu@yahoo.com>
    Re: matching all perldoc names but no more <tadmc@augustmail.com>
        Newbie Question (Ali Ataman)
    Re: Newbie Question <usenet_05_08_2004@stuartmoore.org.uk>
    Re: Newbie Question <tadmc@augustmail.com>
    Re: Newbie Question <jurgenex@hotmail.com>
    Re: Q: re Inline and Benchmark <bik.mido@tiscalinet.it>
        reading a txt file <geen@geen.nl>
    Re: reading a txt file <bik.mido@tiscalinet.it>
    Re: reading a txt file <tadmc@augustmail.com>
        synchronus ftp call (chris)
    Re: synchronus ftp call <nobull@mail.com>
    Re: why not    print $A[0] <stjm2@cam.ac.uk>
    Re: why not    print $A[0] <noreply@gunnar.cc>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 6 Nov 2004 05:57:44 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: an original perldoc viewer
Message-Id: <Xns9598F3C1776E1castleamber@130.133.1.4>

wana wrote:

> I am a complete amateur programmer in the sense that my job does not
> involve programming at all.  I am lucky in the sense that we are very
> well connected at work with many Windows machines connected to the
> internet via cable modem.  I have enough free time during the day to
> browse around online and connect via ssh to my web provider which is
> really the most fun place to do Perl programming for me (I can only
> use vi as editor there). 

Open a second session, and run perldoc there :-)

If you are using PuTTY note that it recently had a necessary security 
update.

> I do hope to someday make a career of developing software when I get
> good enough.  For now, I only get a few precious hours during the week
> with my Linux laptop.
> 
> At work, my PDA can connect to the internet wirelessly, so my little
> program is perfect for a quick perldoc read.  I have it running online
> at an undisclosed location (just in case it's not totally secure).

Security by obscurity is very very bad. And yes, it's insecure.

if (my $doc = param('docname')) {
                $a = `perldoc $doc`;

Very!


-- 
John                               MexIT: http://johnbokma.com/mexit/
                           personal page:       http://johnbokma.com/
        Experienced programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html


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

Date: Sat, 06 Nov 2004 08:02:43 -0500
From: wana <ioneabu@yahoo.com>
Subject: Re: an original perldoc viewer
Message-Id: <10opfh6sfh10h3e@news.supernews.com>

<posted & mailed>

wana wrote:

> I have been reprimanded for my lack of knowledge of perldoc material so I
> have decided to do more reading.  I realized that I am often (%50 of the
> time) working on a machine that does not have Perl but is connected to the
> internet.  My first thought was to go to perldoc.com, but it seemed  to be
> down tonight, so I wrote a simple home-made solution to get by for now.  I
> was hoping pod2html would format my perldocs but it did not work when I
> tried: pod2html perltoc (maybe perldoc pod2html says how to do it).  Here
> it is.  Improvements, especially in output formatting, would be welcome.
> 
> #!/usr/bin/perl
> use strict;
> use warnings;
> use CGI qw(:standard escapeHTML escape);
> $CGI::POST_MAX=1024 * 100;  # max 100K posts
> $CGI::DISABLE_UPLOADS = 1;  # no uploads
> 
> my $a = 'perldoc to be displayed here';
> if (param('display'))
> {
>         if (my $doc = param('docname'))
>         {
>                 $a = `perldoc $doc`;
>         }
> }
> print header(), start_html();
> print start_form(), p('Type name of perldoc'),
>         p(textfield(-name=>'docname')),
>         p(submit(-name=>'display')),
>         end_form();
> print hr, pre($a),end_html();
> 
> 
> Thanks!
> 
> wana

I found a major security hole: someone could run whatever commands they want
on my system.  I was wondering if the following would fix it or if I should
abandon the idea altogether.

if (param('display'))
{
        my $doc;
        if ($doc = param('docname')
        and $doc =~ /\b\w+\b/)
        {
                $a = `perldoc $doc`;
                $a = 'not found' if not $a;
        }
        else
        {
                $a = 'invalid perldoc name';
        }
}

This at least restricts users from entering additional commands like:

perltoc > youdummy

and stuff like that by making sure they can only enter words that
match /\b\w+\b/ which will either be a valid perldoc name or not.  Would
this make it safe enough for online use?


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

Date: Sat, 06 Nov 2004 08:26:09 -0500
From: wana <ioneabu@yahoo.com>
Subject: Re: an original perldoc viewer
Message-Id: <10opgt4psn5pr2f@news.supernews.com>

wana wrote:

> <posted & mailed>
> 
> wana wrote:
> 
>> I have been reprimanded for my lack of knowledge of perldoc material so I
>> have decided to do more reading.  I realized that I am often (%50 of the
>> time) working on a machine that does not have Perl but is connected to
>> the
>> internet.  My first thought was to go to perldoc.com, but it seemed  to
>> be
>> down tonight, so I wrote a simple home-made solution to get by for now. 
>> I was hoping pod2html would format my perldocs but it did not work when I
>> tried: pod2html perltoc (maybe perldoc pod2html says how to do it).  Here
>> it is.  Improvements, especially in output formatting, would be welcome.
>> 
>> #!/usr/bin/perl
>> use strict;
>> use warnings;
>> use CGI qw(:standard escapeHTML escape);
>> $CGI::POST_MAX=1024 * 100;  # max 100K posts
>> $CGI::DISABLE_UPLOADS = 1;  # no uploads
>> 
>> my $a = 'perldoc to be displayed here';
>> if (param('display'))
>> {
>>         if (my $doc = param('docname'))
>>         {
>>                 $a = `perldoc $doc`;
>>         }
>> }
>> print header(), start_html();
>> print start_form(), p('Type name of perldoc'),
>>         p(textfield(-name=>'docname')),
>>         p(submit(-name=>'display')),
>>         end_form();
>> print hr, pre($a),end_html();
>> 
>> 
>> Thanks!
>> 
>> wana
> 
> I found a major security hole: someone could run whatever commands they
> want
> on my system.  I was wondering if the following would fix it or if I
> should abandon the idea altogether.
> 
> if (param('display'))
> {
>         my $doc;
>         if ($doc = param('docname')
>         and $doc =~ /\b\w+\b/)
>         {
>                 $a = `perldoc $doc`;
>                 $a = 'not found' if not $a;
>         }
>         else
>         {
>                 $a = 'invalid perldoc name';
>         }
> }
> 
> This at least restricts users from entering additional commands like:
> 
> perltoc > youdummy
> 
> and stuff like that by making sure they can only enter words that
> match /\b\w+\b/ which will either be a valid perldoc name or not.  Would
> this make it safe enough for online use?

or maybe:
/^[a-z]+$/
seems to work better.

This should allow only wall-to-wall one or more a-z so `perldoc $doc` should
not be able to run any other commands via redirection or pipes.  This is
scary to play around with.  Someone could have deleted all of my stuff
easily if I had let the link get out.



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

Date: Sat, 06 Nov 2004 08:29:04 -0500
From: wana <ioneabu@yahoo.com>
Subject: Re: an original perldoc viewer
Message-Id: <10oph2jp10i89d7@news.supernews.com>

wana wrote:

> wana wrote:
> 
>> <posted & mailed>
>> 
>> wana wrote:
>> 
>>> I have been reprimanded for my lack of knowledge of perldoc material so
>>> I
>>> have decided to do more reading.  I realized that I am often (%50 of the
>>> time) working on a machine that does not have Perl but is connected to
>>> the
>>> internet.  My first thought was to go to perldoc.com, but it seemed  to
>>> be
>>> down tonight, so I wrote a simple home-made solution to get by for now.
>>> I was hoping pod2html would format my perldocs but it did not work when
>>> I
>>> tried: pod2html perltoc (maybe perldoc pod2html says how to do it). 
>>> Here
>>> it is.  Improvements, especially in output formatting, would be welcome.
>>> 
>>> #!/usr/bin/perl
>>> use strict;
>>> use warnings;
>>> use CGI qw(:standard escapeHTML escape);
>>> $CGI::POST_MAX=1024 * 100;  # max 100K posts
>>> $CGI::DISABLE_UPLOADS = 1;  # no uploads
>>> 
>>> my $a = 'perldoc to be displayed here';
>>> if (param('display'))
>>> {
>>>         if (my $doc = param('docname'))
>>>         {
>>>                 $a = `perldoc $doc`;
>>>         }
>>> }
>>> print header(), start_html();
>>> print start_form(), p('Type name of perldoc'),
>>>         p(textfield(-name=>'docname')),
>>>         p(submit(-name=>'display')),
>>>         end_form();
>>> print hr, pre($a),end_html();
>>> 
>>> 
>>> Thanks!
>>> 
>>> wana
>> 
>> I found a major security hole: someone could run whatever commands they
>> want
>> on my system.  I was wondering if the following would fix it or if I
>> should abandon the idea altogether.
>> 
>> if (param('display'))
>> {
>>         my $doc;
>>         if ($doc = param('docname')
>>         and $doc =~ /\b\w+\b/)
>>         {
>>                 $a = `perldoc $doc`;
>>                 $a = 'not found' if not $a;
>>         }
>>         else
>>         {
>>                 $a = 'invalid perldoc name';
>>         }
>> }
>> 
>> This at least restricts users from entering additional commands like:
>> 
>> perltoc > youdummy
>> 
>> and stuff like that by making sure they can only enter words that
>> match /\b\w+\b/ which will either be a valid perldoc name or not.  Would
>> this make it safe enough for online use?
> 
> or maybe:
> /^[a-z]+$/
> seems to work better.
> 
> This should allow only wall-to-wall one or more a-z so `perldoc $doc`
> should
> not be able to run any other commands via redirection or pipes.  This is
> scary to play around with.  Someone could have deleted all of my stuff
> easily if I had let the link get out.

No!  Try:

/^[a-z1-9]+$/

or you won't be able to read your perlfaq1 - perfaq9

oh boy!


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

Date: Sat, 6 Nov 2004 09:09:39 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: an original perldoc viewer
Message-Id: <slrncopq9j.jjg.tadmc@magna.augustmail.com>

wana <ioneabu@yahoo.com> wrote:

> I am often (%50 of the
> time) working on a machine that does not have Perl


Then it follows that during that 50% of the time you are not
doing Perl programming, since perl is not there.

You don't need access to the Perl docs when you are not programming
in Perl, so why is it that you think you need what you think you need?


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


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

Date: 6 Nov 2004 07:46:49 -0800
From: krakle@visto.com (krakle)
Subject: Re: Check POP3 E-mail
Message-Id: <237aaff8.0411060746.379320e@posting.google.com>

"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message news:<Xns9598802954588asu1cornelledu@132.236.56.8>...
> krakle@visto.com (krakle) wrote in
> news:237aaff8.0411050643.56e045a0@posting.google.com: 
> 
> > arguement. mod_perl scripts stay in memory. Unless you reset the
> > values of a variable at the beginning of the script or before that
> > variable is used it may contain the previous users data...
> 
> Your statement is full of half truths. If you don't write 'good' programs, 
> then bad things surely mya happen. However, I have quite a few CGI scripts 
> that are being run under mod_perl, and I have yet to run into such an 
> issue.
> 
> Sinan.

Then you don't use mod_perl much. See my example.


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

Date: 6 Nov 2004 07:50:28 -0800
From: krakle@visto.com (krakle)
Subject: Re: Check POP3 E-mail
Message-Id: <237aaff8.0411060750.73d1c09d@posting.google.com>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<2v1k72F2ev3dmU1@uni-berlin.de>...
> krakle wrote:
> > "A. Sinan Unur" wrote:
> >> krakle@visto.com (krakle) wrote:
> >>> 
> >>> How about for resetting purposes in mod_perl?
> >> 
> >> Care to show what you mean by giving us some code?
> >> 
> >> Please note that I have a pretty good idea what you might be
> >> referring to, but it is your job to actually _make_ an argument
> >> (using code, since this is a programming newsgroup) for the point
> >> you are trying to make.
> > 
> > Since you insist on seeing code for whatever unknown reason before
> > you answer my question (ignorance). I'll show you some...
> > 
> > _WITHOUT resetting variable_
> > 
> > use CGI;
> > my $cgi = new CGI;
> > 
> > my @message;
> > 
> > if (some_other_yada) {
> >    push (@message, "This is message #1: $cgi->param('msg1')");
> > }
> > 
> > if (some_other_yada) {
> >    push (@message, "Now this is message 2: $cgi->param('msg2')");
> > }
> > 
> > if (@message) {
> >    foreach (@message) { print "$_\n" }
> > } else {
>   print "No messages";
> > }
> 
> Did you run that code? Apparently not, since it doesn't even compile
> (under strict). Consequently, it does not serve the purpose of
> illustrating anything.

some_other_yada ISNT a Perl function or sub-routine. I'm not going to
write an entire Perl script to make a point in one single thread in
usenet when you guys know what i'm talking about. And YES this code
serves a purpose.

The purpose is @message will retain ALL data added to the array in
memory unless it is reset when you run under mod_perl.

The POINT is

my @message = ();

ISN'T bad syntax. I consider it proper.

> 
> > If ran as a CGI everything works fine... HOWEVER, if ran as mod_perl
> > @message retains the previous users data then the new users data adds
> > to the array then the next users data will retain the last 2 users
> > and so on... So Even if the current users session never had any
> > "messages" to add @message will not be empty. BUT if you used
> > 
> > my @message = ();
> > 
> > just like the original poster used the array woudl be reset at the
> > start of the script emptying any data left over from the previous
> > session.
> 
> As I explained in another message in this thread, your theory is
> incorrect, and if you had written real code and run it, you'd have found
> out for yourself.

It ISN'T incorrect at all. Have you even used mod_perl??? It keeps the
scripts in memory. And a global variable that does NOT reset it self
or assign itsself a value immediatly before an action will retain the
pervious sessions data.

Wow I can't believe the people here...


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

Date: Fri, 05 Nov 2004 20:57:51 -0500
From: "Shmuel (Seymour J.) Metz" <spamtrap@library.lspace.org.invalid>
Subject: Re: Common file operations
Message-Id: <418c2f9f$8$fuzhry+tra$mr2ice@news.patriot.net>

In <x7d5ywst5f.fsf@mail.sysarch.com>, on 11/02/2004
   at 05:43 AM, Uri Guttman <uri@stemsystems.com> said:

>what is $dirs?

Typo. That should have been 

  if (@dirs==0) {

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org



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

Date: Fri, 5 Nov 2004 22:02:04 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: EOF issue
Message-Id: <sr9t52-utb.ln1@osiris.mauzo.dyndns.org>


Quoth "IanW" <onedoesnot@needto.know>:
> "Thomas Kratz" <ThomasKratz@REMOVEwebCAPS.de> wrote in message
> news:418b939f$0$17108$bb690d87@news.main-rheiner.de...
> [..]
> 
> I don't understand the program logic here..
> 
> >     local $/ = '=' x 15 . "\n";
> 
> ok, so changing the input record separater to '=' x 15 . "\n" (referred to
> as "=15" hereafter for convenience), effectively specifying how you're going
> to split the file (I actually need the =15 when I output the chunks after
> processing them, but I can add that back in when printing out to file).

 ...and you can get Perl to do that for you too, with

local $\ = $/;

Ben

-- 
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
   From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes,        [ Heracles shoots Vulture with arrow. Vulture bursts into ]
 /Alcestis/)        [ flame, and falls out of sight. ]         ben@morrow.me.uk


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

Date: Sat, 6 Nov 2004 11:03:02 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 4.13: How do I find the current century or millennium?
Message-Id: <cmib16$47i$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

4.13: How do I find the current century or millennium?

    Use the following simple functions:

        sub get_century    {
            return int((((localtime(shift || time))[5] + 1999))/100);
        }
        sub get_millennium {
            return 1+int((((localtime(shift || time))[5] + 1899))/1000);
        }

    On some systems, the POSIX module's strftime() function has been
    extended in a non-standard way to use a %C format, which they sometimes
    claim is the "century". It isn't, because on most such systems, this is
    only the first two digits of the four-digit year, and thus cannot be
    used to reliably determine the current century or millennium.



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: Sat, 06 Nov 2004 09:06:17 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Finding consecutive lines
Message-Id: <o3uno0hiti4m5322s4ni1u8mej2ubmkaf2@4ax.com>

On Fri, 05 Nov 2004 17:20:46 -0000, "David K. Wall"
<dwall@fastmail.fm> wrote:

>#!/usr/bin/perl
>use strict;
>use warnings;
>
>my @buffer;
>my @pattern = qw(abc def ghi jkl mno);
>while (<DATA>) {
>    push @buffer, $_;
>    next if @buffer != @pattern;

While your scheme is terse and elegant in that it fills in the buffer
as needed, but even if I'm not one of those paranoids about
efficiency, it bothers me a little that the check is done for all
lines, including the majority of them that would not require it. I'd
pre-load it instead.

>    my $matches = grep /1/, 
>                  map $buffer[$_] =~ /$pattern[$_]/,
>                  0 .. $#pattern;

Well, I'm a big fan of map() and grep(), but in this case it seems to
me an overhead to use them. What about a simple counter instead? Also,
another source of inefficiency is in the fact that all patterns are
tried even if some of them fail, thus...

>    print @buffer if $matches == @pattern;
>    shift @buffer;
>}

 ...all in all I'd rewrite it as


  #!/usr/bin/perl
  
  use strict;
  use warnings;
  
  my @pattern = qw(abc def ghi jkl mno);
  my @buffer = (0, map scalar <>, 1..$#pattern);
  
  LINE: while (<>) {
      shift @buffer; push @buffer, $_;
      $buffer[$_] =~ /$pattern[$_]/ or 
        next LINE for 0..$#pattern;
      print @buffer;
  }
  
  __END__


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: Sat, 06 Nov 2004 21:27:32 +0800
From: "Edward Wijaya" <ewijaya@singnet.com.sg.removethis>
Subject: Hash ref problem in Plucene::Simple (while searching a term)
Message-Id: <opsg1oz6apavcff0@news.singnet.com.sg>

Hi,

I am just beginning to use Plucene::Simple module.
And the following code below tries to search a term in
indexed documents/files which are stored in a subdirectory "$tmp/"

Sample files I use are in this format:
Dir: /tmp/
file1.txt ---> content: test test
file2.txt ---> context: test test

However when I tried to print out the search result
it gives this error:

Can't use string ("test test") as a HASH ref while "strict refs" in
use at /usr/lib/perl5/site_perl/5.8.0/Plucene/Simple.pm line 235.

I have been scratching my head for a while to do this,
but still got no clue what went wrong.
Can anybody explain why this is?

Thanks and hope to hear from you again.

Regards,
Edward WIJAYA
SINGAPORE

__BEGIN__
#! /usr/bin/perl -w

use strict;
use Plucene::Simple;
use Data::Dumper;

my $dir = "tmp/*"; #sub directory where I store files to be indexed
my %documents = ();


%documents = map { $_ => do { local ($/,*F); open F, "<$_"
                   or  die "Error reading '$_': $!"; <F> }} glob($dir);
# end of populating hash from files with file name as key and its content  
as values, successfuly.
# $VAR1 = {
#          'tmp/file2.txt' => 'test test',
#          'tmp/file1.txt' => 'test test'
#        };

#Begin Indexing
     my $index = Plucene::Simple->open( $dir );

     for my $id (keys %documents) {
         $index->add($id => $documents{$id});
     }
     $index->optimize;

#do text search
my @ids = $index->search('test');
print Dumper \@ids;

__END__


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

Date: Sat, 6 Nov 2004 09:23:10 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Hash ref problem in Plucene::Simple (while searching a term)
Message-Id: <slrncopr2u.jjg.tadmc@magna.augustmail.com>

Edward Wijaya <ewijaya@singnet.com.sg.removethis> wrote:

> I am just beginning to use Plucene::Simple module.


> it gives this error:
> 
> Can't use string ("test test") as a HASH ref while "strict refs" in
> use at /usr/lib/perl5/site_perl/5.8.0/Plucene/Simple.pm line 235.


That means that perl is getting the string 'test test' when
it was expecting a reference to a hash instead.


> # $VAR1 = {
> #          'tmp/file2.txt' => 'test test',
> #          'tmp/file1.txt' => 'test test'
> #        };


>      for my $id (keys %documents) {
>          $index->add($id => $documents{$id});


The docs for the module show that the add() method takes two
arguments: a string and a hash ref.

You are calling add with a string and a string instead.

I don't know Plucene, but maybe you need a data structure like

   'tmp/file2.txt' => { text => 'test test'},

or perhaps you could just make the hash ref in the method call:

    $index->add($id => { text => $documents{$id} });

In any case, you need to pass a hashref as add()'s 2nd argument.


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


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

Date: Sat, 06 Nov 2004 05:50:13 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Lexical file handles
Message-Id: <x7hdo3zfu3.fsf@mail.sysarch.com>

>>>>> "GH" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:

  GH> Tintin wrote:
  >> Now that recent versions of Perl have lexical file handles, can
  >> anyone give me some practical examples of why they are useful/better.
  >> The only thing I can think of is that with 'use strict', you'll catch
  >> typos in your filehandles, however I'm sure there's plenty of other
  >> reasons.

  GH> They are automatically closed when out of scope.

so were localized type globs.

lexical handles are better since they are lexical. file globs (or plain
text file handles are always package scoped (global to the package). so
using them could clobber another file with the same name in the same
package. you can't do that with lexical handles. the old way to get a
clean handle was calling Symbol::gensym which returned an anonymous
typeglob so no other code could access the handle. another trick was
something like this: my $fh = do{ local *FOO ; \*FOO }.

so the deep functionality of lexical handles was always available. but
now it is simpler to use in open (and IPC::Open[23] uses them too now
IIRC).

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Sat, 06 Nov 2004 07:36:57 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Lexical file handles
Message-Id: <cmhulv$qa9$1@sun3.bham.ac.uk>



Ala Qumsieh wrote:

>     {
>       open my $fh, $file or die ...;
>       while (<$fh>) { ... }
>     }
> 
> This will automatically close my filehandle upon reaching the end of the 
> block. It also lets me use $fh for every file I open (assuming I have 
> only one open at a time)

Actually the one open at a time restriction does not apply.  You can 
have dozens of variables called $fh in different scopes.  That's like 
the whole point.

It would be dubious coding style to have one $fh inside an inner lexical 
scope masking another but there's no reason why you can't have closures 
that have file handles.

sub make_reader {
   my $file = shift;
   open my $fh, '<', $file or die "open $file: $!";
   sub {
      my $line = <$fh>;
      # Transform $line
      $line;
   }
}



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

Date: 6 Nov 2004 13:59:16 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: map()'s BLOCK [was: "Re: Q: re Inline and Benchmark"]
Message-Id: <cmilbk$c9j$1@mamenchi.zrz.TU-Berlin.DE>

Michele Dondi  <bik.mido@tiscalinet.it> wrote in comp.lang.perl.misc:
> On 5 Nov 2004 11:43:02 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
> Siegel) wrote:
> 
> >The wording of the message is a bit misleading -- the immediate
> >environment of "no" is definitely a block, and "no ..." is a statement,
> >not part of an expression.  I think I'll be able to live with it...
> 
> Well, I guess I can live with it too. Especially since I had never
> even noticed up until now! However, out of curiosity: do you think
> that it "ought" to be allowed, hypothetically speaking?

It ought to work if we expected orthogonal design: Never mind what kind
of block, "use" and "no" can go into it.  But this is Perl...

Anno


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

Date: Sat, 06 Nov 2004 08:40:07 -0500
From: wana <ioneabu@yahoo.com>
Subject: matching all perldoc names but no more
Message-Id: <10ophnae0cv9j5d@news.supernews.com>

I was getting carried away answering myself in another thread so I thought I
should purify my actual problem:

I am allowing a user to enter a perldoc name and I will run 'perldoc $name'
for them.

What regex will match all perldoc names but not allow for a command to be
slipped into the name.

for example, here is my latest:

/^[a-zA-Z1-9\:]+$/

if you allowed just anything:

/.*/

a user could enter 'perlref | rm -r ./*' or something like that.

previous attempts:

/^[a-z]+$/

seemed perfect but left out perlfaq1-9

/^[a-z1-9]+$/

left out CGI and other ones with caps.

Is there a rule for all current and future perldoc names?  I mean, they
can't possible have a | or a > in their name or even a space in the middle,
right?

wana


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

Date: Sat, 6 Nov 2004 09:06:49 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: matching all perldoc names but no more
Message-Id: <slrncopq49.jjg.tadmc@magna.augustmail.com>

wana <ioneabu@yahoo.com> wrote:

> I am allowing a user to enter a perldoc name and I will run 'perldoc $name'
> for them.
> 
> What regex will match all perldoc names but not allow for a command to be
> slipped into the name.


You won't need to solve that problem if you choose an approach
that does not require solving that problem.  :-)

If they can only look up the std docs, then build a lookup table
of the actual installed std docs, see code below.

Or maybe process the =head2 POD tags in perltoc.pod for legal names.

I think this ought to work though:    /^(\w|::)+$/

(leaving out single quote on purpose since it is deprecated.)


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

foreach my $pod ( 'foo bar', qw/ perlnope perl perltoc perlfunc / ) {
   if ( is_pod($pod) )
      { print "$pod is a POD\n" }
   else
      { print "$pod is *not* a POD\n" }
}


BEGIN {
   my %pods;

   chomp( my $dir = qx/ perldoc -l perlfunc / );
   $dir =~ s#/[^/]+$##;  # should use File::Basename here...

   opendir POD, $dir or die "could not open '$dir' directory  $!";
   $pods{ $_ } = 1 for map { s/.pod$// ? $_ : () } readdir POD;
   closedir POD;

   sub is_pod { exists $pods{ $_[0] } ? 1 : 0 }
}
---------------------------------


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


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

Date: 6 Nov 2004 05:10:52 -0800
From: serhant@doruk.net.tr (Ali Ataman)
Subject: Newbie Question
Message-Id: <5831e321.0411060510.294df450@posting.google.com>

Hello 

I have a perl script and I would like to write the output of this perl
script to a file. How can I do this.

I know it is simple but I just started perl..

Thanx


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

Date: Sat, 06 Nov 2004 15:26:29 +0000
From: Stuart Moore <usenet_05_08_2004@stuartmoore.org.uk>
Subject: Re: Newbie Question
Message-Id: <cmiqf3$l0v$1@gemini.csx.cam.ac.uk>

Ali Ataman wrote:

> Hello 
> 
> I have a perl script and I would like to write the output of this perl
> script to a file. How can I do this.
> 
> I know it is simple but I just started perl..
> 

Depending on your OS,

perl your_script.pl > output_file

ought to work.

If you want your script to write some stuff to file, and some to the 
screen, look in perlfunc for open, print and close.


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

Date: Sat, 6 Nov 2004 09:32:01 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Newbie Question
Message-Id: <slrncoprjh.jjg.tadmc@magna.augustmail.com>

Ali Ataman <serhant@doruk.net.tr> wrote:

> Subject: Newbie Question


Please put the subject of your article in the Subject of your article.

Your article is not about newbie questions, it is about output.


> I have a perl script and I would like to write the output of this perl
> script to a file. How can I do this.


   perldoc -f open


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


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

Date: Sat, 06 Nov 2004 15:41:09 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Newbie Question
Message-Id: <pg6jd.1856$bH2.404@trnddc09>

Ali Ataman wrote:
> I have a perl script and I would like to write the output of this perl
> script to a file. How can I do this.

Exactly the same way you would write the output of any other program to a 
file.
How to do that depends on your command shell, but most provide a redirect, 
e.g.

    myperlscript > outputfile

> I know it is simple but I just started perl..

But your question has nothing to do with Perl.

jue 




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

Date: Sat, 06 Nov 2004 09:06:16 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Q: re Inline and Benchmark
Message-Id: <ivtno01spcnrfh83u846v04hl6djnh5ta9@4ax.com>

On Fri, 05 Nov 2004 18:46:01 +0000, Sisyphus
<kalinaubears@iinet.net.au> wrote:

>Just use the 'sisyphus()' subroutine - which is essentially as I posted 
>in the first place - unless someone can convince you to do otherwise.

That's what I was thinking of doing anyway.


TY,
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: Sat, 06 Nov 2004 11:37:19 +0100
From: Patrick <geen@geen.nl>
Subject: reading a txt file
Message-Id: <u6apo0p45m0anbhoihrvv4mb6svencjc7o@4ax.com>

Hi,

I have a file with the following text.

	Titel

	Een stukje tekst.	Een stukje tekst.	Een stukje 	
             tekst. Een stukje tekst.	Een stukje tekst.	
	Een stukje tekst.	Een stukje tekst.	Een stukje 	
             tekst.

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

	Nog een Titel

	Een stukje tekst.	Een stukje tekst.	Een stukje 	
             tekst. Een stukje tekst.	Een stukje tekst.	
	Een stukje tekst.	Een stukje tekst.	Een stukje 	
             tekst.

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

How can I do the following:

var1 = the Titel (line1)
var2 = The rest of the text until "-------------------" 

Skip to the next one.

Gr. Patrick.





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

Date: Sat, 06 Nov 2004 12:32:47 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: reading a txt file
Message-Id: <bddpo0pqjugiua37nucq37nm0ch5etnufo@4ax.com>

On Sat, 06 Nov 2004 11:37:19 +0100, Patrick <geen@geen.nl> wrote:

>How can I do the following:
>
>var1 = the Titel (line1)
>var2 = The rest of the text until "-------------------" 

Very poor description!

Something along the lines of


  while (<>) {
      my $var1=$_;
      local $/='x' x 80;  # or whatever it is!
      my $var2=<>;
      
      # do something useful...
  }
        
      
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: Sat, 6 Nov 2004 09:29:18 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: reading a txt file
Message-Id: <slrncopree.jjg.tadmc@magna.augustmail.com>

Patrick <geen@geen.nl> wrote:

> How can I do the following:
> 
> var1 = the Titel (line1)
> var2 = The rest of the text until "-------------------" 


set the $/ variable (perldoc perlvar) to the appropriate value,
then split() out the 2 interesting parts:

   my( $var1, $var2 ) = split /\n/, $_, 2;


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


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

Date: 5 Nov 2004 23:41:15 -0800
From: nadsinoz@hotmail.com (chris)
Subject: synchronus ftp call
Message-Id: <b8996f29.0411052341.3b8fd119@posting.google.com>

I have the following bit of code that makes a call to the ftp binary. 
The call seems to be happening asynchronusly.  How can I make perl
wait for the print FTP statement to finish?

Is there a better way of doing this (e.g. system() call, etc.,)?  My
perl version is 5.005_02 built for PA-RISC1.1.  I am not able to use
any perl libs such as Net::Ftp.

#################################

open FTP, "|$FTP -n" or die $!;

print FTP <<EndFTP
open $FTP_SITE
user $FTP_USER
pass $FTP_PASS
get README
quit
EndFTP

#################################

Thanks in advance,

Chris


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

Date: Sat, 06 Nov 2004 08:04:05 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: synchronus ftp call
Message-Id: <cmi08q$qvn$1@sun3.bham.ac.uk>



chris wrote:

 > Subject: synchronus ftp call

 > I am not able to use any perl libs such as Net::Ftp.

You are not partitioning your question correctly.  You've concuded that 
you are not able to use Net::FTP but need to use a subprocess.  As such 
the Perl part of your question is only about handling subprocesses an 
not about FTP.

> I have the following bit of code that makes a call to the ftp binary. 
> The call seems to be happening asynchronusly.

 > open FTP, "|$FTP -n" or die $!;
 >
 > print FTP <<EndFTP
 > open $FTP_SITE
 > user $FTP_USER
 > pass $FTP_PASS
 > get README
 > quit
 > EndFTP

When you issue a close(FTP) perl will wait for the subrocess to complete.

> How can I make perl wait for the print FTP statement to finish?

It is not the print statement you want to wait for, it is the subrocess.

> Is there a better way of doing this (e.g. system() call, etc.,)? 

You can put the ftp session input into a temporary file then use 
system().  This, of course, has little to do with Perl - it would apply 
equally in most languages.



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

Date: Sat, 06 Nov 2004 11:16:55 +0000
From: Stuart Moore <stjm2@cam.ac.uk>
Subject: Re: why not    print $A[0]
Message-Id: <cmibr4$lsj$2@gemini.csx.cam.ac.uk>

Gunnar Hjalmarsson wrote:

> This works fine:
> 
>     my @A;
>     open $A[0], '> file';
>     print { $A[0] } "foo\n";
>     close $A[0];
> 
> You just need to take care of the ambiguity.
> 

OOI, how is

print $a[0] "foo\n";

any more ambiguous than

print $a "foo\n";



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

Date: Sat, 06 Nov 2004 12:47:21 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: why not    print $A[0]
Message-Id: <2v3ruaF2fkpiuU1@uni-berlin.de>

Stuart Moore wrote:
> Gunnar Hjalmarsson wrote:
>> This works fine:
>>
>>     my @A;
>>     open $A[0], '> file';
>>     print { $A[0] } "foo\n";
>>     close $A[0];
>>
>> You just need to take care of the ambiguity.
> 
> OOI, how is
> 
> print $a[0] "foo\n";
> 
> any more ambiguous than
> 
> print $a "foo\n";

Guess you'd better check the sorce code of the print() function to find 
out. ;-)

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


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

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


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