[11408] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5008 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 1 02:07:20 1999

Date: Sun, 28 Feb 99 23:00:13 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 28 Feb 1999     Volume: 8 Number: 5008

Today's topics:
    Re: 'x' operator to pre-extend a string (Ilya Zakharevich)
    Re: Anyone have Code Examples for.... <hm@garmisch.net>
    Re: grep syntax question (KLMN2)
    Re: Help - regex to extract two fields in "uptime" (Larry Rosler)
    Re: matching multiple times and remembering each match (Eric Smith)
    Re: PC - UNIX text converter (Bart Lateur)
    Re: perl5.005_02 with djgpp <gellyfish@btinternet.com>
    Re: regex poll results (Abigail)
        regexp (Mark P.)
    Re: Using a glob with sort (Andrew M. Langmead)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 28 Feb 1999 19:27:48 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: 'x' operator to pre-extend a string
Message-Id: <7bc5bk$6dg$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Michael Ryan 
<mikeryan@acm.org>],
who wrote in article <36D1FD81.38ABEC27@acm.org>:
> is the proper syntax pre-extending something like:
> 
> $s = 'a' x ( 1 << 16 )
> $s = ""  # $s is still large

You are waisting a lot of memory here due to Perl's shortcomings.  The
space-efficient way to do it (saves 50% of space) is

  $s = 'a';
  $s x= 1<<16;

Ilya


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

Date: Sun, 28 Feb 1999 22:42:19 +0100
From: Heiko Marschall <hm@garmisch.net>
Subject: Re: Anyone have Code Examples for....
Message-Id: <36D9B83B.B72770EF@garmisch.net>

Pipe is alway a ONE-WAY connection !
But what you want is non-buffering ...
$|=1;

 - Heiko -

"Wade T. Funk" schrieb:
> 
> Perl scripts that use pipes to communicate to and from a
> script that is invoked in the background of the script I am
> writing?  I have no trouble writing to the script, but I can't
> seem to get the return data.  The script I am writing(CGI)
> invokes a larger script that is a while loop which executes
> commands until 'quit' is given as a command.  I want to be
> able to send a command to this backgrounded script, and
> print the reply to a web page (CGI) after each command,
> not after the entire script is finished.


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

Date: 28 Feb 1999 19:33:35 GMT
From: klmn2@aol.com (KLMN2)
Subject: Re: grep syntax question
Message-Id: <19990228143335.13531.00001954@ng-ch1.aol.com>

I finally figured out the problem, thanks to someone who read my post and
e-mailed me. The solution is:

$searchstr = "(?i)$searchstr";

@results = grep(/$searchstr/,@mydata);

Thanks to all of you who gave me your input.

-Kalman Kaminer
http://www.parsha.com
http://www.metzia.com


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

Date: Sun, 28 Feb 1999 13:46:08 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Help - regex to extract two fields in "uptime"
Message-Id: <MPG.114358f44a7703d89896b5@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <7bc7u0$ni$1@gellyfish.btinternet.com>, on 28 Feb 1999 
20:11:44 -0000 gellyfish@btinternet.com says...
 ... 
> if ($uptime =~ /^\s+(.+?)
>                  \s+\w+\s+
>                  (.+?),
>                  \s+(\d+)
>                  \s+users,.+:\ 
>                  ([\d\.]+),\ 
>                  ([\d\.]+),\ 
>                  ([\d\.]+)/x)
> {
>   $uphash{time}             = $1;
>   $uphash{uptime}           = $2;
>   $uphash{users}            = $3;
>   $uphash{one_min_load}     = $4;
>   $uphash{five_min_load}    = $5;
>   $uphash{fifteen_min_load} = $6;
> }

How about this neater way (preserving the world's limited supply of 
semicolons):

    @uphash{ qw( time uptime users one_min_load five_min_load
        fifteen_min_load ) } = $uptime =~ /*your regex here*/x;

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


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

Date: 28 Feb 1999 21:43:04 GMT
From: eric@fruitcom.com (Eric Smith)
Subject: Re: matching multiple times and remembering each match
Message-Id: <slrn7djf0f.8qa.eric@plum.fruitcom.com>

