[9678] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3272 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 28 01:07:39 1998

Date: Mon, 27 Jul 98 22:00:22 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 27 Jul 1998     Volume: 8 Number: 3272

Today's topics:
        .INI profile parser & writer? mhc@my-dejanews.com
    Re: Breaking out of a block <tchrist@mox.perl.com>
    Re: Building and sorting a list of records (Martien Verbruggen)
    Re: Dup STDERR to STDOUT under NT? <aperrin@mcmahon.qal.berkeley.edu>
    Re: embedding perl into VB (Jeremy D. Zawodny)
    Re: file system operations on open files (Ilya Zakharevich)
    Re: having problems reading STDIN (Martien Verbruggen)
        Help reg. exp: shouldn't ^ match at beginning only? cortez@ali.com.au
    Re: Help reg. exp: shouldn't ^ match at beginning only? (Tad McClellan)
    Re: Help reg. exp: shouldn't ^ match at beginning only? (Craig Berry)
    Re: How Do I Access my Modules? (Martien Verbruggen)
    Re: How Do I Access my Modules? (Mike Stok)
    Re: HTTP POST FORMAT Help! (CGI-Unix) (Martien Verbruggen)
    Re: Im Willing to pay or give a free DOMAIN for a custo (Abigail)
    Re: Im Willing to pay or give a free DOMAIN for a custo (Tad McClellan)
    Re: PLEASE HELP: Simple ascii to binary script (Martien Verbruggen)
    Re: Reacting to 1 of 10 or so possible values.... Need  <metcher@spider.herston.uq.edu.au>
    Re: Reacting to 1 of 10 or so possible values.... Need  (Ilya Zakharevich)
        regexp as subroutine parameter <ryanpc@lbin.com>
    Re: Search Script? Please Help <matt@whiterabbit.co.uk>
    Re: sending mail from within perl <pkeefe@ix.netcom.com>
    Re: sending mail from within perl <rmcvay@acm.org>
    Re: Simplish regular expression Question (Craig Berry)
    Re: String to Ascii (Mike Stok)
    Re: String to Ascii (Craig Berry)
    Re: three perl questions for the experts (Craig Berry)
        Transferring files from client to server <webmaster@triologic.com>
    Re: Unable to get REMOTE_HOST (Larry Rosler)
    Re: Variable interpolation in a hash key (Craig Berry)
    Re: Y2K problem in PERL with localtime() (Tad McClellan)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Tue, 28 Jul 1998 02:08:07 GMT
From: mhc@my-dejanews.com
Subject: .INI profile parser & writer?
Message-Id: <6pjbq7$8k4$1@nnrp1.dejanews.com>

Hi, everybody !

  I'm a novice to program cgi in Perl under Linux.
  I need to parse a WIN.INI style configuration file,
  to retrieve current configuration, and modify some settings.

  Is there a standard library or popular script to implement
  the counterparts for M$' GetProfileKey, SetProfileKey
  in Perl available ?

   I don't want to reinvent a  wheel.
  Please give me a hint.

  Best Regards
  M.H. Chou


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: 28 Jul 1998 02:52:49 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Breaking out of a block
Message-Id: <6pjee1$om5$1@csnews.cs.colorado.edu>

In comp.lang.perl.misc, someone who screwed with their address asked
a question.  The simple solution is to double the braces, of course.

--tom
-- 
"Espousing the eponymous /cgi-bin/perl.exe?FMH.pl execution model is like 
reading a suicide note -- three days too late."
	    --Tom Christiansen <tchrist@mox.perl.com>


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

Date: 28 Jul 1998 03:06:25 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Building and sorting a list of records
Message-Id: <6pjf7h$k4p$3@nswpull.telstra.net>

In article <6pfiq6$eeb$1@platane.wanadoo.fr>,
	"Stephane Barizien" <sto41@wanadoo.fr> writes:
> I'm probably gonna be RTFMed on that one, but I couldn't find the answer.

yep. :)

> I want to build a list of records in a loop, then sort that list according
> to a given field.

# perldoc perlfaq4
     How do I sort an array by (anything)?

Martien
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: Mon, 27 Jul 1998 21:35:24 -0700
From: Andrew Perrin <aperrin@mcmahon.qal.berkeley.edu>
Subject: Re: Dup STDERR to STDOUT under NT?
Message-Id: <35BD550B.9BEDF9FE@mcmahon.qal.berkeley.edu>

Um, hello, I haven't done this on NT so maybe there's a difference there,
but Jeremy's code was right for Unix systems; I do it all the time.
Haven't tried Dan's version though; it might work too.  Maybe NT's too
brain-dead to allow dup'ing?

