[23254] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5475 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 10 03:05:39 2003

Date: Wed, 10 Sep 2003 00:05:10 -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           Wed, 10 Sep 2003     Volume: 10 Number: 5475

Today's topics:
        $# is deprecated, $OFMT doesn't work <jidanni@jidanni.org>
    Re: $# is deprecated, $OFMT doesn't work <jwillmore@cyberia.com>
    Re: $# is deprecated, $OFMT doesn't work <steven.smolinski@sympatico.ca>
    Re: $# is deprecated, $OFMT doesn't work <tassilo.parseval@rwth-aachen.de>
    Re: $# is deprecated, $OFMT doesn't work <tassilo.parseval@rwth-aachen.de>
    Re: [newbie] dbi question <tsheets@insightbb.com>
    Re: calculation in string <tcurrey@no.no.no.i.said.no>
    Re: Converting C++ to Perl <kalinabears@iinet.net.au>
    Re: Flocking Advise (David Efflandt)
        Help me beef up my cruddy program <jidanni@jidanni.org>
    Re: Help me beef up my cruddy program <uri@stemsystems.com>
    Re: Help me beef up my cruddy program <uri@stemsystems.com>
    Re: how should i fix this?? <krahnj@acm.org>
    Re: How To activate command line history in debugger? <k.kronschnabl_nospm_@ica-intercom-akademie.de>
    Re: How To Make Filehandle Global To Package? <mooseshoes@gmx.net>
    Re: How To Make Filehandle Global To Package? <uri@stemsystems.com>
    Re: How To Make Filehandle Global To Package? <mooseshoes@gmx.net>
    Re: looping every x seconds <jwillmore@cyberia.com>
    Re: looping every x seconds <jwillmore@cyberia.com>
    Re: Making a script write to a file (take 2) (Philip)
    Re: Parsing to insert single quotes (Jay Tilton)
    Re: Parsing to insert single quotes <nospam@xx.com>
    Re: pass cmd line file glob to grep for readdir (qanda)
    Re: Reading Data File Records <jwillmore@cyberia.com>
    Re: simple regex problem <Nekid@jaybird.com>
        subroutines may be located anywhere in the main program <jidanni@jidanni.org>
    Re: subroutines may be located anywhere in the main pro <tassilo.parseval@rwth-aachen.de>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 10 Sep 2003 12:23:58 +0800
From: Dan Jacobson <jidanni@jidanni.org>
Subject: $# is deprecated, $OFMT doesn't work
Message-Id: <877k4hqnj5.fsf@jidanni.org>

$ perl -wle '$#="%.2f";print 1/3'
Use of $# is deprecated at -e line 1.
0.33
$ man perlvar
$ perl -wle '$OFMT="%.2f";print 1/3'
Name "main::OFMT" used only once: possible typo at -e line 1.
0.333333333333333

What is the matter with me?
perl, v5.8.0


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

Date: Wed, 10 Sep 2003 05:37:49 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: $# is deprecated, $OFMT doesn't work
Message-Id: <20030910013755.0fa73eef.jwillmore@cyberia.com>

On Wed, 10 Sep 2003 12:23:58 +0800
Dan Jacobson <jidanni@jidanni.org> wrote:

> $ perl -wle '$#="%.2f";print 1/3'
> Use of $# is deprecated at -e line 1.
> 0.33
> $ man perlvar
> $ perl -wle '$OFMT="%.2f";print 1/3'
> Name "main::OFMT" used only once: possible typo at -e line 1.
> 0.333333333333333
> 
> What is the matter with me?
> perl, v5.8.0

Why not just use printf?

jim@maxine:~> perl -wle 'printf "%.2f\n", 1/3'
0.33
jim@maxine:~> 

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
Life is like a simile. 



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

Date: Wed, 10 Sep 2003 06:10:06 GMT
From: Steven Smolinski <steven.smolinski@sympatico.ca>
Subject: Re: $# is deprecated, $OFMT doesn't work
Message-Id: <2fz7b.3002$z5.237577@news20.bellglobal.com>

