[18243] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 411 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Mar 4 09:05:39 2001

Date: Sun, 4 Mar 2001 06:05:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <983714713-v10-i411@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 4 Mar 2001     Volume: 10 Number: 411

Today's topics:
        a beginner i perl- suiciadal <nina.ahlberg@ntlworld.com>
    Re: a beginner i perl- suiciadal <krahnj@acm.org>
    Re: a beginner i perl- suiciadal <parrot0123@yahoo.ca>
    Re: Convert macintosh file to unix <gellyfish@gellyfish.com>
    Re: Dynamic naming of arrays or hashes (OTR Comm)
    Re: Dynamic naming of arrays or hashes (Eric Bohlman)
    Re: Dynamic naming of arrays or hashes (OTR Comm)
    Re: flock and close   with  empty read strangeness (Martien Verbruggen)
    Re: flock and close   with  empty read strangeness <bart.lateur@skynet.be>
    Re: flock and close   with  empty read strangeness <flavell@mail.cern.ch>
    Re: Is Perl right for me? (Miguel Cruz)
    Re: Is Perl right for me? (Miguel Cruz)
    Re: Is Perl right for me? (Miguel Cruz)
    Re: Is Perl right for me? <parrot0123@yahoo.ca>
    Re: Is Perl right for me? <bart.lateur@skynet.be>
    Re: milliseconds <ubl@schaffhausen.de>
    Re: question on how to code a program <bart.lateur@skynet.be>
        random numbers from subroutine .... <e96mani@yahoo.dk>
    Re: random numbers from subroutine .... <krahnj@acm.org>
    Re: random numbers from subroutine .... <joe+usenet@sunstarsys.com>
    Re: Reading non-ASCII from XML file using DOM module (Mihai N.)
    Re: Reading non-ASCII from XML file using DOM module (Martien Verbruggen)
        running perl functions from tcl scripts <orinoki@hotmail.com>
    Re: Submitting Forms from Code (Martien Verbruggen)
        truncate <s0218327@unix1.cc.ysu.edu>
    Re: truncate (Martien Verbruggen)
    Re: truncate <bart.lateur@skynet.be>
    Re: unlink problems <bart.lateur@skynet.be>
    Re: Uploading a file (Garry Williams)
    Re: Uploading a file (Martien Verbruggen)
    Re: Uploading a file <flavell@mail.cern.ch>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sun, 4 Mar 2001 09:42:01 -0000
From: "nina.ahlberg" <nina.ahlberg@ntlworld.com>
Subject: a beginner i perl- suiciadal
Message-Id: <b0oo6.7596$mt.1064948@news2-win.server.ntlworld.com>

Hello! I'm just sttarting to learn how to program in perl...
and already got stuck. I'm suppose to do a telephone directory, where the
user is simply inputting names and telephonenumbers until the name is null
or the word "none" is used for the name, after this the system should ask
for a name whoes telephonenumber is required and display the correct number
in case of a match or an error message. if the word "none" is typed or null
is given the program should terminate. SIMPLE!
but having problems..... my initial attempts...:
#!/usr/local/bin/perl


while()
{
        print "please enter a name:";
        chomp ($name=<STDIN>);

if ($name ne "none")
{
        print "please enter a number:";
        chomp ($number =<STDIN>);
        $directory{name}='$number';
}
else
{
        print "please enter the name of the person, whoes number you
require:";
        chomp ($name=<STDIN>);
  print "the number of $name is $directory{'name'}";
}
}

SIGH!!!!! does not work, if somebody can help me i'm very grateful....
Nina





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

Date: Sun, 04 Mar 2001 10:21:03 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: a beginner i perl- suiciadal
Message-Id: <3AA21863.7F57C31F@acm.org>

"nina.ahlberg" wrote:
> 
> Hello! I'm just sttarting to learn how to program in perl...
> and already got stuck. I'm suppose to do a telephone directory, where the
> user is simply inputting names and telephonenumbers until the name is null
> or the word "none" is used for the name, after this the system should ask
> for a name whoes telephonenumber is required and display the correct number
> in case of a match or an error message. if the word "none" is typed or null
> is given the program should terminate. SIMPLE!
> but having problems..... my initial attempts...:
> #!/usr/local/bin/perl

#!/usr/local/bin/perl -w
use strict;

my ( $name, $number, %directory );


> 
> while()
> {
>         print "please enter a name:";
>         chomp ($name=<STDIN>);
> 
> if ($name ne "none")
> {
>         print "please enter a number:";
>         chomp ($number =<STDIN>);
>         $directory{name}='$number';

You've got two problems on this line. You are assigning the literal
string '$number' (not the value of the variable $number) to the key
'name' (not the value of the variable $name) to the hash. This should
be:
    $directory{ $name } = $number;


> }
> else
> {
>         print "please enter the name of the person, whoes number you
> require:";
>         chomp ($name=<STDIN>);
>   print "the number of $name is $directory{'name'}";

    print "the number of $name is $directory{$name}";

> }
> }


John


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

Date: Sun, 04 Mar 2001 12:42:24 GMT
From: "Parrot" <parrot0123@yahoo.ca>
Subject: Re: a beginner i perl- suiciadal
Message-Id: <QKqo6.335531$f36.11821771@news20.bellglobal.com>