Andy Perrin

Dan Nguyen wrote:

> Jeremy Mortimer <mortimer@ifrc.org> wrote:
> :     open(STDERR, ">&STDOUT");
>
> : My Perl is the Activeware port on Windows NT, and it just writes to a
> : file called STDOUT. Am I doing something really dumb, or is this a
> : problem with NT? Either way, what can I do about it?
>
> Unfortunately you are doing something dumb.  Perl thinks your trying
> to open a file called STDOUT.
>
> *STDERR = *STDOUT;
>
> Any time you refer to STDERR it'll go to STDOUT.  However for some
> reason, which I'm not sure of 'warn' will still print to STDERR.
>
> -dan
>
> --
>            Dan Nguyen            | There is only one happiness in
>         nguyend7@msu.edu         |   life, to love and be loved.
> http://www.cse.msu.edu/~nguyend7 |                   -George Sand



--
-------------------------------------------------------------
Andrew J. Perrin - NT/Unix/Access Consulting -  (650)938-4740
aperrin@mcmahon.qal.berkeley.edu (Remove the Junk Mail King
http://socrates.berkeley.edu/~aperrin        to e-mail me)
    e-mail wheres-andy@socrates.berkeley.edu to find me!
-------------------------------------------------------------




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

Date: 27 Jul 1998 23:18:54 -0400
From: jzawodn@wcnet.org (Jeremy D. Zawodny)
Subject: Re: embedding perl into VB
Message-Id: <m3emv6hdcx.fsf@peach.z.org>

Jeffee Kiser <jkiser@best.com> writes:

> Does anyone know if there are any ways (or know where some documentation
> may be) on embedding the perl interpretter into an application written
> in Visual Basic?  Thanks

Have a look at some of the stuff that the folks at ActiveState have
whipped up (like PerlCOM).

http://www.activestate.com/

Jeremy
-- 
Jeremy D. Zawodny                   Web Geek, Perl Hacker, etc.
http://www.wcnet.org/~jzawodn/      jzawodn@wcnet.org

LOAD "LINUX",8,1


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

Date: 28 Jul 1998 04:46:44 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: file system operations on open files
Message-Id: <6pjl3k$fs6$1@mathserv.mps.ohio-state.edu>
Keywords: chute escrow fowl officious

[A complimentary Cc of this posting was sent to Mark-Jason Dominus
<mjd@op.net>],
who wrote in article <6pj579$2sm$1@monet.op.net>:
> It's fine.  It's perfectly OK to link, unlink, rename, or chmod a file
> that is open.  On Unix systems

It is *absolutely* unportable to link, unlink, rename, or chmod a file
that is open.  The only excuse you have is that I do not know a
non-Unixish system with /etc/password.  ;-)

Ilya


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

Date: 28 Jul 1998 03:09:43 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: having problems reading STDIN
Message-Id: <6pjfdn$k4p$4@nswpull.telstra.net>

In article <6pecd0$51e$1@ash.prod.itd.earthlink.net>,
	"Brent Verner" <REPLY_TO_damonbrent@earthlink.net> writes:

> while(<STDIN>)

You do realise that this reads form STDIN?

> {
>     read STDIN, $buffer, 4096, length($buffer);

As well as this?

You'll have to make up your mind about which of the two you want to use.

Martien
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: Tue, 28 Jul 1998 01:59:16 GMT
From: cortez@ali.com.au
Subject: Help reg. exp: shouldn't ^ match at beginning only?
Message-Id: <6pjb9k$7u0$1@nnrp1.dejanews.com>

Hello, could anybody explain why the following works as it does?:

 ...........................................
$s = 'This is a test line';
$s =~ /^([^ ]* )*/;
print $1, "\n";
 ...........................................

The script above will give:
test

Isn't  ' ^ ' suppossed to match at the beginning of the string only?
The same result is obtained with :  $s =~ /^([^ ]* )+/

And if this is not necessarily the case, how come the following does work as
intended?:

 ...........................................
$s = 'This is a test line';
$s =~ /^([^ ]* ) */;
print $1, "\n";
 ...........................................

The script above will give:
This

I would appreciate any explanation.

Carlos

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Mon, 27 Jul 1998 22:50:13 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Help reg. exp: shouldn't ^ match at beginning only?
Message-Id: <lphjp6.frb.ln@localhost>

cortez@ali.com.au wrote:
: Hello, could anybody explain why the following works as it does?:

: ............................................
: $s = 'This is a test line';
: $s =~ /^([^ ]* )*/;
: print $1, "\n";
: ............................................

: The script above will give:
: test

: Isn't  ' ^ ' suppossed to match at the beginning of the string only?

   Yes, it is supposed to match at the beginning of the string only.

   Yes, it is matching at the beginning of the string only.

   ;-)

