[13573] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 983 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 4 16:17:27 1999

Date: Mon, 4 Oct 1999 13:10:32 -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: <939067832-v9-i983@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 4 Oct 1999     Volume: 9 Number: 983

Today's topics:
    Re: open("...|") and stderr <ltl@rgsun5.viasystems.com>
    Re: open("...|") and stderr (Bill Moseley)
        pattern match. & ? operator (s. morgan friedman)
    Re: Seem to be getting substring instead of array eleme <ehowarth@axtive.com>
    Re: Seem to be getting substring instead of array eleme (Abigail)
    Re: Simple - yet won't work! <reidg@crosskeys.com>
    Re: Simple - yet won't work! (Larry Rosler)
    Re: Simple - yet won't work! <nihad@yahoo.com>
        sort routine - can it ignore numeric values? <mikej@1185design.com>
        Specifying start row for DB access pyammine@my-deja.com
    Re: Split() on vertical bar | (H. Merijn Brand)
        Test this please <webmaster@mybegin.com>
    Re: Test this please <makkulka@cisco.com>
    Re: Test this please (Abigail)
    Re: Test this please <webmaster@mybegin.com>
    Re: Test this please <webmaster@mybegin.com>
    Re: Wow! cgi.pm is great! <uri@sysarch.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 4 Oct 1999 15:13:00 GMT
From: lt lindley <ltl@rgsun5.viasystems.com>
Subject: Re: open("...|") and stderr
Message-Id: <7tag5s$f71$1@rguxd.viasystems.com>

Halfdan Ingvarsson <halfdan@no-junkmail-please.pison.com> wrote:
:>Is there anyway of getting hold of the stderr handle when you open files
:>with open(FILE, "...|") ? Or even multiplexing stdout and stderr into
:><FILE> ($_) ?

perldoc -q stderr

describes several methods of dealing with stderr.  I have also used
IPC::Open3, but that may be overkill.

-- 
// Lee.Lindley   /// I used to think that being right was everything.
// @bigfoot.com  ///  Then I matured into the realization that getting
////////////////////   along was more important.  Except on usenet.


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

Date: Mon, 4 Oct 1999 08:21:35 -0700
From: moseley@best.com (Bill Moseley)
Subject: Re: open("...|") and stderr
Message-Id: <MPG.126265dc7780b5c79897ca@206.184.139.132>

Halfdan Ingvarsson (halfdan@no-junkmail-please.pison.com) seems to 
say...
> Is there anyway of getting hold of the stderr handle when you open files
> with open(FILE, "...|") ? Or even multiplexing stdout and stderr into
> <FILE> ($_) ?

Take a look at IPC::Open3 and see if that does what you like.


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


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

Date: 4 Oct 1999 19:54:26 GMT
From: morgan@dept.english.upenn.edu (s. morgan friedman)
Subject: pattern match. & ? operator
Message-Id: <7tb0li$kfh$1@netnews.upenn.edu>

	hi all,

	i'm having a problem pattern matching and i can't seem to
	find any help in o'reilly nor the FAQ, so i'm hoping
	someone here has an idea :) i'm pretty new to all this,
	and i've been studying assiduously the documentation,
	but i think i missed something :(

	i want to match a pattern either like "one" or "one (two)";
	if there're parenthesis i want to get both data (one and
	two in this example) or if not, return the entire string
	(one). i'm trying to do it like this:

$string = "one (two)";
if ($string =~ /(.*)(\(.*\))?/) {
        print "one: $1\n";
	print "two: $2\n";
}

	but this doesn't return the expected results, instead:

one: one (two)
two: 		

	what's interesting, though, is that if i take out the ?
	(which refers to the '(two)'), ie so that the (two) is
	no longer optional but mandatory, then it works perfectly!
	code:

$string = "one (two)";
if ($string =~ /(.*)(\(.*\))/) {
        print "one: $1\n";
	print "two: $2\n";
} 

	output:

one: one
two: (two)

	the problem with this is i want the (two) to be optional.
	this leads me to suggest my problem has something to do
	with the ?. i also tried using the .*? because i guessed
	it might be a greed problem, but to no avail. i'm clueless.
	do any of you have any ideas? thanks so much!!

	morgan
	
--
______________________
steven morgan friedman
http://www.westegg.com
"I have always imagined that paradise will be a kind of library."
"Me figuraba el paraíso bajo la especie de una biblioteca."



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

