[22364] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4585 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 19 14:07:06 2003

Date: Wed, 19 Feb 2003 11:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 19 Feb 2003     Volume: 10 Number: 4585

Today's topics:
        -T problems <j.j.konkle-parker@larc.nasa.gov>
    Re: -T problems <noreply@gunnar.cc>
    Re: -T problems <nobull@mail.com>
        1 form insert into multiple tables <bob@vdpcorp.com>
    Re: 1 form insert into multiple tables <ubl@schaffhausen.de>
    Re: 1 form insert into multiple tables <bob@vdpcorp.com>
    Re: Bidir Array <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: Bidir Array <jurgenex@hotmail.com>
    Re: Bidir Array <branco@markdata.pt>
    Re: Compiling Perl with Intel Linux C++ Compiler (Christian)
    Re: Creating PDF files that include images <urael@zrgebcbyvf.arg.nh>
    Re: dbd-pg (postgres) on windows (Andrew Perrin (CLists))
        Dealing with a reference to a hash of references <mlm@nospam.com>
    Re: Dealing with a reference to a hash of references <nobull@mail.com>
    Re: Dealing with a reference to a hash of references <mlm@nospam.com>
    Re: Extracting patterns <remccart@uiuc.edu.spam>
        Free workshops and Open House <catac@digitalartschool.com>
    Re: how to join 2 text files sql style in perl (Domenico Discepola)
    Re: how to join 2 text files sql style in perl (Helgi Briem)
    Re: Input file format <rereidy@indra.com>
    Re: Input file format <nobull@mail.com>
        Is "123abc" a number? (John Brock)
        looping through arrays <roach01@cfl.rr.com>
    Re: Memory usage/cleanup & hashes <nobull@mail.com>
        net command <no.name@eidosnet.co.uk>
    Re: net command <nobull@mail.com>
        opendir question <cb@sebaw.com>
    Re: opendir question <nobull@mail.com>
        pipe() + fork() + exit() == problem? gordan@_NOSPAM_bobich.net
    Re: Regular Expression Noob <perl-dvd@darklaser.com>
    Re: Regular Expression Noob <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: Returning the field list from DBI (Jason Singleton)
    Re: Unsuccesful "Print" <nobull@mail.com>
    Re: Using different hashes. <spikey-wan@bigfoot.com>
        Variables from 'require' not initialized <j.j.konkle-parker@larc.nasa.gov>
    Re: Variables from 'require' not initialized <nobull@mail.com>
    Re: Variables from 'require' not initialized <rereidy@indra.com>
        Win32::internet (Gimler)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 19 Feb 2003 10:23:46 -0500
From: Joel Konkle-Parker <j.j.konkle-parker@larc.nasa.gov>
Subject: -T problems
Message-Id: <3E53A182.2000402@larc.nasa.gov>

What's wrong with this check?

----------
GetOptions ("inputfile|f=s" => \$inputfile);

if ($inputfile !~ /[^\w\.]/) {
   require $inputfile;
}
else {
   print "Invalid characters in filename\n";
   exit;
}
----------

- joel



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

Date: Wed, 19 Feb 2003 17:08:43 GMT
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: -T problems
Message-Id: <vSO4a.800$ID6.1903@newsc.telia.net>