Dan Jacobson <jidanni@jidanni.org> wrote:
> $ perl -wle '$OFMT="%.2f";print 1/3'
> Name "main::OFMT" used only once: possible typo at -e line 1.
> 0.333333333333333

Note to OP: in perlvar it should tell you that to use the long names of
the punctuation variables you need to:

use English;

But since $# is deprecated, see printf instead.


Question to everyone:

Should perlvar in 5.8.0 still mention $OFMT when it has been removed
from English.pm?

I don't know how to submit a documentation patch to p5p, but I suppose I
can learn.

Steve


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

Date: 10 Sep 2003 06:28:55 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: $# is deprecated, $OFMT doesn't work
Message-Id: <bjmgb7$b74$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Dan Jacobson:

> $ perl -wle '$#="%.2f";print 1/3'
> Use of $# is deprecated at -e line 1.
> 0.33
> $ man perlvar
> $ perl -wle '$OFMT="%.2f";print 1/3'
> Name "main::OFMT" used only once: possible typo at -e line 1.
> 0.333333333333333

If you want to use the long variable names for the punctuation
variables, you need the English module. However, $OFMT isn't handled by
that because $# is deprecated. Therefore:

    *OFMT = \$#;
    $OFMT = "%.2f\n";
    print 1/3;
    __END__
    0.33

The first line will make $OFMT an alias for $#.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: 10 Sep 2003 06:37:40 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: $# is deprecated, $OFMT doesn't work
Message-Id: <bjmgrk$bj2$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Steven Smolinski:

> Dan Jacobson <jidanni@jidanni.org> wrote:
>> $ perl -wle '$OFMT="%.2f";print 1/3'
>> Name "main::OFMT" used only once: possible typo at -e line 1.
>> 0.333333333333333
> 
> Note to OP: in perlvar it should tell you that to use the long names of
> the punctuation variables you need to:
> 
> use English;
> 
> But since $# is deprecated, see printf instead.
> 
> 
> Question to everyone:
> 
> Should perlvar in 5.8.0 still mention $OFMT when it has been removed
> from English.pm?

I just wondered about that, too, when I saw that alias to the deprecated
variables are commented out in English.pm. Either perlvar removes the
symbolic name of deprecated variables or the aliases remain in
English.

> I don't know how to submit a documentation patch to p5p, but I suppose I
> can learn.

perlvar.pod is just a plain file in the Perl source tree so you'd patch
it as any other file. See 'perldoc perlhack' for an instruction on how
to patch Perl and submit those patches.

Essentially: rsync one of the branches (blead, aka 5.9.0 or maint
[5.8.1-to-come]), cp pod/perlvar.pod to pod/perlvar.pod~ or so, patch
perlvar.pod, run

    diff -u pod/perlvar.pod~ pod/perlvar.pod > patch

and send the patch as attachment to perl5-porters@perl.org while
mentioning against which branch this patch is (althouth the porters
might figure that out themselves).

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Wed, 10 Sep 2003 04:26:21 GMT
From: tsheets <tsheets@insightbb.com>
Subject: Re: [newbie] dbi question
Message-Id: <NJx7b.407262$Ho3.63386@sccrnsc03>

John Bokma wrote:
> tsheets wrote:
> 

>> I have an HTML form, that lets the user select which fields to include 
>> in the results.  Also, a text box for the where clause.
>>
>> for example, the table contains firstname, lastname, phone, address, 
>> and zip.
>>
>> Lets say you only want firstname, lastname, and zip (checkboxes), 
>> where lastname = smith.

> 
> Be *extremely* careful with building a select statement from a form. 
> Never ever trust what a user enters. Check each field and make sure it 
> matches *only* characters that are allowed. Don't try to fix silently 
> but report an error (for example if you expect a number make sure it is 
> a number, don't throw away non-digits but warn if you get anything that 
> is not a digit, see also URL in my sig).

Thanks for the advise.  I haven't yet taken steps to validate the data, 
but, at this point, I am going for basic function and am the only one 
with access to the system.  I will definitely add that in.