nina.ahlberg <nina.ahlberg@ntlworld.com> wrote in message
news:b0oo6.7596$mt.1064948@news2-win.server.ntlworld.com...
> Hello! I'm just sttarting to learn how to program in perl...
> and already got stuck. I'm suppose to do a telephone directory, where the
> user is simply inputting names and telephonenumbers until the name is null
> or the word "none" is used for the name, after this the system should ask
> for a name whoes telephonenumber is required and display the correct
number
> in case of a match or an error message. if the word "none" is typed or
null
> is given the program should terminate. SIMPLE!
> but having problems..... my initial attempts...:

Why didn't you put any conditions in your while loop?  You need to give it
some conditions so that it knows when to exit.  Try something like:

while ($name ne "none" && $name ne "")
{
    #Code to get the name and number here
}

#Code to ask for the name and do a search here




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

Date: 3 Mar 2001 14:13:44 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Convert macintosh file to unix
Message-Id: <97qu6o$jil$1@orpheus.gellyfish.com>

On Sat, 03 Mar 2001 10:30:21 GMT kj Copeland wrote:
> In article <mMOn6.1623$I4.189558@e420r-sjo3.usenetserver.com>,
>  "TcN" <aleister@nomade.fr> wrote:
> 
>> Hello,
>> 
>> I'll try to convert a macintosh text file in Unix Format.
>> My problem is with the accent (I'm french..sorry ;-)
>> Do you a script to do that ??
>> 
> 
>   If you want a quick (and likely inefficient) script that can be called 
> like "mac2unix sourcefile destfile" or "unix2mac sourcefile destfile", 
> depending on which way you want it to go, try this (untested, but should 
> work okay):
> 

Tom Christiansen posted a program caled nlcnvt here a year or so ago which
did exactly the same depending on what it was called.

/J\
-- 
Jonathan Stowe                      |     
<http://www.gellyfish.com>          |      This space for rent
                                    |


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

Date: Sun, 04 Mar 2001 08:38:22 GMT
From: otrcomm***NO-SPAM***@wildapache**NO-SPAM***.net (OTR Comm)
Subject: Re: Dynamic naming of arrays or hashes
Message-Id: <3aa1fa78.2506090517@news.wildapache.net>

On Sun, 04 Mar 2001 06:33:49 GMT, cfedde@fedde.littleton.co.us (Chris
Fedde) wrote:

>It's posible to do this using "symbolic" variables when you don't have 'use
>strict' in force.  but that not what you usualy want to do in these cases.
>I think that you realy want  to use a hash of hashes.
>
>    push(@{$past_due{$customer_id}, $invoice_number);
>

Thanks for the help here!

I now have:

my %past_due = ();

<snip>

push(@{ $past_due{$customer_id} }, $invoice_number);

<snip>

foreach $customer_id (@email) {

  if ( @{ $past_due{$customer_id} } ) {

    foreach $i (0 .. $#{ $past_due{$customer_id} }) {

      print "$customer_id has invoice $past_due{$customer_id}[$i] past
       due\n";

    } # End foreach $i (0 .. $#{ $past_due{$customer_id} })

  } # End if ( @{ $past_due{$customer_id} } )

} # End foreach $customer_id (@email)

<snip>

I have about 8000 customer_ids in the @email array and there will
normally be a few thousand past due invoices in a given month.

Then I have another array called @regular_mail that has over 15000
customer_ids that have to be processed the same way.  There will also be
a few thousand past due invoices here in a given month.

I have considerable processing to do on each invoice that is identified
in the foreach $i loop (for both the @email and @regular_mail arrays)
and need to have this optimized as much as possible.

Does this look like the most efficient way to get access to the
individual 'invoice_numbers' for each 'customer_id' that has over due
invoices?

Thanks,
Murrah Boswell

>-- 
>    This space intentionally left blank



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

Date: 4 Mar 2001 09:02:51 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Dynamic naming of arrays or hashes
Message-Id: <97t0br$iel$6@bob.news.rcn.net>

OTR Comm <otrcomm***NO-SPAM***@wildapache**no-spam***.net> wrote:
> foreach $customer_id (@email) {

>   if ( @{ $past_due{$customer_id} } ) {

>     foreach $i (0 .. $#{ $past_due{$customer_id} }) {

>       print "$customer_id has invoice $past_due{$customer_id}[$i] past
>        due\n";

>     } # End foreach $i (0 .. $#{ $past_due{$customer_id} })

>   } # End if ( @{ $past_due{$customer_id} } )

The entire "if" block could be written as:

  foreach (@{$past_due{$customer_id}}) {
    print "$customer_id has invoice $_ past due\n";
  }


> } # End foreach $customer_id (@email)


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

Date: Sun, 04 Mar 2001 10:11:31 GMT
From: otrcomm***NO-SPAM***@wildapache**NO-SPAM***.net (OTR Comm)
Subject: Re: Dynamic naming of arrays or hashes
Message-Id: <3aa2142b.2512669217@news.wildapache.net>

On 4 Mar 2001 09:02:51 GMT, ebohlman@omsdev.com (Eric Bohlman) wrote:


>The entire "if" block could be written as:
>
>  foreach (@{$past_due{$customer_id}}) {
>    print "$customer_id has invoice $_ past due\n";
>  }
>
>
>> } # End foreach $customer_id (@email)

Thank you!
This works very well!

Now off to the fun part of dealing with the past due invoices :-)

My best regards,
Murrah Boswell


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

Date: Sun, 4 Mar 2001 19:23:01 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: flock and close   with  empty read strangeness
Message-Id: <slrn9a3ur5.5vn.mgjv@martien.heliotrope.home>