Joel Konkle-Parker wrote:
> What's wrong with this check?
> 
> ----------
> GetOptions ("inputfile|f=s" => \$inputfile);
> 
> if ($inputfile !~ /[^\w\.]/) {

What is $inputfile expected to contain? The pure file name or the full 
path to the file? If the latter is the case, and provided that the file 
name may not include e.g. '-' or spaces, I suppose you'd better say:

     (my $filename = $inputfile) =~ s!.*[\\/]!!;
     if ($filename !~ /[^\w\.]/) {
       require $inputfile;

Also: Why did you choose the subject "-T problems"?

/ Gunnar

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



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

Date: 19 Feb 2003 17:42:25 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: -T problems
Message-Id: <u94r70goam.fsf@wcl-l.bham.ac.uk>

Joel Konkle-Parker <j.j.konkle-parker@larc.nasa.gov> writes:

> What's wrong with this check?

Nothing.

> ----------
> GetOptions ("inputfile|f=s" => \$inputfile);
> 
> if ($inputfile !~ /[^\w\.]/) {
>    require $inputfile;
> }

If you want to use tainted value $inputfile in a context requiring an
un-tainted value you should, of course, check that it is safe to
untaint $inputfile.  You must, however, then _actually_ _do_ _so_.

 if (($inputfile) = $inputfile =~ /^([\w\.]+)$/) {
    require $inputfile;
 }

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


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

Date: Wed, 19 Feb 2003 15:36:49 GMT
From: "Bob Van Der Ploeg" <bob@vdpcorp.com>
Subject: 1 form insert into multiple tables
Message-Id: <lwN4a.8966$bZ5.131625@twister.tampabay.rr.com>

Has anybody come up with a way to insert values from 1 input form into
multiple database tables?

--------------------
|    HTML form     |
| field_for_table 1  |
| field_for_table 2  |
| ...                        |
| field_for_table n  |
--------------------
        |  |
        V
Parse to %somehash
        | |
        V
mysql Database
----------      ----------       ----------
| Table 1 |      | Table 2 |       | Table n |
----------      ----------  ...  ----------







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

Date: Wed, 19 Feb 2003 16:40:43 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: 1 form insert into multiple tables
Message-Id: <b30bp7$k07$1@news.dtag.de>

Bob Van Der Ploeg wrote:
> Has anybody come up with a way to insert values from 1 input form into
> multiple database tables?

Yes, what is your problem?

->malte



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

Date: Wed, 19 Feb 2003 16:10:28 GMT
From: "Bob Van Der Ploeg" <bob@vdpcorp.com>
Subject: Re: 1 form insert into multiple tables
Message-Id: <U%N4a.9608$bZ5.135031@twister.tampabay.rr.com>

My insert script parses the data from the HTML form a single hash
%ele=mymodule::cgiparse();    {field->value}

Then then I pass the entire hash to an insert subroutine in my module
($last_insert_id)=mymodule::insert($ele{table},%ele);

I need a dynamic insert script that will parse the html form, and put the
values entered into the correct fields of multiple tables.

My problem is that I can figure out how to write the script without hard
coding the table names or manully create seperate hashes that corespond to
the colums in that table.

Thanks
Bob



"Malte Ubl" <ubl@schaffhausen.de> wrote in message
news:b30bp7$k07$1@news.dtag.de...
> Bob Van Der Ploeg wrote:
> > Has anybody come up with a way to insert values from 1 input form into
> > multiple database tables?
>
> Yes, what is your problem?
>
> ->malte
>
>




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

Date: Wed, 19 Feb 2003 14:07:27 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Bidir Array
Message-Id: <Xns9327992AF3A99elhber1lidotechnet@62.89.127.66>

Nuno Branco wrote:

> 
> I am trying to make a bidirectional array, been spending some time at
> google and perldoc.com and I'm surprised I didn't found what I am
> looking for. 
> 
> Basically what I want is to have something like @array[1][5] and
> access this, but I cannot find a way to do it.
> Can someone help me with some code or redirect me to nice
> documentation? 


I think what you're looking for is an array of arrays. If so have a look 
at:


  perldoc perlreftut
  perldoc perlref
  perldoc perldsc

 
-- 
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'



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

Date: Wed, 19 Feb 2003 15:08:24 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Bidir Array
Message-Id: <I5N4a.40883$rE3.17566@nwrddc01.gnilink.net>

Nuno Branco wrote:
> I am trying to make a bidirectional array,

What is a bidirectional array? I've never heard that term before.
Are you referring to a double-linked list maybe?

> been spending some time at
> google and perldoc.com and I'm surprised I didn't found what I am
> looking for.
>
> Basically what I want is to have something like @array[1][5] and
> access this, but I cannot find a way to do it.

That would be a two-dimensional array. In Perl it is known as array of
arrays (AoA) which however is a sloppy term for what actually is an array of
references to arrays.

You may want to check
perldoc perldata
perldoc perlreftut
perldoc perlref

jue




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

Date: Wed, 19 Feb 2003 15:35:13 +0000
From: Nuno Branco <branco@markdata.pt>
Subject: Re: Bidir Array
Message-Id: <SuN4a.3443$Ls7.1724445@newsserver.ip.pt>

bidirectional was a typo ... i was talking about bidimensional.
Either way i guess my problem is solved for the moment with:

my @array = (
[ 'one', 'two'] ,
[ '1' , '2'] ) ;


Jürgen Exner wrote:

> Nuno Branco wrote:
>> I am trying to make a bidirectional array,
> 
> What is a bidirectional array? I've never heard that term before.
> Are you referring to a double-linked list maybe?
> 
>> been spending some time at
>> google and perldoc.com and I'm surprised I didn't found what I am
>> looking for.
>>
>> Basically what I want is to have something like @array[1][5] and
>> access this, but I cannot find a way to do it.
> 
> That would be a two-dimensional array. In Perl it is known as array of
> arrays (AoA) which however is a sloppy term for what actually is an array
> of references to arrays.
> 
> You may want to check
> perldoc perldata
> perldoc perlreftut
> perldoc perlref
> 
> jue

-- 
Best Regards,
Nuno Branco




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

Date: 19 Feb 2003 07:09:13 -0800
From: cstaudinger@hotmail.com (Christian)
Subject: Re: Compiling Perl with Intel Linux C++ Compiler
Message-Id: <60b634ba.0302190709.1d9d4f50@posting.google.com>

Did you try to ask the question in the Intel C++ (for Windows and
Linux) user forum at
http://intel.forums.liveworld.com/forum.jsp?forum=160. Users and
Inel's C++ engineers are discussing different applications.

brundlefly76@hotmail.com (Seth Brundle) wrote in message news:<53e2ec95.0302182039.54ead4f4@posting.google.com>...
> I was wondering if anyone had successfully compiled Perl with this
> compiler.
> 
> A CERN scientist reports 30% faster executables with it (on Intel
> machines I would imagine), and good GNU compatibility.


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

Date: Thu, 20 Feb 2003 01:28:39 +1030
From: Henry <urael@zrgebcbyvf.arg.nh>
Subject: Re: Creating PDF files that include images
Message-Id: <urael-1A37A2.01283920022003@news.metropolis.net.au>

In article <l1u45vcj5but8fo8ufrpdd6ahetjf0s7v1@4ax.com>,
 Mark <mfowle@ATnavicominc.dropme.com> wrote:

> >> I nead to create PDF files using Perl
> >> 
> >> I have tried PDF::create which works but I can't include images using it.
> >> 
> >> Does anyone know how to do this
 ...
> I've just started using PDF::API2
> 
> it works great for creating PDF's, I've not aded an image yet, but the
> documentation seems to be straight forward. 

use PDF::API2;

$pdf = PDF::API2->new(-file=>"filename.pdf");
$page = $pdf->page($number);
$gfx = $page->gfx;
$img = $pdf->image("image.jpg");
$gfx->image($img, 0, 100, 264, 68);
$page->update;
$pdf->update;

exit;

> If you are going to bedoing alot of this.
> Perl Graphics Programing by O'Reilly, just came out it  is great
> ISBN 0-596-00219-x

Oh, yeah.

Henry.


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

Date: 19 Feb 2003 09:26:53 -0500
From: clists@perrin.socsci.unc.edu (Andrew Perrin (CLists))
Subject: Re: dbd-pg (postgres) on windows
Message-Id: <84r8a4jqhe.fsf@perrin.socsci.unc.edu>

swen <swen@news.com> writes:

> Hi,
> 
> I'm guessing someone here has probably used postgres with perl on
> windows. I'm having problems at DBI->connect. for example,
> 
> $dbh = DBI->connect('dbi:Pg:dbname=test','','');
> 
> dies with error:
> 
> "DBI->connect(dbname=test) failed: could not create socket: An address
> incompatible with the requested protocol was used"

It's been a while since I did this, but my best guess is that the DBI
is trying to use a unix socket to connect to the database. Since
Windows doesn't have unix sockets, you'd get a similar error to
that. Try, perhaps, putting an explicit hostname in the connection
string (localhost should do):

$dbh = DBI->connect('dbi:Pg:dbname=test;host=localhost','','') 
        or die $DBI->errstr;

-- 
----------------------------------------------------------------------
Andrew J Perrin - http://www.unc.edu/~aperrin
Assistant Professor of Sociology, U of North Carolina, Chapel Hill
clists@perrin.socsci.unc.edu * andrew_perrin (at) unc.edu


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

Date: Wed, 19 Feb 2003 11:44:52 -0600
From: mlm <mlm@nospam.com>
Subject: Dealing with a reference to a hash of references
Message-Id: <vi-dnVMweqEJX86jXTWcog@giganews.com>

I have two layers of references to deal with.  

$hash holds a reference to a hash.
The keys of the hash are integers.
The values of the hash are references to arrays.

I had no problem printing out the keys and values in unsorted order.

I create a sorted list of keys in @keys.

Now I want to print, in sorted order by key, each key followed by the 
first element of the array referenced by the value associated with the 
key.  I don't know how to do this.

So how do I find the first element of the array if I have the key?

Thanks for your help!
Mark


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

Date: 19 Feb 2003 17:53:48 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Dealing with a reference to a hash of references
Message-Id: <u9n0ksf977.fsf@wcl-l.bham.ac.uk>

mlm <mlm@nospam.com> writes:

> I have two layers of references to deal with.  
> 
> $hash holds a reference to a hash.
> The keys of the hash are integers.
> The values of the hash are references to arrays.
> 
> I had no problem printing out the keys and values in unsorted order.
> 
> I create a sorted list of keys in @keys.
> 
> Now I want to print, in sorted order by key, each key followed by the 
> first element of the array referenced by the value associated with the 
> key.  I don't know how to do this.

for my $key ( @keys ) {
   print "$key: $hash->{$key}[0]\n";
}

> So how do I find the first element of the array if I have the key?

The first element of an array is always the one with subscript 0
(unless you've been mucking with $[ ).

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


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

Date: Wed, 19 Feb 2003 12:22:43 -0600
From: mlm <mlm@nospam.com>
Subject: Re: Dealing with a reference to a hash of references
Message-Id: <LdacnRGxBpTuVs6jXTWcog@giganews.com>

Thank you kindly.  That worked, and I will now do some homework to try to 
figure it out.
Mark


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

Date: Wed, 19 Feb 2003 12:14:53 -0600
From: Ryan McCarthy <remccart@uiuc.edu.spam>
Subject: Re: Extracting patterns
Message-Id: <TLP4a.291$o7.4905@vixen.cso.uiuc.edu>

Jay, Gunnar, Benjamin:

Thanks for all your help.  Much appreciated.

Ryan McCarthy wrote:
> I am trying to extract to an array all the different permutations of a 
> string formatted like this:
> 
> ABCD(E|F)GHI...
> 
> Where this would produce an array with two entries
> 
> 1. ABCDEGHI
> 2. ABCDFGHI
> 
> The trick is that there can be 0 or more of these (X|Y) notations. 
> Anybody have any suggestions?
> 
> Thanks!
> 



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

Date: Wed, 19 Feb 2003 18:28:14 GMT
From: "CATAC" <catac@digitalartschool.com>
Subject: Free workshops and Open House
Message-Id: <21Q4a.4089$bK4.600327@ursa-nb00s0.nbnet.nb.ca>

Want to get a head start on a career in information technology, recordings
arts or 3D animation? Well then check out the upcoming open houses and
workshops at the Center for Arts and Technology Atlantic Canada.

We are located at 425 King St, Fredericton NB.

Please call (506)460-1280 or check out our website
http://www.digitalartschool.com  for more information!!

The Center for Arts and Technology, where dreams become reality.

catac@digitalartschool.com






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

Date: 19 Feb 2003 08:04:07 -0800
From: joeminga@yahoo.com (Domenico Discepola)
Subject: Re: how to join 2 text files sql style in perl
Message-Id: <698c67f.0302190804.1859a9f1@posting.google.com>

I appreciate everyone's honest opinion.  The reason that I didn't want
to use any external packages is that I was having problems getting
them to work (I don't wish to discuss this further, as this isn't the
purpose of this post).  My problem was solved using this code (I
manually wrote the code in this post so my apologies if I made any
syntax errors):

open(CUST, "<infile.txt") || die "Cannot open file1\n";
while ( <CUST> )
{	
   ( $field1, $field2a ) = split /,/, $_, 2;
   open(FDESC, "<infile2.txt"|| die "Cannot open file2\n";
   while ( <FDESC> )
   {
      ( $field2b, $field3 ) = split /,/, $_, 2;
      #the line below simulates the join
      if ( $field2a eq $field2b )
      {
         printf("%s|%s|%s\n", $field1, $field2a, $field3);
      }
   }
   close(FDESC);
}
close (CUST);

I also realize that some people may cringe at my method (especially
re-reading the inner file for every line in the outer file) but, given
the relatively small file sizes, this works "very well" and gets the
job done.  As you can probably tell, I don't consider myself a
programmer (and still consider myself a beginner with PERL).  However,
attacking problems from different angles, and with an open mind is
what the game (re-engineering processes) is all about.

I'm not knocking external modules - on the contrary, they've provided
me with enormous benefits. If someone else wishes to 'enhance' the
simple code I've provided (e.g. reading in files into an array for
instance), I wouldn't mind
;-)

helgi@decode.is (Helgi Briem) wrote in message news:<3e52617d.967732806@news.cis.dfn.de>...
> On 18 Feb 2003 07:04:39 -0800, joeminga@yahoo.com (Domenico
> Discepola) wrote:
> 
> >Spent many hours trying to solve my practical problem that I'm sure
> >would benefit others as well...  I have 2 text files (.csv) with a
> >common column in each file:
> 
> <SNIP>
> 
> >I prefer not using any external packages such as DBI, AnyData, etc.  I
> >was surprised to find a lack of postings / documentation on this so
> >any help would be greatly appreciated...
> 
> I suggest using DBI and DBD::CSV.    
> 
> "I prefer" is not a valid excuse for not doing the job 
> correctly.


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

Date: Wed, 19 Feb 2003 16:44:36 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: how to join 2 text files sql style in perl
Message-Id: <3e53ade0.1052830360@news.cis.dfn.de>

On 19 Feb 2003 08:04:07 -0800, joeminga@yahoo.com (Domenico
Discepola) wrote:

First of all, don't top-post.  It annoys the regulars and
*SEVERELY* reduces your chances of receiving useful
help. If you don't know what top-posting (TOFU) is, read
the following:
http://jargon.watson-net.com/jargon.asp?w=top%2Dpost

For further guidelines on how to post to 
comp.lang.perl.misc, read:
http://mail.augustmail.com/~tadmc/clpmisc.shtml

    For more information about netiquette in general, see
the "Netiquette Guidelines" at:

http://andrew2.andrew.cmu.edu/rfc/rfc1855.html


>helgi@decode.is (Helgi Briem) wrote in message news:<3e52617d.967732806@news.cis.dfn.de>...
>> I suggest using DBI and DBD::CSV.    
>> "I prefer" is not a valid excuse for not doing the job 
>> correctly.

Second, I wasn't joking when I suggested you use
the modules.  I wrote a program that did what you
asked for, but I'm not going to share it with you yet.

Why?  Because I thought of all the little things that
can go wrong and the reasons why the module
was written to solve those problems correctly and
reinventing the wheel is too much work and too
error prone.

Unless your code is written for educational purposes
only, use a module!

>I appreciate everyone's honest opinion.  The reason that I didn't want
>to use any external packages is that I was having problems getting
>them to work (I don't wish to discuss this further, as this isn't the
>purpose of this post).  

Well, I do and I am free to discuss whatever I bloody well
like.  Why don't you ask us how to install external modules
and get them to work?

Thousands of people have and been helped.  

>My problem was solved using this code (I  manually wrote the code 
>in this post so my apologies if I made any syntax errors):

Why should we excuse such a blatant breach of
netiquette?  Copy and paste working code, don't retype
it.  Why should we have to do a machine's work for
strangers?

While we're at it, you should do yourself a BIG favour
and enable warnings and strictures in your code.

You will thank yourself a million times over for letting
the computer do the job of searching for errors rather
than doing it yourself.

>open(CUST, "<infile.txt") || die "Cannot open file1\n";
>while ( <CUST> )
>{	
>   ( $field1, $field2a ) = split /,/, $_, 2;
>   open(FDESC, "<infile2.txt"|| die "Cannot open file2\n";
>   while ( <FDESC> )
>   {
>      ( $field2b, $field3 ) = split /,/, $_, 2;
>      #the line below simulates the join
>      if ( $field2a eq $field2b )
>      {
>         printf("%s|%s|%s\n", $field1, $field2a, $field3);
>      }
>   }
>   close(FDESC);
>}
>close (CUST);
>
>I also realize that some people may cringe at my method (especially
>re-reading the inner file for every line in the outer file)

Well, yes that is an awful, awful thing to do.  Use a hash
for the first file if you absolutely must do this by hand.  
(Let's pretend I didn't tell you how to do this, because I 
still maintain you should do it with modules.

>but, given
>the relatively small file sizes, this works "very well" and gets the
>job done.  As you can probably tell, I don't consider myself a
>programmer (and still consider myself a beginner with PERL).  However,
>attacking problems from different angles, and with an open mind is
>what the game (re-engineering processes) is all about.
>
>I'm not knocking external modules - on the contrary, they've provided
>me with enormous benefits. If someone else wishes to 'enhance' the
>simple code I've provided (e.g. reading in files into an array for
>instance), 

No, I wouldn't.  I would read them into a hash.

-- 
Regards, Helgi Briem
helgi AT decode DOT is


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

Date: Wed, 19 Feb 2003 09:23:44 -0700
From: Ron Reidy <rereidy@indra.com>
Subject: Re: Input file format
Message-Id: <3E53AF90.4030306@indra.com>

Think database.

Joel Konkle-Parker wrote:
> I need to create an input file format for my perl script that will allow 
> a user to input different numerical parameters, based on which the 
> script will perform different tasks, repeat certain steps, et c.
> 
> An example of what may need to be included in the input file:
> 
> wingspan = number
> chord = number
> grid type = text
> velocity = number
> angle of attack = number
> 
> et c., where any of these can have multiple values so the script can do 
> iterations.
> 
> So my question: what's the best input file format to use for this type 
> of thing? Easiest for me, the programmer? Easiest for the (professional) 
> user? Most flexible?
> 
> - Joel
> 



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

Date: 19 Feb 2003 17:43:11 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Input file format
Message-Id: <u9znosf9ow.fsf@wcl-l.bham.ac.uk>

Joel Konkle-Parker <j.j.konkle-parker@larc.nasa.gov> writes:

> I need to create an input file format for my perl script that will
> allow a user to input different numerical parameters, based on which
> the script will perform different tasks, repeat certain steps, et c.
> 
> An example of what may need to be included in the input file:
> 
> wingspan = number
> chord = number
> grid type = text
> velocity = number
> angle of attack = number
> 
> et c., where any of these can have multiple values so the script can
> do iterations.
> 
> So my question: what's the best input file format to use for this type
> of thing? Easiest for me, the programmer? Easiest for the
> (professional) user? Most flexible?

Perl

(perldoc -f do)

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


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

Date: 19 Feb 2003 13:22:23 -0500
From: jbrock@panix.com (John Brock)
Subject: Is "123abc" a number?
Message-Id: <b30i0v$9o2$1@panix1.panix.com>

In Perl 5.004 I find that the statement

	$x = "123abc" / 2;

sets $x to 61.5.  Is this a feature?  Testing with other values
the rule seems to be treat a string as a number up until you hit
a character which cannot be interpreted as part of a number, and
then ignore everything from there on (note that with the -w flag
I do get a warning message).  This would be useful to me if I knew
I could count on it, but I did a quick search of Programming Perl
(3rd Edition) and I couldn't find this behavior described.  Is this
an official part of the language?
-- 
John Brock
jbrock@panix.com



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

Date: Wed, 19 Feb 2003 18:02:30 GMT
From: "roach_01" <roach01@cfl.rr.com>
Subject: looping through arrays
Message-Id: <WEP4a.11223$cP3.134534@twister.tampabay.rr.com>

Hello!

I worling on a script that parses log files and finds start and end times
for
servers.

My problem is when more than one occurances happen for the same server.
What happens is my script only catches the first occurance.

 ...
foreach $b (keys %backup) {
    $id = $backup{$b};
    @1=grep/Node: $b)  Elapsed/ .. /time:/g,@log;
}

&parse_times if @1;

}


sub parse_times {
  @end=map { "@{[ (split)[1]]}" }$1[0] ;
  @elapse=map { "@{[ (split)[-1] ]}" }$1[1] ;

 .....
}

Now if @log has more than one instance of the server like this:

02/05/03 12:38:34 Node: SERVER1) Elapsed
processing time: 00:56:36
02/05/03 16:38:03 Node: SERVER1) Elapsed
processing time: 00:45:07
02/05/03 20:35:18 Node: SERVER1) Elapsed
processing time: 00:22:48