> you can do:
> 
> SELECT Name, Address, Phone FROM table WHERE Name='John';
> 
> this gives all rows with Name John and only the columns Name, Address 
> and Phone. So you can specify which columns you want.

Actually, that is the part I wasn't quite getting.  I thought the DBI 
fetchrow function was grabbing the entire row, not just the columns I 
specified in the select statement.


> You could do something like:
> 
> @cols = ();
> @checkboxes = qw(name phone address);
> 
> foreach checkbox (@checkboxes)
>     push(@cols, checkbox) if checked(checkbox);
> }
> 
> query = "select " . join(", ", @cols) . " from table ...";
> 
> (pseudo perl)

I'll have to play with that.  It's much more elegant than what I was 
doing.  I was checking the status of each checkbox and concatonating the 
ones that were "true" and doing some clean-up, etc.  ex...
$selectFields .= ",Name" if(param("selName"));
$selectFields .= ",Phone" if(param("selPhone"));

Then clean off the leading ',' and split on the remaining ',' and stuff 
it into an array for later processing!

Like I said, your method is much more elegant. :-)

Ahhh well, Live and Learn, right??

Thanks for the help!

Tim



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

Date: Tue, 9 Sep 2003 23:25:21 -0700
From: "Trent Curry" <tcurrey@no.no.no.i.said.no>
Subject: Re: calculation in string
Message-Id: <bjmg8p$o9u$1@news.astound.net>

"Daniel" <dvdoord@planet.nl> wrote in message
news:3f4c7dbf$0$49114$e4fe514c@news.xs4all.nl...
> I've a dynamic variable
> $var_tmp = "/18";
> where the "/18" can also be "/18+100"
> I also got a variable
> $var_prize = 2000
> now the thing is I have to get this
> $var_total = 2000/18+100;
>
> anybody knows how this works ?!?

   $var_total = eval($var_tmp);
will do what you want.

Also, alt.comp.lang.perl & comp.lang.perl are very rare if not virtually
extinct news groups. I don't think too many people get them. Though there
seems to be SOME activity in those two said groups...

Or is alt.comp.lang.perl just a lesser known group?




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

Date: Wed, 10 Sep 2003 16:23:52 +1000
From: Sisyphus <kalinabears@iinet.net.au>
Subject: Re: Converting C++ to Perl
Message-Id: <3f5ec426$0$23610$5a62ac22@freenews.iinet.net.au>

Kenny McCarty wrote:

> 
> The C++ is run on Windows XP and the perl is run on Free-BSD.  For the
> perl part I want the user to input the volume serial number of their C
> drive and I want to create a strign using this data.  I think that the
> conversions are different between windows and unix and that is where
> my problem is but I am not sure.  In windows the "3" becomes a "056"
> but in unix it becomes a "53".  Any help would be apprecieated. 
> Thanks.

Are you sure about this ?
Both 'C' and 'perl' report an ASCII value of 51 for '3' (on both Linux 
and Windows) for me - which is as I would expect. (Your perl script 
outputs '51-48-51'.)

Hth.

Cheers,
Rob



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

Date: Wed, 10 Sep 2003 06:28:41 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Flocking Advise
Message-Id: <slrnblth4p.nhi.efflandt@typhoon.xnet.com>

On Tue, 9 Sep 2003, news@roaima.freeserve.co.uk 
<news@roaima.freeserve.co.uk> wrote:
><news@roaima.freeserve.co.uk> asked:
>> Can anyone give a concrete explanation as to why the seek is required
>> immediately after the flock?
> 
> David Efflandt <efflandt@xnet.com> wrote:
>> perldoc -f flock
> 
> The seek to EOF is correct when you're appending to a file. In the
> general case (and particularly when reading) it's not required.
> 
>> Basically something else could open the file (possibly for reading)  
>> between the time you open it, and flock it, so the file pointer might not
>> be at the beginning of the file when you go to read it.
> 
> The file pointer is on a per-filehandle basis, not on a per-file
> basis. We'd get mighty upset if I changed my file pointer and yours
> updated too.