On Sun, 04 Mar 2001 02:11:17 -0500,
	ZepHead <groovyt@erols.com> wrote:
> In article <slrn9a0s5c.qmu.mgjv@martien.heliotrope.home>,
>  mgjv@tradingpost.com.au (Martien Verbruggen) wrote:
> 
> 
>> 
>> perldoc doesn't suggest anything, really. It's just a program to look at
>> the standard perl documentation. If you refer to the documentation,
>> maybe you should mention which documentation. perlopentut contains this
>> information, for example.
>> 
>> Martien
> 
> well i said "suggests" for a reason    ; )
> 
> all the examples of hit counters and file read/write
> with fast turn around all show sysopen and not open +<
> 
> if yor read one of the tutorials it even says WHY to use sysopen
> over open.   Too me that suggest sysopen should be used.  Is it 100%
> clear on this?  nope and why i said suggests and not demands   lol
> 
> Also think about my problem.
> if i went with +< then how do I create the files?

The first time I encountered this problem, I figured I could do it with
>>+, a seek to the start, a lock, then a truncate and a write. (In fact,
this did get suggested in another part of the thread as well). I
actually encountered this problem in C, before I ran into it in Perl. n
C, the standard can be read to track down whether that's guaranteed to
work. In perl, unless it's explicitly stated, you don't know diddly,
really.

> yes i feel the docs need to set the record straight here
> and sadly they do not.  : (     (at least as far as i could find)

Indeed. And that is becoming a problem more and more.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Hi, Dave here, what's the root
Commercial Dynamics Pty. Ltd.   | password?
NSW, Australia                  | 


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

Date: Sun, 04 Mar 2001 11:38:55 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: flock and close   with  empty read strangeness
Message-Id: <6r94at02303mce70v55o8jcc5608ef95bp@4ax.com>

Martien Verbruggen wrote:

>But, why would you go through the trouble of doing all this, and making
>the system work like this, when sysopen with the appropriate arguments
>will do this, and this is guaranteed?

Because two argument open is simpler than sysopen, or we'd all be using
sysopen all the time, I go along to some extent with Zephead's idea. At
least, there should be at least one file mode that DOES create a file if
it didn't exist, DOES NOT truncate the file, and leaves the seek pointer
at the start of the file. Like "+<", but with built-in
create-if-missing. And which is garanteed to work across platforms.
You'd still have to truncate by hand, or maybe, just maybe, the file
could be automatically be truncated as soon as you write to the file.

Now, you can do:

	open FILE, ">>$file";
	open FILE, "+<$file";

which opens the file twice in a row, the first time creating the file if
it didn't exist, and automatically closing it when opening it for the
second time.

-- 
	Bart.


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

Date: Sun, 4 Mar 2001 14:34:38 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: flock and close   with  empty read strangeness
Message-Id: <Pine.LNX.4.30.0103041433530.25392-100000@lxplus003.cern.ch>

On Sun, 4 Mar 2001, Bart Lateur wrote:

> Now, you can do:
>
> 	open FILE, ">>$file";
> 	open FILE, "+<$file";
>
> which opens the file twice in a row, the first time creating the file if
> it didn't exist, and automatically closing it when opening it for the
> second time.

But how would that jive with flocking?




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

Date: Sun, 04 Mar 2001 09:12:18 GMT
From: mnc@admin.u.nu (Miguel Cruz)
Subject: Re: Is Perl right for me?
Message-Id: <SFno6.1711$6A6.899827@typhoon2.ba-dsg.net>

Holly Bortfeld <maximom@mindspring.com> wrote:
> I don't mind doing the work or buying a piece of software but want to do all
> the work ourselves as far as tagging all the recipe files and being able to
> update them at any time as well as designing the webpage and search engine.
> We have been offered space on someone's server for free to hold the data as
> well.
>
> I will go check out Cold Fusion and if you can think of anything else,
> please let me know.

Cold Fusion ain't cheap either.

If cost is an option, there are free options on either major platform
(unix/micros~1). PHP and Perl work on both, and ASP works on Windows (there
are ASP modules for Unix web servers but they are rarely installed and since
ASP provides the weakest functionality and most annoying programming
environment of the three it's to be avoided unless you have no other choice.

Perl is a substantially meatier language than PHP. It's also harder to get
started with, because of its complexity. Most people can pick up a PHP book
and be writing rudimentary dynamic pages within an hour or two. On the other
hand, as your project grows, you may find that Perl better suits your
long-term needs because of its broader literature and support base, or the
greater number of programmers available, or the fact that it can just Do
More Things.

A key consideration will be the environment that's available on the server
you'll be using.

miguel


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

Date: Sun, 04 Mar 2001 09:14:44 GMT
From: mnc@admin.u.nu (Miguel Cruz)
Subject: Re: Is Perl right for me?
Message-Id: <8Ino6.1712$6A6.900934@typhoon2.ba-dsg.net>

Holly Bortfeld <maximom@mindspring.com> wrote:
> My understanding of this is that each recipe file would have on it a tag
> that the search engine would find. The tags would be something like
> WF,GF,CF,MF,NF (etc) to mean wheat free, gluten free, corn free, milk free,
> nut free.  so the engine would only pull up recipes that included those
> items in the tag.  The actual information in the file below the tag would
> not matter to the search engine as I would instruct it only to files that
> had the right tag assigned and not search the text of the whole file.

This is more a database issue. The process will be basically the same in any
language, since you'll be sending commands off to the database (which has
its own, different language, generally "SQL") to do the retrieval. Your
Perl/ASP/PHP will just create HTML for forms displayed in the browser, and
then format and display the results retrieved from the database.

miguel


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

Date: Sun, 04 Mar 2001 09:16:57 GMT
From: mnc@admin.u.nu (Miguel Cruz)
Subject: Re: Is Perl right for me?
Message-Id: <dKno6.1713$6A6.901425@typhoon2.ba-dsg.net>

Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
> Perl is not right for you. To write an effective and efficient program to
> accomplish your task, you will need a minimum of one year's worth of
> intensive working experience with Perl. Learning Perl itself, will take
> you at least a year as well.

Give the lady some credit. Anyone who requires a year to learn enough Perl
to set up a site this simple has serious problems well beyond the scope of
this newsgroup.

miguel


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

Date: Sun, 04 Mar 2001 12:12:34 GMT
From: "Parrot" <parrot0123@yahoo.ca>
Subject: Re: Is Perl right for me?
Message-Id: <Siqo6.335367$f36.11820296@news20.bellglobal.com>


Godzilla! <godzilla@stomp.stomp.tokyo> wrote in message
news:3AA188E5.1FD2CFCF@stomp.stomp.tokyo...
>
> Perl is not right for you. To write an effective and efficient
> program to accomplish your task, you will need a minimum of
> one year's worth of intensive working experience with Perl.
> Learning Perl itself, will take you at least a year as well.
>
Oh Come On! - I was able to learn the basics of Perl in a day, and I was
able to program rudimentary CGI applications within a week.  Perl's really
not that hard a language - I know, I've studied Cobol! (I don't mean to bash
Cobol if there are any advocates of the language out there, but it does take
a little getting used to.)

