[13816] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1226 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 29 21:10:45 1999

Date: Fri, 29 Oct 1999 18:10:31 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <941245831-v9-i1226@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 29 Oct 1999     Volume: 9 Number: 1226

Today's topics:
    Re: perl lang parser <slanning@bu.edu>
    Re: perl safe_mysqld (Bill Moseley)
        Perl script to check OS system <hdo@ea.com>
    Re: Reading a file backwards? <cassell@mail.cor.epa.gov>
    Re: Reading a file backwards? <lr@hpl.hp.com>
        Remember Me Option rancorr@hotmail.com
    Re: Remember Me Option (Matthew Bafford)
        RFC: Making array using range op and map louhevly@my-deja.com
    Re: RFC: Making array using range op and map <uri@sysarch.com>
    Re: RFC: Making array using range op and map <lr@hpl.hp.com>
    Re: RFC: Making array using range op and map (Matthew Bafford)
        simple regex question (Philip A. Viton)
    Re: simplifying a script (Abigail)
    Re: simplifying a script (Abigail)
        storing non-persistant cookies in perl script -- HELP?! <enemyNO-SPAM@yahoo.com>
        Stripping live HTML into text <ryan_richards_2000[NOSPAM]@yahoo.com>
    Re: Stripping live HTML into text (Nobody)
    Re: Stripping live HTML into text <slanning@bu.edu>
    Re: Stripping live HTML into text (Matthew Bafford)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 29 Oct 1999 19:30:41 -0400
From: Scott Lanning <slanning@bu.edu>
Subject: Re: perl lang parser
Message-Id: <kus66zpg2xq.fsf@bottom.bu.edu>

kpreid@ibm.net (Kevin Reid) writes:
> BEGIN {
>   eval 'sub foo (' . (rand > .5 ? '@' : '$') . ') {join "-", @_}';
> }
> 
> print foo 1, 2, "\n";
> # the way this line is parsed depends on the prototype of foo(),
> # which is random.

Dear god make it stop, MAKE IT STOP!!!
I'll be good -- I promise!

:)

-- 
qualification: I'm a dimwit according to someone who emailed me


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

Date: Fri, 29 Oct 1999 15:50:04 -0700
From: moseley@best.com (Bill Moseley)
Subject: Re: perl safe_mysqld
Message-Id: <MPG.1283c473ee116135989826@nntp1.ba.best.com>

Mike Sosteric (mikes@athabascau.ca) seems to say...
> 
> I have a problem which is probably easy. I have a perl script that tests to see 
> if the mysqld is running on the system (uses DBI to connect). If no handle
> is returned, we start iterating through a number of strategies to start the daemon. Problem is, 
> I find mysql and try to start it, but the the perl script hangs because safe_mysqld does not return.

Did you look at "Complete Dissociation of Child from Parent" in perlipc?  
That might be one way to start the daemon.

-- 
Bill Moseley mailto:moseley@best.com
pls note the one line sig, not counting this one.


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

Date: Fri, 29 Oct 1999 18:01:45 -0700
From: "Hai Do" <hdo@ea.com>
Subject: Perl script to check OS system
Message-Id: <s1kgl6r8csf42@corp.supernews.com>

Hello,

I want to write a Perl script that check the OS without calling the system
command such as 'uname' on Unix. It will dectect both Unix and Windows and
return the platform name. Is there any Perl built-in command or module to
check the OS? Please help.

Thanks,
Hai Do
SW Rel Eng.
EA Online Eng.




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

Date: Fri, 29 Oct 1999 15:17:14 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Reading a file backwards?
Message-Id: <381A1CEA.F4A7283C@mail.cor.epa.gov>

Jacob Rosenschein wrote:
> 
> Can I read a file, line by line, beginning with the last line and moving
> upward towards the beginning of the file? If so, how would I do this in
> Perl?

You've gotten some answers already.  But here's an important
answer that I haven't seen yet.

Type at a command prompt:
    perldoc -q tail
and read what the FAQ has to say on the subject.  Then
learn about perldoc:
    perldoc perldoc
    perldoc -h
and about some of the many docs Perl gives you:
    perldoc perl
    perldoc perlfaq5
[this last one is the FAQ part which contains your answer]
 
> Thanks,
> Koby Rosenschein (a newbie)

For a newbie, you wrote a good Subject: line.  Congrats.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Fri, 29 Oct 1999 16:55:14 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Reading a file backwards?
Message-Id: <MPG.1283d3c1a542f2c898a160@nntp.hpl.hp.com>

In article <381A0783.8736FAAF@eng.umd.edu> on Fri, 29 Oct 1999 16:45:55 
-0400, Vinodh R Cuppu <ramvinod@eng.umd.edu> says...
> > Can I read a file, line by line, beginning with the last line and moving
> > upward towards the beginning of the file? If so, how would I do this in
> > Perl?
> 
> use, "seek FILEHANDLE,POSITION,WHENCE", where POSITION can be negative
> counter and WHENCE is 2 for setting a position from the EOF. so something
> like seek MYFILE, -1, 2 should set it to the last line of the file.

