[24546] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6724 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 24 14:05:36 2004

Date: Thu, 24 Jun 2004 11:05:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 24 Jun 2004     Volume: 10 Number: 6724

Today's topics:
    Re: [Newbie] Stupid problem need simple answer (Array & <nobull@mail.com>
        [SortofNewbie] Addusers with script on crontab <hotten@zonnet.nl>
    Re: [SortofNewbie] Addusers with script on crontab <noreply@gunnar.cc>
    Re: Find length of files <postmaster@castleamber.com>
    Re: Graphs using perl <postmaster@castleamber.com>
    Re: help with perl dbi and update without locks <jcharth@hotmail.com>
    Re: Help! - Need a CGI redirect which passes a querystr (Randal L. Schwartz)
    Re: Help! - Need a CGI redirect which passes a querystr <noreply@gunnar.cc>
    Re: how add the multi, or arbitrary precision capabilit (Jack)
        Logfile scanning assistance <squidsonata@hotmail.com>
    Re: Logfile scanning assistance <jgibson@mail.arc.nasa.gov>
        LWP <abc@microsoft.com>
        problem to setup a socket (Lim kiang Leng)
        Strange Behaviour with Hash??? <fergus.toolan@ucd.ie>
    Re: Strange Behaviour with Hash??? <noreply@gunnar.cc>
    Re: Strange Behaviour with Hash??? <mritty@gmail.com>
    Re: Using closures with "use strict" <this.is@invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 24 Jun 2004 17:54:03 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: [Newbie] Stupid problem need simple answer (Array & RegExp)
Message-Id: <u9u0x0gams.fsf@wcl-l.bham.ac.uk>

"Daedalus" <daedalus@videotron.ca> writes:

> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> a écrit dans le message de
> news: cbeg3h$gii$2@mamenchi.zrz.TU-Berlin.DE...
> > Thomas Kratz  <ThomasKratz@REMOVEwebCAPS.de> wrote in comp.lang.perl.misc:
> > > Anno Siegel wrote:
> > >
> > > >
> > > > Your code (in all variants) has another problem.  You are not supposed
> > > > to change an array while running a for-loop over it.  (See "foreach"
> in
> > > > perlsyn, I suppose.)  That it appears to work in this instance doesn't
> > > > mean it will with other versions of Perl.
> > >
> > > AFAIK you are not supposed to change the array, but changing the aliased
> > > elements should be ok.
> > >
> > > so:
> > >
> > > push(@array, $_) for @array # not recommended
> > >
> > > s/A/B/g for @array          # ok
> > >
> > > Right?
> >
> > Right.
> 
> Well the problem is that s///g don't do what I want, since it change every
> thing at the same time.

If you only want to change the first occurance in each string then
remove the /g.

If you want to append the changed version of the array to the original
array then why not:

  s/A/B/g for my @array_copy = @array;
  push @array, @array_copy;

> Anyway (for now) it couldn't turn into an infinite loop, since the content
> of the loop...

I asume you are talking about the effect of pushing into @array at the
same time with for().

How do you know that?  

Bare in mind that the behaviour of for() when iterating over an array
that grows or shrinks is _undefined_.  Undefined means anything could
happen, and also the thing that happens now may not be the thing that
happens in the next version of Perl.

If tomorrow the behaviour of pushing onto the array was to cause the
loop to reset to the start of the array then it could very well create
an infinite loop.

> I know it's not the perfect solution (and I'll try to find a better way
> while i'm on my learning process), so if someone have any idea... I'd be
> glad to correct this misuse.

See several better solutions already given in this thread.

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


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

Date: Thu, 24 Jun 2004 19:51:56 +0200
From: "Henk" <hotten@zonnet.nl>
Subject: [SortofNewbie] Addusers with script on crontab
Message-Id: <40db12f5_14@Output.100ProofNews.com>

Ok guy's i need some help i have to create allot of users on an new
webserver (also the must have ftp access vistualhost and so on) i've got an
script allready but there comes an new user (and here it comes) i don't know
how to check if the username already exists in linux and perl how can i do
this ? is there any one who allready has done thius please show me an
snippet of that code ;)

Many thnx...




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

Date: Thu, 24 Jun 2004 19:58:05 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: [SortofNewbie] Addusers with script on crontab
Message-Id: <2k0j4kF16jbckU1@uni-berlin.de>