Date: Mon, 04 Oct 1999 15:37:08 GMT
From: Evan Howarth <ehowarth@axtive.com>
Subject: Re: Seem to be getting substring instead of array element
Message-Id: <7tahj3$5e9$1@nnrp1.deja.com>


> open(CHOICES,"textfile");
> while (<CHOICES>) {
>   @quesvals = split(/:/,$_);
>   @name_lab = split(/|/,$quesvals[0]);
>   print "$name_lab[0]\n";
> }
The pipe character needs to be escaped:
@name_lab = split('\|',$quesvals[0]);


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


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

Date: 4 Oct 1999 14:28:02 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Seem to be getting substring instead of array element
Message-Id: <slrn7vi0ds.dhe.abigail@alexandra.delanet.com>

George Jempty (jb4mt@verbatims.com) wrote on MMCCXXV September MCMXCIII
in <URL:news:Yt2K3.568$ry3.6921@news.rdc1.ne.home.com>:
() 
() politics|Are you a: Democrat|Republican
() religion|Are you a: Catholic|Protestant
() 
() but when I execute the following:
() 
() open(CHOICES,"textfile");
                           ^
                           |
                          Urg.

() while (<CHOICES>) {
()   @quesvals = split(/:/,$_);
()   @name_lab = split(/|/,$quesvals[0]);
()   print "$name_lab[0]\n";
() }
() 
() I get
() 
() p
() r


Read the current thread in this group about splitting on `|'s.
Is looking at the current threads before posting even asking too much
nowadays?



Abigail
-- 
package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
                                      print } sub __PACKAGE__ { &
                                      print (     __PACKAGE__)} &
                                                  __PACKAGE__
                                            (                )


  -----------== 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: Mon, 04 Oct 1999 11:56:08 -0400
From: Reid Gravelle <reidg@crosskeys.com>
Subject: Re: Simple - yet won't work!
Message-Id: <37F8CE18.3F3858B6@crosskeys.com>

Try opening the file in a read/write appending mode

open ( INFO, "+<$pagepath" );

Then you can lock it and do your processing.

Here's what I think is happening:
1.> Script is being started and it reads the value of count.
2.> The script opens the file again in order to write out the new counter value
but flock is not yet called.  At this point you have truncated the file
contents.
3.> A new instance of the script is being started.  It attempts to read the
value of the counter but the file is empty so count is assigned a value of 0.
4.> The original script becomes active again, gets a lock on the file, and
writes the value of the counter.
5.> The second instance of the script is now active, gets a lock on the file,
and writes the new value of the counter (which is one), and continues on
processing.


By doing the above open and then locking the file only one instance of the
script should be able to read the counter at one time and hopefully your
problem will be taken care of.

Reid.



Stuart Yeates wrote:

> nihad@yahoo.com wrote:
> : Hi,
>
> : I have a very simple counter that gets accessed 250,000+ times a day, the
> : counter is doing all the right things except it keeps resting itself a few
> : times a day!
>
> : here is part of the code:
>
> : 1  open (INFI, "$pagepath");
> : 2  $count = <INFI>;
> : 3  close INFI;
> : 4
> : 5  $count = $count + 1;
> : 6  open(INF,">$pagepath");
> : 7  flock(INF, 2);
> : 8  print INF "$count";
> : 9  close INF;
>
> : I'm not sure what's wrong with the code since it's a very simple task and
> : the file locking should protect the counter log from getting overwritten.
>
> try switching the open and the flock (lines 6 and 7) around, that way
> you can be sure that you're not reading the file when it's also being
> written.
>
> stuart
> --    stuart yeates <s.yeates@cs.waikato.ac.nz> aka `loam'
>                        carpe noctem
> X-no-archive:yes



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

Date: Mon, 4 Oct 1999 00:33:25 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Simple - yet won't work!
Message-Id: <MPG.1261f818739a9d6f98a02c@nntp.hpl.hp.com>

In article <939019663.206064@clint.waikato.ac.nz> on 4 Oct 1999 06:47:44 
GMT, Stuart Yeates <syeates@manuka.cs.waikato.ac.nz> says...
> nihad@yahoo.com wrote:

 ...

> : 6  open(INF,">$pagepath");				
> : 7  flock(INF, 2);

 ...

> try switching the open and the flock (lines 6 and 7) around, that way 
> you can be sure that you're not reading the file when it's also being 
> written.