Perhaps you mean that it will take that long for her to become an expert at
Perl - But let's face the facts, she really doesn't need to know all the ins
and outs of the language.  She doesn't even need to know how to program
stand alone applications.  She just needs to understand how to write an
effective CGI script.

I don't know how good she is at programming and catching on to these
concepts - nor do I know how well her idea will be able to perform under
scrutiny, but if it takes somebody in excess of a year to learn Perl, then
programming is obviously not their thing.




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

Date: Sun, 04 Mar 2001 13:19:21 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Is Perl right for me?
Message-Id: <e2g4atgl5ek67e37quvv6h0t48cem12b5i@4ax.com>

Holly Bortfeld wrote:

>I can write HTML
>from scratch without an editor.

Wow, that is strong. So how do you write HTML? Using a speech
recognition system?

>I want to create a website for parents of kids with multiple food allergies
>that allows users to click boxes as to what thier child cannot have in a
>recipe, then the search engine or script would sort through the 25,000+
>tagged recipes to show the site user only the recipes that fit their entered
>criteria in a particular category.
>The site does not need to be fancy with pictures or Java, just efficient to
>sort through the vast amounts of recipe files in a short amount of time.

If this could be described in terms of SQL, then any language that can
access an SQL database from within a CGI script (or similar) will do.
I'd suggest using PHP, at least it's free. ColdFusion is rather
expensive.

If that's not good enough, then maybe you do need Perl.

>At
>CompUSA, a young man suggested DreamWeaver but the description on the site
>does not look like that will fit my needs.

Ooh, no. I think Dream Weaver is NOTHING BUT a WYSIWYG HTML editor.

-- 
	Bart.


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

Date: Sun, 04 Mar 2001 13:08:33 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: milliseconds
Message-Id: <3AA23040.D9A9A243@schaffhausen.de>

Arthur Wolst schrieb:
> Is there any other function available to get the exact time values with
> milliseconds?