match the beginning of the string, then
match 1:  'This '
match 2:  'is '
match 3:  'a '
match 4:  'test '

   Since the final * is not in the parens, $1 will be only the last
   value matched ('test ').


: And if this is not necessarily the case, how come the following does work as
: intended?:


   I guess we have to infer what is intended?

   You could have just told us what you _want_ it to do...


: ............................................
: $s = 'This is a test line';
: $s =~ /^([^ ]* ) */;
: print $1, "\n";
: ............................................


match the beginning of the string, then
match 1:  'This '

   It can only match the given string one time.


: The script above will give:
: This

: I would appreciate any explanation.


   In this regex the parenthesised part cannot repeat.

   The final * lets the _space_ be repeated.



   I hope that explained it.

   I would have liked to give you code that does what you want,
   but I can't figure out exactly what it is that you want.


   match up to, and including, the first space:

      $s =~ /^([^ ]* )/;

   keep in mind that if $s contains no spaces, then the match will
   fail, and $1 will not be set at all (it will retain its *previous*
   value)...

------------
#!/usr/bin/perl -w

$s = 'This';
$s =~ /^(.)/;        # get some value into $1

$s =~ /^([^ ]* )/;   # no match, so $1 is unchanged
print "'$1'\n";
------------

output:

'T'


So you should do:

   print "'$1'\n" if $s =~ /^([^ ]* )/;

if you want to rely on $1 having a new value.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 28 Jul 1998 04:25:45 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Help reg. exp: shouldn't ^ match at beginning only?
Message-Id: <6pjjs9$7de$3@marina.cinenet.net>

cortez@ali.com.au wrote:
: Hello, could anybody explain why the following works as it does?:
: ...........................................
: $s = 'This is a test line';
: $s =~ /^([^ ]* )*/;
: print $1, "\n";
: ...........................................
: 
: The script above will give:
: test

This surprised me for a moment, too, but it turns out to be the right
answer.

: Isn't  ' ^ ' suppossed to match at the beginning of the string only?

It does, but that only constrains the first match, of which there can be
zero or more.

: The same result is obtained with :  $s =~ /^([^ ]* )+/

Ditto.  Consider that the capturing parens are modified externally by the
* or + quantifier; thus the match on 'zero or more nonspace followed by
space') can occur many times, each overlaying the previous value of $1.
Only the last one, 'test ', survives.

: And if this is not necessarily the case, how come the following does work as
: intended?:
: 
: ...........................................
: $s = 'This is a test line';
: $s =~ /^([^ ]* ) */;
: print $1, "\n";
: ...........................................
: 
: The script above will give:
: This

Yup.  That says "Beginning of line, followed by a captured series of zero
or more nonspaces followed by space, followed by zero or more spaces."  In
this case the captured part isn't quantified, so matches exactly once, at
'This '.  And the trailing zero-or-more-spaces always gets zero on your
test string, by the way.

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: 28 Jul 1998 03:04:44 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: How Do I Access my Modules?
Message-Id: <6pjf4c$k4p$2@nswpull.telstra.net>

In article <35BCE124.E5D504C5@cowboys.anet-dfw.com>,
	Tom Turton <tturton@cowboys.anet-dfw.com> writes:

> push (@INC,"/home/tturton/PERL/MyPerlLib");
> use MyPerlLib::Airline;

This will only work for require. For use, you will need to put this in
a BEGIN block. Of course, you could have just done what Ralph Jaeger
said, and do use lib.

It's all in the documentation.

Martien
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: 28 Jul 1998 03:08:46 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: How Do I Access my Modules?
Message-Id: <6pjfbu$mdk@news-central.tiac.net>

In article <35BCE124.E5D504C5@cowboys.anet-dfw.com>,
Tom Turton  <tturton@cowboys.anet-dfw.com> wrote:

>> you can either extend the @inc or you can use
>>
>> use lib 'mydirectorywheremyperllibsarein';
>
>Still getting same behavior.
>Added:
>
>push (@INC,"/home/tturton/PERL/MyPerlLib");
>use MyPerlLib::Airline;
>
>When running from /home/tturton/PERL,  what_airline.pl (located in
>/home/tturton/PERL) works fine, but when I run what_airline.pl from any other
>directory, it "Can't locate MyPerlLib/Airline.pm in @INC"
>
>Any additional clues?