What do you hope to accomplish by flock'ing using an invalid filehandle 
(a filehandle for a file that hasn't been opened yet)?  Of course, each 
of those system calls should be tested for success.  The flock, if done 
first, will always fail.

As John Callender said earlier, there is correct code in perlfaq5.

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


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

Date: Mon, 04 Oct 1999 20:00:05 GMT
From: <nihad@yahoo.com>
Subject: Re: Simple - yet won't work!
Message-Id: <rvi1q5v1rad81@corp.supernews.com>

Thanks for all the responses, Here's what seems to work:

if (-e $pagepath){
open(INF, "+<$pagepath");
    flock(INF, 2);
    $num = <INF>;
    seek(INF, 0, 0);
    (print INF $num+1);
    close INF;
    flock(INF, 8); 
}else{
open(INF, ">$pagepath");
    (print INF "1");
close INF;
}

Thanks again everyone.

------------------  Posted via CNET Help.com  ------------------
                      http://www.help.com/


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

Date: Mon, 04 Oct 1999 12:18:04 -0700
From: mikej <mikej@1185design.com>
Subject: sort routine - can it ignore numeric values?
Message-Id: <37F8FD6A.707A872A@1185design.com>

Hello,

I have a list of names and corresponding ID numbers in an array that
goes something like this:

0    Rossi, Valentino
1    Abe, Norick
2    Okada, Tadayuki
 ..................on and on until..............
5089    Roberts, Kenny

My dilemma is that I want to sort this list alphabetically by the last
names while ignoring any and all the numbers in front. Putting the
numbers in back of the name is unfortunately not an option. Is this
possible using the sort routine and if so can someone give me an
example?

Thanks for your help!

mike
 



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

Date: Mon, 04 Oct 1999 16:34:04 GMT
From: pyammine@my-deja.com
Subject: Specifying start row for DB access
Message-Id: <7taktr$85o$1@nnrp1.deja.com>

I was wondering if anybody knew if it is possible with DBI::ODBC and/or
WIN32::ODBC to specify what row/record to start fetching from in a
database. Meaning, If I execute a SQL statement and than want to put
the records into arrays, can I say I only want it to start at the 10th
record and end at the 20th?

Currently, I read all the records into an array and use the element
number to decide where to start printing and when to end. Here is an
example of my SQL commands (this one is with Win32 but I am changing it
all over to DBI::ODBC).

Thanks, Pascal

##Get Status IDs from search
if ($db->sql($sql))
{
   print "Get Records  Error[" . $db->Error() ."]";
   $db->ShutDown();
}

my @ColumnNames = $db->FieldNames();

my $n = 0;
my $rec;
while ($db->FetchRow())
{
   $Rec = "";
   foreach $Column (@ColumnNames)
   {
     $Rec = $db->Data($Column);
     push(@{'Record' . $n}, $Rec)
   }
   $n++;
}


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


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

Date: 4 Oct 1999 09:43:22 GMT
From: h.m.brand@hccnet.nl (H. Merijn Brand)
Subject: Re: Split() on vertical bar |
Message-Id: <8E557A876Merijn@192.0.1.19>

>in <URL:news:37F2638B.A9826D7A@msx.upmc.edu>:
>.. Any ideas on how to split() a line on a vertical bar (hash mark) | ?
>.. Thanks.

# Would this do?
@chunks = split m/\s*\|\s*/;    	# Also removes whitespace around the pipe
    	    	    	    	    	    	# Comes in handy with some SQL output


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

Date: Mon, 04 Oct 1999 20:20:29 +0100
From: Danny Verkade <webmaster@mybegin.com>
Subject: Test this please
Message-Id: <37F8FDFC.71FEBE1E@mybegin.com>

Hi,

I've created a CGI/Perl program and hope that you can test it. The
program will retrieve the latest headlines and displays them in my own
format. Can you please tell me what you think about it?? Is anything
wrong with it, do you see mistakes?

Thanks
Danny Verkade
Webmaster MyBegin.com
E-Mail: webmaster@mybegin.com
Tel. : +31 6 504 64 540
-----------------------------------------------------------------------------------

MyBegin - Your Internet starts here.
http://www.mybegin.com



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

Date: Mon, 04 Oct 1999 11:05:01 -0700
From: Makarand Kulkarni <makkulka@cisco.com>
Subject: Re: Test this please
Message-Id: <37F8EC4D.160ECC20@cisco.com>

[ Danny Verkade wrote:

> Can you please tell me what you think about it?? Is anything
> wrong with it, do you see mistakes?

I don't see any code.
--



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

Date: 4 Oct 1999 14:28:56 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Test this please
Message-Id: <slrn7vi0fi.dhe.abigail@alexandra.delanet.com>

Danny Verkade (webmaster@mybegin.com) wrote on MMCCXXV September MCMXCIII
in <URL:news:37F8FDFC.71FEBE1E@mybegin.com>:
$$ 
$$ I've created a CGI/Perl program and hope that you can test it. The
$$ program will retrieve the latest headlines and displays them in my own
$$ format. Can you please tell me what you think about it?? Is anything
$$ wrong with it, do you see mistakes?


I think it's perfect. Nice and quiet.



Abigail
-- 
sub A::TIESCALAR{bless\my$x=>A};package B;@q=qw/Hacker Another
Perl Just/;use overload'""'=>sub{pop @q};sub A::FETCH{bless\my
$y=>B}; tie my $shoe => 'A';print "$shoe $shoe $shoe $shoe\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: Mon, 04 Oct 1999 22:00:41 +0100
From: Danny Verkade <webmaster@mybegin.com>
Subject: Re: Test this please
Message-Id: <37F91578.474B3F61@mybegin.com>



Makarand Kulkarni wrote:

> [ Danny Verkade wrote:
>
> > Can you please tell me what you think about it?? Is anything
> > wrong with it, do you see mistakes?
>
> I don't see any code.

Well, of course you don't see any code. It's a CGI/Perl program wich is
being excecuted. I wanted to know everything works smooth.

>
> --



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

Date: Mon, 04 Oct 1999 22:01:22 +0100
From: Danny Verkade <webmaster@mybegin.com>
Subject: Re: Test this please
Message-Id: <37F915A1.31335ACB@mybegin.com>



Abigail wrote:

> Danny Verkade (webmaster@mybegin.com) wrote on MMCCXXV September MCMXCIII
> in <URL:news:37F8FDFC.71FEBE1E@mybegin.com>:
> $$
> $$ I've created a CGI/Perl program and hope that you can test it. The
> $$ program will retrieve the latest headlines and displays them in my own
> $$ format. Can you please tell me what you think about it?? Is anything
> $$ wrong with it, do you see mistakes?
>
> I think it's perfect. Nice and quiet.

Great, any reccomentations.?

>
>
> Abigail
> --
> sub A::TIESCALAR{bless\my$x=>A};package B;@q=qw/Hacker Another
> Perl Just/;use overload'""'=>sub{pop @q};sub A::FETCH{bless\my
> $y=>B}; tie my $shoe => 'A';print "$shoe $shoe $shoe $shoe\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: 04 Oct 1999 14:52:27 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Wow! cgi.pm is great!
Message-Id: <x7n1tzt0us.fsf@home.sysarch.com>

>>>>> "JM" == James Moore <bokler_1@hiwaay.net> writes:

  JM> On 2 Oct 1999 22:26:05 -0000, Jonathan Stowe <gellyfish@gellyfish.com>
  JM> wrote:

  >> Oh you were referring to Uri's ever so slightly critical comment
  >> werent you?

  JM> Oh - well how would you describe him? Is he a natural resource that
  JM> you've adopted for protection, a personal friend, or just someone who
  JM> makes you feel that you should go "shushing" to anyone who expresses
  JM> an opinion contrary to his?

  JM> I did listen. I didn't insult the man any more than he insulted the
  JM> publisher and book's author. In this case his post was critical, and
  JM> without value... kind of like ours, Jonathan.

i seemed to have missed the followups to my criticism of the cgi
book. but it doesn't matter and i can defend myself without any
trouble. and i can take all the barbs that newbies wish to send my way
since my skin is thick and they shoot nerf darts.

as for the book, my main point is that it could have been (and should be)
a much much better book. cgi.pm is a valuable perl resource and deserves
a better book about it. the publisher is mostly to blame for their poor
production and editing. the content is decent but could be
better. lincoln stein has written much better books (apache modules, how
to build and maintain web sites) so i know he can do better. that is why
i suspect the publisher is mostly at fault. i don't tell people not to
buy the book, i just don't say it is great and a must have for your perl
shelf. it is cheap enough ($18 on line) that it is worth having even if
you don't reference it so much. i sometime use it and sometimes i use
the pod. if the book had a better organization (again publisher's fault)
i would use it more.

if i were to give it rating from 1-10, it would be a 5. 

as for my book reviewing interests, look soon for the perl books page
(when my site is finally transfered to the new isp. damned network
solution assholes!)

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

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


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