It would just pull the first.
Can anyone point me in the right direction on
looping through the array to find more than one of the same in the
array?
Thanks

-r





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

Date: 19 Feb 2003 17:46:13 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Memory usage/cleanup & hashes
Message-Id: <u9vfzgf9ju.fsf@wcl-l.bham.ac.uk>

Daniel Jaeggi <jaeggi@embl-heidelberg.de> writes:

> I've got a problem with a reasonably sized Perl program that can have some
> large and complex data structures (namely hashes of hashes (of hashes)).
> 
> The program runs well, produces all its output - the last line of code has
> been executed. Except that the process keeps on running, sometimes for
> quite a while...
> 
> I suspect that this is something to do with the use of the complex data
> structures and Perl's internal memory cleanup. Can anyone shed any more
> light on this problem?

Perl has to dismantle all the data structures bit by bit so that
DESTROY and END subroutines get done at the right time.  

> Is there any way of avoiding it (other than rewriting the code
> massively)? Is there any way to exit the script quickly (like
> hitting CTRL+C)?

POSIX::_exit

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


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

Date: Thu, 20 Feb 2003 03:21:11 -0000
From: "No Name" <no.name@eidosnet.co.uk>
Subject: net command
Message-Id: <3e53c688$0$5523$afc38c87@news.eidosnet.co.uk>