Look for the module: Time::HiRes (I'm not totally sure about the spelling)

Bye,
->malte


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

Date: Sun, 04 Mar 2001 11:58:57 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: question on how to code a program
Message-Id: <obb4atggcsqjanao7irmbkmkdj8jr0ijj7@4ax.com>

Steven Smolinski wrote:

>I was in my local bookstore, and saw a Perl/CGI book by Matt Wright.
>The few pages I skimmed had a few errors, as suspected, and I was
>putting it back with a snort when I saw a quote on the back.
>
>The quote was from Randal!  It said that the book ought to be on every
>programmer's bookshelf or some such glowing comment. 
>
>Randal!  What's happened?  Did they threaten to kill your family?  If
>you can't speak freely, rot13 your reply and we'll figure out a way to
>get you and your loved ones to safe Switzerland!

This has come up here before. Unforetunately, the transition of DejaNews
to Google seems to have caused the loss of quite a lot more posts, than
ever before. Like, almost every single one of them.

-- 
	Bart.


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

Date: Sun, 04 Mar 2001 11:17:26 GMT
From: <e96mani@yahoo.dk>
Subject: random numbers from subroutine ....
Message-Id: <avpo6.23908$dD.797154@twister.sunsite.dk>

hi all,
I have hard time to figure out; why does this piece of code not give me
different sets of random numbers when i call it many times from the
subroutines.
could any one take a look at the code and say what I'am overlooking here.

thanks in advance.

----result------
-> '04:05:06:12'
-> '04:05:06:12' # should be different from the previous
-> '04:05:06:12' # this to
-> '04:05:06:12''# this to
-> '04:05:06:12' # ...
---code--------
#!/usr/bin/perl -w
#use strict;
#require 'dumpvar.pl';

# 5 times set of numbers

for (my $i=0;$i<5;$i++){
$re = sub {\&run1(1,4,16)};
dumpValue( &$re());
}

# 1st level sub
sub run1{
my($count, $length , $opt) = @_;
my @nr = run2($count, $length , $opt );
return @nr;
}

# second
sub run2 () {
srand( time() ^ ($$ + ($$ << 15)) );
my ($count, $length , $opt) = @_ ;#or (30,5);

my ($loop,$temp,$temp1,@temp1,@nr);
my @characters = (1..$opt);
#
for (; $count > 0; $count--) {
    for ($loop = 0; $loop < $length; $loop ++) {
        $temp = int(rand $mulighed) + 1;
  ($temp1,$characters[$temp]) =  $characters[$temp] ? $characters[$temp] :
redo ;
 @temp1 = (@temp1,  ($temp1 < 10 ? "0" . $temp1 : $temp1));
 }
    @temp1 = sort numerically @temp1;
    @nr = (@nr, join (":",@temp1));     @temp1='';
    @characters = (1..$opt);

}
return @opt;
}

# sort by numbers
sub numerically { $a <=> $b; }
exit;




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

Date: Sun, 04 Mar 2001 11:57:43 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: random numbers from subroutine ....
Message-Id: <3AA22F09.B2939992@acm.org>

e96mani@yahoo.dk wrote:
> 
> hi all,
> I have hard time to figure out; why does this piece of code not give me
> different sets of random numbers when i call it many times from the
> subroutines.
> could any one take a look at the code and say what I'am overlooking here.

perldoc -f srand

srand   Sets the random number seed for the rand()
        operator.  If EXPR is omitted, uses a semi-random
        value supplied by the kernel (if it supports the
        /dev/urandom device) or based on the current time
        and process ID, among other things.  In versions
        of Perl prior to 5.004 the default seed was just
        the current time().  This isn't a particularly
        good seed, so many old programs supply their own
        seed value (often time ^ $$ or time ^ ($$ + ($$ <<
        15))), but that isn't necessary any more.
[snip]
        Do _not_ call srand() multiple times in your program
        unless you know exactly what you're doing and why
        you're doing it.  The point of the function is to
        "seed" the rand() function so that rand() can
        produce a different sequence each time you run
        your program.  Just do it once at the top of your
        program, or you _won't_ get random numbers out of
        rand()!

> 
> thanks in advance.

You're welcome.


John


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

Date: 04 Mar 2001 07:34:53 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: random numbers from subroutine ....
Message-Id: <PCqo6.4$L67.861@news1.atl>

<e96mani@yahoo.dk> writes:

> hi all,
> I have hard time to figure out; why does this piece of code not give me
> different sets of random numbers when i call it many times from the
> subroutines.

That's usually an indication that you've recalled srand with the same
seed each time.  If you are using a relatively modern perl, You 
shouldn't call srand anymore- Perl will handle this for you.

> could any one take a look at the code and say what I'am overlooking here.
> 

[...]

> # second
> sub run2 () {
> srand( time() ^ ($$ + ($$ << 15)) );
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Bingo.  Comment this line out and you may get better results.
(I didn't look carefully at your script, so this might not be the
only problem.)

If you are on an old perl, just move it to the top of your script
so it only gets called _once_.  (btw- this seed is a rather poor choice,
since anyone with a 'ps' utility can duplicate your rand() sequence.) 
See the documentation in

  % perldoc -f srand

for a better seed, and a warning about calling srand multiple times. 

> thanks in advance.

  % perldoc -q random

also discusses this problem - did you check the FAQ before posting?

-- 
Joe Schaefer         "I never think of the future. It comes soon enough."
                                               --Albert Einstein


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

Date: Sun, 04 Mar 2001 11:27:58 GMT
From: nmihai_2000@yahoo.com (Mihai N.)
Subject: Re: Reading non-ASCII from XML file using DOM module
Message-Id: <905A2B8F4MihaiN@24.1.64.32>

><?xml version="1.0" encoding="ISO-8859-1"?>
><content>
>   <matter>rrÎ aÏkA d]ukA ejgjuRCADkA Lisx |MkilÍj[
>rrÎ akmjujqdX Qfk]jiØk;
>do}AsfMju Qgk dkc{fjÙjg[
>Lixksm sdlhkckdX djhk]jSrl]j;</matter>
></content>

The XML you posted does not look like UTF8 and not as anything else.

Is this the result of the parsing, or the file to be parsed?
Can you please include as attachment the original file and the result of
the parsing?

And what language is this supposed to be? No language supported by 
ISO-8859-1 has so many accented characters to get damaged so bad.
Or is this just a dummy text?

Regards,
Mihai



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

Date: Sun, 4 Mar 2001 23:04:43 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Reading non-ASCII from XML file using DOM module
Message-Id: <slrn9a4bqr.5vn.mgjv@martien.heliotrope.home>

On Thu, 1 Mar 2001 15:54:49 -0600,
	Thomas Theakanath <thomastk@prodigy.net> wrote:
> Hi:
> 
> I use XML::DOM module to read a simple XML file with following format, that
> has non-ASCII chars in the text nodes.
> 
><?xml version="1.0" encoding="ISO-8859-1"?>
><content>
>    <matter>rrÎ aÏkA d]ukA ejgjuRCADkA Lisx |MkilÍj[
> rrÎ akmjujqdX Qfk]jiØk;
> do}AsfMju Qgk dkc{fjÙjg[
> Lixksm sdlhkckdX djhk]jSrl]j;</matter>
></content>

