[18763] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 931 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 18 14:05:35 2001

Date: Fri, 18 May 2001 11:05: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: <990209110-v10-i931@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 18 May 2001     Volume: 10 Number: 931

Today's topics:
    Re: "Re: Match Parsing Glitch (Tad McClellan)
        Accessing remote NT Web server <jpcrisci@usgs.gov>
    Re: Accessing remote NT Web server <kistler@gmx.net>
    Re: Accessing remote NT Web server <me@my_no_spam.org>
    Re: Adding lines to the beginning of a data file? <josef.moellers@fujitsu-siemens.com>
    Re: Adding lines to the beginning of a data file? <kistler@gmx.net>
    Re: Can you build GUI's with perl? (Dan Baker)
    Re: DBD and oracle 8.1.7 <rereidy@indra.com>
        File Test Operator Problem <steen@biochip.com>
    Re: garbage collection in perl (M.J.T. Guy)
    Re: Has this already been done? (Craig Berry)
    Re: Hash: keys to variable names, or variable names to  (Tad McClellan)
    Re: Hash: keys to variable names, or variable names to  <uri@sysarch.com>
    Re: Importing variables (Tad McClellan)
    Re: Importing variables (Tad McClellan)
    Re: Importing variables <ren@tivoli.com>
    Re: Match Parsing Glitch (Tad McClellan)
    Re: non-blocking "print" on a client socket ?? <bkennedy99@Home.com>
        Only one line of code returning from form? <Ask@For-It.Com>
    Re: random ip-adress (M.J.T. Guy)
    Re: Random Numbers Script (Craig Berry)
        redirect link help please.. <Ask@For-It.Com>
    Re: redirect link help please.. <Ask@For-It.Com>
        Searching for Postal Code (Jean Cooper)
        Stubborn regex won't work <EUSWMCL@am1.ericsson.se>
    Re: Stubborn regex won't work (John Joseph Trammell)
    Re: Stubborn regex won't work <keesh@users.pleaseremovethisbit.sourceforge.net>
    Re: Transliteration Creates A \r Character Accidently?? <godzilla@stomp.stomp.tokyo>
    Re: Transliteration Creates A \r Character Accidently?? nobull@mail.com
    Re: Transliteration Creates A \r Character Accidently?? <godzilla@stomp.stomp.tokyo>
    Re: Transliteration Creates A \r Character Accidently?? <godzilla@stomp.stomp.tokyo>
    Re: URGENT: CGI program wanted! <uri@sysarch.com>
    Re: Using PERL to gather system metrics??? <rereidy@indra.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 18 May 2001 08:48:35 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: "Re: Match Parsing Glitch
Message-Id: <slrn9ga6h3.s9r.tadmc@tadmc26.august.net>

Eric <nospam@xx.com> wrote:

>error message and don't understand it.


The first step in understanding error (and other) messages from
perl is to read the documentation for messages from perl:

   perldoc perldiag

Then search until you find the message that you are getting
and read what it says.

Or, if you would like to have perl look up the explanation of the
message for you, just add this near the top of your program:

   use diagnostics;


Use the docs, Luke!


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


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

Date: Fri, 18 May 2001 15:17:05 GMT
From: John Crisci <jpcrisci@usgs.gov>
Subject: Accessing remote NT Web server
Message-Id: <3B053CF1.63356F05@usgs.gov>

I am in a bind and need to get this working by Monday.
I have an NT web server running IIS. I am using perl to generate an
input form and that data must be saved on a remote NT server class
machine. Inside the perl program this is how I am opening and writing to
the file:

unless (open(DRR1,
">>..\\Webserver\\LIMS8\\District\\ddrr_out\\drr.".$filedate)) {
     die ("cannot open OUTPUT DRR1 file drr.$date$time $!\n");
}

I keep getting an error that says it can't find the file or directory. I
have never seen an example of how to use Perl to write out to a remote
machine. Desperation is here. I have been searching everywhere for a
week.

TIA

John



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

Date: Fri, 18 May 2001 17:53:42 +0200
From: Per Kistler <kistler@gmx.net>
To: John Crisci <jpcrisci@usgs.gov>
Subject: Re: Accessing remote NT Web server
Message-Id: <3B054586.1EE12CB9@gmx.net>

John Crisci wrote:
> unless (open(DRR1,
> ">>..\\Webserver\\LIMS8\\District\\ddrr_out\\drr.".$filedate)) {
>      die ("cannot open OUTPUT DRR1 file drr.$date$time $!\n");
> }

It's not that clear, what you want to do with the WWW, expect opening a
file
for appending. To find the error I would break it down to
first puting the file name into a variable, then check for the
file with some -f $file or -w $file and only then trying to open it.
If it says no to -f $file then one could try to open the
respective directory with opendir(), to see what happens.
Maybe do the same thing for directories above it, to get closer
to the problem, step by step.
And print out the same variable $filedate, not $date$time, or one
cannot see, whether it got the propper name.

Per.

PS: Instead of the \\ thing, I'd do: q(\path\path) or often
it understands "/path/path/";


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

Date: Fri, 18 May 2001 12:18:02 -0400
From: Dave VP <me@my_no_spam.org>
Subject: Re: Accessing remote NT Web server
Message-Id: <3B054B3A.A4E90A65@my_no_spam.org>