Hi,

Does anyone here know if it is possible to connect to netbios shares using
perl?

Basicaly i want to be able to simulate the windows "net" command if
possible.

If this is possible i would be grateful if you could point me in the
direction to how i go about this.

Thanks for your time


---
This e-mail has been virus scanned and is certified virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.443 / Virus Database: 248 - Release Date: 1/10/03




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

Date: 19 Feb 2003 18:07:57 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: net command
Message-Id: <u9el64f8jm.fsf@wcl-l.bham.ac.uk>

"No Name" <no.name@eidosnet.co.uk> writes:

> Does anyone here know if it is possible to connect to netbios shares using
> perl?
> 
> Basicaly i want to be able to simulate the windows "net" command if
> possible.
> 
> If this is possible i would be grateful if you could point me in the
> direction to how i go about this.

You can call the net command using system() or use the relevant
subroutine from Win32::* modules.  Looking in the manual is left as an
exercise for the reader.

Of course, most of the time, you are better off just using UNC.

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


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

Date: Wed, 19 Feb 2003 16:27:31 GMT
From: "Dartnagnan" <cb@sebaw.com>
Subject: opendir question
Message-Id: <SfO4a.4603241$6N5.614076@post-03.news.easynews.com>

This may be a silly question but how do you close a directory handle so you
can open a different one.