Actually I had problems with a CGI script that just read a file without
flocking it.  If more than one instance tried to read from the file at the
same time, it apparently got confused where the file pointer was and the
Perl (CGI) scripts would go into endless loops (the host notified me about
the endless processes).  Flocking solved that.  I think that was on
Solaris, which may do things differently than other Unix systems.

-- 
David Efflandt - All spam ignored  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/


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

Date: Wed, 10 Sep 2003 13:22:33 +0800
From: Dan Jacobson <jidanni@jidanni.org>
Subject: Help me beef up my cruddy program
Message-Id: <8765k1qkti.fsf@jidanni.org>

Help me beef up my cruddy program.  It should then even run on Microsoft,
by the way.

#!/usr/bin/perl -ws
#use strict; #can't use due to -s.
$, = "\t";
$\ = "\n";
my $A = 0.00001549;
my $B = 0.000006521;
my $C = 807.8;
my $D = 248.6;
if ( $I ) {
    foreach my $i ( $A, $B, $C, $D ) { $i = -$i }
}
while (<>) {
    my @F = split;
    print $F[0] - $C - $A * $F[0] - $B * $F[1],
      $F[1] + $D - $A * $F[1] - $B * $F[0], "@F";
}


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

Date: Wed, 10 Sep 2003 06:21:09 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Help me beef up my cruddy program
Message-Id: <x7smn5cgky.fsf@mail.sysarch.com>

>>>>> "DJ" == Dan Jacobson <jidanni@jidanni.org> writes:

  DJ> Help me beef up my cruddy program.  It should then even run on Microsoft,
  DJ> by the way.

  DJ> #!/usr/bin/perl -ws
  DJ> #use strict; #can't use due to -s.

wrong. use vars or our can fix that.

  DJ> $, = "\t";
  DJ> $\ = "\n";
  DJ> my $A = 0.00001549;
  DJ> my $B = 0.000006521;
  DJ> my $C = 807.8;
  DJ> my $D = 248.6;
  DJ> if ( $I ) {
  DJ>     foreach my $i ( $A, $B, $C, $D ) { $i = -$i }
  DJ> }
  DJ> while (<>) {
  DJ>     my @F = split;
  DJ>     print $F[0] - $C - $A * $F[0] - $B * $F[1],
  DJ>       $F[1] + $D - $A * $F[1] - $B * $F[0], "@F";
  DJ> }

if you picked better var names and decribed what this is supposed to do,
someone might help. i won't waste my time on the above.

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
Damian Conway Class in Boston - Sept 2003 -- http://www.stemsystems.com/class


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

Date: Wed, 10 Sep 2003 06:23:56 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Help me beef up my cruddy program
Message-Id: <x7r82pcgep.fsf@mail.sysarch.com>

>>>>> "DJ" == Dan Jacobson <jidanni@jidanni.org> writes:

  DJ> Help me beef up my cruddy program.  It should then even run on Microsoft,
  DJ> by the way.

  DJ> #!/usr/bin/perl -ws
  DJ> #use strict; #can't use due to -s.

wrong. use vars or our can fix that.

  DJ> $, = "\t";
  DJ> $\ = "\n";
  DJ> my $A = 0.00001549;
  DJ> my $B = 0.000006521;
  DJ> my $C = 807.8;
  DJ> my $D = 248.6;
  DJ> if ( $I ) {
  DJ>     foreach my $i ( $A, $B, $C, $D ) { $i = -$i }
  DJ> }
  DJ> while (<>) {
  DJ>     my @F = split;
  DJ>     print $F[0] - $C - $A * $F[0] - $B * $F[1],
  DJ>       $F[1] + $D - $A * $F[1] - $B * $F[0], "@F";
  DJ> }

if you picked better var names and decribed what this is supposed to do,
someone might help. i won't waste my time on the above.

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
Damian Conway Class in Boston - Sept 2003 -- http://www.stemsystems.com/class


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

