[22612] in Perl-Users-Digest
Perl-Users Digest, Issue: 4833 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 11 18:06:15 2003
Date: Fri, 11 Apr 2003 15:05:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 11 Apr 2003 Volume: 10 Number: 4833
Today's topics:
Re: Access errors trying to use ActiveState perlsvc <goldbb2@earthlink.net>
Re: Allowing User to delete image files via HTML page i <nospam@raytheon.com>
Capture URL Title & Regex <paanwa@hotmail.com>
Consistent ithreads limit on Win32... ? (Dave Byrd)
Re: Consistent ithreads limit on Win32... ? <nospam-abuse@ilyaz.org>
Re: Consistent ithreads limit on Win32... ? <goldbb2@earthlink.net>
Re: Convert curses screen output to space-delimited tex <sean@deletethistorespond.seanoneill.deletethistorespond.info>
Re: extract the first word in a string (Sara)
Re: From Perl 5.6 migration to 5.8 problem <goldbb2@earthlink.net>
Re: hashes as lists (Tad McClellan)
Re: hashes as lists <uri@stemsystems.com>
Re: hashes as lists (Sara)
Re: hashes as lists <uri@stemsystems.com>
Re: hashes as lists <goldbb2@earthlink.net>
Re: hashes as lists <goldbb2@earthlink.net>
Re: Help with Win32::Process <goldbb2@earthlink.net>
Re: help, help Regex <bob@aol.com>
Re: How to standardize variable output length (Mike Grimes)
Re: memleak in perl 5.8.0 ? <goldbb2@earthlink.net>
Re: mod_perl uses old values in subroutines <nobull@mail.com>
Re: My 1st japh!! <goldbb2@earthlink.net>
Re: no backtick output on client-side perlscript under <fixerdave@hot-nospam-mail.com>
Re: no backtick output on client-side perlscript under <me@privacy.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 11 Apr 2003 17:47:13 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Access errors trying to use ActiveState perlsvc
Message-Id: <3E9737E1.66F2C2F8@earthlink.net>
John Ramsden wrote:
[snip]
> # Run the _actual_ service (must work out
> # how to get command line options to it!)
> #
> system ('actual_svc.pl');
Try changing this to either:
do 'actual_svc.pl';
Or:
require 'actual_svc.pl';
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Fri, 11 Apr 2003 13:13:45 -0500
From: Chris Olive <nospam@raytheon.com>
Subject: Re: Allowing User to delete image files via HTML page in flat text database
Message-Id: <sCDla.281$35.1126@dfw-service2.ext.raytheon.com>
Helgi Briem wrote:
> On Fri, 11 Apr 2003 02:33:18 -0400, "George"
> <georgeconklin@NO.SpaM.re.move.this.ALL.comcast.net> wrote:
>
>
>>Thanks very much, I will try it out. I just realized the server is a Windows
>>NT or Windows2000 server and came back to post that -fast response, Jay!
>>
>>Will unlink() work on the Windows web servers?
>>
>>Something like this?
>>
>>the_file = (filename passed from form)
>>unlink(the_file)
>
>
> Yes, given the appropriate permissions.
>
> Note two things:
>
> The web server runs as a special user with restricted
> privileges. Often called nobody or httpd on apache
> web servers, IUSR_machinename on IIS servers
> and so on.
>
> Allowing anonymous users to delete files on
> your web servers is a *very* hazardous thing.
> Take extra, extra care that you can't enter
> C: or *.* or ..\..\..\* into the file field and
> have your program delete files there.
Far better to simply place a checkbox on the form beside the picture
that says "Delete picture?", and if checked, the SCRIPT handles the
delete for just that picture behind the scenes. The holes provided by
allowing a typed filename (or even a so-called "locked in" filename via
a combo or list box since the POST can be reconstructed on the
client-side) are too numerous to mention.
Chris
-----
Chris Olive
Systems Consultant
Raytheon Technical Services Corporation
Indianapolis, IN
email: olivec(AT)indy(DOT)raytheon(DOT)com
------------------------------
Date: Fri, 11 Apr 2003 15:18:18 -0400
From: "Paanwa" <paanwa@hotmail.com>
Subject: Capture URL Title & Regex
Message-Id: <3e9714fa$0$89190$a0465688@nnrp.fuse.net>
I am wondering if there is a better way of capturing the title of a URL. I
am using it in conjunction with a 'send this page to a friend' script. Is
there a more efficient way of capturing the title?
code example:
--------------------------------
my $Url;
my $UrlTitle;
$Url = $ENV{HTTP_REFERER}; # The URL of the referring page.
use LWP::Simple;
$UrlTitle = get $Url; #Read the content of the URL
into a string variable.
s/.*(<title>)//s for $UrlTitle; #Dump all text prior to <title>
tag.
s/(<\/title>).*//s for $UrlTitle; #Dump all text after </title>
tag.
PAW
------------------------------
Date: 11 Apr 2003 12:15:41 -0700
From: digitalarcana@charter.net (Dave Byrd)
Subject: Consistent ithreads limit on Win32... ?
Message-Id: <392a1d54.0304111115.40535003@posting.google.com>
I have an ithreads perl (5.8) application on Win2000 and am running
into a strange but very consistent limitation.
I have a main thread that launches a bunch of "polling threads" that
gather information from various devices in a network. It creates them
like so:
# Start poll manager threads.
for ($i = 0; $i < $I_MAX_CONCURRENT_POLLS; $i++) {
$thrPollMgr[$i] = threads->new(\&PollManager);
my $iChildThreadID = $thrPollMgr[$i]->tid;
DebugPrint ("Launched poll manager thread $i. " .
"(Child is Thread $iChildThreadID)\n");
}
Each of those threads starts running sub PollManager, which mostly
just does this:
DebugPrint ("Poll manager thread started.\n");
It also gets a handle to a DB through DBI.
Here's the problem. No matter how I structure the creation of these
threads: have the main thread create all subthreads, or have some
worker threads spawn other worker threads in a "pyramid", I run into
weird behavior when I try to spawn the 111th thread (threadid 110).
I get no error from the create(). I get back a thread object that I
can query and get the ->tid. BUT the thread never starts executing
the PollManager subroutine I gave it. It just hangs out and does
nothing. The DebugPrint in the sub never shows up. The 110 threads
before that work fine and I get the DebugPrint.
Does this problem sound familiar to anyone? I can't figure out where
this behavior comes from.
Wanting that 111th thread...
--Dave
------------------------------
Date: Fri, 11 Apr 2003 19:44:32 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Consistent ithreads limit on Win32... ?
Message-Id: <b775v0$18qn$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Dave Byrd
<digitalarcana@charter.net>], who wrote in article <392a1d54.0304111115.40535003@posting.google.com>:
> Here's the problem. No matter how I structure the creation of these
> threads: have the main thread create all subthreads, or have some
> worker threads spawn other worker threads in a "pyramid", I run into
> weird behavior when I try to spawn the 111th thread (threadid 110).
>
> I get no error from the create().
See my postings on c.l.p.moderated. itheads as shipped is completely
bork'd. [Well, there is a lot of broken-by-design facets, but I do
not discuss them now.] It does not check the return value from
create_thread() call. It does not deallocate the semaphores it
requests.
But keep in mind that your *actual* problem is most probably
orthogonal to this one. You are trying to run 111 threads
simultaneously? Perl REx engine is (was?) very stack hungry; if you
want to use RExes, you better have megabytes of stack. Even with 1M
of stack (pretty low - one can match circa 4000 (groups)'s in
/(COMPLICATED_REX)*/) you get 111M of virtual memory allocated for the
stacks. In short: at some moment you will run off the virtual memory.
Hope this helps,
Ilya
------------------------------
Date: Fri, 11 Apr 2003 17:43:11 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Consistent ithreads limit on Win32... ?
Message-Id: <3E9736EF.68C57206@earthlink.net>
Ilya Zakharevich wrote:
> Dave Byrd wrote:
> > Here's the problem. No matter how I structure the creation of these
> > threads: have the main thread create all subthreads, or have some
> > worker threads spawn other worker threads in a "pyramid", I run into
> > weird behavior when I try to spawn the 111th thread (threadid 110).
> >
> > I get no error from the create().
[snip]
> But keep in mind that your *actual* problem is most probably
> orthogonal to this one. You are trying to run 111 threads
> simultaneously?
If he's trying to do IO on multiple thingys which don't like IO::Select,
(as I infer from the "Poll" in \&PollManager) he probably has to.
> Perl REx engine is (was?) very stack hungry; if you want to use RExes,
> you better have megabytes of stack. Even with 1M of stack (pretty low
> - one can match circa 4000 (groups)'s in /(COMPLICATED_REX)*/) you get
> 111M of virtual memory allocated for the stacks. In short: at some
> moment you will run off the virtual memory.
Well, hopefully he's designing his program so that each io thread passes
it's data back to the main thread, and all regex matching is done there;
this would decrease the amount of memory needed.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Fri, 11 Apr 2003 22:47:41 GMT
From: Sean O'Neill <sean@deletethistorespond.seanoneill.deletethistorespond.info>
Subject: Re: Convert curses screen output to space-delimited text output ?
Message-Id: <tvde9vkmpp9o58q20n2mc9488c2q3d7lul@4ax.com>
On 11 Apr 2003 10:47:57 GMT, Thomas Dickey <dickey@saltmine.radix.net>
wrote:
>Sean O'Neill <sean@deletethistorespond.seanoneill.deletethistorespond.info> wrote:
>> Does anyone know of a modules or combo of modules that will take
>> curses screen output and convert it to space-delimited text output ?
>
>> Basically, this:
>
>> ^[[1;40r^[[m^[[?7h^[[H^[[J^[[6Cusers Load^M^[[2BMem:KB
>> REAL^[[3;27HVIRTUAL^[[21CVN PAGER SWAP PAGER^[[4;9HTot
>> Share^[[6CTot Share Free^[[9Cin out in
>> out^M^[[BAct^[[43Ccount^M^[[BAll^[[43Cpages^[[7;59Hzfod
>> Interrupts^M^[[BProc:r p d s w Csw Trp Sys Int Sof
>> Flt^[[8Ccow^[[9Ctotal^[[9;59Hwire^[[B^H^H^H^Hact^M^[[B . %Sys .
>> %Intr . %User . %Nice . %Idle^[[9Cinact^M^[[B| | | |
>> | | | | | | |^[[7Ccache^[[13;59H
>
>> to this:
>
>you'd need something like a terminal emulator. If you limit it to the
>20-or-so escape sequences that are used, it's just a big case statement
>matching patterns in perl. Note that ^[[J is the erase-display, which
>is a good starting point for a new page in the resulting output.
That's what I was kinda thinkin' but what about different terminal
types ? Not that I'm worried about a large number of them - probably
just VT100, VT220, sun, xterm, and maybe a few others. I haven't dug
into this yet but I would assume that the curses control sequences are
slightly different between terminal types and the "20-or-so" sequences
would actually be more.
Thanks for the reply BTW.
------------------------------
Date: 11 Apr 2003 11:58:26 -0700
From: genericax@hotmail.com (Sara)
Subject: Re: extract the first word in a string
Message-Id: <776e0325.0304111058.475a42b9@posting.google.com>
thejaswi@hotmail.com (Raj Thejaswi) wrote in message news:<a19b3874.0304101118.64e8a866@posting.google.com>...
> I have many strings like
> "Settled Date:04/30/02BostonSale"
> "Settled Date:04/30/02New YorkSale"
> "Settled Date:04/30/02San FranciscoSale"
> Can someone help me figure out how I can get "Boston","New York","San
> Francisco"
> into a variable ?
>
> I am chopping of "Settled Date" and "Sale" from the string using
> substr() with index(), since these two strings are constant. My
> problem is in extracting the words from what is left:
> 04/30/02Boston"
> 05/15/02New York"
> 02/17/03San Francisco"
>
> Thanks in advance,
>
> - RT
Hi RT:
A few thoughts you might find useful:
(1)
You don't say how these items are stored- in an array perhaps? If in a
file I recommend you slurp them up into an array, assuming the size of
the file isn't prohibitive. Use something like:
die "huh? cant open it??' unless open N, 'myNamefile.txt'
my @names=<N>;
close N;
(2)
Ok now you have your file in an array which is much nicer to work with
than data through a file handle. A simple operation will get you the
data you see; basically you might want to apply something like this:
s/.+\d(.+)Sale/$1/;
Assuming that (a) the data doesn't have lines NOT in this format, and
(b) there is only one such string per element.
(3)
now, how to apply this to the array? map comes to mind:
@names = map /.+\d(.+)Sale/, @names;
so the whole program:
#!/usr/bin/perl -wd
die "huh? cant open it??\n\n" unless open N, 'myNamefile.txt';
my @names=<N>;
close N;
print "$_\n" for @names;
@names = map /.+\d(.+)Sale/, @names;
print "$_\n" for @names;
Notice- no explicit loops except prints, and no *ick!!* substr().
substr() is what people who don't know regexes use since it "looks
like c". Avoid it. It has very limited use in Perl and its unfortunate
it was even included. (I'm sort of negative on substr, can you tell?)
(4)
FINALLY, say you have duplicate cities in the file but you want an
array of *unique* cities from the original? Sound like a possibility?
We can use a hash to help us- substitute the map and print lines with
(we throw away the values):
my %names = map /.+\d(.+)(Sale)/, @names;
print "$_\n" for keys %names;
Now you get a list of UNIQUE names. How much easier can this get!?
Hope some of this was helpful..
Cheers, have a nice weekend...
-Gx
------------------------------
Date: Fri, 11 Apr 2003 15:34:30 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: From Perl 5.6 migration to 5.8 problem
Message-Id: <3E9718C6.F26E3431@earthlink.net>
Kasp wrote:
>
> Hi,
>
> I am facing a peculiar problem. Wonder if anyone out here has faced
> something similar and has a solution.
>
> I can compile and run a piece of code (on Windows 2000) written in C++
> that uses Perl libraries (Perl56.lib + PerlEz.lib). Now that I want it
> to run with Perl 5.8, I simply tried to replace these files with those
> from version Perl5.8.
You can't do that. Perl 5.8 is not binary compatible with perl 5.6.
Didn't you read the perldelta file?
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Fri, 11 Apr 2003 15:06:56 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: hashes as lists
Message-Id: <slrnb9e830.1v7.tadmc@magna.augustmail.com>
Sara <genericax@hotmail.com> wrote:
[ got snipped earlier, was something like:
%a = (%a, %b);
]
> Now I have a request. Eric and I talked about (2) useful ways to deal
> with hashes with a succinct and effective syntax. I suspect the Guru's
> know about 1000 more that we hadn't thought of- so even though it may
> see obvious to you, please post more here?
One alternative to the above using "hash slices":
@a{keys %b} = @a{values %b};
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 11 Apr 2003 19:33:52 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: hashes as lists
Message-Id: <x78yugomlb.fsf@mail.sysarch.com>
>>>>> "TM" == Tad McClellan <tadmc@augustmail.com> writes:
TM> Sara <genericax@hotmail.com> wrote:
TM> [ got snipped earlier, was something like:
TM> %a = (%a, %b);
TM> ]
TM> One alternative to the above using "hash slices":
TM> @a{keys %b} = @a{values %b};
the issue that comes up here is do you want the values in %b to override
the values in %a or not? the above two assignments have %b overriding
%a. this code keeps the values in %a and only assigns the ones from %b
that aren't in %a:
%a = (%b, %a);
there is no simple hash slice equivilent for that. it can be replicated
with some extra code in various ways like:
exists $a{$_} or $a{$_} = $b{$_} for keys %b ;
that could be faster than the list assignment if the hashes are large
since it doesn't have to listify them (and unlistify the result).
for more on hash slices see my tutorial at:
http://www.sysarch.com/perl/tutorials/hash_slices.txt
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: 11 Apr 2003 13:23:47 -0700
From: genericax@hotmail.com (Sara)
Subject: Re: hashes as lists
Message-Id: <776e0325.0304111223.37842ddc@posting.google.com>
tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnb9dedv.5er.tadmc@magna.augustmail.com>...
> Sara <genericax@hotmail.com> wrote:
>
> > %h = reverse %h
> >
> > makes the keys of %h the values and visa versa..
>
>
> Better not do that if there are duplicated values in %h though.
They mentioned that as well- as long as one realizes dups get tossed-
no problems mate.
It sorta goes without saying that duplicate keys translate into one
hash element. The *mysterious* part of that is for duplicates- which
of the Original keys persists as the final value? Since a hash has no
order, my intuition is that it's indeterminant, and may in fact vary
from perl release/OS?
Cheers.. C'mon weekend almost here...
Gx
------------------------------
Date: Fri, 11 Apr 2003 20:37:10 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: hashes as lists
Message-Id: <x7istkn53d.fsf@mail.sysarch.com>
>>>>> "S" == Sara <genericax@hotmail.com> writes:
S> tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnb9dedv.5er.tadmc@magna.augustmail.com>...
>> Sara <genericax@hotmail.com> wrote:
>>
>> > %h = reverse %h
>> >
>> > makes the keys of %h the values and visa versa..
>>
>>
>> Better not do that if there are duplicated values in %h though.
S> They mentioned that as well- as long as one realizes dups get tossed-
S> no problems mate.
S> It sorta goes without saying that duplicate keys translate into one
S> hash element. The *mysterious* part of that is for duplicates- which
S> of the Original keys persists as the final value? Since a hash has no
S> order, my intuition is that it's indeterminant, and may in fact vary
S> from perl release/OS?
your guess is correct. it is a function of the order that
keys/values/each will return and that is not specified nor should ever
be relied upon. reversing hashes is a neat trick but it has to be done
with the understanding about losing dups. but if you know your values
are unique and you need to map from value to key (a feature i have
needed a few times) the reverse trick is the answer.
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: Fri, 11 Apr 2003 17:31:59 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: hashes as lists
Message-Id: <3E97344F.E6815C32@earthlink.net>
Sara wrote:
> Tad McClellan wrote:
> > Sara wrote:
> >
> > > %h = reverse %h
> > >
> > > makes the keys of %h the values and visa versa..
> >
> >
> > Better not do that if there are duplicated values in %h though.
>
> They mentioned that as well- as long as one realizes dups get tossed-
> no problems mate.
>
> It sorta goes without saying that duplicate keys translate into one
> hash element. The *mysterious* part of that is for duplicates- which
> of the Original keys persists as the final value? Since a hash has no
> order, my intuition is that it's indeterminant, and may in fact vary
> from perl release/OS?
It varies base on perl release, but not by OS.
Only if the perl hashing function changes, does the order change.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Fri, 11 Apr 2003 17:36:44 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: hashes as lists
Message-Id: <3E97356C.794CCDBD@earthlink.net>
Uri Guttman wrote:
> Tad McClellan wrote:
>
>> Sara <genericax@hotmail.com> wrote:
>> [ got snipped earlier, was something like:
>>
>> %a = (%a, %b);
>> ]
>>
>> One alternative to the above using "hash slices":
>>
>> @a{keys %b} = @a{values %b};
>
> the issue that comes up here is do you want the values in %b to
> override the values in %a or not? the above two assignments have %b
> overriding %a. this code keeps the values in %a and only assigns the
> ones from %b that aren't in %a:
>
> %a = (%b, %a);
>
> there is no simple hash slice equivilent for that. it can be replicated
> with some extra code in various ways like:
>
> exists $a{$_} or $a{$_} = $b{$_} for keys %b ;
>
> that could be faster than the list assignment if the hashes are large
> since it doesn't have to listify them (and unlistify the result).
If the %b hash is large, this is still not great, since keys %b is a big
list. If you used the each operator it might be better.
exists $a{$_} or $a{$_} = $b{$_} while defined($_ = each %b);
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Fri, 11 Apr 2003 14:47:39 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Help with Win32::Process
Message-Id: <3E970DCB.F88E6ABB@earthlink.net>
George Bouras wrote:
>
> # The following should start Windows notepad.exe program at
> # background ( hidden - no window ) but it keeps poping up!
> # What I am doing wrong with that , please help (Win2K).
>
> use Win32::Process;
> my $prc=Win32::Process;
> $prc->Create(
> "$ENV{SystemRoot}\\Notepad.exe",
> 'Notepad win.ini',
> 0,
> CREATE_NO_WINDOW,
> $ENV{SystemRoot},
> ) || die "$^E\n";
Try creating it minimized instead of without a window.
Specifying not to create a window is for running console programs which
*normally* would create a console window, and you want to prevent that
console window from being created.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Fri, 11 Apr 2003 19:59:14 GMT
From: Optional <bob@aol.com>
Subject: Re: help, help Regex
Message-Id: <bj7e9v08no9fhp5201fltlhfguq7pn5vf1@4ax.com>
I've heard a rumor that on Tue, 08 Apr 2003 12:14:38 GMT, Devop
<as@hotmail.com> wrote the following:
>correction.
>
>i mean to print if each of them found or not !!
>
>rgds
>
>
>Devop wrote:
>
>> Thanks a lot guys.
>>
>> But what about if i want to search more than one string from file, and print if i have
>> found each one of them !!!
>>
>> the code was working perfectly ( after ? is added , thanks).
>>
>> rgds
>>
>> Anno Siegel wrote:
>>
>> > Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net> wrote in comp.lang.perl.misc:
>> > > Anno Siegel wrote:
>> > >
>> > > > Devop <as@hotmail.com> wrote in comp.lang.perl.misc:
>> > > >> Hi.
>> > > >>
>> > > >> I have problem here.
>> > > >>
>> > > >> I would like to read file , then find some text (string) in that file ,
>> > > >> if that string is found, then print some thing, if not print some thing
>> > > >> else !! ( the matched string will not be printed )
>> > > >
>> > > > open my $f, $file or die "Can't read $file: $!";
>> > > > my $found;
>> > > > while ( <$f> ) {
>> > > > last if $found ||= /string/;
>> > > > }
>> > > > print $found : "something\n" : "something else\n";
>> > > ^
>> > >
>> > > That should be '?'.
>> >
>> > Oh, right. I also forgot to mention that it was untested, at least
>> > that line was.
>> >
>> > Thanks for catching that. It's reassuring to see that code is well
>> > scrutinized around here.
>> >
>> > Anno
Does your Professor know you are getting your programs in a newsgroup
instead of writing them yourself?
------------------------------
Date: 11 Apr 2003 12:12:21 -0700
From: michael.e.grimes@fritolay.com (Mike Grimes)
Subject: Re: How to standardize variable output length
Message-Id: <96b99672.0304111112.3e5b63c@posting.google.com>
> > A loop that splits fields from an input line. The first field contains
> > text of varying lengths but I want to standardize the variable output
> > length to 80 bytes. Like:
> >
> > Print $field1;
> > output from field1....................................
>
> I'm sure there is a better method but some ideas
>
> while (length $field1 < 80) {
> $field1 .= '.'; }
>
> $field1 .= '.' x (80 - length $field1);
>
Thanks for the help, this works great!
------------------------------
Date: Fri, 11 Apr 2003 18:01:06 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: memleak in perl 5.8.0 ?
Message-Id: <3E973B22.A5504949@earthlink.net>
peter pilsl wrote:
[snip]
> sub new{
> my $class=shift;
> my $s={};
> bless($s,$class);
>
> $s->{bigarray}=[];
> $#{$s->{bigarray}}=5000000;
>
> $s->{s}=sub{return &{$s->{private}->{subsub}}();};
> # $s->{s}=sub{return 4};
>
> return $s;
> }
The problem is that
sub { ... $s ... };
Contains a reference to $s.
And $s, (in the ->{s} slot) contains a reference to the sub.
Try this:
sub new {
my $s = bless {}, shift;
$s->{bigarray} = [];
$#{ $s->{bigarray} } = 5e7;
my $p = $s->{private} = {};
$s->{s} = sub { return &{ $p->{subsub} }() };
return $s;
}
Now, the anon sub refers to $p, and $s refers to $p and to the anon sub,
but at no point does $p refer to the anon sub, or to $s, nor does the
anon sub refer to $s. Thus, there's no circular reference.
Here's another possibility:
sub new {
my $s = bless {}, shift;
$s->{bigarray} = [];
$#{ $s->{bigarray} } = 5e7;
my $p = \ $s->{private}{subsub};
$s->{s} = sub { return &{ $$p }() };
return $s;
}
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: 11 Apr 2003 18:59:16 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: mod_perl uses old values in subroutines
Message-Id: <u9fzoo9aq3.fsf@wcl-l.bham.ac.uk>
Rafael Garcia-Suarez <rgarciasuarez@free.fr> writes:
> Tom Cat wrote in comp.lang.perl.misc :
> > I recently found out that mod_perl "saves" subroutines and apparently
> > uses values passed to the subroutines from previous runs instead of
> > the current values.
> >
> > Is there anyway around this "feature"?
>
> You're probably using Apache::Registry to run perl programs as
> pseudo-CGI scripts. And there are [non-anonymous] subroutines in your
> scripts.
>
> Have you enabled warnings ? If so, have you noticed that
> "variable $foo will not stay shared" in your logs ? (if you didn't,
> please do, when developing. Warnings are helpful.)
>
> See : "CGI to mod_perl Porting. mod_perl Coding guidelines."
> http://perl.apache.org/docs/1.0/guide/porting.html#The_First_Mystery
> HTH
But ignore what it says about how to fix it. Most of the "fixes"
offered are massively unwhieldy or actually create far worse problems.
Simply change my() to local(our()) for the variables for which you get
"will not stay shared" warnings.
For further discussion see
<4dafc536.0211211047.5da49e9a@posting.google.com>
http://groups.google.com/groups?selm=4dafc536.0211211047.5da49e9a%40posting.google.com
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 11 Apr 2003 16:10:58 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: My 1st japh!!
Message-Id: <3E972152.489374EC@earthlink.net>
Michele Dondi wrote:
>
> Sorry, I've been away lately: too busy to read news... but yesterday,
> without having planned it, I wrote my 1st (and only?) japh. OK, it has
> nothing to do with the incredible things you see around, but for my
> limited skills, IMHO it's not so bad after all: any comments?
>
> Michele
> $\=q.,.,$\.=$/,print qq,\112,,(qw,a c e h,,map{$_-=1<<5if/112/;chr}107..
> 117,32)[map {s/^/0/;hex} split//,join q,2B,,qw$ECDF078D3 F9 5F3014$,$,];
Not bad, though it would have been better to try and get the lines
shorter.
$\=q.,.,$\.=$/,print qq,\112,,(qw,a c e h,, map{$
_-=1<<5if/112/;chr}107.. 117,32)[map {s/^/0/;hex}
split//,join q,2B,,qw$ECDF078D3 F9 5F3014$,$,];
Also, skilled perl programmers can see past tricks like using alternate
delimiters with q, qq, and qw -- those only obscure things a little bit.
Obscuring the source of the data itself, on the other hand, is much
cooler, imho.
I prefer my own japh from a while back.
tr/`/ /, s/.//, print "@{[map --$| ? ucfirst lc : lc, split]},\n"
for pack 'u',pack 'H*','ab5cf4021bafd28972030972b00a218eb9720000'
(This is even strict and warnings clean.)
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Fri, 11 Apr 2003 13:17:06 -0700
From: "fixerdave" <fixerdave@hot-nospam-mail.com>
Subject: Re: no backtick output on client-side perlscript under w2k
Message-Id: <3e9722d9$1@obsidian.gov.bc.ca>
"Norbert Schmidt" <me@privacy.net> wrote in message
> Did you try AS-Perl 5.8?
No, but that's a good point, I'll try it on a test box to see if it makes a
difference - or if it breaks some module I'm depending on elsewhere...
> Maybe it's a side effect of some internet security option in IE.
I tried turning all the security off in IE, with no difference. Security
was my first guess but now that I know it runs the command but doesn't
return the results, I'm thinking it's something else. I've heard horror
stories about MS security... but allowing an external program to run from a
web page, and just not letting you know it ran, would be pretty poor
protection :)
> You might try:
>
> open XFILE, "getmac |";
> @x = <XFILE>;
> close XFILE;
same results... good thought though.
> And if that doesn't work either, bite the bullet and do something like:
>
> `getmac >$tempfile`;
> open XFILE, $tempfile;
> @x = <XFILE>;
> close XFILE;
well, I know I can open a file within the IE/W2k combo, and I can write a
file through redirection, so this will definitely work. But, I think I'm
going to hold out for something a little more elegant ;)
I'll try the newer release to see if it makes a difference. If it doesn't,
and I can't think of anything else to test, I'll probably pull the code out
of the web page and build my own graphic front-end around it. (I'm using
the web page to make a pretty user interface around some administration
utilities - it's local, no web server or anything like that.)
But, thanks for the response... Like I said, I'm running out of ideas to
try.
David...
------------------------------
Date: Fri, 11 Apr 2003 23:04:13 +0200
From: Norbert Schmidt <me@privacy.net>
Subject: Re: no backtick output on client-side perlscript under w2k
Message-Id: <1k9r771dohjn8.y32ooet59bfs$.dlg@40tude.net>
Hello David,
> and I can't think of anything else to test, I'll probably pull the code out
> of the web page and build my own graphic front-end around it. (I'm using
> the web page to make a pretty user interface around some administration
> utilities - it's local, no web server or anything like that.)
then several possible solutions spring to my warped mind: ;-)
1. (maybe a little overkill) install an apache and run your stuff as
CGI-Scripts.
2. write a little "Server-Script" that runs in the background and waits on
a socket and executes the commands on request and returns the result via
socket. Then you "just" have to modify your Scripts that they call the
server an get their answers from there.
3. Look the Perl module set "Prima". Lots of useful prefab and extensible
GUI parts. (Yes, for Windows, too!)
Regards, Norbert
------------------------------
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.
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 4833
***************************************