opendir(DH,$dir) || die "Couldn't open the current directory:$!";
while ($_ = readdir(DH)){
next if $_ eq "." or $_ eq "..";
my @test =  $_,;
my $test = $_;
copy ("$file", "$dir\\$test");

Once I do this want to do it again on a different directory.

Any thoughts or should I setup a sub routine to get the variables... but
then I would still need to close it before I get another one.

CB




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

Date: 19 Feb 2003 17:38:18 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: opendir question
Message-Id: <u98ywcgohh.fsf@wcl-l.bham.ac.uk>

"Dartnagnan" <cb@sebaw.com> writes:

> This may be a silly question 

It is.

> but how do you close a directory handle

If the function to open a directory handle is opendir() what would you
guess the function to close a directory handle would be called?!

Anyhow if you use autovivfing GLOBrefs rather than bare handles then
you just let the GLOBref go out of scope. 

> so you can open a different one.

There is no need.  Re-opening implicitly closes.

> opendir(DH,$dir) || die "Couldn't open the current directory:$!";
> while ($_ = readdir(DH)){
> next if $_ eq "." or $_ eq "..";
> my @test =  $_,;
> my $test = $_;
> copy ("$file", "$dir\\$test");


What are the variables $test and @test for?

Why is "$file" in quotes?

Why is there a dangling comma on the assignment of @test?

Why does the error message say "Couldn't open the current directory"
when it tries to open $dir (not '.')?  Isn't that just a tiny bit
confusing?

> Once I do this want to do it again on a different directory.
> 
> Any thoughts or should I setup a sub routine to get the variables... but
> then I would still need to close it before I get another one.

That makes no sense.

I'm not sure what you wanted to ask but the answer will
probably be either:

 1) Use autovivfing GLOBrefs rather than bare handles: 
    opendir( my $dh, $dir) or die "...: $!";
 2) use File::Find;

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


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