Date: Wed, 10 Sep 2003 05:42:37 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: how should i fix this??
Message-Id: <3F5EB9CA.A99D0502@acm.org>

jend wrote:
> 
> my @thoseLabels = qw(Tom's John's Jim's mike blah bloh);
> 
> my $this_array = "'".join("','", map { $_ =~ /\'/ ?  $_ =~ s/\'/\\'/g
> : $_ } @thoseLabels)."'";
> 
> print $this_array;
> 
> >> '1','1','1','mike','blah','bloh'
> 
> However I want it to come out like this:
> 
> >> 'Tom\'s','John\'s','Jim\'s','mike','blah','bloh'
> 
> is it possible to rewrite this one liner to do this?
> any tips would be greatly appreciated!!

If you want to escape all non-word characters then this will work:

my $this_array = join ',', map "'\Q$_\E'", @thoseLabels;


If you only want to escape the apostrophes then this will work:

my $this_array = join ',', map { s/'/\\'/g; "'$_'" } @thoseLabels;



John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 10 Sep 2003 09:03:50 +0200
From: Kurt Kronschnabl <k.kronschnabl_nospm_@ica-intercom-akademie.de>
Subject: Re: How To activate command line history in debugger?
Message-Id: <bjmida$ab4$00$2@news.t-online.com>


Daniel Pfeiffer schrieb:

Hi Daniel,

> M-x shell

Sorry "I am standing on the hose" :=) What do you mean with this line 
and the Debug session?

> (with highlighting for the prompts :-)  
 > When you hit Return at the end of buffer,
 > everything after the prompt gets sent.
 > On Return elsewhere,
 > the command on that line first gets copied to the end.

This sounds good again, but again: How to do?

Regards, Kurt



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

Date: Wed, 10 Sep 2003 04:11:08 GMT
From: mooseshoes <mooseshoes@gmx.net>
Subject: Re: How To Make Filehandle Global To Package?
Message-Id: <wvx7b.2511$%O5.2455@newssvr25.news.prodigy.com>

Uri,

I dropped "our $socket_handle" back in at the top and now it's working.

Such is life.


Peace,

Moose


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

Date: Wed, 10 Sep 2003 05:00:31 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: How To Make Filehandle Global To Package?
Message-Id: <x7wuchck5s.fsf@mail.sysarch.com>

>>>>> "m" == mooseshoes  <mooseshoes@gmx.net> writes:

  >> so just store the handle in a package var. or even better if the class
  >> code is all in one file, store the handle in a file scoped lexical.
  >> 

  m> <<< I did try declaring "our $socket_handle" for the package and using that
  m> instead of the named handle but ran into the same problem.  If it is that
  m> simple, then I'm likely doing something else wrong such that another
  m> subroutine in the same package thinks the filehandle is closed.

that isn't what i said. if you read perlopentut carefully you will see
that a named filehandle (FH) is not the same as using a varaible like
$fh. in recent perls, a variable with undef will get autovivified to
have a unique handle when it is used in open (and i would guess socket,
pipe, and other handle creators). so what version of perl are you
running?

and you should show the code that failed for you when doing a file
lexical. and our does not create file lexicals. use my outside any sub
to get that.

  >> bah, use IO::Socket and remove all that mess.

  m> <<< It was originally done with IO::Socket.  I ran into trouble with it
  m> because socket sends are done independent of socket receives (eg. can't
  m> take advantage of the stored peer address) and for multiple clients.  The
  m> portaddr needs to get set outside the socket declaration and for some
  m> reason IO::Socket gives me "can't find peer address" errors during sends
  m> even when I seemingly set the portaddr correctly and include it in send
  m> command.  

huh?? what does send and recv being independent have to do with
anything? you can set the port address with send via the TO
argument. peer addresses are meaningful only when receiving UDP
messages. so why are you trying to get the peer address after you sent
something and you know the address you sent it to?

  m> <<< I haven't done much with OO but can see how much cleaner it is.  I'll
  m> try to give IO::Socket another try and store the handle.  