That doesn't look right. I don't know all languages, but that certainly
doesn't look like a language that would be using ISO-8895-1 encoding.
Are you certain that the XML that you fed into XML::DOM is valid? Maybe
you should run it through some other parser, just to see what it does
with this stuff.

Maybe all that's wrong is your encoding specification.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | 
Commercial Dynamics Pty. Ltd.   | "Mr Kaplan. Paging Mr Kaplan..."
NSW, Australia                  | 


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

Date: Sun, 4 Mar 2001 14:07:22 +0200
From: "Richard Jones" <orinoki@hotmail.com>
Subject: running perl functions from tcl scripts
Message-Id: <3aa22e72@news.bezeqint.net>

Hi

I've been struggling with this problems for some time.

Does anyone know of a good way to do it?

I found in the web something called minotaur, does anyone use it?
http://www.equi4.com/minotaur/minotaur.html

    thanks for all your help

       Rick.





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

Date: Sun, 4 Mar 2001 19:54:47 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Submitting Forms from Code
Message-Id: <slrn9a40mn.5vn.mgjv@martien.heliotrope.home>

On Sun, 04 Mar 2001 06:53:06 GMT, Joe Moore <joemoore@att.net> wrote:
> 
> "brian d foy" <comdog@panix.com> wrote in message
> news:comdog-BD561F.17515215022001@news.panix.com...
> 
>> > > I have built a Perl Script which grabs data from a web page and
>> > > performs some calculations on that data. The calculations
>> > > returned need to be entered into a form on another webpage. Is
>> > > there a way that I can enter the returned data into the webpage
>> > > form and submit it from the Perl script?
>>
>>
>> > Sure, but you don't really want to load it into another webpage,
>> > you want your perl script to emulate the webpage, right?
>>
>> > Then you can just redirect to the page you are submitting to
>> >
>> > print "Location: $url?$query_string\n\n";
>>
>> that only works (maybe) if your script is another CGI script. based
>> on the OP's question, that doesn't sound right though.
>>
>> the HTTP::Request docs show an example that answers the question:
>>
>>     http://search.cpan.org/doc/GAAS/libwww-perl-5.50/lib/LWP.pm
> 
> Thanks for adding to the confusion. 

brian d foy's response was correct. He usually is about things in this
area. Youshould probably have stopped for a minute, and thought about
_why_ he thought your response wasn't correct. You could have easily
figured it out by rereading the original request, and your response (I
have reformatted the mess your newsreader made of it, so it's readable
again)

>                                      Clearly the OP wants to insert
> the data into a web page and automatically submit it and you can't do
> that.  You have to do it the easy way, like I explained,

Your 'easy way' won't even work. And I don't agree at all with your
assessment of what the OP wanted. What people with questions say, and
what they want is hardly ever the same thing.

The OP's question was about emulating a client requesting a web page,
not about a web server side program. Reread it if you're still not
convinced. The canonical way to be a HTTP client in Perl is to use the
LWP modules, just like brian d foy recommended.

Your solution seems to involve printing out a line to STDOUT. What good
does this do for a HTTP client? you've just told the person sitting at
the temrinal where the output goes:

Location: $url?$query_string\n\n

with the variables properly substituted. And then? I think that people
nowadays are more or less used to HTTP clients figuring out for
themselves where a URL points to.

>                                                          or if the
> form requires a POST submission, then they can use a request as you
> indicated.

The client should retrieve the first page, probably with a GET request,
then do its calculations, construct a proper GET or POST request
(whichever that particular form submission needs, read the HTML to find
out) with a HTTP::Request object, hand it off to the LWP::UserAgent
object, and receive the output of the POST submission. There is no need
for any Location headers, or other CGI specific stuff, because you're at
the client, not at the server end.

>             However, if the user expects to put the data into a
> webpage form that executes JavaScript, then neither of our solutions
> will work.  I figured I'd go after the nail before looking at the
> splinter.

JavaScript was never mentioned. besides that, it may very well be that
the calculation the OP wants to perform is to replace some JavaScript.
rereading the OP's request again, I can't even see how JavaScript got
into this. All they asked was: I get some data (from a web page). From
that data I construct other data with which I need to emulate a form
submission to a web server.

Not that hard a question, and it can be simply answered with:

	get LWP.

And I believe someone answered in exactly that way.

Martien

PS. Sorry for the long post, but in another thread you were whinging
about not being wanted. If you want to make yourself be wanted, then
learn to eat criticism when it comes your way. Learn that you are not
always right, and you don't always _have_ to be right. accept that some
people know more than you do about some subjects. Instead of getting
defensive, learn. 

PPS. Thanks for at least quoting your post correctly this time.
-- 
Martien Verbruggen              | 
Interactive Media Division      | 
Commercial Dynamics Pty. Ltd.   | What's another word for Thesaurus?
NSW, Australia                  | 


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

Date: Sun, 4 Mar 2001 03:30:35 -0500
From: NagaPutih <s0218327@unix1.cc.ysu.edu>
Subject: truncate
Message-Id: <Pine.A41.4.20.0103040304010.617294-100000@unix1.cc.ysu.edu>


hello,

i have a script that updates content of a file, which was
working and operational until I updated my perl to 5.6.

