[19579] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1774 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 19 14:10:46 2001

Date: Wed, 19 Sep 2001 11:10:11 -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: <1000923011-v10-i1774@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 19 Sep 2001     Volume: 10 Number: 1774

Today's topics:
    Re: Problem with DBI+DBD MySQL, using fetchall_arrayref (Tad McClellan)
        regex needed <peter_icaza@REMOVE2REPLYuhc.com>
    Re: regex needed <dtweed@acm.org>
        returnvalues in perl (Markus)
    Re: select() timeout problem <philippe.perrin@sxb.bsf.alcatel.fr>
    Re: select() timeout problem (Michel Dalle)
        Simple Server/Client <webmaster@kwakeb.net>
    Re: Simple Server/Client (Malcolm Dew-Jones)
    Re: Simple Server/Client <webmaster@kwakeb.net>
        Sorting Hashes <mjvincent@lucent.com>
    Re: split SuchKindOfWord into individual words <sun_tong@users.sourceforge.net>
    Re: split SuchKindOfWord into individual words <joe+usenet@sunstarsys.com>
    Re: This has got to be a bug <dha@panix.com>
    Re: What does this error mean? (Stan Brown)
    Re: What does this error mean? (Ronald Blaschke)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 19 Sep 2001 14:05:28 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Problem with DBI+DBD MySQL, using fetchall_arrayref and dereferencing with random function
Message-Id: <slrn9qh6hg.4bg.tadmc@tadmc26.august.net>

Altair04 <altair_04@altavista.com> wrote:

>if I assign the same expression to a
>variable, it contains always a '1':


>print @{@{$countries_ref}[rand(@{$countries_ref})]};
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

   perldoc -f print

tells us that the expression is in list context here.



>#################################
># but this prints always a '1': #
>#################################
>$country = @{@{$countries_ref}[rand(@{$countries_ref})]};


The "Context" section in

   perldoc perldata

tells us that the expression is in scalar context here.


>I'd like to know why $country does not contain the name of a country
>(this is what I get from the first print).


scalar vs. list context


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Wed, 19 Sep 2001 10:45:46 -0400
From: peter <peter_icaza@REMOVE2REPLYuhc.com>
Subject: regex needed
Message-Id: <3BA8AF9A.3DD42BF9@REMOVE2REPLYuhc.com>

 hi,
it has ben awhile....

i need to scan any number of files to find patterns similar to the
following:

           (set! glErrorParameters (list (string-append "Stored
Procedure Name= " (get ~input%etd_Event_Tri
gger_Out.payload)) (string-append "Oracle Error= " (db-get-error-str
connection-handle))))^M

the string i key off now is "set! glErrorParameter" but that doesnt get
me the whole pattern acroos multiple lines i need to match.  what i need
is to match the first, opening paren to the left of the set! command and
then match to the corresponding, closing paren.  please provide a regex
to accomplish this task.

i plan on wrapping this  in a shell script which first finds the list of
files with the pattern "set! glErrorParameters" and tehn have perl scan
the files  and create a list of file names and found patterns.  other
suggestions for this will be appreciated.

tia,
peter
ps
i know it is against net-equette to ask to cc me, but we got hit with
the readme.exe worm and i have had trouble getting to the new groups, so
please cc me.



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

Date: Wed, 19 Sep 2001 15:06:50 GMT
From: Dave Tweed <dtweed@acm.org>
Subject: Re: regex needed
Message-Id: <3BA8B34E.72B91D0F@acm.org>

[mailed and posted]

peter wrote:
> i need to scan any number of files to find patterns similar to the
> following:
> 
>            (set! glErrorParameters (list (string-append "Stored
> Procedure Name= " (get ~input%etd_Event_Tri
> gger_Out.payload)) (string-append "Oracle Error= " (db-get-error-str
> connection-handle))))^M
> 
> the string i key off now is "set! glErrorParameter" but that doesnt get
> me the whole pattern acroos multiple lines i need to match.  what i need
> is to match the first, opening paren to the left of the set! command and
> then match to the corresponding, closing paren.  please provide a regex
> to accomplish this task.

A regex alone cannot handle the general problem of delimiter matching.
You're going to have to actually parse the string. One place to start
is Text::DelimMatch.

-- Dave Tweed


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