Henk wrote:
> Ok guy's i need some help i have to create allot of users on an new
> webserver (also the must have ftp access vistualhost and so on)
> i've got an script allready but there comes an new user (and here
> it comes) i don't know how to check if the username already exists
> in linux and perl how can i do this ? is there any one who allready
> has done thius please show me an snippet of that code ;)

Unfortunately I don't have such a script.

Where can I sign up for an account on your server?

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Thu, 24 Jun 2004 11:26:07 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Find length of files
Message-Id: <40db009f$0$864$58c7af7e@news.kabelfoon.nl>

Rusty Phillips wrote:

>>Uhm, I guess for every file you have to fork, so I doubt it.
>>
> You only have to run wc once ("wc -w *"), so there should only be one
> fork.  Because wc is a compiled program designed especially for this

Ah, indeed. Getting rusty ;-)

-- 
John                               MexIT: http://johnbokma.com/mexit/
                            personal page:       http://johnbokma.com/
    Experienced Perl programmer available:     http://castleamber.com/
             Happy Customers: http://castleamber.com/testimonials.html


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

Date: Thu, 24 Jun 2004 11:24:10 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Graphs using perl
Message-Id: <40db002b$0$864$58c7af7e@news.kabelfoon.nl>

Ram Laxman wrote:

> Hi all,
>        I am having the csv file.Does anybody knows how to make a bar
> graph/chart extracting some fields from the csv file?
> 
> For exp:
> 
> "empno","age","sal"
>  1,23,10000
>  2,3,5
> 
> I want to plot a graph between empno and sal. 

On Windows, and if you have Excel, use Win32::OLE;
I think there is a way to interface with Open Office, but never looked 
into it.

-- 
John                               MexIT: http://johnbokma.com/mexit/
                            personal page:       http://johnbokma.com/
    Experienced Perl programmer available:     http://castleamber.com/
             Happy Customers: http://castleamber.com/testimonials.html


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

Date: Thu, 24 Jun 2004 17:12:31 GMT
From: joe <jcharth@hotmail.com>
Subject: Re: help with perl dbi and update without locks
Message-Id: <Xns951285BE5CF6Ajosephthecianet@207.69.154.202>

thanks for the replies. 
i am glad i got the idea thourgh. i am considering a couple alternatives, i 
want to use standar sql because this is the only small glitch that would 
not allow my run the script in mysql mssql and oracle. 
1. set a table for each user
2. combine the sql insert and the select max pk statements into one.
3. leave it the way it is a dig a couple of errors here and there
4. use SET TRANSACTION ISOLATION LEVEL SERIALIZABLE


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

Date: Thu, 24 Jun 2004 15:41:48 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Help! - Need a CGI redirect which passes a querystring  value
Message-Id: <b81a63ea92afdff7d2869fb34ed0b937@news.teranews.com>

>>>>> "Gunnar" == Gunnar Hjalmarsson <noreply@gunnar.cc> writes:

Gunnar> Don't take for granted that mod_perl is an available option. The OP in
Gunnar> this thread used the wording "the Windows server I am hosted on".

mod_perl works fine on Windows Apache.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Thu, 24 Jun 2004 18:42:47 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Help! - Need a CGI redirect which passes a querystring  value
Message-Id: <2k0enaF16dmffU1@uni-berlin.de>

Randal L. Schwartz wrote:
> Gunnar Hjalmarsson wrote:
>> Matt Garrish wrote:
>>> Both mod_perl and aspx scripts only need to compile once (and
>>> with mod_perl you can precompile the modules).
>> 
>> Don't take for granted that mod_perl is an available option. The
>> OP in this thread used the wording "the Windows server I am
>> hosted on".
> 
> mod_perl works fine on Windows Apache.

You misunderstood me, Randal. "Hosted" was the intended keyword. It's
(unfortunately) very unusual that mod_perl is available to web sites
on shared servers (whether the platforms are *nix or Windows).

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 24 Jun 2004 08:27:12 -0700
From: jack_posemsky@yahoo.com (Jack)
Subject: Re: how add the multi, or arbitrary precision capability to perl programs
Message-Id: <209b7e58.0406240727.10285e1f@posting.google.com>

Paul Lalli <mritty@gmail.com> wrote in message news:<20040623131727.B23512@dishwasher.cs.rpi.edu>...
> On Wed, 23 Jun 2004, Jack wrote:
> 
> > Greetings, I am trying to work beyond 15 floating pt decimal places in
> > my perl calculations, wondering where to find info on how display and
> > calculate at a higher level of precision.. is it a special library ?
> 
> Have a look at
> perldoc Math::BigFloat
> 
> That might do what you want.
> 
> Paul Lalli