Date: Wed, 19 Feb 2003 17:06:30 +0000
From: gordan@_NOSPAM_bobich.net
Subject: pipe() + fork() + exit() == problem?
Message-Id: <Pine.LNX.4.44.0302191647140.29590-100000@skynet.shatteredsilicon.net>

Hi!

Got a small problem. I'm trying to write an application that regulates the 
number of forked children according to it's outstanding workload (within 
limits, obviously).

I use pipes to communicate the process queue between the queue process and 
the worker processes. There is one pipe for writing to the queue, and one 
pipe for the forked worker threads to read from. This method works very 
nicely, and I'd like to keep it.

But, the problems start when it's time for some of the worker  
processes to die out. As soon as they exit, the pipe they use to read 
from queue (and probably the one they use to write to the queue, but I 
haven't checked that yet) seems to flush and re-set. All of it's contents 
are gone, and now my queued jobs are lost.

I looked around and thought that this is caused by the close-on-exec flag 
being set on pipes. I did a

local $^F = 65536;

in the constructor just before the pipes are created, and that seems to 
have cleared the flag, but the problem still persists.

The way the forking and reaping process works is that the main thread 
forks some initial number of worker processes. If over-capacity is 
detected, workers will exit, and the main thread will not re-fork more 
until under-capacity is detected.

As far as I can tell, the pipe flush/re-set happens at exit() point, but I 
could be wrong, in that it could be happening at the point where a new 
process is forked.

Is there any way to preserve the content of the pipes during the exit and 
re-fork process of some of the child processes?

If not, what similar alternatives are available? I have considered using 
more communication between the queue and the workers where each job is 
requested separately, on separate pipes to each process, but I don't 
really like the idea of using a separate pipe pair between each worker and 
the queue.

Other things that come to mind are using sockets instead of 
pipes, but the socketpair() functionality seems eerily similar to pipe(), 
so I'm afraid that it will have the same problem.

Finally, I've thought about mapping a pair of scalars into a piece of 
shared memory and using them as a queue. This seems really daft because it 
kind of re-invents the pipe in a different, less efficient way. OTOH, it 
could be useful because the size of the "pipe" is now not limited and 
explicitly set by the file system. Unfortunately, expect it to be quite 
CPU intensive with the copy-edit-restore required when working with shared 
memory in Perl...

Does anyone have any suggestions regarding the best course of action?

TIA.

Gordan



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

Date: Wed, 19 Feb 2003 14:28:42 GMT
From: "David" <perl-dvd@darklaser.com>
Subject: Re: Regular Expression Noob
Message-Id: <uwM4a.34$F6.8301@news-west.eli.net>

"Abigail" <abigail@abigail.nl> wrote in message
news:slrnb54tcr.263.abigail@alexandra.abigail.nl...
> David (perl-dvd@darklaser.com) wrote on MMMCDLVIII September MCMXCIII
in
> <URL:news:gxt4a.25$F6.6438@news-west.eli.net>:
> []
> []  my @ani_list = $string =~ /ANI\=(\d+)/g; # untested
>
>
> Why did you escape the equal sign?

Sorry, bad habit (escape any special characters).

David




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

Date: Wed, 19 Feb 2003 14:30:38 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Regular Expression Noob
Message-Id: <Xns93279D184CCE3elhber1lidotechnet@62.89.127.66>

David wrote:

> "Abigail" <abigail@abigail.nl> wrote in message
> news:slrnb54tcr.263.abigail@alexandra.abigail.nl...
>> David (perl-dvd@darklaser.com) wrote on MMMCDLVIII September MCMXCIII
> in
>> <URL:news:gxt4a.25$F6.6438@news-west.eli.net>:
>> []
>> []  my @ani_list = $string =~ /ANI\=(\d+)/g; # untested
>>
>>
>> Why did you escape the equal sign?
> 
> Sorry, bad habit (escape any special characters).


But the point is that '=' is not a special character. :)