Date: 19 Sep 2001 10:37:55 -0700
From: markus.moldaschl@lion.cc (Markus)
Subject: returnvalues in perl
Message-Id: <a7ef180a.0109190937.61ee1d5b@posting.google.com>

hi,
i'm new in programming perl, my problem is that I use http_get to a
perlscript and this script should not gernerate html-code it should
only return one value,
has anybody got a code-snippet or an example how this script could
look like??

thank you very much,

greeting from austria
markus


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

Date: Wed, 19 Sep 2001 17:14:14 +0200
From: Philippe PERRIN <philippe.perrin@sxb.bsf.alcatel.fr>
Subject: Re: select() timeout problem
Message-Id: <3BA8B646.9E22C587@sxb.bsf.alcatel.fr>

Philippe PERRIN wrote:
> the problem

Since nobody seems very inspired by my previous message, here is some
more information :
1) my perl version is 5.005_03
2) my bug happens on linux AND solaris (same version or 5.6.0)
3) since my problem arises on different platforms/machines, I think I
made a mistake somewhere. I'd juste like to know if someone manages to
make my script work ; and could anyone give me another example of script
that does the same thing (fifo reading with timeout), and which has been
tested bug-free ?

Thanx a lot !

-- 
PhP

($r1,$r2,$r3,$r4)=("19|20","0|1","28|29","5|24");($r5,$r6)=("9|10|15|16|$r1|$r2","9|10|$r3");%h=("1|",$r6,"1=","[1-5]|2[0-4]","1/","0|19","1\\","6|25","2|","0|6|19|25|$r6","2/","1|20","2\\",$r4,"3|","$r2|6|$r1|25|$r6","3/",$r4,"4|","$r2|$r1|$r6","4=","2|3|4|11|12|13|14|21|22|23","4/",$r4,"4\\",15,"5|","$r2|9|15|$r1|20|$r3","5/",10,"6|",$r5,"7|",$r5,"7/",$r3);for($l=1;$l<8;$l++){b:for($i=0;$i<30;$i++){c:foreach(keys
%h){next c if(!(/^$l(.*)$/));$a=$1;if($i=~/^($h{$_})$/){print $a;next
b;}}print " ";}print "\n";}


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

Date: Wed, 19 Sep 2001 17:03:52 GMT
From: news@mikespub.net (Michel Dalle)
Subject: Re: select() timeout problem
Message-Id: <9oajjo$esu$1@dackel.pdb.sbs.de>

In article <3BA88CDD.94299297@sxb.bsf.alcatel.fr>, Philippe PERRIN <philippe.perrin@sxb.bsf.alcatel.fr> wrote:
>Hi
>
>I use the script below on a linux box. The "myFifo" file is a fifo,
>created with mkfifo. While running, it is supposed to wait for data to
>be readable in this fifo, then display them. This works fine.
>The problem is, that it is also supposed to timeout after 5 seconds...
>and this never happens ! The select() call only exits when I send bytes
>in the fifo, and the value of $left is always 5. Why doesn't it timeout
>??
>
>Thanks

FIFO files are weird things - you need to have them open both for reading
*and* writing before you can do any input or output from either side (at
least according to the glibc docs).

When I tried it out on my system, the script 'hung' on the open() until
some other process opened the FIFO for writing, and *then* it timed out
after the select() - if the other process still hadn't printed anything to the
FIFO after 5 seconds...

Some additional comments on the code :

1) from the description of select() in perlfunc :

WARNING: One should not attempt to mix buffered I/O (like read or <FH>) with 
select, except as  permitted by POSIX, and even then only on POSIX systems.
You have to use sysread instead.

2) you don't check whether the open succeeded at all

3) are you sure you want to open/close/define the vars *inside* your while (1)
loop ?

HTH,

Michel.

-- 
Welcome to Mike's Pub
http://mikespub.net/forum/


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

Date: Wed, 19 Sep 2001 19:07:30 +0300
From: "Kwakeb.net - Administrator" <webmaster@kwakeb.net>
Subject: Simple Server/Client
Message-Id: <9oag48$7ou$1@ns1.isu.net.sa>

Hi all

I want to give me a small simple code to create a server and client by any
good modules

Regards,
eDeveloper






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

Date: 19 Sep 2001 09:43:22 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Simple Server/Client
Message-Id: <3ba8cb2a@news.victoria.tc.ca>