John Crisci wrote:
> 
> I am in a bind and need to get this working by Monday.
> I have an NT web server running IIS. I am using perl to generate an
> input form and that data must be saved on a remote NT server class
> machine. Inside the perl program this is how I am opening and writing to
> the file:
> 
> unless (open(DRR1,
> ">>..\\Webserver\\LIMS8\\District\\ddrr_out\\drr.".$filedate)) {
     ^^^^

This path is unclear.  Are you attempting to write to a directory called
"webserver" which is located one level above your current directory, as
suggested by the double dots (..).  If so, try specifying the path as an
absolute, rather than with this relative method.

If "Webserver" is the name of the remote machine, you need to specify
with an extra pair of '\', e.g. ">>\\\\Webserver\\LIMS8....."

*And* you don't use the leading dots.

Lastly, be sure that whatever account the web server is running as has
permissions to the directory (and file) you want to append to.

[ snip ]

HTH,

Dave


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

Date: Fri, 18 May 2001 17:15:32 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Adding lines to the beginning of a data file?
Message-Id: <3B053C94.5067DDA0@fujitsu-siemens.com>

Nick wrote:
> =

> Hello,
> =

> I'm using the following (simplified from what I'm actually doing) code =
to
> save a line of data to a text file:
> =

> open(USERLOG, ">>log.dat");
>  seek(USERLOG,0,0);
>  print USERLOG "New line of information.\n";
> close(USERLOG);
> =

> which appends the new line onto the end of the current document. My que=
stion
> is: Is there a way of adding lines of data to the top of a text file
> instead. In essence, is it possible to put the newest stuff at the top =
and
> have everything else 'bumped' down a line?

This is a FAQ, iirc. You have to rewrite the file.

-- =

Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett


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

Date: Fri, 18 May 2001 18:00:30 +0200
From: Per Kistler <kistler@gmx.net>
To: Nick <nick@3db.co.uk>
Subject: Re: Adding lines to the beginning of a data file?
Message-Id: <3B05471E.F609B00@gmx.net>

Nick wrote:
> open(USERLOG, ">>log.dat");
>  seek(USERLOG,0,0);
>  print USERLOG "New line of information.\n";
> close(USERLOG);

If you open the file with sysopen and use syswrite after
the seek stuff, it should work. I've just tested it a short
while ago. ( sysopen($file,O_RDWR | O_CREAT) etc. )
(If you open for appending like you show, it probably will append).

Per.


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

Date: 18 May 2001 10:13:52 -0700
From: dtbaker_dejanews@my-deja.com (Dan Baker)
Subject: Re: Can you build GUI's with perl?
Message-Id: <217329ed.0105180913.5f4f874f@posting.google.com>

"jackkon" <jck1@mail2000.com.tw> wrote in message news:<9e1ud9$fg8@netnews.hinet.net>...
> Dan Baker <dan@nospam_dtbakerprojects.com> wrote in message > Managing state
> information is a challange, but with cookies, temp text
> > files, or database interfaces it is certainly possible. I have found
> > prototyping an interface with standard html tools to be faster than
> > learning TK....
> > D
> 
> 
> HI..........
> I am new in Tk.
> Could you show me some examples about prototyping an interface with standard
> html tools?
> I am very interested.
> Thanks a lot.

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

examples? just use any html composer to create html forms; complete
with all the widgets like pull-downs, buttons, tables images, colrs,
etc
Design your <FORM> actions to call perl scripts, and set required
paramters with <INPUT> statements, or cookies, or whatever.
Basically, and interface design that is possible with HTML forms can
be used to "drive" an application as long as you have access to a
webserver to handle the transactions between the browser client and
the server.
For local applications, it is very easy to get a little webserver up
and running in the background on a PC... install the freebie from
www.xitami.com and you'll have a http://localhost

Dan


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

Date: Fri, 18 May 2001 10:22:00 -0600
From: Ron Reidy <rereidy@indra.com>
Subject: Re: DBD and oracle 8.1.7
Message-Id: <3B054C28.169A9B8F@indra.com>

Lance Duncan wrote:
> 
> I am trying to complile gnu perl 5.005.03 with DBD-Oracle-1.06 and Oracle
> 8.1.7 on HP-UX 11.  The compile fails, even when I link statically.  Does
> anyone know what modifications I need to make to the DBD files in order to
> get the compile to work?

Did you read all of the readme files?  Look at README.java(?).  There
are some things you will need to do to libclntsh.so to allow DBD to work
correctly.

Error message would also be helpfull.
-- 

Ron Reidy
Oracle DBA
Reidy Consulting, L.L.C.


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

Date: Fri, 18 May 2001 19:04:31 +0100
From: Helge Steen <steen@biochip.com>
Subject: File Test Operator Problem
Message-Id: <3B05642F.753070C8@biochip.com>

Hi all,

I am experiencing a strange problem with the -f file test operator on a
IRIX 6.5 machine.

I am trying to identify regular files in a directory listing, generated
using

@ALLFILES = readdir DIRHANDLE;

The listing is fine when logged in as root as well as when logged in as
a user.  In both cases I can nicely read and write files in the listed
directory, but  (-f filename) will never become true when logged in as a
user. When logged in as root, -f is OK. Sounds like an access problem,
but I can not imagine where things go wrong...