No, it would set it to the last byte of the file.

> check out 'perldoc -f seek", for exact details.

Check out `perldoc -f seek`, for exact details.

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


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

Date: Fri, 29 Oct 1999 22:08:41 GMT
From: rancorr@hotmail.com
Subject: Remember Me Option
Message-Id: <7vd5t7$et5$1@nnrp1.deja.com>

I want to implement a "remember me" option on my website -- where users
don't have to log-on again in order to enter premium services on my
site taht usually require a password.  what's the best way to do this?


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Fri, 29 Oct 1999 23:59:50 GMT
From: *@dragons.duesouth.net (Matthew Bafford)
Subject: Re: Remember Me Option
Message-Id: <slrn81kcb7.1p4.*@dragons.duesouth.net>

Once upon a time (Fri, 29 Oct 1999 22:08:41 GMT), rancorr@hotmail.com
was attempting to figure out Ilya's new Perl regex features, and
accidently sent the following to comp.lang.perl.misc: 
: I want to implement a "remember me" option on my website -- where users
: don't have to log-on again in order to enter premium services on my
: site taht usually require a password.  what's the best way to do this?

Dunno.

What part of your Perl program are you having problems with?
 
--Matthew


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

Date: Fri, 29 Oct 1999 22:31:54 GMT
From: louhevly@my-deja.com
Subject: RFC: Making array using range op and map
Message-Id: <7vd78r$g1p$1@nnrp1.deja.com>

Greetings:

My goal is to produce a single array of numbers from 50,000 to 200,000
in increments of 10,000; then from 225,000 to 600,000 in increments of
25,000. So the array would go:
50,000, 60,000, 70,000, etc. up to 200,000, then 225,000, 250,000,
275,000 etc. up to 600,000.

Here's my code; I would be grateful for any suggestions to improve it.

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

my @price = ( [5..20], [20..60] );
@{$price[0]} = map {$_ * 10} @{$price[0]};
@{$price[1]} = grep /[5|0]$/, @{$price[1]};
@{$price[1]} = map {$_*10,  $_*10+25} @{$price[1]};
shift @{$price[1]}; pop @{$price[1]};
my @final = map { map {$_*1000} @{$_} } @price;
print "$_\n" for @final;

--
JAPHW
Lou Hevly
lou@visca.com


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 29 Oct 1999 19:50:19 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: RFC: Making array using range op and map
Message-Id: <x7iu3pd8w4.fsf@home.sysarch.com>

>>>>> "l" == louhevly  <louhevly@my-deja.com> writes:

  l> My goal is to produce a single array of numbers from 50,000 to 200,000
  l> in increments of 10,000; then from 225,000 to 600,000 in increments of
  l> 25,000. So the array would go:

  l> #!/usr/bin/perl -w
  l> use strict;

good. you use strict and -w

  l> my @price = ( [5..20], [20..60] );

  l> my @price = ( [5..19], [20..60] );

why duplicate 20? you do a lot of work to remove it.

  l> @{$price[0]} = map {$_ * 10} @{$price[0]};

	$_ *= 10_000 for @{$price[0]} ;

  l> @{$price[1]} = grep /[5|0]$/, @{$price[1]};

that line is why a for loop (see below) is better.
also | is not needed in a char class. read perlre for more on that.

  l> @{$price[1]} = map {$_*10,  $_*10+25} @{$price[1]};

more wackiness.

combine the mess in one map/map:

	@{$price[1]} = map $_ *= 1_000,
		       map { /[50]$/ ?
				($_ * 10 , $_ * 10 + 25 ) : () } @{$price[1]};

	pop @{$price[1]} ;