Kwakeb.net - Administrator (webmaster@kwakeb.net) wrote:
: Hi all

: I want to give me a small simple code to create a server and client by any
: good modules

: Regards,
: eDeveloper

to quote perlfunc.pod

	See the example in L<perlipc/"Sockets: Client/Server
	Communication">


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

Date: Wed, 19 Sep 2001 21:00:02 +0300
From: "eDeveloper" <webmaster@kwakeb.net>
Subject: Re: Simple Server/Client
Message-Id: <9oamn9$f4i$1@ns1.isu.net.sa>

Hi
Thanks too much

It really useful

I created a server and client

my question is how to pass a scalar form the client to the server ? or from
the server to client

Thanks again
eDeveloper

"Malcolm Dew-Jones" <yf110@vtn1.victoria.tc.ca> wrote in message
news:3ba8cb2a@news.victoria.tc.ca...
> Kwakeb.net - Administrator (webmaster@kwakeb.net) wrote:
> : Hi all
>
> : I want to give me a small simple code to create a server and client by
any
> : good modules
>
> : Regards,
> : eDeveloper
>
> to quote perlfunc.pod
>
> See the example in L<perlipc/"Sockets: Client/Server
> Communication">




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

Date: 19 Sep 2001 17:27:22 GMT
From: "Michael J. Vincent" <mjvincent@lucent.com>
Subject: Sorting Hashes
Message-Id: <Xns912189DA8F7ABjohnnyfingers@135.7.153.102>

perl guru's,

    	I have a hash whose index is IP addresses and value is the number of 
times the IP address appears in a file.  I'd like to print output sorted by 
the most occurances to the least and secondary sorted on the increasing IP 
address.

    	An example:

    	$hash{172.16.5.1} = 5
    	$hash{172.16.5.2} = 5
    	$hash{172.16.5.3} = 7
    	$hash{172.16.6.1} = 10
    	$hash{172.16.7.1} = 2

    	I would like the output to be:

    	10 172.16.6.1
      7 172.16.5.3
      5 172.16.5.1
      5 172.16.5.2
      2 172.16.7.1

    	I've attached the following code which is basically a cheap work-
around to get the job done.  However, this code does not produce the 
increase IP address sorting.  For instance, in the above example run through 
the following code, the 2 IP address with 5 occurances may appear as 5.2 
then 5.1 where I would like the 5.1 to always come first.

    	%switch_list in the following code is the hash described above.

----------<CLIP HERE>----------
sub sort_adj {
    $PADDING = "123456789";
    $i = 0;
    foreach $x (keys %switch_list) {
        # add some padding between the ADJ and SwitchIP
        # so we can split by search and replace later for formatting
        $switcharray[$i] =  $switch_list{$x} . $PADDING . $x;
        $i++
    }

    @switcharray = sort { $b <=> $a } @switcharray;

    $i = 0;
    while ($switcharray[$i]) {

        # Split the line into parts so we can format nicely
        @lineParts = split (/$PADDING/, $switcharray[$i]);
        printf "  %3i  x  $lineParts[1]\n", $lineParts[0];
        $i++
    }

}
----------<CLIP HERE>----------

    	cheers.    	


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

Date: 19 Sep 2001 13:45:37 -0300
From: * Tong * <sun_tong@users.sourceforge.net>
Subject: Re: split SuchKindOfWord into individual words
Message-Id: <sa8adzr5du6.fsf@suntong.personal.users.sourceforge.net>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:

>     @words = /([A-Z][a-z]*)/g;

I thought the winner goes to the split version contributed by Steve