Thank you very much .. I tried using this, and not being a Perl
expert, have a few questions b/c it is not clear...I am running an
equation that is iterative, and my basic request is to print and
calculate precision > 15 floating point..So I added this code around
my critical variables at the top of my program..

use Math::BigFloat;
Math::BigFloat->precision(30);
$x = Math::BigFloat->new($str);
$x->precision(30);

And it doesnt provide what I seeking, any tips from the experts out
there on how to precisionify a program's variables ?

Thanks and Regards,

Jack


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

Date: Thu, 24 Jun 2004 11:39:25 -0400
From: Jim <squidsonata@hotmail.com>
Subject: Logfile scanning assistance
Message-Id: <cbesj5$1kl$1@gargoyle.oit.duke.edu>

Hi

I have a logfile where I need to do the following:

1. Scan the logfile
2. If a date and time are found at the beginning of a line
   a. Check 8 lines below, if the 8th line below has the following string
   "Foo", then
     i. save the date/time from Step 2 in alternate logfile
     ii. save the 8th line down in alternate logfile
3. Continue scanning logfile/repeat

Perl is not my speciality, so if anyone has any suggestions on how best 
to accomplish this, it would be greatly appreciated.  Thanks.

Jim



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

Date: Thu, 24 Jun 2004 09:26:10 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Logfile scanning assistance
Message-Id: <240620040926101402%jgibson@mail.arc.nasa.gov>

In article <cbesj5$1kl$1@gargoyle.oit.duke.edu>, Jim
<squidsonata@hotmail.com> wrote:

> Hi
> 
> I have a logfile where I need to do the following:
> 
> 1. Scan the logfile

The following suggestions are untested and may not be complete or
error-free:

Put at the top of your program:

   #!/path/to/perl    <- use what is suitable on your system
   use strict;
   use warnings;

Use the open function to open the logfile. Type 'perldoc -f open' at a
command line to get information on the open function. Test to make sure
the open worked. Something like:

   my $logfile = 'test.log';
   open( LOG, $logfile ) or die("Can't open $logfile: $!");

Open an alternate logfile:

   my $newfile = 'new.log';
   open( NEW, ">$newfile" ) or die("Can't open $newfile for ouput: $!");

Read the file one line at a time into the default variable $_ in a loop:

   while( <LOG> ) {

> 2. If a date and time are found at the beginning of a line

Use a regular expression to match your date format and capture the date
at the same time (the following looks for and captures a date of the
type 01/02/2004 anywhere in the line). Note the use of alternate
regular expression delimiters to avoid escaping slashes expected in the
date:

      if( m|(\d{2}/\d{2}/\d{4})| ) {
         my $date = $1;

See 'perldoc perlre' for more information on regular expressions.

>    a. Check 8 lines below, if the 8th line below has the following string
>    "Foo", then

Read 8 more lines from the file:

         <LOG> for 1..8;

You will need to something different than the above if you worry about
a premature end of file, but I leave that as an exercise.

Test to see if last line read contains 'Foo':

         if( /Foo/ ) {

>      i. save the date/time from Step 2 in alternate logfile
---------------------------------------^ Step 1?

Write the date to the new file

            print NEW "$date\n";

>      ii. save the 8th line down in alternate logfile

            print NEW;
(print defaults to the $_ variable):


> 3. Continue scanning logfile/repeat

         }
      }
   }

   close(LOG);
   close(NEW);

> 
> Perl is not my speciality, so if anyone has any suggestions on how best 
> to accomplish this, it would be greatly appreciated.  Thanks.

There are improvements that could be done, of course, but this should
be enough to get you started.

If you run into trouble, post your code here. Make sure it compiles
correctly, and describe what it is doing and what you want it to do
instead.


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

Date: Thu, 24 Jun 2004 17:43:46 GMT
From: "Indigo5" <abc@microsoft.com>
Subject: LWP
Message-Id: <HztqKy.61y@news.boeing.com>





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

Date: 24 Jun 2004 10:33:45 -0700
From: kiangleng@hotmail.com (Lim kiang Leng)
Subject: problem to setup a socket
Message-Id: <4282e185.0406240933.6016ad1d@posting.google.com>

I am new to try up the socket programming, I try to set up a socket in
my company but seem like it failed. Althught , it know the present of
the server, but seem like they cant talk. Below is my server and
client's program. Is any one know why i failed to communicate?