beyond storing the handle, i am not sure what you are doing with this
UDP socket. explain the larger picture and i bet there is a much simpler
solution and design. this need of yours to share the handle for peer
address stuff makes me suspect an XY problem. you found a direction to
go even if it isn't the best way to solve the real problem.

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
Damian Conway Class in Boston - Sept 2003 -- http://www.stemsystems.com/class


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

Date: Wed, 10 Sep 2003 06:24:56 GMT
From: mooseshoes <mooseshoes@gmx.net>
Subject: Re: How To Make Filehandle Global To Package?
Message-Id: <Ysz7b.669$oQ3.264@newssvr27.news.prodigy.com>


<snip>


> that isn't what i said. if you read perlopentut carefully you will see
> that a named filehandle (FH) is not the same as using a varaible like
> $fh. in recent perls, a variable with undef will get autovivified to
> have a unique handle when it is used in open (and i would guess socket,
> pipe, and other handle creators). so what version of perl are you
> running?

<<< using 5.8.  Are you saying that using a variable instead of a named
filehandle is more likely to break?  I'm having success now by using a
variable that is global to the package.  Is it better to change it to a
name filehandle?

<snip>

> and you should show the code that failed for you when doing a file
> lexical. and our does not create file lexicals. use my outside any sub
> to get that.


<<< I traced it back to a thread problem.  I had opened the socket on a
thread mistakingly and the send call couldn't find the socket so it assumed
it was closed.  Yes, the plot thickens.  Read on.


<snip>

> huh?? what does send and recv being independent have to do with
> anything? you can set the port address with send via the TO
> argument. peer addresses are meaningful only when receiving UDP
> messages. so why are you trying to get the peer address after you sent
> something and you know the address you sent it to?

<<< I don't remember seeing any "TO" argument in my documentation.  I did
use the form $sock->send($msg, $portaddr), however, and each time would get
a "can't find peer address" error or something to that affect.  Not sure
why.

<snip>

> beyond storing the handle, i am not sure what you are doing with this
> UDP socket. explain the larger picture and i bet there is a much simpler
> solution and design. this need of yours to share the handle for peer
> address stuff makes me suspect an XY problem. you found a direction to
> go even if it isn't the best way to solve the real problem.

<<<Uri, you're OK.  I like your energy and your knowledge is likely to help
more than just me in this forum.  UDP sockets are used in two ways in the
program.  There are Stayalive sockets (read) and a Message socket (send). 
The Stayalives support up to X clients that periodically send messages to
keep a "logged on" status and update the send_to_port data (routers
constantly change this data).  The Message socket sends a message to a
client when a message becomes available from the main program.  The IP
address and port number are looked up prior to the send.  Stayalive and
Message sockets live on ithreads.  There is also a TCP login socket which
is also threaded but not relevant to this discussion.  There are a number
of ways to do all this, but using UDP in this manner is the least resource
intensive even when compared to HTTP.  Enough said, I suppose.  If you want
more detail, let me know.

Moose



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

Date: Wed, 10 Sep 2003 05:01:54 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: looping every x seconds
Message-Id: <20030910010200.1c770c46.jwillmore@cyberia.com>

On Wed, 10 Sep 2003 10:57:28 +0800
kernal32 <surakshan@removethisYahooRemove.com> wrote:
> > In PERL how do I execute a block of code every "x" seconds?
> > I'm talking a loop or similar but it runs every x seconds, where x
> > is given.
> 
> Sorry I didnt think I was clear.
> I'm using sleep 5 to wait 5 second before executing some code.
> 
> my question is, how can I keep the rest of the program running
> whilst the loop continues in pararel

Use fork.  That's just one suggestion.

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

my $child = fork();
die "Can't fork: $!\n" unless defined $child;

if($child > 0){
    #parent process
}else{
    $child process
}


You'll need to add some signal handlers and maybe use some POSIX
fuctionality.  Basically, 'salt to taste' ;)

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
If you think the United States has stood still, who built the
<largest shopping center in the world?   -- Richard M. Nixon 


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