As always, thank you Larry ...
> 
> if (/tagA(matchedstring)tagB/g) { 
> 
> >                   push(@contents,$1);   # (<- I think the syntax is ok here)
> > }
> should pick up only the first match.  Replace 'if' by 'while'.  That's 
> about as minor as surgery can get.
Tried this ...
while (s/%SC%([\n\w\W]*?)%EC%//g) {     #contents bit
                        push(@contents,$1);
} 
---
Still gave me only the _second or final_ matched string and not the
concatenation of the matches. :(
> 
> A more extensive surgery would replace the whole construct by this:
> 
>   @contents = /tagA(matchedstring)tagB/g; 

Now I tried your eloquent and pithy ...
@contents = s/%SC%([\n\w\W]*?)%EC%//g;
if (@contents)  {
                print "\n" . "THE CONTENTS:\n"  . "@contents\n";
}


<sample of output>
The Electronic system automatically reads electronic information received.

THE CONTENTS:
2
</sample of output>
---
the `2' seems to be obviously the number of matches, and in this sense it is
correct.
btw the code needs to remove the tags and the matched string from the
output and put the matched string in at the bottom

mmmm...


Eric Smith
<eric@fruitcom.com>


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

Date: Sun, 28 Feb 1999 22:09:07 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: PC - UNIX text converter
Message-Id: <36d9bd79.399854@news.skynet.be>

Fred O'Brian wrote:

>Am I missing something REALLY obvious here?
>All I need is a tool to add/remove the carrage returns in
>text files.  Surely this must already exsist! Can anybody suggest
>one? (I am using Redhat linux / Win95)

How about... Perl?

Unix -> PC:
On PC:

	open(IN,"$file);
	binmode(IN);
	while(<IN>) {
		print;
	}

On Unix:

	$\ = "\r";
	while(<>) {
		print;
	}

PC->Unix:
On PC:
	binmode(STDOUT);
	while(<>) {
		print;
	}

On Unix:

	while(<>) {
		tr/\r//d;
		print;
	}


	
	
	Bart.


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

Date: 26 Feb 1999 23:55:38 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: perl5.005_02 with djgpp
Message-Id: <7b7c9q$up$1@gellyfish.btinternet.com>

On Fri, 26 Feb 1999 16:09:28 +0100 Tristan Braun wrote:
> Hi,
> 
> I installed Perl version 5.00307 on my PC (Win NT).
> 
> I have installed ActivState509. Now I get an errormessage like follows:
> 
>> Perl lib version (5.00402) doesn't match executable version (5.00307) at
>> D:\TOOLS\PERL\lib/Config.pm line 7.
>> BEGIN failed--compilation aborted.
> 

I would suggest that you should delete the lot and install the ActivePerl
again - I think that you probably have managed to install the two (three ?)
into the same directory and that some of the files were read only from the
earlier install and thus were not overwritten.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 27 Feb 1999 12:05:50 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: regex poll results
Message-Id: <7b8n2u$k1n$1@client2.news.psi.net>

Uri Guttman (uri@home.sysarch.com) wrote on MMVI September MCMXCIII in
<URL:news:x7d82wgs8h.fsf@home.sysarch.com>:
## 
## 5.005_03	2


Over 5% of the responders uses a non-existing version of Perl?




Abigail
-- 
sub _'_{$_'_=~s/$a/$_/}map{$$_=$Z++}Y,a..z,A..X;*{($_::_=sprintf+q=%X==>"$A$Y".
"$b$r$T$u")=~s~0~O~g;map+_::_,U=>T=>L=>$Z;$_::_}=*_;sub _{print+/.*::(.*)/s}
*_'_=*{chr($b*$e)};*__=*{chr(1<<$e)};
_::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))


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

Date: Sun, 28 Feb 1999 21:55:25 GMT
From: mag@imchat.com (Mark P.)
Subject: regexp
Message-Id: <36d9b989.613413081@news.ionet.net>

	Lets try this again. Although using URI::URL might be helpful,
from the documentation, I'm only able to return a relative path. What
I need is to get just the document without anything following it. IE;
turn http://www.what.com/what/index.shtml#whatever, to index.shtml. 
	I need a rexexp that will do this. It seems to me to be the
best way, unless someone can point me to some good examples of how to
use URI::URL to do the same thing. I haven't found anything yet that
suggests I should use the module.

	What I have so far will return a long string of .txt.tx.tx.txt
blah blah. So its getting rid ov everything instead of leaving the
name of the document.

$file = "$ENV{'HTTP_REFERER'}";
$file =~ s/[http:\/\/]/\.html/ig;
$file =~ s/.html/.txt/ig;
$file =~ s/.shtml/.txt/ig;
$file =~ s/.htm/.txt/ig;
$file =~ s/.cgi/.txt/ig;





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

Date: Sat, 27 Feb 1999 12:20:04 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Using a glob with sort
Message-Id: <F7tBLG.JBw@world.std.com>

moseley@best.com (Bill Moseley) writes:

>And I'm trying to figure out how to create the subroutine on the fly by 
>creating anonymous subs.  I've tried a bunch of things, but haven't had 
>any luck.

As you imply later, you don't have anonymous subs there, you have
nested subroutines, which don't really work.

How about something like this:

%sortroutines = ( Date =>
		sub {
		  $students{$a}{TIME} <=> $students{$b}{TIME}
		}, 
		Status =>
		sub {
		  $status_sort[$students{$a}{STATUS}]
		     <=>
		  $status_sort[$students{$b}{STATUS}]
		},

{
  local(*sub_sort);
  die "Invalid sort criteria\n" unless exists $sortroutines{$sortby};
  *sub_sort = $sortroutines{$sortby};
  @sorted = sort sort_sub keys %students;
}

Much more efficient than Larry Rosler's suggestions, which perform a
extra dereference for each comparision. (I wonder why he posted a URL
to a thread in Deja News and only repeat the slowest solutions?)
-- 
Andrew Langmead


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

Date: 12 Dec 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 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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