########
#server#
########
print "prgram is in running ... \n" ;
use IO::Socket;
 my $sock = new IO::Socket::INET (
 LocalHost => 'machine.mycompany.com',
 LocalPort => '7000',
 Proto => 'tcp',
 Listen => 1,
 Reuse => 1,
 );
die "Could not create socket: $!\n" unless $sock;
my $new_sock = $sock->accept();
print "$_" ;
while(defined(<$new_sock>)) {
print $_;
}
close($sock);




########
#client#
########

use IO::Socket;
print "programming " ;
my $sock = new IO::Socket::INET (
                                   PeerAddr =>
'machine.mycompany.com',
                                   PeerPort => '7000',
                                   Proto => 'tcp',
                                  );
  die "Could not create socket: $!\n" unless $sock;
  print $sock "Hello there!\n";
  close($sock);


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

Date: Thu, 24 Jun 2004 18:44:11 +0100
From: Fergus Toolan <fergus.toolan@ucd.ie>
Subject: Strange Behaviour with Hash???
Message-Id: <newscache$k7nuzh$i43$1@weblab.ucd.ie>

Hi all,
We're currently writing some scripts that deal with hashs and are 
getting some strange behaviour with them. We have very little experience 
with dealing with hashs so I want to check something.

Is it correct to assign one hash to another? For instance

%H1 = %H2;

I want the hashs to be distinct. Will the above statement completely 
overwrite the current contents of %H1?

Any comments would be much appreciated
Regards
Fergus



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

Date: Thu, 24 Jun 2004 19:54:16 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Strange Behaviour with Hash???
Message-Id: <2k0iteF16m0jgU1@uni-berlin.de>

Fergus Toolan wrote:
> Is it correct to assign one hash to another? For instance
> 
> %H1 = %H2;

Yes.

> I want the hashs to be distinct. Will the above statement
> completely overwrite the current contents of %H1?

Yes.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Thu, 24 Jun 2004 13:58:32 -0400
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Strange Behaviour with Hash???
Message-Id: <20040624135340.Y23512@dishwasher.cs.rpi.edu>

On Thu, 24 Jun 2004, Fergus Toolan wrote:

> Hi all,
> We're currently writing some scripts that deal with hashs and are
> getting some strange behaviour with them. We have very little experience
> with dealing with hashs so I want to check something.
>
> Is it correct to assign one hash to another?

'correct' is a relative term.  It depends on what you want to do.

> For instance
>
> %H1 = %H2;
>
> I want the hashs to be distinct.

They will not necessarily be completely individual entities.  If %H2's
values are references to other data (as in multi-level data structures
like hash of hashes or hash of arrays, or even just references to other
scalar data), those references will be copied.  The data will not.  For
example, if $H2{'arr'} = \@array, then after the assignment, $H1{'arr'}
will also be a reference to @array.  Any changes you make to @{$H1{'arr'}}
will be reflected in @{$H2{'arr'}}.

There are a couple ways of creating fully independent structures.  The one
I'm remembering right now is via a module called Clone.  Look for it at
search.cpan.org

> Will the above statement completely overwrite the current contents of %H1?

Yes.  Any prior contents of %H1 are gone from that hash, and cannot be
accessed throw $H1{'(anything)'}.

> Any comments would be much appreciated

Perhaps if you told us exactly what the strange behavior was that you're
seeing, we could help you more effectively diagnose the problem.

Paul Lalli


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

Date: Thu, 24 Jun 2004 19:44:03 +0200
From: ddtl <this.is@invalid>
Subject: Re: Using closures with "use strict"
Message-Id: <4a4md05q6vhcdvblm4l10n3qikvoihjpf9@4ax.com>


>> -------------------------------------------
>> use strict;
>> 
>> {
>>      our $f = sub {print "Hi\n";};
>>}
>> 
>> &$f;
>> -------------------------------------------
>
>That doesn't fit my idea of a closure. It's just a code reference. 
>As you noted, the code above is broken because variables declared 
>with our() are lexically scoped. 
>
>A closure (as I understand it) is a subroutine that keeps track of 
>lexical variables that are within scope when that subroutine is 
>defined, so that later it can still access those variables even 
>though they're out of the present scope.

You are right of course - this is not actually a closure, but  was just too 
lazy to type the whole ~10 more characters to provide anonymous sub
with it's "personal" scoped variables :). Anyway, the question was clearly
understood by everybody, despite of my lazyness.

ddtl.


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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