Perl's applening MyPerlLib/Airline.pm to the end of each entry of @INC
(plus a path separator), so when it gets to /home/tturton/PERL/MyPerlLib
and is looking for MyPerlLib/Airline.pm the file name it uses is

  /home/tturton/PERL/MyPerlLib/MyPerlLib/Airline.pm

Maybe you want 

  use lib '/home/tturton/PERL';

note that there are a couple of phases of execution of an interpreted perl
script, a compilation phase and an execution phase.  use happens during
the compilation phase, so if you *really* want to ignore the lib pragma
you need to wrap your push in a BEGIN block to make it happen during the
compilation phase.

Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: 28 Jul 1998 03:37:16 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: HTTP POST FORMAT Help! (CGI-Unix)
Message-Id: <6pjh1c$la8$1@nswpull.telstra.net>

[Posted and mailed]

Please read the following information on how to choose a good subject
line:

http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post


In article <35BB348E.1950AC40@cienz.unizar.es>,
	miedo <431854@cienz.unizar.es> writes:
> <HTML>

Please, don't post in HTML. Usenet is a plain text medium, and I, for
one, will not attempt to decipher your HTML post.

> I am using this function but it don&acute;t works correctly, for example
> i tried:
> <BR><I>print "&amp;get_page("www.arrakis.es", "/index.htm", 80)";</I>

This is unreadable.

Martien
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: 28 Jul 1998 02:57:40 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Im Willing to pay or give a free DOMAIN for a custom cgi!
Message-Id: <6pjen4$8ct$1@client3.news.psi.net>

method98 (method98@iname.com) wrote on MDCCXCII September MCMXCIII in
<URL: news:6pj6hr$cle$1@reader1.reader.news.ozemail.net>:
++ Can Anyone Make a Hidden Cgi that clicks on sponser
++ undectably to the user viewing the web page and the sponsers
++ itself... I am willing to pay Webmasters or Hosters $400 USD with my
++ credit card, or buy a DOMAIN to anyone how can make this cgi-script
++ and the DOMAIN is for 1 year.


Do you pay $400 for a proof that's it is impossible as well?



Abigail
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'


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

Date: Mon, 27 Jul 1998 22:19:38 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Im Willing to pay or give a free DOMAIN for a custom cgi!
Message-Id: <a0gjp6.jlb.ln@localhost>

method98 (method98@iname.com) wrote:
: Can Anyone Make a Hidden Cgi that clicks on sponser
: undectably to the user viewing the web page and the sponsers
: itself... I am willing to pay Webmasters or Hosters $400 USD with my
: credit card, or buy a DOMAIN to anyone how can make this cgi-script
: and the DOMAIN is for 1 year.

: IT MUST BE 110% UNDECTABLE TO THE SPONSERS AND THE USERS!!!
     ^^^^^^^^^^^

   Do you realize that that is IMPOSSIBLE?

   100% is "perfect".

   110% is nonsense...


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 28 Jul 1998 03:02:29 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: PLEASE HELP: Simple ascii to binary script
Message-Id: <6pjf05$k4p$1@nswpull.telstra.net>

In article <6pietj$773$1@news.nero.net>,
	stanley@skyking.OCE.ORST.EDU (John Stanley) writes:

> #!/usr/local/bin/perl -w
> # a simple script to read ASCII, write binary.
> 
> # for every line you take in in ASCII
> while(<>) {
> 	# print it right back out, since ASCII is binary.
> 	print;
> }

# perl -pe ''

Martien
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: Tue, 28 Jul 1998 13:29:10 +1000
From: Jaime Metcher <metcher@spider.herston.uq.edu.au>
Subject: Re: Reacting to 1 of 10 or so possible values.... Need some streamlining help.
Message-Id: <35BD4586.9019CE79@spider.herston.uq.edu.au>

Mark-Jason Dominus wrote:
> 
> In article <35BBD43C.7F5A9B72@spider.herston.uq.edu.au>,
> Jaime Metcher  <metcher@spider.herston.uq.edu.au> wrote:
> >Genuine, non-sarcastic question: I can see that this is more perlish,
> >but why is it more streamlined?  For only ten possibilities, if all
> >equally likely, the original version is doing an average of five tests
> >per run.
> 
> Making the program faster is not the point.  The dispatch table is
> better not because it is faster, but because it makes the code
> smaller.
> 

Hell, I couldn't care less about squeezing speed out of the script.  The
original poster was wondering if there was a more streamlined solution. 
He may have meant speed, or he may have meant readability.

> Instead of a large, multi-way test that is spread out over many lines,
> the test is very small and is in one place in the program.  The
> multi-way test has been replaced by a table that is so compact that
> you can see the whole thing at once.
> 