,-----
| split (/(?<=[a-z])(?=[A-Z])/,$string);
`-----

But your blows me away. After trying it, I still can't understand
how on earth it can work. :-) 

-- 
Tong (remove underscore(s) to reply)
  *niX Power Tools Project: http://xpt.sourceforge.net/
  - All free contribution & collection


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

Date: 19 Sep 2001 13:02:47 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: split SuchKindOfWord into individual words
Message-Id: <m3elp315c8.fsf@mumonkan.sunstarsys.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:

> According to Michael Budash  <mbudash@sonic.net>:
> > 
> > based strictly on your example, here's one way:
> > 
> > push @words, $1 while /([A-Z][^A-Z]+)/g;
>                                  ^ ^ ^
> Besides the obvious typo, 

Typo?  What's wrong with using [^A-Z] instead of [a-z] ?

> you may want "*" instead of "+" (ACatAndADog).  Shorter and perhaps
> faster:
> 
>     @words = /([A-Z][a-z]*)/g;
                ^           ^

Useless use of parens ... :)

-- 
Joe Schaefer       "The man who sets out to carry a cat by its tail learns
                something that will always be useful and which never will grow
                                      dim or doubtful."
                                               --Mark Twain



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

Date: 19 Sep 2001 14:00:47 GMT
From: "David H. Adler" <dha@panix.com>
Subject: Re: This has got to be a bug
Message-Id: <slrn9qh9ag.5gs.dha@panix2.panix.com>

In article <9n231g$9ev$1@news.panix.com>, David Combs wrote:
> In article <9m8poo$hj4$1@news.doit.wisc.edu>,
> art blair  <arthur@ablair.physics.wisc.edu> wrote:
>>Thanx to all. \Q \E worked. 
>>I need to get a better perl book.
>>
>>Art.
> 
> The "Bible" of perl is "Programming Perl", 3rd edition,
> pub= O'Reilly.

Actually, the "Bible" is the documentation that comes with perl... books
get outdated pretty quickly.

That said, as paper books go, you *would* be hard pressed to find a
better candidate.

dha, picking nits...

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"When the bug expands, I contract.  When it contracts, I expand.  And
when an opportunity appears, I do not fix the bug -- my keyboard does
it, on its own."	- Chip Salzenberg


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

Date: 19 Sep 2001 10:56:39 -0400
From: stanb@panix.com (Stan Brown)
Subject: Re: What does this error mean?
Message-Id: <9oabn7$7a3$1@panix1.panix.com>

In <QE0q7.28908$5A3.9603631@news1.rdc2.pa.home.com> "Ben Kennedy" <bkennedy99@Home.com> writes:


>"Stan Brown" <stanb@panix.com> wrote in message
>news:9oa3qq$56o$1@panix3.panix.com...

>> Tk::Error: Can't use an undefined value as a symbol reference at ./stan.pl
>> line 175.
>>
>> Here's line 175:
>>
>>     pipe my ($reader, $writer) or die "pipe: $!";
>>
>> What is perl trying to tell me?

>This is definitely a 5.6 vs 5.5 issue - you get the same error on 5.5 with

>open(my $handle, "filename") or die "Cannot open: $!";

>It looks like 5.5 treats the variable as a soft reference to a glob - so if
>you set $out to HANDLE, you can then read/use HANDLE after the open
>statement.  In 5.6, if you pass it a variable that is undef it will be smart
>and fill the variable with an anonymous glob reference that can be used as a
>handle - all in all a better solution.  Perhaps someone else knows where
>this is officially documented?  The perl docs seem a bit behind the times


Sorry, most of that went over my head :-(

Let me as a simpler question.

What should this look like to work corectly in 5.005_03?



-- 
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
						-- Benjamin Franklin


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

Date: 19 Sep 2001 17:44:31 GMT
From: TGVCDPVNTLMI@spammotel.com (Ronald Blaschke)
Subject: Re: What does this error mean?
Message-Id: <9oalhv$bu064$1@ID-57488.news.dfncis.de>

On 19 Sep 2001 10:56:39 -0400, Stan Brown <stanb@panix.com> wrote:
> >> Tk::Error: Can't use an undefined value as a symbol reference at ./stan.pl
> >> line 175.
> >>
> >> Here's line 175:
> >>     pipe my ($reader, $writer) or die "pipe: $!";
> >>
> >> What is perl trying to tell me?
> 
> >This is definitely a 5.6 vs 5.5 issue - you get the same error on 5.5 with
> 
> >open(my $handle, "filename") or die "Cannot open: $!";
[snipped explanation]
> 
> Sorry, most of that went over my head :-(
> 
> Let me as a simpler question.
> 
> What should this look like to work corectly in 5.005_03?

Try generating your own anonymous globs.

use Symbol;
my ($reader, $writer) = (gensym, gensym);
pipe($reader, $writer) or die "pipe: $!";

Seems to work for my 5.005_03 build...

Ron
-- 


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

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


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