still need that fix given this method. :-(


  l> shift @{$price[1]}; pop @{$price[1]};

boundary fixes. more work.

  l> my @final = map { map {$_*1000} @{$_} } @price;

not needed in my fixed up version of your code.

    my @final = map @{$_}, @price;

that merges the 2 lists.


that seems like a lot of work and odd code for such a simple
problem. here is one of the few times i would use a c style for
loop. this it very linear and not anywhere as convoluted as your code.

for ( $price = 50_000 ; $price < 200_000 ; $price += 10_000 ) {

	push @prices, $price ;
}

for ( ; $price <= 600_000 ; $price += 25_000 ) {

	push @prices, $price ;
}

print "$_\n" for @prices ;

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Fri, 29 Oct 1999 17:07:51 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: RFC: Making array using range op and map
Message-Id: <MPG.1283d6b0d4dc70ea98a161@nntp.hpl.hp.com>

In article <7vd78r$g1p$1@nnrp1.deja.com> on Fri, 29 Oct 1999 22:31:54 
GMT, louhevly@my-deja.com <louhevly@my-deja.com> says...
> My goal is to produce a single array of numbers from 50,000 to 200,000
> in increments of 10,000; then from 225,000 to 600,000 in increments of
> 25,000. So the array would go:
> 50,000, 60,000, 70,000, etc. up to 200,000, then 225,000, 250,000,
> 275,000 etc. up to 600,000.
> 
> Here's my code; I would be grateful for any suggestions to improve it.
> 
> #!/usr/bin/perl -w
> use strict;
> 
> my @price = ( [5..20], [20..60] );
> @{$price[0]} = map {$_ * 10} @{$price[0]};
> @{$price[1]} = grep /[5|0]$/, @{$price[1]};
> @{$price[1]} = map {$_*10,  $_*10+25} @{$price[1]};
> shift @{$price[1]}; pop @{$price[1]};
> my @final = map { map {$_*1000} @{$_} } @price;
> print "$_\n" for @final;

There's a lot of heavy lifting going on there!

How about this:

my ($incr1, $incr2) = (10_000, 25_000);

my @final = (map($incr1 * $_ =>  50_000/$incr1 .. 200_000/$incr1),
             map($incr2 * $_ => 225_000/$incr2 .. 600_000/$incr2));

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


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

Date: Fri, 29 Oct 1999 23:59:52 GMT
From: *@dragons.duesouth.net (Matthew Bafford)
Subject: Re: RFC: Making array using range op and map
Message-Id: <slrn81kd4a.1p4.*@dragons.duesouth.net>

On Fri, 29 Oct 1999 22:31:54 GMT, louhevly@my-deja.com enriched us with: 
: Greetings:
: 
: My goal is to produce a single array of numbers from 50,000 to 200,000
: in increments of 10,000; then from 225,000 to 600,000 in increments of
: 25,000. So the array would go:
: 50,000, 60,000, 70,000, etc. up to 200,000, then 225,000, 250,000,
: 275,000 etc. up to 600,000.
:
: Here's my code; I would be grateful for any suggestions to improve it.

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

sub make_range {
    my @a;
    
    for my $range ( @_ ) {
        my($min, $max, $step) = @{$range};
        
        push @a, $_ * $step + $min for 0 .. ($max - $min)/$step;
    }

    @a;
}

use Data::Dumper;
print Dumper make_range([50_000, 200_000, 10_000], [225_000, 600_000, 25_000]);

: Lou Hevly

--Matthew


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

Date: Fri, 29 Oct 1999 19:17:21
From: pviton@magnus.acs.ohio-state.edu (Philip A. Viton)
Subject: simple regex question
Message-Id: <pviton.484.00134AA4@magnus.acs.ohio-state.edu>


If I do

  s|c:\\|d:\\|;

within a script, I can change c:\  to d:\ .  I'd like to generalize this, so I 
can pass the two strings to a script in the command line. But if I pass, eg 

  myroutine.pl myfile.txt c:\\  d:\\

and do

   s|$ARGV[1]|$ARGV[2]|;

c:\  gets changed to d:\\  (ie with an extra \). Can anyone see what I'm doing 
wrong?

Thanks!


----------------
Philip A. Viton
City & Regional Planning, OSU, 190 W. 17th Avenue, Columbus OH 43210
pviton@magnus.acs.ohio-state.edu


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

Date: 29 Oct 1999 17:08:20 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: simplifying a script
Message-Id: <slrn81k6ll.66b.abigail@alexandra.delanet.com>

Greg Bacon (gbacon@ruby.itsc.uah.edu) wrote on MMCCL September MCMXCIII
in <URL:news:7vccti$iua$1@info2.uah.edu>:
'' 
'' Use arrays. :-)

Use map :-)

''     my @table_data = qw(
''         bobbhtml/TableData1.txt
''         bobbhtml/TableData2.txt
''         bobbhtml/TableData3.txt
''         bobbhtml/TableData4.txt
''         bobbhtml/TableData5.txt
''         bobbhtml/TableData6.txt
''         bobbhtml/TableData7.txt
''         bobbhtml/TableData8.txt
''         bobbhtml/TableData9.txt
''         bobbhtml/TableData10.txt
''         bobbhtml/TableData11.txt
''     );


       my @table_data = map {"bobbhtml/TableData${_}.txt"} 1 .. 11;



Abigail
-- 
               split // => '"';
${"@_"} = "/"; split // => eval join "+" => 1 .. 7;
*{"@_"} = sub {foreach (sort keys %_)  {print "$_ $_{$_} "}};
%{"@_"} = %_ = (Just => another => Perl => Hacker); &{%{%_}};


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: 29 Oct 1999 17:08:50 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: simplifying a script
Message-Id: <slrn81k6mi.66b.abigail@alexandra.delanet.com>