here's the error message:
"Insecure dependency in truncate while running setgid at
/cgi-bin/submit.pl line 52, <HSTABLE> line 10."

snippet of the code:
 ...
seek(HSTABLE,0,0);
print HSTABLE $newtable;
truncate(HSTABLE,length($newtable));    <-- error occured
 ...

any ideas?
thank's in advance!




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

Date: Sun, 4 Mar 2001 20:00:41 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: truncate
Message-Id: <slrn9a411p.5vn.mgjv@martien.heliotrope.home>

On Sun, 4 Mar 2001 03:30:35 -0500,
	NagaPutih <s0218327@unix1.cc.ysu.edu> wrote:
> 
> hello,
> 
> i have a script that updates content of a file, which was
> working and operational until I updated my perl to 5.6.
> 
> here's the error message:
> "Insecure dependency in truncate while running setgid at
> /cgi-bin/submit.pl line 52, <HSTABLE> line 10."

You need to read the perldiag documentation, which contains all the
error message that Perl generates.

# man perldiag
[snip]
       Insecure dependency in %s
           (F) You tried to do something that the tainting mecha­
           nism didn't like.  The tainting mechanism is turned on
           when you're running setuid or setgid, or when you
           specify -T to turn it on explicitly.  The tainting
           mechanism labels all data that's derived directly or
           indirectly from the user, who is considered to be
           unworthy of your trust.  If any such data is used in a
           "dangerous" operation, you get this error.  See the
           perlsec manpage for more information.
[snip]

Especially pay attention to the reference to more documentation given at
the end.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | 
Commercial Dynamics Pty. Ltd.   | "Mr Kaplan. Paging Mr Kaplan..."
NSW, Australia                  | 


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

Date: Sun, 04 Mar 2001 11:46:24 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: truncate
Message-Id: <7pa4ats2pktcjq5g6ndditlfurpm62nc5c@4ax.com>

NagaPutih wrote:

>seek(HSTABLE,0,0);
>print HSTABLE $newtable;
>truncate(HSTABLE,length($newtable));    <-- error occured
>...
>
>any ideas?

It seems like you can skip this whole issue, and truncate the file's
length to 0 before writing the string.

-- 
	Bart.


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

Date: Sun, 04 Mar 2001 10:16:21 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: unlink problems
Message-Id: <5c54ats03puuh7ie3eqfun6negfgbai0q6@4ax.com>

Ken Brown wrote:

>OK I'm new to this so I took the example from unlink and changed it a
>little bit pp236 seems to work fine until it comes across wild carded
>filenames
>
>I originally had it as you suggested but my *.txt files still failed so
>I went back to the book.

unlink doesn't work with widlcards, so you need to glob explicitely,
yourself. But Tad's code took care of that, so it seems:

	unlink(glob('*.txt'))

That should have worked. The only thing I can imagine to have gone
wrong, is that file globbing doesn't produce the proper results. So
print out the names of the files, instead of directly deleting them.
Don't forget to add separators between the file names, or you won't be
able to see where one name stops, and the next begins. Setting $\ and/or
$, can help.

-- 
	Bart.


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

Date: Sun, 04 Mar 2001 08:35:39 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Uploading a file
Message-Id: <v7no6.212$mU5.9428@eagle.america.net>

[Jeopardectomy performed]

On Sun, 04 Mar 2001 07:05:05 GMT, Joe Moore <joemoore@att.net> wrote:
>"Alan J. Flavell" <flavell@mail.cern.ch> wrote in message
>news:Pine.LNX.4.30.0102160249300.17336-100000@lxplus003.cern.ch...
>> On Fri, 16 Feb 2001, Joe Moore wrote:
>>
>> > 0A in a text file is a "\n" character.
>>
>> \n is not a "character", it's an end of line.  How that is represented
>> is platform-dependent.
>>
>> >  0D is the "\r" character.
>>
>> And so on.  You really ought to make yourself more familiar with the
>> discussion in perldoc perlport, before offering misleading advice to
>> innocent readers.
>>
>> > In Unix text files all lines end with a "\n".
>>
>> In Perl, all lines end by definition in "\n", irrespective of
>> platform.  But what that "\n" is, is platform-dependent.
>>
>> > "Mark" <mark_shutt@hotmail.com> wrote in message
>> > news:t8ot4de4n71a28@corp.supernews.com...
>>
>> Oh dear, an upside-down fullquoter.  Figures.
>>
>> The questioner should also, of course, make themselves familiar with
>> the discussion in perldoc perlport.
>>
>Sorry.
>
>'0A' is a newline character as defined in ASCII
>'0D' is a carriage return character as defined in ASCII
>
>The fact that these bad boys keep getting switched in an upload file is
>clearly an indication of an improper conversion.
>
>My response to use binary mode may have helped.  Your response?
>
>Well you proved you are way smarter than me, congratulations.
>
>I know when I'm not wanted <sob> goodbye cruel Perl world </sob>

Maybe you're both right.  

Question one: What does the string "test\n" contain?  

On a Windows machine:
  $ uname -a
  MS-DOS VFR 7 10 pc
  $ perl -wle 'print map { " " . ord } split //, "test\n"'
   116 101 115 116 10
  $

On a Unix machine: 
  $ uname -a
  SunOS zweb 5.7 Generic_106541-11 sun4u sparc SUNW,Ultra-60
  $ perl -wle 'print map { " " . ord } split //, "test\n"'
   116 101 115 116 10
  $ 