Any help is highly appreciated!

Greets,
Helge



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

Date: 18 May 2001 16:03:52 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: garbage collection in perl
Message-Id: <9e3h58$k86$1@pegasus.csx.cam.ac.uk>

Ilya Zakharevich  <ilya@math.ohio-state.edu> wrote:
>
>But b has a loophole: one can circumvent the runtime-effect, and leave
>only the compile-time effect (creation of a "name") of my():
>
>  my $var if 0;

But note that's a bug.   It might even get mended some day.
(The only reason it hasn't been mended already is that nobody knows
how to fix it without adding overhead in the much more common case

   my $var = 'some_initial_value';


Mike Guy


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

Date: Fri, 18 May 2001 17:09:52 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Has this already been done?
Message-Id: <tgalr02k05mla9@corp.supernews.com>

David Soming (davsoming@lineone.net) wrote:
: Im new to perl so have a laugh at my expense if you will but...
: Just an idea for creating a unique 12 digit ID Using the date and time :)
: If such a module exists already based on this concept please ignore.
: 
: Today's date 18:05:01
: Time 10:41:21
:  concatenation= "180501104121" =Unique 12 digit ID
: 
: If its a crap idea, well OK.

Not so much a crap idea as one with limited utility.  If you can guarantee
that you won't get multiple requests for a unique id during a single
second, this works as well as any other technique -- though you can get
the same effect with less work by just using the seconds-since-epoch value
returned by the time() function.  However, guaranteeing that you won't get
multiple requests in a single second can get arbitrarily tricky,
especially as your application grows and mutates over time. 

: If there is a module which is better, (in the sense of output being easily
: readable-and readily understood, meaningful) or gives similar output then I
: don't wish to reinvent the wheel right?

No module that I know of.  In general, assigning unique IDs without
depending on time-separated requests involves stashing information about
what IDs have already been used in a persistent file, or using key
generation facilities in a database.  This isn't the sort of thing which
can be easily encapsulated as a stand-alone module. 

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

Date: Fri, 18 May 2001 09:44:22 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Hash: keys to variable names, or variable names to keys?
Message-Id: <slrn9ga9pm.s9r.tadmc@tadmc26.august.net>

Paul Johnson <pauljohn@ukans.edu> wrote:
>I wrote a CGI script that processes a bunch of string variables and saves
>them into a dataset.  I find my self doing the same repetitive, stupid
>things, one variable after another.  


You disparage yourself below, but recognizing the above as an
opportunity for automation is insightful. You have promise :-)


>I wonder why can't I find a way to
>make a hash of variable names and then just iterate over the hash?


I suggest that you rewrite your program to use a hash instead of
a bunch of individually named scalars. This has 2 benefits:

   1) no Symbolic references
   2) your "validation" problem becomes trivial

#1 alone should be enough to convince you the change is warranted.

See:

   http://www.plover.com/~mjd/perl/varvarname.html
   http://www.plover.com/~mjd/perl/varvarname2.html
   http://www.plover.com/~mjd/perl/varvarname3.html


>Earlier, the script has already read
>the values out of the CGI input with declarations like
>
>$lastname = $cgi_input->param('lastname');


My suggestion above means that you would read them in like this instead:

   # the %p hash contains "variables"
   $p{lastname} = $cgi_input->param('lastname');  


>sub validateLengths {
>    
>    if ( 
>	 30 < (my $lastnameLength = length("$lastname")) || 
>	 
>	 20 < (my $firstnameLength = length("$firstname")) || 

[snip more length checks]

>	print "Here are the particulars:<p><p>";
>	if ($lastnameLength > 30) {
>            print qq[Your entry for last name is too long.  
>           We allowed 30 characters, but your name took $lastnameLength.
>            Sorry, can you give us something shorter <p>];
>        }
>	     
>        if ($firstnameLength > 20) { 
>             print qq[Your first name entry is too long. 
>            We allowed 20 characters, but your input took $firstnameLength.
>             Sorry, can you find an alias or abbreviate somehow?<p>] ;
>             }

[snip yet more length checks]

>My idea is that I could create a hash using the variables as keys and the
>contents would be arrays, say holding the maximum length allowed and the
>observed length, and then I could iterate.  


Good plan.

Much better plan if you first take my suggestion above :-)


>I need to be able to take the
>keys and use them both as variable names 


symrefs are evil. I will not help you use them. You are on
your own if you insist on hurting yourself.

Here is how evilness could manifest itself if you use symrefs:

   Bad Guy sends form data with a param named "_". Your symref
   code would assign its value to the $_ variable. Uh oh!


On top of that, symrefs only work with "dynamic variables", and you
should be working (as near to exclusively as practicable) with
"lexical variables" (my) instead.

The bad things about symrefs are significant and numerous.

Warning Will Robinson!


>like $lastname as well as
>convert them to strings like "lastname" for printing out.
>
>Am I just looking for a too-easy/simple minded approach?


Nope. It is wildly simple if you rearchitect things a bit.
(choice of data structure is a Very Important consideration
 when designing software. I think you have made an unfortunate
 choice.
)


>All the examples of hashes I find have keys that are strings or such, not
                                                      ^^^^^^^
>variable names.  
 ^^^^^^^^^^^^^^

Note that "variable names" _are_ strings and a mapping suggests itself :-)