Date: Wed, 10 Sep 2003 05:04:40 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: looping every x seconds
Message-Id: <20030910010447.19571fc4.jwillmore@cyberia.com>

On Wed, 10 Sep 2003 05:01:54 GMT
James Willmore <jwillmore@cyberia.com> wrote:
>     $child process
should be:
#child process

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
Only adults have difficulty with childproof caps. 



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

Date: 9 Sep 2003 21:08:15 -0700
From: drew@perlmad.com (Philip)
Subject: Re: Making a script write to a file (take 2)
Message-Id: <9826ff94.0309092008.35913517@posting.google.com>

> $orders_dat = "http//....path to file"

that's your problem.  you need to use the real system path to the
file, not it's HTTP URL.


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

Date: Wed, 10 Sep 2003 04:13:06 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Parsing to insert single quotes
Message-Id: <3f5ea387.623816251@news.erols.com>

Eric <nospam@xx.com> wrote:

: Ooops...just noticed that FOUR zeros get added onto each of the numbers
: in the numeric/decimail field from:
: 
: >  printf FILE "(%d,'%s',%f,'%s')%s\n",
: 
: How can I correct this?

See perldoc -f sprintf for a list of the different formatting
conversions available.

If you want, say, two decimals in the third field, change "%f" to
"%.2f".

Or if you would just like that field to pass through unchanged, change
"%f" to "%s" .



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

Date: Tue, 09 Sep 2003 21:23:21 -0700
From: Eric <nospam@xx.com>
Subject: Re: Parsing to insert single quotes
Message-Id: <3F5EA739.42652362@xx.com>

Jay Tilton wrote:
> 
> Eric <nospam@xx.com> wrote:
> 
> : Ooops...just noticed that FOUR zeros get added onto each of the numbers
> : in the numeric/decimail field from:
> :
> : >  printf FILE "(%d,'%s',%f,'%s')%s\n",
> :
> : How can I correct this?
> 
> See perldoc -f sprintf for a list of the different formatting
> conversions available.
> 
> If you want, say, two decimals in the third field, change "%f" to
> "%.2f".
> 
> Or if you would just like that field to pass through unchanged, change
> "%f" to "%s" .

Thanks.  I found an example using %g that seems to work.

BTW, I've been studying your code and am simply baffled on how you get
auto-incrementing of the 1st field.  I'm trying to learn from this, and
also stumped as to exactly HOW the parsing of the 3 fields occurs to
include leaving the white spaces between multi-word city names.  Is that
the split function?

This is another (humbling) educational experience for me!


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

Date: 9 Sep 2003 23:05:36 -0700
From: fumail@freeuk.com (qanda)
Subject: Re: pass cmd line file glob to grep for readdir
Message-Id: <62b4710f.0309092205.768b2b92@posting.google.com>

Thanks guys and girls, I wasn't aware it had been improved in the new
versions; I'm limited (by customer) to using 5.005.

As for the argument limit, yes the underlying issue is with the OS, as
I understand it the limit is set by ARG_MAX in limits.h.

Would anyone be able to answer the (original) question for me,
certainly if using a newer version of Perl glob would be fine; however
I can't do that for this particular problem and the only overhead I
want for the user is to possibly quote the file glob so we avoid find
and/or xargs, etc.

Thanks again.


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

Date: Wed, 10 Sep 2003 04:49:24 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: Reading Data File Records
Message-Id: <20030910004929.58adffc4.jwillmore@cyberia.com>

On 9 Sep 2003 15:41:03 -0700
GrahamWilsonCA@yahoo.ca (Graham) wrote:
> It seems it isn't just you.  All I am trying to do is get the data
> blocks into a suitable perl structure so I can calculate some simple
> statistics and reformat it for another program.  See comments in the
> second while loop.
> 
> I really appreciate the help.  I have a pile of files with this type
> of structure (a legacy of an ancient postdoc) that I need to
> manipulate and reformat.