-- 
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'



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

Date: 19 Feb 2003 06:29:41 -0800
From: jsn@microlib.demon.co.uk (Jason Singleton)
Subject: Re: Returning the field list from DBI
Message-Id: <5b7e0283.0302190629.7c5b62c8@posting.google.com>

Thaks for the feedback luckily I'm using a fixed configuration which
is using MySQL so I can use the LIMIT option and luckily the data
never changes in peek periods so the result set won't change and the
table structure never changes so it looks like the ideal thing to use.

Thanks to the otheres on the field name part have got that working now
:)


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

Date: 19 Feb 2003 17:49:50 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Unsuccesful "Print"
Message-Id: <u9r8a4f9dt.fsf@wcl-l.bham.ac.uk>

"Mikey" <PleaseDontThrowSpam@Me.com> writes:

> "Jay Tilton" <tiltonj@erols.com> wrote in message
> news:3e52f4e4.32989123@news.erols.com...
>
> >     our($opt_h, $opt_a);
> 
> If I do this, I get errors:
> 
> Global symbol "$opt_a" requires explicit package name at ./perlfile
> Global symbol "$opt_h" requires explicit package name at ./perlfile

> It's being run by Perl, version 5.005_03 built for sun4-solaris

our() was intrduced in 5.6.

In 5.5 change it to:

  use vars qw( $opt_h $opt_a);

Note: 5.5 is very old.  The current Perl is 5.8.

BTW: Do you have permission from the owner of the domain me.com to use
it in your From headers?

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


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

Date: Wed, 19 Feb 2003 16:38:49 -0000
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Re: Using different hashes.
Message-Id: <b30c0f$3o5$1@newshost.mot.com>

> > Really, though, your data structures are awkward. There's probably
> > a better way to organize your data that would make the code much
> > cleaner.
>
> That's more or less why I posted an example illustrating an idea rather
> than modifying the OP's code.  Alternately, I was too lazy to try and
> figure out which parts to change.  :-)

Thanks. I'll look at my structure, I think ;-)

R.




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

Date: Wed, 19 Feb 2003 12:53:10 -0500
From: Joel Konkle-Parker <j.j.konkle-parker@larc.nasa.gov>
Subject: Variables from 'require' not initialized
Message-Id: <3E53C486.7000903@larc.nasa.gov>