Walter van den Berg (wvandenbergNOSPAM@ttpdiskad.nl) wrote on MMCCL
September MCMXCIII in <URL:news:7vcf0h$8fh$1@news1.xs4all.nl>:
 .. 
 .. 
 .. I will use arrays! Just have to read further in my Perl for Dummies-book...
 .. Thank you for the code!


Are you a dummy?



Abigail
-- 
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Fri, 29 Oct 1999 22:55:29 GMT
From: "KJS" <enemyNO-SPAM@yahoo.com>
Subject: storing non-persistant cookies in perl script -- HELP?!?!?
Message-Id: <BBpS3.508$xd4.6476@news.rdc1.wa.home.com>

Hello!

If anyone can help me solve this problem it would be GREATLY appreciated!!

I'm having a bit of a problem trying to "fool" a server into thinking it is
talking to a browser and store cookies that are sent.  The server requests
storage of both persistent and non-persistent cookies.   I'm mostly
concerned with the non-persistent (session) cookies.  The code below seems
like it should work but I'm not having any luck.  I just want to store any
incoming cookies and then return the cookies with the next request -- like a
web browser does.

$ua = new LWP::UserAgent;
$cookie_jar = new HTTP::Cookies;

#Make first request and store cookie(s) in cookie jar
$res = $ua->request(GET 'http://somesite.com');
$cookie_jar->extract_cookies($res);

#Send stored cookie(s) in second request
$request = new HTTP::Request GET => 'http://somesite.com/cookie_wanted.pl';
$cookie_jar->add_cookie_header($request);
print $ua->request($request)->as_string;

This is not working for me -- is their something I am overlooking???

Thanks Again!!
Kevin





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

Date: Fri, 29 Oct 1999 22:34:25 GMT
From: "Ryan" <ryan_richards_2000[NOSPAM]@yahoo.com>
Subject: Stripping live HTML into text
Message-Id: <RhpS3.4009$49.263485@news.flash.net>

I need to come up with a solution to strip text from an html page and place
it in a file on the local machine. I was thinking Java, Javascript, PERL
etc. Any ideas would be most welcome!

Ryan




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

Date: Fri, 29 Oct 1999 22:48:27 GMT
From: nobody@this.location (Nobody)
Subject: Re: Stripping live HTML into text
Message-Id: <381a23e2.32940365@news.hiwaay.net>

On Fri, 29 Oct 1999 22:34:25 GMT, "Ryan"
<ryan_richards_2000[NOSPAM]@yahoo.com> wrote:

>I need to come up with a solution to strip text from an html page and place
>it in a file on the local machine. I was thinking Java, Javascript, PERL
>etc. Any ideas would be most welcome!


lynx -dump <url>




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

Date: 29 Oct 1999 19:55:04 -0400
From: Scott Lanning <slanning@bu.edu>
Subject: Re: Stripping live HTML into text
Message-Id: <kus3dutg1t3.fsf@bottom.bu.edu>

"Ryan" <ryan_richards_2000[NOSPAM]@yahoo.com> writes:
> I need to come up with a solution to strip text from an html page
> and place it in a file on the local machine. I was thinking Java,
> Javascript, PERL etc. Any ideas would be most welcome!

#(untested but i'm pretty sure it's okay)

#!/usr/local/bin/perl -w
use strict;
use HTML::FormatText;
use HTML::TreeBuilder;

my $file = "foo.html";
my $html = get_html($file);   #or LWP::Simple::get()
my $form = HTML::FormatText->new();
my $tree = HTML::TreeBuilder->new();
$tree->parse($html);
my $text = $form->format($tree);
print $text;

sub get_html {
    my $file = shift;
    my $html;
    open(FILE, $file) or die "open: $!";
    $html .= $_ while <FILE>;
    close(FILE)       or die "close: $!";
    return $html;
}


-- 
qualification: I'm a dimwit according to someone who emailed me


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

Date: Fri, 29 Oct 1999 23:59:51 GMT
From: *@dragons.duesouth.net (Matthew Bafford)
Subject: Re: Stripping live HTML into text
Message-Id: <slrn81kccq.1p4.*@dragons.duesouth.net>

And so it happened, on Fri, 29 Oct 1999 22:34:25 GMT, Ryan"
<ryan_richards_2000@yahoo.com> typed random characters into
perl, and ended up with the following posted to
comp.infosystems.www.authoring.html,comp.lang.java,comp.lang.perl.misc: 
: I need to come up with a solution to strip text from an html page and place
: it in a file on the local machine. I was thinking Java, Javascript, PERL
: etc. Any ideas would be most welcome!

wget -dump <url>
 
: Ryan

--Matthew
-- 
Use the tools, Luke!


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 1226
**************************************


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