A variable ($var) is a scalar. A hash value ($p{var}) is a scalar.
Whatever you can do with $var you can do with $p{var}, and avoid
the possibility of introducing very hard to fix bugs.


>And I can't understand the writeup I get from this
>perldoc -q "How can I use a variable as a variable name?"
>
>If you have advice, I'm listening.
                     ^^^^^^^^^^^^^

Go read about how bad symrefs are again, then redesign  :-)

A rough untested sketch of how it might be done:


   my %p;   # (p)arameters
   # loading would really be done in a loop
   $p{lastname} = $cgi_input->param('lastname');
   $p{firstname} = $cgi_input->param('firstname');
   ...

   my %max = qw(
      lastname      30
      firstname     20
   );

   foreach my $param ( sort keys %p ) {
      if ( length $p{$param} > $max{$param} ) {
         print "'$param' field is too long (maximum is $max{$param})\n";
      }
   }


[ Note that the code above has two "parallel" hashes that are supposed
  to each have an identical list of keys. This suggests a multilevel
  data structure to associate the key with _two_ things: its "value"
  and its maximum length. But you have enough to do already :-)
]

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


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

Date: Fri, 18 May 2001 16:23:57 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Hash: keys to variable names, or variable names to keys?
Message-Id: <x7r8xm7hia.fsf@home.sysarch.com>

>>>>> "KP" == Koos Pol <koos_pol@nl.compuware.com.NOJUNKMAIL> writes:

  KP> How about something like:
  KP> @list_of_checks (
  KP>   {
  KP>     criterium => '$lastnameLength > 30',
  KP>     message   => "Your entry for last name is too long. ".
  KP>                  "We allowed 30 characters, but your name took ".
  KP>                  "$lastnameLength. Sorry, can you give us something ".
  KP>                  "shorter";
  KP>   },
  KP>   {
  KP>     criterium => '$middleLength > 20' ,
  KP>     message   => "Your middle name entry is too long. " .
  KP>                  "We allowed 20 characters, but your input took " .
  KP>                  "$middleLength. Sorry, can you find an alias or ".
  KP>                  "abbreviate somehow?"
  KP>   }
  KP> )
  KP> foreach $testrun (@list_of_checks) {
  KP>    print $testrun->{message} if (eval $testrun->{criterium});
  KP> }

gack! that eval is evil. way overkill for this. use some nested data
structures as others have posted. use eval only when nothing else will
do.

you can convert each criterium to a list of the name part and
length. that can be indexed into the the data hash and the length
checked. it is not that complex so don't be afraid of it.

perllol, perldsc are all about this. the perl cookbook has several
related examples.

  KP> I am positive this code does not run as written here. But I hope I 
  KP> demonstrated how you can keep the data and logic seperated.

no, you converted one problem for another. eval is not meant to solve
the symbolic ref issue. use hashes and data structures instead.

uri


-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: Fri, 18 May 2001 10:01:21 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Importing variables
Message-Id: <slrn9gaaph.s9r.tadmc@tadmc26.august.net>

Bart Lateur <bart.lateur@skynet.be> wrote:
>Real wrote:
>
>>There's a "main" program and a library that is "required" in this program. I
>>want to define a global array which routines in both scripts can use.


>>I thought I could reference the array using;
>>   *Global_Array = \@MainProgram::Global_Array;


Type globs only work with dynamic variables.


>>... if I also define this main program as a package using;
>>   package MainProgram;
>>   my(@Global_Array);


@Global_Array is a lexical variable.


>Drop the "my".


so that @Global_Array will be a dynamic variable, allowing globbing to work.


>Jeezes, strict is doing more harm than good again. 
>
>	use vars '@Global_Array';


No!

strict is doing exactly what is should be doing.

It is requiring that you do "something special" in order to
use a global variable.

strict is a promise to not be bad.

Using "accidentally global" variables would be a bad thing,
so forcing you to _say_ that you want it global is a good thing
(indicates that it wasn't an accident).


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


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

Date: Fri, 18 May 2001 10:07:21 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Importing variables
Message-Id: <slrn9gab4p.s9r.tadmc@tadmc26.august.net>

Real <real@earthling.net> wrote:
>"Bart Lateur" <bart.lateur@skynet.be> wrote in message
>news:e31agtk8erofe4qap34v93ehu7qrvt35nf@4ax.com...
>> >There's a "main" program and a library that is "required" in this
>program. I
>> >want to define a global array which routines in both scripts can use. 

>> >   *Global_Array = \@MainProgram::Global_Array;

>> >   package MainProgram;
>> >   my(@Global_Array);
>>
>> Drop the "my".

>The trick is in the "use vars
>'@Global_Array';" line. 


(one of) the _solutions_ to the problem is "use vars".

The _trick_ is discovering the root cause of the problem. See below.


>I'll include a minimal-version of both scripts for
>future Google-searchers :)


And I'll include a FAQ reference (part 7) that explains the root cause :-)

   "What's the difference between dynamic and lexical (static) scoping?  
    Between local() and my()?"


And a reference to an MJD article, "Coping with Scoping":

   http://perl.plover.com/FAQs/Namespaces.html


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


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