if ($case1) { &handle_case1; }
elsif ($case2) { &handle_case2; }
# etc

> It's also more flexible.  The subroutine that chooses an action based
> on inputs no longer has its behavior hardwired in; instead, you can
> pass it the dispatch table as an argument, and get different behaviors
> by passing in different dispatch tables.

I couldn't agree more.  The dispatch table is *the* general solution. 
It's also a great example of several perl techniques.  Better than all
of that, it's *clever*!.

-- 
Jaime Metcher (feeling sorry for the much-maligned but extremely
descriptive if...elsif statement)


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

Date: 28 Jul 1998 04:51:47 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Reacting to 1 of 10 or so possible values.... Need some streamlining help.
Message-Id: <6pjld3$g9p$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to John Porter 
<jdporter@min.net>],
who wrote in article <35BCEAE6.1E84@min.net>:
> Oof.  Too true.  How's this:
> 
>     for ( $reqType ) {
>         s/^typeOne$/ &handle_typeOne; $& /e    or
>         s/^typeTwo$/ &handle_typeTwo; $& /e    or
>                      &handle_default;
>     }

Close to the optimal:

      use 5.005;
      m{
         ^typeOne$ (?{ Do-type-one })
       |
         ^typeTwo$ (?{ Do-type-two })
       |
         (?{ Do-default })
       }x;

Ilya


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

Date: Mon, 27 Jul 1998 19:07:21 -0700
From: ryan pc gibson <ryanpc@lbin.com>
Subject: regexp as subroutine parameter
Message-Id: <35BD3259.32F272A5@lbin.com>

hello,

	i damn near lost my mind trying to figure out how to pass a regexp as a
parameter to a subroutine (that i am trying to make as general as
possible).  the tricky part is i want the perl regexp to contain
variables that get interpolated once they are inside the subroutine, not
before.
	i would be very interested in any suggestions or thoughts.

	- ryan*(pc)

	here is a skeleton of the code...

########################################
# somewhere in main loop

$regexp = 's/$id/$hash{$id}/gism'
&insert_hash(\%hash,$file);

########################################
# replaces occurences of the key with value for each hash item

sub insert_hash {
  
    my %hash = %{@_[0]};    # hash of ids/values to replace
    my $file = @_[1];       # file to modify

    # convert file to string
    open(IN,$file); $contents=join('',<IN>); close IN;

    foreach $id (keys %hash) {	$contents =~ $regexp;     };

    open(OUT,">$file") or die "Could not open $file for output\n";
    print OUT $contents or die "Could not write to $file\n";
    close OUT;

}; # end insert_hash sub

-- 
::__            ____________ ryan pc gibson __________________
::__ webmaster: ___                                       ____
::_________________ lightbinders, inc., san francisco, ca ____


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

Date: Tue, 28 Jul 1998 04:35:12 +0100
From: Matt Pryor <matt@whiterabbit.co.uk>
Subject: Re: Search Script? Please Help
Message-Id: <35BD46F0.41E85344@whiterabbit.co.uk>

Hello Daniel,

@paragraph__key_words is a list of key words (or phrases) which you're
searching for in the text which the user inputs.

$user_input is the text string entered by the user.

@relevant_topics is the list produced containing keywords relevant to
the query.

So:

foreach $a(@paragraph_key_words) {               # loop through keywords
         if ($user_input =~ /\Q$a\E/ig) {        # does user's input
#                                                   contain keyword?
                 push (@relevant_topics,$a);     # yes so add to list.
         }
}

Let's make things a little more sophisticated - pay attention!

If the key phrases contain more than one word, eg "Computer Science", it
may be worth testing for each of the words individually.

I'd do something along these lines:

foreach $a(@paragraph_key_words) {
# loop through each of the key phrases same as above

        if ($match_percent{$a} = does_match ($a,$user_input)) {
# call subroutine to test for match (see below).  If subroutine returns 
# a value, then:

                push (@relevant_topics,$a);

# add that topic to the list of relevant topics.
        }
}

@relevant_topics = sort by_match (@relevant_topics);

sub by_match {
        return $match_percent{$a} <=> $match_percent{$b};
}

# The above four lines sort the list of relevant topics into order of
how closely they match.


Here's the sub to test for matches:

sub does_match {
        my ($a);
        my $phrase_to_match = $_[0];           # 1st arg to subroutine
        my $text_to_search = $_[1];            # 2nd arg to subroutine
        my @words = split (/ /,$phrase_to_match);   # list words
        foreach $a(@words) {                   # loop thru words
                $matching_words++ if ($text_to_search =~ /\Q$a/E/gi);

# add to count of matching words if phrase contains that word.

        }
        my $count = @words;

# $count now equals the possible number of words that could match

        my $success = int ($matching_words/$count) * 100;

# Calculate a match percentage based on how many words match.

        return $success;

# Pass that percentage back to calling statement.

}