First, let me say that each language is going to handle files and
variables differently.  I say this because you commented on using
FORTRAN.  I know nothing about FORTRAN, but have had _some_ dealings
with COBOL.  Some functionality in COBOL is unavailable in Perl (such
as strictly defining variables).  By the same token, there's
functionaility in Perl that is not available in COBOL (such as regular
expressions).  Having said that, here is some untested code that _may_
fit the bill for you.  Again, it's untested and may _not_ be exactly
what you're looking for.  If I'm off, I'm hoping someone will point
out where the errors are.

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

#define the name of the file
my $file = 'name_of_file_here';

#define a hash (associative array) for your records
my %records;

#open a file handle to the file - die if we can't open it
open(FILE, $file)
    or die "Can't open file $file: $!\n";

#get the header - if it's the first line and
#leads with a "!"
my $header = <FILE> if /^!/;
#if you want the number of levels, get the portion before the first
"!"
#can be done with substr - regular expression used for 
#demonstration purposes
my $numLev = $1 if $header =~ m/^(.*)!/;

#while the file is open and does not return eof
while(<FILE>){
    #chomp the newline off the line
    chomp;
	#stick the line of the file into variable $line
    my $line = $_;
    #get the begining of the line up until the first "!"
	#(strip the comments)
    #again - substr could be used
    my $uncommented_line = $1 if m/^(.*)!/;
    #if the record is 132 characters in length, separated by
whitespace
    #spilt the line on whitespace and place each 'section' into an
array
    my @data = split / /, $uncommented_line;
    #create the key for the record using the block id
    my $key = shift @data;
#store the record as an array into the hash using the block id as the
key
    push @{$records{$key}}, @data;
}

#to retrieve the records ...
foreach my $k(sort keys %records){
    print "$k => ",join(" ",@{$record{$k}}),"\n";
}
==untested==

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
What this country needs is a good five cent microcomputer. 



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

Date: Wed, 10 Sep 2003 00:19:08 -0400
From: Buck <Nekid@jaybird.com>
Subject: Re: simple regex problem
Message-Id: <pan.2003.09.10.04.19.06.486717@jaybird.com>

On Mon, 08 Sep 2003 10:35:00 +0100, JS wrote:

> Hi,
> 
> I'm trying to build a regex to put the department name into a variable 
> $dept and the rest of the line into another variable $stats:

I know its not a regex, but with variable dept name lenghts, why not:

while (<DATA>) {
	my $f = 4;
	my @x = split /\s+/;
	my ($dept,$stats) = ( join(" ",@x[0 .. ($#x-$f)]), join(" ",@x[-($f) .. -1]) );
	print "Dept: $dept\tStat: $stats\n";
}
	

__DATA__
E-Test            3    -    4    -
Health and Safety       -       1       1    -
Finance                 -       3       -       -


Dept: E-Test	Stat: 3 - 4 -
Dept: Health and Safety	Stat: - 1 1 -
Dept: Finance	Stat: - 3 - -

budman


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

Date: Wed, 10 Sep 2003 11:07:13 +0800
From: Dan Jacobson <jidanni@jidanni.org>
Subject: subroutines may be located anywhere in the main program
Message-Id: <878yoxqr32.fsf@jidanni.org>

Perlsub says subroutines may be located anywhere in the main program;
and indeed,
$ perl -e 'if(0){sub x{print "wow"}};x;'
wow

Anything non ideal here?


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

Date: 10 Sep 2003 06:19:44 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: subroutines may be located anywhere in the main program
Message-Id: <bjmfq0$at0$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Dan Jacobson:

> Perlsub says subroutines may be located anywhere in the main program;
> and indeed,
> $ perl -e 'if(0){sub x{print "wow"}};x;'
> wow
> 
> Anything non ideal here?

Readability perhaps. At least I'd be confused to see a subroutine
declared in an if-branch.

Other than that, there is not much wrong with it as long as you don't
expect to impose a certain scope or visibility on your subroutines.
They'll always be globally accessible (within the same package) and Perl
doesn't know about inner functions or so.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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


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