Date: 18 May 2001 10:55:31 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Importing variables
Message-Id: <m3wv7efy8c.fsf@dhcp9-172.support.tivoli.com>

On Fri, 18 May 2001, real@earthling.net wrote:

> Yes, this works !  Thanks a lot. The trick is in the "use vars
> '@Global_Array';" line. I'll include a minimal-version of both
> scripts for future Google-searchers :)

With recent versions of Perl, you can also use:

our @Global_Array;

-- 
Ren Maddox
ren@tivoli.com


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

Date: Fri, 18 May 2001 08:45:47 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Match Parsing Glitch
Message-Id: <slrn9ga6br.s9r.tadmc@tadmc26.august.net>

Eric <nospam@xx.com> wrote:
>Tad McClellan wrote:
>> 
>> You have an old version of perl. What does "perl -v" say?
>
>5.003_07 which I must use as is 


perldoc perlhist says that was released 1996-Oct-10.

There is a CERT advisory against that version of perl.

Lots has changed in four and a half years. Expect that lots of
OPC (Other People's Code) won't be of any use to you.

If you stick with that version, then you will need to be a better
programmer than if you upgrade, because you will not be able to
reuse OPC without these backward-version "repairs". If you show
up here often trying to get help with such an endeavor, the
readership of your articles will decline.

Your provider well and truly <insert invective here>. I'd really
really think about moving out of the Stone Age...


>to complete this task tonight!


I guess that means last night (Thursday), so it is too late to help now.

No point in following this thread anymore then.

Hope you got it working though.


>>   my ($dummy1, $vendor, $dummy2, $price, $dummy3, $addr) =
>>      unpack 'A11 A7 A10 A10 A11 A25', $_;
                                         ^^
                                         ^^
Did you see the followup correcting that typo that I propogated?


>  "Use of uninitialized value at stats5.pl line 22


What does line 22 look like?

Seeing the code is a great aid to debugging the code.


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


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

Date: Fri, 18 May 2001 16:08:41 GMT
From: "Ben Kennedy" <bkennedy99@Home.com>
Subject: Re: non-blocking "print" on a client socket ??
Message-Id: <dObN6.3348$uk2.919202@news1.rdc2.pa.home.com>


"Heiko Brey" <cico@icomag.de> wrote in message
news:3B049405.C86B191@icomag.de...

> Now my question:
>
> Is there a possibility to make the "print" on the client socket
> something like "non-blocking" ? Or does anyone have a better
> solution for this ? I attached the "server" code at the bottom
> of this message. Any help will be welcome! Maybe someone knows
> about some docs ?! :-)
>
> Thank you! Heiko

I would definitely suggest looking at the standard IO::Select and IO::Socket
modules, which the web page you got the exmaples from hints at.  You can
access the documentation with "perldoc IO::Select" and "perldoc IO::Socket",
plus "perldoc perlipc" has lots of good info.  Also, the "Perl Cookbook"
contains lots of good server examples, including a recepie for a
non-blocking TCP server, though a fork()'ing server may be more appropriate
for you.  Hope this helps--

--Ben Kennedy




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

Date: Fri, 18 May 2001 18:20:20 +0100
From: "Robb Meade" <Ask@For-It.Com>
Subject: Only one line of code returning from form?
Message-Id: <9e3lh7$28u$1@newsg2.svr.pol.co.uk>

Hi all

I have a form that submits code to an ASP page, and then forwards it on
again to my Perl script..

For some reason I am only getting the first line of text from the <textarea>
field being sent in any emails from my Perl script...

I'm not quite sure whats going wrong..

I've check the ASP pages, and they are sending the info as it should be, so
it must be something up with the Perl code...

I've cut&pasted it below - if you could help I'd be very greatful :)

******* BEGINS *****************

#!/usr/bin/perl -w
use strict;
use CGI qw(:all);
use CGI::Carp qw(fatalsToBrowser);
my $site=param("site");
my
$target="http://www.kingswoodweb.net/clientmailingconfirm.asp?site=$site";

####################################
# new sub to retrieve mailing list #
####################################
sub send_to($)
{
my $file = shift;
my @list;
open(SEND, "< $file") or die "Could not open $file: $!";
@list = <SEND>;
close SEND;
return(@list);
}

sub send_mail {


  my $sendmail="/usr/sbin/sendmail -t -oi";

  my $from="mailing.list\@boomshankers.com";

my $subject=param("subject");
my $message=param("message");


############################################################
# return value of send_to sub is placed into your new list #
############################################################

my @email_list = send_to("email.txt");

##################################
# loop through each item in list #
##################################

for my $to (@email_list)
{
chomp $to;

open(MAIL, "|$sendmail") || die "Can't start sendmail: $!";
  print MAIL<<END_OF_HEADER;
From: $from
To: $to
Subject: $subject

$message

END_OF_HEADER

  close(MAIL);
} # for loop complete
}

send_mail();

print redirect( -url => $target );

******** ENDS ******************

I should add that I dont really know much about Perl, and I am learning very
slowly, some of this script came from a friend, which got me started, and
then it was added to by a user of this group to allow more than one person
receiving the emails (ie, its reading a list)...

Thanks in advance for any help :)

--

Robb Meade

Kingswood Web Services
www.kingswoodweb.net






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