An example of the above in action:

I enter "I want to study computer science, as I like mathematics.";
The key phrases to search for are:

Advanced Mathematics
Quantum Mechanics
Computer Science

1) Does my phrase contain "advanced" or "mathematics" ?  Yes, but one
word only.  Subroutine returns 50.
2) Does my phrase contain "quantum" or "mechanics" ?  No.  Subroutine
returns 0.
3) Does my phrase contain "computer" or "science"? Yes and yes - the
subroutine returns a match of 100.

This then results in @relevant_topics containing a list of the
following:

Advanced Mathematics
Computer Science

Which are then sorted into this order:

Computer Science
Advanced Mathematics

============
Program Ends
============

These keywords would then be linked to the relevant paragraphs using
hashes.  Eg:

$para{"Computer Science"} = "blah..blah..blah";

foreach $a(@relevant_topics) {
        print $para{$a};
}

exit(0);

This loops through the relevant topics and prints the corresponding
paragraphs of information.


I hope this explains things.  

Good luck!


-- 
Matt Pryor

http://www.whiterabbit.co.uk/cgi/cartoons.txt




Daniel Newman wrote:
> 
> I've got a quick question, how could i do the following?
> 
> i want a big text file that has different seperated "paragraphs" each
> with its own "keywords".  After
>           a user inputs some sentences i want a script to find the
> keywords and then output a HTML page with
>           the paragraphs from the text file that apply.
>           For example:
>           a user types in:
> 
>           "I want to go to a medium sized college. I want to major in
> computer science. I have  a 4.0
>           GPA and I got  a 1480 on my SATs."
> 
>           the HTML page would display the 4 paragraphs titled(the full
> paragraphs, not links to them):
> 
>           MEDIUM SIZED COLLEGES
>           COMPUTER SCIENCE
>           GPA INFORMATION
>           SAT SCORE INFORMATION
> 
> Thank you very much!
> 
> -Daniel Newman
> impulse@usa.net

-- 
Matt Pryor

http://www.whiterabbit.co.uk/cgi/cartoons.txt


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

Date: Sun, 26 Jul 1998 22:19:25 -0400
From: "Pete Keefe" <pkeefe@ix.netcom.com>
Subject: Re: sending mail from within perl
Message-Id: <6pjcf8$9vp@dfw-ixnews6.ix.netcom.com>

Look at Net::SMTP and I think you will find this solves your problem.

Dave Stephens wrote in message <35BCBA54.4DB2336F@gusun.georgetown.edu>...
>Use Jgaa's wsendmail.  Works like a charm.
>http://www.jgaa.com/cgi-bin.htm
>
>--Dave Stephens
>
>> > Hi:
>> >
>> > I'm running Perl under windows 95.  I want to send mail from a script
but do
>> > not have a mail server running.  I am connected 24/7 and wonder if I
can use
>> > my mail host (smtp.gte.net) to send the mail for me?
>> >
>> > Thanks.
>> >
>> > Bob
>> >
>> > --
>
>
>




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

Date: Mon, 27 Jul 1998 21:31:22 -0500
From: Ray McVay <rmcvay@acm.org>
Subject: Re: sending mail from within perl
Message-Id: <35BD37FA.AE55BC8E@acm.org>

Bob L. wrote:
> I tried to use it but I get "Document Contains No Data".  I looked in the
> Perl directory and found other Net:  types but not SMTP.  Do I have to get
> the SMTP module?  I was told it would be part of Perl.  I'm using the latest
> version from activestate.

That's your problem.  Toss the Activestate Perl and get the standard
Perl 5.004, the GS port.  I've done both SMTP and MAPI/Exchange mail
with it.

-- 

Ray

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ "All the world is but a play. Be thou the joyful players." +
+ Maya - Incredible String Band                              +
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++




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

Date: 28 Jul 1998 03:21:57 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Simplish regular expression Question
Message-Id: <6pjg4l$465$2@marina.cinenet.net>

dwarren1@my-dejanews.com wrote:
: I think I have a decent grasp of regular expressions but I'm not sure
: what the best way to accomplish this would be.  I have a string in the
: form of:
: "/dir/file" or "/dir/file.c" or "dir/file" or "dir/file.c"
: and in each case I would like to change the string to simply be "dir/file"

  $str =~ s!^/?(.*?)(?:\.c)?$!$1!;