Hmm.  No difference.  In other words, "\n" is _always_ interpolated as
the ASCII newline character no matter what the OS or hardware.  

Question two: What does the string "test\n" contain _after_ it is
written to a file that has not been set for binmode?  

On a Windows machine: 
  $ perl -we 'print "test\n"'|od -to1
  0000000 164 145 163 164 015 012
  0000006
  $

On a Unix machine: 
  $ perl -we 'print "test\n"'|od -to1
  0000000 164 145 163 164 012
  0000005
  $

Well, that's what everybody expected.  

Maybe you two are talking about two different things.  

-- 
Garry Williams


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

Date: Sun, 4 Mar 2001 19:37:23 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Uploading a file
Message-Id: <slrn9a3vm3.5vn.mgjv@martien.heliotrope.home>

[Please, in the future, put your reply _after_ the suitably trimmed
quoted text you reply to. This is the commonly accepted quoting style on
this newsgroup, and Usenet in general]

On Sun, 04 Mar 2001 07:05:05 GMT,
	Joe Moore <joemoore@att.net> wrote:
> "Alan J. Flavell" <flavell@mail.cern.ch> wrote in message
> news:Pine.LNX.4.30.0102160249300.17336-100000@lxplus003.cern.ch...
>> On Fri, 16 Feb 2001, Joe Moore wrote:
>>
>> > 0A in a text file is a "\n" character.
>>
>> \n is not a "character", it's an end of line.  How that is represented
>> is platform-dependent.
>>
>> >  0D is the "\r" character.
>>
>> And so on.  You really ought to make yourself more familiar with the
>> discussion in perldoc perlport, before offering misleading advice to
>> innocent readers.
>>
>> > In Unix text files all lines end with a "\n".
>>
>> In Perl, all lines end by definition in "\n", irrespective of
>> platform.  But what that "\n" is, is platform-dependent.
>>
>> > "Mark" <mark_shutt@hotmail.com> wrote in message
>> > news:t8ot4de4n71a28@corp.supernews.com...
>>
>> Oh dear, an upside-down fullquoter.  Figures.
>>
>> The questioner should also, of course, make themselves familiar with
>> the discussion in perldoc perlport.
>>
> Sorry.
> 
> '0A' is a newline character as defined in ASCII
> '0D' is a carriage return character as defined in ASCII

Yes, and \n is defined as the end of line. On some platforms that \x0a, on
some that's \x0d, on some a combination of the two. But in Perl, the
end-of line is a single character, "\n", no matter what the underlying
OS thinks it should write to text files.

newline is not end of line. carriage return is not end of line. The
difference matters, and matters greatly.

> The fact that these bad boys keep getting switched in an upload file is
> clearly an indication of an improper conversion.

Maybe, maybe not, but that is besides the issue. You gave wrong
information, and were corrected. This is how one learns. This is also
how the quality of response can be maintained at a reasonable level. If
we let misinformation get through and survive, it'll keep coming back to
haunt us. isinformation eneds correction.

> My response to use binary mode may have helped.  Your response?

Maybe it did. It probably did, but that doesn't take away the fact that
you gave misinformation. This is a Perl language group. On any language
group it is recommended to be as precise and correct as you can, lest
you want to be corrected. 

> Well you proved you are way smarter than me, congratulations.

Sarcasm won't get you anywhere.

> I know when I'm not wanted <sob> goodbye cruel Perl world </sob>

Nonsense. You're being dramatic for no reason, and it's certainly not
endearing. It's pathetic. None of this has anything to do with you being
wanted or not. It has to do with being technically correct on a
technical newsgroup, and about following the guidelines of that group.
That means that if you talk about newline, that you make sure you've got
it right. It also means that you try to accept the normal posting and
quoting style of the group, and you use it.

If you can't live with these simple rules, then I do indeed suggest that
you stay away from Usenet. Or you go and sit in a corner and sulk. I
really don't care either way. But expect to be corrected when you post,
and accept it. Even people who've been posting here for years, and who
have far more Perl experience than you, still get corrected now and
again. I've never seen any of them react by sulking off or being
dramatic.

Get a thick skin. You need it on Usenet.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | 
Commercial Dynamics Pty. Ltd.   | "Mr Kaplan. Paging Mr Kaplan..."
NSW, Australia                  | 


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

Date: Sun, 4 Mar 2001 11:57:02 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Uploading a file
Message-Id: <Pine.LNX.4.30.0103041148580.1275-100000@lxplus003.cern.ch>

On Sun, 4 Mar 2001, Martien Verbruggen wrote:

> > "Alan J. Flavell" <flavell@mail.cern.ch> wrote in message
> > news:Pine.LNX.4.30.0102160249300.17336-100000@lxplus003.cern.ch...

> >> \n is not a "character", it's an end of line.  How that is represented
> >> is platform-dependent.

[...]
> >> In Perl, all lines end by definition in "\n", irrespective of
> >> platform.  But what that "\n" is, is platform-dependent.

> Yes, and \n is defined as the end of line. On some platforms that \x0a, on
> some that's \x0d, on some a combination of the two. But in Perl, the
> end-of line is a single character, "\n", no matter what the underlying
> OS thinks it should write to text files.

Point taken.  When I said '\n is not a character', I was trying to
stress that \n was not one specific character (just as you are doing).
As far as its behaviour in regard to lengths of strings, substring
comparison etc. it's clearly relevant to know its length.

Thanks for the clarification.

all the best



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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 411
**************************************


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