Date: 18 May 2001 16:39:32 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: random ip-adress
Message-Id: <9e3j84$me7$1@pegasus.csx.cam.ac.uk>

In article <u9d79agwk8.fsf@wcl-l.bham.ac.uk>,  <nobull@mail.com> wrote:
>Have you considered string concatenation?
>
>int ( rand * 256) . '.' . int ( rand * 256) . '.' . int ( rand * 256) . '.' . int ( rand * 256)
>
>Of course you could also do something like:
>
>join '.', map { int ( rand * 256) } 1..4

You obviously haven't tried that:

perl -wle 'print join ".", map { int ( rand * 256) } 1..4'
Argument "*main::256" isn't numeric in rand at -e line 1.
Argument "*main::256" isn't numeric in rand at -e line 1.
Argument "*main::256" isn't numeric in rand at -e line 1.
Argument "*main::256" isn't numeric in rand at -e line 1.
0.0.0.0


Mike Guy


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

Date: Fri, 18 May 2001 16:59:48 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Random Numbers Script
Message-Id: <tgal841lsrdc28@corp.supernews.com>

AvA (a.v.a@home.nl) wrote:
: Craig Berry wrote:
: >   $id = 10_000 + int rand 90_000
: 
: Nice coding Craig.
: Could you point me to the documentation where from you learned that?

Thanks.  I don't believe I learned that from any doc, and certainly not
from perl-related doc; I've been using the idiom since my Atari Basic
days, some <mumble> years before Larry Wall decided to put various unix
shell utilities into a blender. :)  My shorthand name for it is "span-
offset", and I have no idea if I 'invented' it or copied it from someone
else's code.  In any case, it's pretty fundamental; you'll see it used
pretty much universally to generate a range of uniformly distributed
random numbers with nonzero lower bound.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

Date: Fri, 18 May 2001 17:54:30 +0100
From: "Robb Meade" <Ask@For-It.Com>
Subject: redirect link help please..
Message-Id: <9e3k2o$gei$1@newsg1.svr.pol.co.uk>

Hi all,

I posted a question here a little while back and I was told you could use
variables within a string for a URL (probably didnt explain that very well),
here's the code..

my $site=param("site");
my
$target="http://www.kingswoodweb.net/clientmailingconfirm.asp?site=$site";

I dont get any errors or anything, but the $site is return emtpy?  have I
got something wrong with the code in the first line? or the second? or would
this indicate that the information wasnt passed to the script (which I'm
sure it was)..

Thanks for any help..

Regards

--

Robb Meade

Kingswood Web Services
www.kingswoodweb.net






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

Date: Fri, 18 May 2001 18:16:33 +0100
From: "Robb Meade" <Ask@For-It.Com>
Subject: Re: redirect link help please..
Message-Id: <9e3la4$t6i$1@newsg4.svr.pol.co.uk>

ok - I've fixed that one now...but its opened up another problem....

I've reposted it with a new topic, as I got my wrists slapped last time for
not giving the right info in the subject for this group...

hehe

--

Robb Meade

Kingswood Web Services
www.kingswoodweb.net





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

Date: Fri, 18 May 2001 19:02:34 GMT
From: tlc3data@hincksdellcrest.org (Jean Cooper)
Subject: Searching for Postal Code
Message-Id: <3b0570b4.16455723@meganews.idirect.com>

Hi,

I'm trying to search through some text and find the Postal Code
(Canadian).  The form of the PC is M4M 2B2.  So I wrote a little Perl
script, which isn't working too well.  If anyone can let me know where
I've gone wrong, I'd appreciate it.

open (PC, "PCFile.txt") or die "Can't find file\n";

if ($ARGV[0] =~ s/[a-z][0-9][a-z]\s[0-9][a-z][0-9]/i   {

	print "Found something that resembles a Postal Code\n"

}

Jean	


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

Date: Fri, 18 May 2001 13:04:24 -0400
From: William Cardwell <EUSWMCL@am1.ericsson.se>
Subject: Stubborn regex won't work
Message-Id: <3B055618.1AB65E3C@am1.ericsson.se>

In the following, I'm trying to pull the "ERI000001" in every case, but
I can't get it.
Can anyone help?


$x='DISK02:[USERS.EUSWILC]ERI000001.INO;1';
$y='DISK02:[USERS.EUSWILC]ERI000001.;1';
$z='DISK02:[USERS.EUSWILC]ERI000001.';
$w='DISK02:[USERS.EUSWILC]ERI000001.INO';

# Last word string terminated by a period
for $t ($x,$y,$z,$w) {
  if ($t =~ /(\w+)\.\G/g) {$a = $1} # this for example doesn't work
  print "$a\n";
}


Thanks so much.

Will Cardwell


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

Date: Fri, 18 May 2001 17:32:41 GMT
From: trammell@bayazid.hypersloth.invalid (John Joseph Trammell)
Subject: Re: Stubborn regex won't work
Message-Id: <slrn9gakpb.8a3.trammell@bayazid.hypersloth.net>

On Fri, 18 May 2001 13:04:24 -0400, William Cardwell wrote:
> In the following, I'm trying to pull the "ERI000001" in every case, but
> I can't get it.
> Can anyone help?
> 
> 
> $x='DISK02:[USERS.EUSWILC]ERI000001.INO;1';
> $y='DISK02:[USERS.EUSWILC]ERI000001.;1';
> $z='DISK02:[USERS.EUSWILC]ERI000001.';
> $w='DISK02:[USERS.EUSWILC]ERI000001.INO';
> 
> # Last word string terminated by a period
> for $t ($x,$y,$z,$w) {
>   if ($t =~ /(\w+)\.\G/g) {$a = $1} # this for example doesn't work
>   print "$a\n";
> }

You might want to look into module File::Basename.

Otherwise how 'bout:

  for (@files)
  {
      if (/\](.*)\.[^.]*$/) { print "$1\n" }
  }