: My current regexp looks like:
: #!/usr/bin/perl

No -w ?

: $str="\"/dir/file.c\"";

Hmm, that string (which is easier to write as qq!"/dir/file.c"!) has
literal double-quotes as characters in the string, not matching your spec
above.  Which one is right?

: $str=~s/^"[\/]?([\w\/]*)(\.c)?\"$/"$1"/;
: print "'$str'\n";
: and it works, however I don't like [\w\/]* i'd like to use lookahead and
: say (.*) except '.c' together.  However I'm not quite sure how to best
: do that.

Not sure that's the best approach.  My version above will stop at each .c
and see if it's followed by newline/end-of-string, completing the match if
so, continuing if not.  Amounts to the same thing, really.

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: 28 Jul 1998 03:18:04 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: String to Ascii
Message-Id: <6pjftc$mut@news-central.tiac.net>

In article <35BCED5B.47FB7DE1@gusun.georgetown.edu>,
Dave Stephens  <stepherd@gusun.georgetown.edu> wrote:
>Here you go:
>
>$string = "A string to be converted into ascii";
>
>@letters = split (//, $string);
>
>while (@letters[$count] ne "")
>{
> @ascii[$count] = ord("@letters[$count]");
> $count++;
>}

@ascii = map {ord} split //, "A string to be converted into ascii";

or 

@ascii = unpack 'C*', "A string to be converted into ascii"

(which I prefer...) are a couple of other ways to do it.

Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: 28 Jul 1998 04:15:52 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: String to Ascii
Message-Id: <6pjj9o$7de$2@marina.cinenet.net>

Dave Stephens (stepherd@gusun.georgetown.edu) wrote:
: Here you go:
: 
: $string = "A string to be converted into ascii";
: @letters = split (//, $string);
: 
: while (@letters[$count] ne "")

That should be a $, not a @.  What you have is an array slice of one
element.

: {
:  @ascii[$count] = ord("@letters[$count]");

Ditto.

:  $count++;
: }
: $count = 0;
: foreach $letter (@ascii)
: {
:  $count++;
:  print "Letter $count = $letter\n\n";
: }

Seems a bit more concise to say:

  my @ascii = map { ord } split //, $string

  for (my $n = 0; $n < @ascii; $n++) {
    print "Letter $n = $ascii[$n]\n\n";
  }

Also avoids a few extraneous variables.

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: 28 Jul 1998 04:05:45 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: three perl questions for the experts
Message-Id: <6pjimq$7de$1@marina.cinenet.net>

KHeise (kheise@aol.com) wrote:
: 1) how can i direct output to a printer (for a printed report) using
: perl? i suspect it has to do with redirecting STDIO, but i have not been
: able to find any info on how to accomplish this.

This depends very strongly on what OS you're using.  Under Unix, you could
open an output pipe to lpr, among other options.  Alternatively, just have
your app write to stdout as usual, and redirect it where it's needed:

  > myapp | lpr

This is the (old) Unix Way, and it makes for very flexible programs.  For
example, you can easily hand your output to another app without recoding.
The downside is that there's more to type (and remember) to do the routine
stuff, but you can use aliases or shell scripts to encapsulate the common
pipelines you need to build.

: 2)
[snip] 
: most files i receive, but i noticed something perl is doing to some of my data
: which is unacceptable for my purposes:  when a line-feed character (hex 0A)
: falls in the middle of one of my records a carriage-return character (hex 0D)
: is inserted before the line-feed, thus adding a charcter to my record.
[snip]

Oops, guess you're *not* under Unix. :(  See the doc on 'binmode' (perldoc
-f binmode) on how to fix this.

: 3) lastly, if there is an end of file marker (hex 1A) in a file i am
: processing, it stops my program dead in its tracks. is this the same sort of
: problem as question 2? is there any way to get around this?

Yep, another job for binmode.

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Tue, 28 Jul 1998 03:17:59 GMT
From: Nick Forte <webmaster@triologic.com>
Subject: Transferring files from client to server
Message-Id: <35BD40B8.F1C999BC@triologic.com>

I've been having a tough problem creating this script that will upload
images (*.jpg) from the client's machine to the server. The ISP has
changed ownership of the directory to the same as what the perl script
runs under and I can't figure it out. Maybe if someone looked at my code
real quick:

I'm using the cgi.pm module for passing the form info:

# Get the Perl5 CGI object library
use CGI qw(:standard :html);
$query = new CGI;


Here's the routine to submit the file to the server:

sub PhotoToFile
{

# Get the filename from path information
@filename = split(/\\/, $filename);
$newfile = pop @filename;


if (open(OUT, ">$INCOMING/$newfile"))
{
  while (<$filename>)
  {
  print OUT;
  }
  close(OUT);
}
else
 { Error("Could not create $newfile on the server.");}

# Update the photo file
if (open(FILE, "+<$DATAPATH/$datafile"))
{
 @records = <FILE>;
 $insert = "$id~$name~$email~$place~$date~$host~$newfile~$description";
 seek(FILE, 0, 0);
 print FILE "$insert\n";
 print FILE @records;

 close(FILE);
}
else
{ Error('Unable to update photo file.');}
}


Any help would be much appreciated.

Thanks,
Nick Forte



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

Date: Mon, 27 Jul 1998 21:42:54 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Unable to get REMOTE_HOST
Message-Id: <MPG.1026f6a9697e5e69989796@nntp.hpl.hp.com>

In article <35bc7239.107644534@news2.cais.com> on Mon, 27 Jul 1998 
12:35:20 GMT, root.noharvest.\@not_even\here.com (-) says...
 ...
> Rather than ask the ISP to enable hostname lookups, just add this to
> your perl scripts to get the host names:
> 
> use Socket;
> 
> $hostname = gethostbyaddr(inet_aton($ENV{REMOTE_ADDR}),AF_INET);	
> 
> $hostname *should* now hold the host name, if DNS resolution
> succeeded.  If not, it'll just have the IP address - but that's what
> you'd get with hostname lookups anyway.

Are you quite sure about this?  My experience is that when gethostbyaddr 
fails to do a DNS resolution, it returns the undefined value, not the IP 
address.

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 28 Jul 1998 03:12:05 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Variable interpolation in a hash key
Message-Id: <6pjfi5$465$1@marina.cinenet.net>

Dan Nguyen (nguyend7@egr.msu.edu) wrote:
: Your problem is with $query_hash{"c",$x,"black"}.  You probably mean
: $query_hash{"c".$x."black"}.  

Or even: $query_hash{"c${x}black"}

Note the use of {} to bound the extent of the variable name x, so it
doesn't get parsed as 'xblack'.

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Mon, 27 Jul 1998 22:02:52 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Y2K problem in PERL with localtime()
Message-Id: <s0fjp6.jlb.ln@localhost>

Erdem Ozsaruhan (EOZSARUH@nsf.gov) wrote:

: Thanks for enlightening me!

: >># date +"%m-%d-%y"
: >>02-29-00

: >  Looks like you have a year 2000 problem _there_ though.

: >  Is that 1800?  1900?  2000?  2100? ...

: 02-29-100  looks like a year  2000 problem, too.


   No. It does not.


: Is that 2100? 3100? or ????


   2100 - 1900 = 200    100 !=  200, so it is not 2100

   3100 - 1900 = 1200   100 != 1200, so it is not 3100

   No confusion at all, given the ability to work arithmetic.



: I didn't do my homework and learned that localtime() returns 
: the current year - 1900


   Since 

      100 = year - 1900 

   then

      year = 100 + 1900


   High School algebra.
   

   So 02-29-100 is *unambiguously* (100 + 1900) the year 2000

   It can be no other year.

   It can only be 2000.

   No bug.



: That's how PERL handles it.

: And below is how UNIX handles it as you yourself pointed out!!!

: There is no right or wrong!


   You are kidding here. Right?


   The crux of the y2k problem is ambiguous specification of the
   year. You get strange results when the wrong one of several
   choices is chosen.

   Perl's method of representing the date gives only ONE possible
   date, so ... no choice to be made, no problem!


: >DATE(1L)                                                 DATE(1L)

: >NAME
: >       date - print or set the system date and time

: > ...

: >       %y     last two digits of year (00..99)
: >-------------

: >  Hmmm. That "last two digits" part sounds just like the classic
: >  year 2000 problem.

: >  Good thing there are no problems like that with the way perl
: >  handles years, huh?

: Neither solution looks right without looking at their manual. 
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


   But nobody uses a function without reading what to expect
   from the function. If they do, then y2k is only one type of the
   myriad bugs that their programs can expect to exhibit...

   
: However, since 
: SUN, IBM and possibly HP chooses to show the year 2000 as 00 


   Where do they do that?

   Most certainly not by virtue of the %y format.


   The *programmer* that chose to use that option introduced
   the y2k bug.

   It is a bug in the *program*, not in the *system* nor the "language".

   If the programmer had decided to use %Y instead, then they
   would not have _introduced_ a bug.





   Does seem that searching for '%y' in source code would be
   a good idea if trying to find y2k problems though...


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

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

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

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 3272
**************************************

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