I have a script that calls an input file to load certain variables. When 
I run it, though, it always comes back with 'variable not initialized' 
errors. Is there something I'm missing here?

Script:
----------
#!/bin/perl -wT

push (@INC, ".");

use strict;
use Getopt::Long;
use Math::Trig;

my ($inputfile, $filename, $rawfilename, $span, $outboard_chord, 
$grid_type, $velocity, $aoa_degrees, $aoa);
$ENV{PATH} = "/bin:/usr/local/bin:/ump/fldmd/home/joeljkp/pmarc/exe";


#####################
# Argument handling
#####################


GetOptions ("filename|f=s" => \$inputfile);

if ($inputfile =~ /^([-\w.]+)$/) {
   $inputfile = $1;
   require $inputfile;
}
else {
   die "Invalid characters in filename\n";
}

print $span;

 .
 .
 .
more
 .
 .
 .
----------

Input file:
----------
$rawfilename = 'temp';  # Filename for script output files (no 
extension, no periods)
$span = 10.0;           # Wingspan (inboard chord is 1.0000)
$outboard_chord = 0.5;  # Outboard chord length (inboard chord is 1.0000)
$grid_type = 'ss';      # Grid type (ss = structured surface, sv = 
structured volume, uv = unstructured volume)
$velocity = 100.0;      # Velocity (m/s)
$aoa_degrees = 0.0;     # Angle of attack (degrees)

1;
----------

Any ideas?

- Joel



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

Date: 19 Feb 2003 18:05:27 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Variables from 'require' not initialized
Message-Id: <u9isvgf8ns.fsf@wcl-l.bham.ac.uk>

Joel Konkle-Parker <j.j.konkle-parker@larc.nasa.gov> writes:

> I have a script that calls an input file to load certain
> variables. When I run it, though, it always comes back with 'variable
> not initialized' errors.

No it does not.

The error message is actually "Use of uninitialized value".  Now
actually the phrase "uninitialized value" is nonsensical.  Most people
subconciously read it as "uninitialized variable".  Actually it should
be read as "undefined value".  Just to cloud the issues, it just so
happens that in this _particular_ case the reason that there is an
undefined value is because a variable has not been initialized.

> Is there something I'm missing here?

The fact that lexically scoped variables are _lexically_ _scoped_.

When you declare a variable with my() the scope of the declaration is
from the end of the current statment to the end of the current lexical
scope.  i.e. until the first unmatched '}' in the _current_ source
file.

If you process another file with require() or do() then that file is
processed in a fresh lexical scope.
 
If you want a file included with requre to alter variable in the
calling environment you need to be using package scoped variables.

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


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

Date: Wed, 19 Feb 2003 11:17:15 -0700
From: Ron Reidy <rereidy@indra.com>
Subject: Re: Variables from 'require' not initialized
Message-Id: <3E53CA2B.50804@indra.com>

Looks like a scoping problem.

Joel Konkle-Parker wrote:
> I have a script that calls an input file to load certain variables. When 
> I run it, though, it always comes back with 'variable not initialized' 
> errors. Is there something I'm missing here?
> 
> Script:
> ----------
> #!/bin/perl -wT
> 
> push (@INC, ".");
> 
> use strict;
> use Getopt::Long;
> use Math::Trig;
> 
> my ($inputfile, $filename, $rawfilename, $span, $outboard_chord, 
> $grid_type, $velocity, $aoa_degrees, $aoa);
Do not declare the variables from your input file.

> $ENV{PATH} = "/bin:/usr/local/bin:/ump/fldmd/home/joeljkp/pmarc/exe";
> 
> 
> #####################
> # Argument handling
> #####################
> 
> 
> GetOptions ("filename|f=s" => \$inputfile);
> 
> if ($inputfile =~ /^([-\w.]+)$/) {
>   $inputfile = $1;
>   require $inputfile;
> }
> else {
>   die "Invalid characters in filename\n";
> }
> 
> print $span;
> 
> .
> .
> .
> more
> .
> .
> .
> ----------
> 
> Input file:
> ----------
> $rawfilename = 'temp';  # Filename for script output files (no 
> extension, no periods)
> $span = 10.0;           # Wingspan (inboard chord is 1.0000)
> $outboard_chord = 0.5;  # Outboard chord length (inboard chord is 1.0000)
> $grid_type = 'ss';      # Grid type (ss = structured surface, sv = 
> structured volume, uv = unstructured volume)
> $velocity = 100.0;      # Velocity (m/s)
> $aoa_degrees = 0.0;     # Angle of attack (degrees)
> 
> 1;
> ----------
> 
> Any ideas?
> 
> - Joel
> 



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

Date: 19 Feb 2003 07:16:25 -0800
From: gimler@gmx.de (Gimler)
Subject: Win32::internet
Message-Id: <43bf4daf.0302190716.402d0183@posting.google.com>

how can i kill the internet conection?

		$INET = new Win32::Internet();
		$INET->OpenURL($URL, "http://www.bla.de/gimler/");
		$bytes = $URL->QueryDataAvailable();
		$file = $URL->ReadEntireFile();
		#print $file, "\n";
		$INET->Close();

With $INET = new Win32::Internet(); can i open the connection but i can´t close it.

It must work with Win98/2000/XP. Can you help me.


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

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


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