-- 
To think intelligently about copyrights, patents or trademarks, you must
think about them separately.  The first step is declining to lump them
together as "intellectual property".                  - Richard Stallman


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

Date: Fri, 18 May 2001 18:36:22 +0100
From: "Ciaran McCreesh" <keesh@users.pleaseremovethisbit.sourceforge.net>
Subject: Re: Stubborn regex won't work
Message-Id: <9e3me7$52l$1@news6.svr.pol.co.uk>

In article <3B055618.1AB65E3C@am1.ericsson.se>, "William Cardwell"
<EUSWMCL@am1.ericsson.se> wrote:
> # Last word string terminated by a period
> for $t ($x,$y,$z,$w) {

Surely foreach ?

>   if ($t =~ /(\w+)\.\G/g) {$a = $1} # this for example doesn't work

How about /\]([a-zA-Z0-9]+)\..*?$/ or something along those lines? Slight
modification on what you specified, but if all the data you have is like
the examples then that should work...

There are probably better ways of doing it, but that appears to give you
what you want.

Regards,
Ciaran

-- 
Ciaran McCreesh
mail:    keesh@users.sourceforge.net
web:     http://www.opensourcepan.com/


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

Date: Fri, 18 May 2001 09:14:35 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Transliteration Creates A \r Character Accidently??
Message-Id: <3B054A6B.891ED1DE@stomp.stomp.tokyo>

Godzilla! wrote:

(snipped article)

I am becoming increasingly confused trying to
pinpoint what is happening. It appears this may
be system specific. Has anyone successfully
replicated this problem of a \r creation?

Additional testing yielded a minimum data set,
yielded results where both a substitution and
transliteration cause this and, most perplexing,
any print statement following my last print,
causes this glitch to stop.

After my final print shown below in test script,
I tried verifying the presence of a \r in my
fields using a transliteration count, substituting
in an "X" for \r , indexing for \r , even tried
substring to capture it. No luck. The moment I add
a print after my final print in this test script
below, the glitch vanishes. I cannot view results!

My best guess is, the print function is somehow
becoming messed up, prints a \r or its equal
numerically. Adding an additional print, a print
of anything, clears this for whatever reason.

System specific? Any guesses?

Godzilla!
--

#!perl

print "Content-type: text/plain\n\n";

$string = 'MXF  082,400,000  4285 AN ADDRESS HERE  ';

$field1 = substr ($string, 0, 7);
$field2 = substr ($string, 7, 10);
$field3 = substr ($string, 18, 22);

$field2 =~ s/,//g;
# $field2 =~ tr/,//d;

print "Vendor : $field1\n",
      "Field  : $field2\n",
      "Field  : $field3\n\n";

$string = 'MXF  08¦2400000¦4285 AN ADDRESS HERE';

($field1, $field2, $field3) = split (/¦/, $string);

print "Vendor : $field1\n",
      "Field  : $field2\n",
      "Field  : $field3\n\n";

exit;


PRINTED RESULTS (browser cgi method):
________________


Vendor : MXF  08
Field  : 2400000 
Field  : 4285 AN ADDRESS HERE  

Vendor : MXF  08
Field  : 2400000

Field  : 4285 AN ADDRESS HERE


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

Date: 18 May 2001 17:18:35 +0100
From: nobull@mail.com
Subject: Re: Transliteration Creates A \r Character Accidently??
Message-Id: <u9ae4aockk.fsf@wcl-l.bham.ac.uk>

"Godzilla!" <godzilla@stomp.stomp.tokyo> writes:

> I have removed as much data as possible, I think, and still
> have this extra blank line appear. I have used as many same
> variable names as possible and still have this glitch show.
> Here are other tests I have tried:
> 
> Comment out the transliteration - effect stops.
> Remove the "r" from Vendor, both - effect stops.
> Remove one digit from 2400000 - effect stops.
> Remove one trailing space from the first string - effect stops.
> Change from a browser to a DOS command line - effect stops!!

Sounds like an obscure Perl internal error.  As such exact version,
build and platform information is likely to be relevant.

Since you fail to provide this information I'll have to draw some
logical inferences from what you _do_ say.  Your code clearly appears to
have been written for Perl4 and you mention a "DOS prompt".

ISTR experiencing very similar erratic behavour of tr/// in
DOS/Windows ports of Perl4 - but then again, that was a _long_ time
ago.  I simply modified all my Perl scripts that had to run on DOS not
to use tr/// ever. 

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Fri, 18 May 2001 09:44:27 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Transliteration Creates A \r Character Accidently??
Message-Id: <3B05516B.E8E19CB3@stomp.stomp.tokyo>

Godzilla! wrote:
 
> Godzilla! wrote:

(snipped again)

How fun talking to myself! I am becoming as talented
as our Man / Woman of a Thousand Ugly Mugs! 

Hmm... I keep forgetting to fake my header stuff though..


Ok, so I am thinking, this test script with which I am
playing, generates a certain combination of printed
characters which confuses my Mozilla 4.7 browser.

This glitch doesn't show in document source, but does
show in my main browser window. I am considering an
extra newline \n character is being generated by
Mozilla itself due to the data received.

My first thought was \r was being generated because
removal of "r" in "Vendor" defeats this bug.

Does this seem logical? A conflict created by a very
select data stream messing up my browser main window? 

Godzilla!


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

Date: Fri, 18 May 2001 09:54:36 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Transliteration Creates A \r Character Accidently??
Message-Id: <3B0553CC.6A7D30CF@stomp.stomp.tokyo>

nobull@mail.com wrote:
 
> Godzilla! wrote:
 
(snipped my blatherings)

> Sounds like an obscure Perl internal error.  As such exact version,
> build and platform information is likely to be relevant.

I have some subsequent articles which provide more information.
Not so sure now this is actually Perl related. Kinda looks like
I stumbled into a really rare data set which messes up Mozilla.

> Since you fail to provide this information I'll have to draw some
> logical inferences from what you _do_ say.  Your code clearly appears to
> have been written for Perl4 and you mention a "DOS prompt".

(snipped)
 
Apache/1.3.14 <Win32> mod_perl/1.24-dev running

This is perl, v5.6.0 built for MSWin32-x86-multi-thread

I am running a Pentium 3 with the first Mozilla 4.7 series.

Kinda suspect this might actually be a browser problem.

Thanks for you input. I am very perplexed by this. However,
I shouldn't really be wigging-out on this. I have only noticed
this glitch once before over a span of nearly two years.


Godzilla!


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

Date: Fri, 18 May 2001 16:11:22 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: URGENT: CGI program wanted!
Message-Id: <x7vgmy7i39.fsf@home.sysarch.com>

>>>>> "WH" == Walter Hafner <hafner-usenet@ze.tu-muenchen.de> writes:

  WH> Sorry, but I don't get this.

well, you will and then you will smack your head saying "why did i use
these buggy scripts!"

  WH> Just because a bad coder (just for argument - I don't know him and
  WH> his code) starts a site, you can't condemn the whole site.

you can condemn it. most (a very large percentage) of the scripts there
derive (by cutting and pasting) from matt's scripts. so they have
cargo-culted his crap code and spread it like a virus. i have explored
scripts there and didn't find any that were written to a basic level of
quality. they had all sorts of kiddie problems that i won't go into.

  WH> Say, a bad coder starts an operating system. Mostly by buying all
  WH> he needs and reassembling it. Over the years the operating system
  WH> gets used more and more and more and more applications are
  WH> developed. Some of the applications are good, some are very good,
  WH> while the underlying technology is still bad. You surely won't say
  WH> that every programmer who does applications based on this bad code
  WH> is a bad coder himself. And no, I don't think this is a Dilbert
  WH> type analogy. :-)

this has nothing to do with that. most free cgi scripts out there
stink. period. matt has large collection of free cgi scripts. so that is
therefore a pile of fetid manure.

  WH> In the meantime there are roughly 2000 Perl scripts available on
  WH> cgi-resources. I tried a few of them and found the majority quite
  WH> useful. E.g., I wouldn't program my own umptieth greeting card
  WH> program but use an existing one. And instead of searching the
  WH> whole web myself I'd try the largest CGI index I know about.

and you will get burned trying to maintain them, keeping crackers out of
your system, etc. 

  WH> Note: I don't have any script from that site in production right now,
  WH> but I surely would if there was the need and the script did the job
  WH> right.

that last part is key, doing the job right. are you skilled enough to
judge that? many others have the skill and have judged his code as well
as his collection to be utterly worthless. 

  WH> If that makes me a bad coder in your opinion, well ...

IMO it makes you gullible and naive. i can't stop you from using scripts
from there. but i can vigorously warn you against it. i have tried to do
so and you don't seem to get it. this is not just my opinion but most
professional perl hackers would agree with me. think about it, you won't
find almost any scripts there by people who have contributed to CPAN or
perl core, or who go to perl conferences, etc. it is an entirely
different community and they are mostly kiddies. do you really want to
trust their code?

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: Fri, 18 May 2001 10:18:33 -0600
From: Ron Reidy <rereidy@indra.com>
Subject: Re: Using PERL to gather system metrics???
Message-Id: <3B054B59.3DD353FD@indra.com>

RGS wrote:
> 
> Does anyone know how to use PERL (Win32) to get system information, such as
> CPU utilization and memory usage? I'm looking for a PERL function or
> module...no external utilities.
> 
> -RGS
Look at the Win:: modules.  Some sites you might want to look at
(besides CPAN) are:

http://www.Generation.NET/~aminer/Perl/
http://www.roth.net/

You also might want to look at win2000mag.com.  They don't really talk
about Perl, but sometimes they have articles about using WMI to get
system information.

Good Luck
-- 

Ron Reidy
Oracle DBA
Reidy Consulting, L.L.C.


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

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


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