[22067] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4289 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 19 14:05:55 2002

Date: Thu, 19 Dec 2002 11:05:11 -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           Thu, 19 Dec 2002     Volume: 10 Number: 4289

Today's topics:
        ActiveState ppm packages <linuxnb@yahoo.com>
    Re: Arguing about the advantage of Perl <uri@stemsystems.com>
    Re: Configuration INC under Windows <noemail@nowhere.net>
    Re: csv file to mysql import <jeff@vpservices.com>
    Re: csv file to mysql import <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
    Re: csv file to mysql import <GPatnude@adelphia.net>
    Re: csv file to mysql import <nobull@mail.com>
    Re: Extracting last element from a list <GPatnude@adelphia.net>
    Re: Hard Anodized  11665 <Graham.T.Wood@oracle.com>
    Re: help:  perl script to make all DNA sequence Nmers? ctcgag@hotmail.com
        Internet  SQLstore available (laffle)
        Localising large data structures to a sub <simon.andrews@bbsrc.ac.uk>
    Re: Localising large data structures to a sub <palladium@spinn.net>
    Re: Localising large data structures to a sub <nobull@mail.com>
    Re: Localising large data structures to a sub <uri@stemsystems.com>
    Re: perl script to capture streaming audio <control153@NOSPAMyahoo.com>
    Re: Replacing text strings contains more than 1 dot (raj)
    Re: splitting array, each element holding multiple valu <jurgenex@hotmail.com>
    Re: splitting array, each element holding multiple valu <GPatnude@adelphia.net>
    Re: splitting array, each element holding multiple valu <uri@stemsystems.com>
        Stat() function not working.  Kind of... (Mac)
    Re: Stat() function not working.  Kind of... (Tad McClellan)
        Sys Adminy Advice Requested <lou.moran@gellerandwind.com>
    Re: Tracking User's OS type? <jurgenex@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 19 Dec 2002 17:40:23 GMT
From: matt <linuxnb@yahoo.com>
Subject: ActiveState ppm packages
Message-Id: <bwnM9.398211$P31.145818@rwcrnsc53>

Hi people,

Just wondering if anyone can help me out with PPM. I am going on a trip, and 
I won't have Internet access. I downloaded all of the Active State perl 
 .ppd files, and the associated tarballs to my laptop so that I would have 
all of the modules I might need during my trip. The problem is that I am 
not running ActiveState perl. I am running the perl that came with my 
Mandrake Linux 9.0 distro - v5.8.0 built for i386-linux-thread-multi.

I installed PPM, and added the local directory as a repository. The problem 
is the architechture. PPM fails because it says that there are no valid 
architectures found. It wants perl 5.8.0 built for i686-linux-thread-multi. 
Is there a big difference here? Can I get away with installing these 
modules? 

The .ppd files all have the following line in them:

<ARCHITECTURE NAME="i686-linux-thread-multi-5.8" />

Can I just change the 'i686' to 'i386'? I haven't tried it yet, because I 
don't want to break anything. I thought I would check with the guru's 
first.

Of course I could just install ActiveState perl and be done with it, but I 
want the "already configured" mod_perl and Apache instalation to still 
work.

TIA -- Matt



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

Date: Thu, 19 Dec 2002 18:17:07 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Arguing about the advantage of Perl
Message-Id: <x765tpq3fh.fsf@mail.sysarch.com>

>>>>> "Psa" == Pierre synergy all <pierre.rolin@soredi-group.com> writes:

  Psa> "Tintin" <me@privacy.net> a écrit dans le message de news:
  Psa> atsc6p$28djr$1@ID-172104.news.dfncis.de...
  >> 
  >> "news.dial.oleane.com" <pierre.rolin@soredi-group.com> wrote in message
  >> news:atqldj$9ld$1@s1.read.news.oleane.net...
  >> > As i must convert programs from JCL
  >> > I have to argue about the avantage of using PERL instead of vb scripts.
  >> >
  >> > could anyone help me on that way.
  >> > thanks a lot.
  >> 
  >> 
  >> Please read http://www.cs.tut.fi/~jkorpela/usenet/xpost.html before you
  Psa> get
  >> the urge to multi-post again.

  Psa> This message is the only one on the net, as the one sent on
  Psa> "comp.lang.perl.misc"
  Psa> have been corrected ...

this IS comp.lang.perl.misc so you must be mistaken. and i saw the
multiposting too.

  Psa> I gess that the urge of correcting one to another and the willing
  Psa> to be the "wise guy" have made you forget the reality of things.

and your question is not being answered because of your mistake. live
with it. the only wise guy in this thread is you. just use vb and screw
it up and don't learn perl. you will be much better off outside the perl
community where things like usenet rules are generally obeyed.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 19 Dec 2002 14:21:56 GMT
From: nobody <noemail@nowhere.net>
Subject: Re: Configuration INC under Windows
Message-Id: <Xns92E95FE724E93abccbaabc@129.250.170.99>

>> How to configure @INC under windows ... Is there a variable as
>> PERLLIB  or something like that to set ??? 
> Yes, see "ENVIRONMENT" section of perlrun.  This is no different on
> Win32 or Unix.

I think Win32 Perl uses semicolons instead of colons to separate
items in PERLLIB, PERL5LIB, etc. See perlwin32.


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

Date: Thu, 19 Dec 2002 06:35:26 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: csv file to mysql import
Message-Id: <3E01D92E.7010005@vpservices.com>

Arunav Mandal wrote:

> I am trying to import the csv style address book in mysql database
> 
> chdir '$file';


Is that really what you mean?  Your data is in a directory whose name 
begins with a literal dollar sign?  And are you sure you end up in the 
right place?


> my $count = 0;
> for (<*>) {
> 
> 
>     my $sth = $csv->prepare("SELECT * FROM $_") or die $DBI::errstr;


That seems dangerous -- you are accepting input from the user and 
passing it directly into a SQL statement without any form of checking or 
validation.  At a minimum you should check to see that $_ contains a 
valid SQL table name.  Remember that in SQL (and DBD::CSV enforces it) 
that the period in "foo.csv" means something different than the file 
name "foo.csv" and if your file names have periods (or any character 
that isn't alphanumeric or underscore) in them, you need to use the 
$dbh->{csv_tables} settings to associate table names with file names.


>     $sth->execute() or die $DBI::errstr;
>     my $n;
>     while (my @ref = $sth->fetchrow_array) {
>         @insert{@cols} = @ref;


Is %insert correct at this point or is your program failing somewhere else?

-- 
Jeff



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

Date: Thu, 19 Dec 2002 15:42:58 +0100
From: Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Subject: Re: csv file to mysql import
Message-Id: <newscache$mjfd7h$i3m$1@news.emea.compuware.com>

Arunav Mandal wrote (Thursday 19 December 2002 14:55):

> I am trying to import the csv style address book in mysql database
> with the following script but it always inserts a blank row everytime
> I run the perl script. Can I anybody let me know where is the problem?
> 
> 
> 
> #!/usr/bin/perl
> 
> #use strict;
  ^
  ^
   You must have a very good reason to leave it out. Perl code
   posted to this newsgroup should always start with:

   use strict;
   use warnings;


> use CGI qw(param);
> use DBI;
> 
> 
> use vars qw(
>             $q
>             );
> 
> $q = CGI->new;


    I don't see any global use/need of $g. Instead, use:
    
    my $q = $CGI->new;
    

> my @cols = qw/
> user
>     Name
> email
> Subject
>     Body
>     FromName
>     FromAddress
>     FromType
>     ToName
>     ToAddress
>     ToType
>     CCName
>     CCAddress
>     CCType
>     BCCName
>     BCCAddress
>     BCCType
>     BillingInformation
>     Categories
>     Importance
>     Mileage
>     Sensitivity
> /;
> 
> 
> 
> 
> 
> chdir '$file';
        ^     ^
        ^     ^

   Single quotes prevent interpolation. Also, you forgot to check
   the return value:

   chdir $file or die "Could not chdir to $file ($!)\n";

   But it will still not work as expected, as you did not
   initialize $file. Read "perldoc -f chdir" to see what happens
   when you use chdir without an argument.


> my %insert;
> my $dbh = DBI->connect("DBI:mysql:database=address", "user", "pass");


   You did not use RaiseError. Now you definitely need to check
   the return value:

    my $dbh = DBI->connect("DBI:mysql:database=address",
        "user", "pass") or die "Connection failed.\n";


> my $csv = DBI->connect("DBI:CSV:") or die "connect" . $DBI::errstr;
> my $count = 0;
> for (<*>) {
        ^
        ^

    As the chdir failed, these files are not the ones you need.


>     my $sth = $csv->prepare("SELECT * FROM $_") or die $DBI::errstr;
>     $sth->execute() or die $DBI::errstr;
>     my $n;
>     while (my @ref = $sth->fetchrow_array) {
>         @insert{@cols} = @ref;

          ^^^^^^^^^^^^^^^^^^^^^

   You stole this code, didn't you? It's perfectly valid Perl and
   it works beautifully. 10 pts if you can tell why.


[rest of the code snipped]



-- 
KP


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

Date: Thu, 19 Dec 2002 14:55:50 GMT
From: "codeWarrior" <GPatnude@adelphia.net>
Subject: Re: csv file to mysql import
Message-Id: <W5lM9.33336$VA5.4094849@news1.news.adelphia.net>


"Koos Pol" <koos_pol@NO.nl.JUNK.compuware.MAIL.com> wrote in message
news:newscache$mjfd7h$i3m$1@news.emea.compuware.com...
> Arunav Mandal wrote (Thursday 19 December 2002 14:55):
>
> > I am trying to import the csv style address book in mysql database
> > with the following script but it always inserts a blank row everytime
> > I run the perl script. Can I anybody let me know where is the problem?
> >
> >
> >
> > #!/usr/bin/perl
> >
> > #use strict;
>   ^
>   ^
>    You must have a very good reason to leave it out. Perl code
>    posted to this newsgroup should always start with:
>
>    use strict;
>    use warnings;
>
>
> > use CGI qw(param);
> > use DBI;
> >
> >
> > use vars qw(
> >             $q
> >             );
> >
> > $q = CGI->new;
>
>
>     I don't see any global use/need of $g. Instead, use:
>
>     my $q = $CGI->new;
>
>
> > my @cols = qw/
> > user
> >     Name
> > email
> > Subject
> >     Body
> >     FromName
> >     FromAddress
> >     FromType
> >     ToName
> >     ToAddress
> >     ToType
> >     CCName
> >     CCAddress
> >     CCType
> >     BCCName
> >     BCCAddress
> >     BCCType
> >     BillingInformation
> >     Categories
> >     Importance
> >     Mileage
> >     Sensitivity
> > /;
> >
> >
> >
> >
> >
> > chdir '$file';
>         ^     ^
>         ^     ^
>
>    Single quotes prevent interpolation. Also, you forgot to check
>    the return value:
>
>    chdir $file or die "Could not chdir to $file ($!)\n";
>
>    But it will still not work as expected, as you did not
>    initialize $file. Read "perldoc -f chdir" to see what happens
>    when you use chdir without an argument.
>
>
> > my %insert;
> > my $dbh = DBI->connect("DBI:mysql:database=address", "user", "pass");
>
>
>    You did not use RaiseError. Now you definitely need to check
>    the return value:
>
>     my $dbh = DBI->connect("DBI:mysql:database=address",
>         "user", "pass") or die "Connection failed.\n";
>
>
> > my $csv = DBI->connect("DBI:CSV:") or die "connect" . $DBI::errstr;
> > my $count = 0;
> > for (<*>) {
>         ^
>         ^
>
>     As the chdir failed, these files are not the ones you need.
>
>
> >     my $sth = $csv->prepare("SELECT * FROM $_") or die $DBI::errstr;
> >     $sth->execute() or die $DBI::errstr;
> >     my $n;
> >     while (my @ref = $sth->fetchrow_array) {
> >         @insert{@cols} = @ref;
>
>           ^^^^^^^^^^^^^^^^^^^^^
>
>    You stole this code, didn't you? It's perfectly valid Perl and
>    it works beautifully. 10 pts if you can tell why.
>
>
> [rest of the code snipped]
>
>
>
> --
> KP

for WHAT ? each ? ($I ==0; $i <= $sth->rowcount(); $i++) {

 ???




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

Date: 19 Dec 2002 17:42:44 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: csv file to mysql import
Message-Id: <u9vg1pykff.fsf@wcl-l.bham.ac.uk>

Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com> writes:

> Arunav Mandal wrote (Thursday 19 December 2002 14:55):

> > use vars qw(
> >             $q
> >             );
> > 
> > $q = CGI->new;
> 
> 
>     I don't see any global use/need of $g. Instead, use:
>     
>     my $q = $CGI->new;

See thread recent thread '[Q] my vs. our' where I explain in message
<u9smxxtqco.fsf@wcl-l.bham.ac.uk> why in the particular case of CGI
scripts package variables are often preferable to file-scoped
lexicals.

http://groups.google.com/groups?selm=u9smxxtqco.fsf%40wcl-l.bham.ac.uk

Note: most of the objections raised to global variables are objections
to the programming style that uses them.  For these purposes lexical
variables declared at file scope still count as global variables so
just chaning 'use vars' or 'our' to 'my' doesn't address the concerns
that prompted the original objections.

(There's also a small performance issue).

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


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

Date: Thu, 19 Dec 2002 15:07:41 GMT
From: "codeWarrior" <GPatnude@adelphia.net>
Subject: Re: Extracting last element from a list
Message-Id: <1hlM9.33344$VA5.4096013@news1.news.adelphia.net>


"Andrew Luke NESBIT" <alnesbit@students.cs.mu.OZ.AU> wrote in message
news:atrk8a$18h$1@mulga.cs.mu.OZ.AU...
> Hi, I'm pretty new to Perl, and have the following question.
>
> Consider the following code:
>
> ----------------------------------------------------------------------
> #!/usr/bin/perl -w
>
> my ($first, $last, @rest);
> my @array = ("one", "two", "three");
>
> ($first, @rest) = @array;
> print "First element is: $first\n";
>
> (@rest, $last) = @array;
> print "Last element is: $last\n";
> ----------------------------------------------------------------------
>
> It gives the following output:
>
> $ ./foo.pl
> First element is: one
> Use of uninitialized value at ./foo.pl line 10.
> Last element is:
>
> The statement which extracts the head and tail from @array seems
> pretty idiomatic in Perl.
>
> So, I thought I could extract the last element similarly (i.e., the
> last two lines).  But it doesn't seem to work.  Why is this?  And
> what's the idiomatic way to do this operation?
>
> BTW, I was trying to get the two "my" declarations merged into one
> "my" declaration, but perl didn't seem to like any of my attempts.  Is
> this possible?
>
> Thanks for any feedback.
>
> Andrew.
>

$last = $array[$#array];






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

Date: Thu, 19 Dec 2002 14:59:08 +0000
From: Graham Wood <Graham.T.Wood@oracle.com>
Subject: Re: Hard Anodized  11665
Message-Id: <3E01DEBB.2B9DAC9D@oracle.com>

Isn't there a module for this already?

Graham





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

Date: 19 Dec 2002 18:04:22 GMT
From: ctcgag@hotmail.com
Subject: Re: help:  perl script to make all DNA sequence Nmers?
Message-Id: <20021219130422.613$h3@newsreader.com>

Benjamin Goldberg <goldbb2@earthlink.net> wrote:
> ctcgag@hotmail.com wrote:
> >
> > isen@molbio.mgh.harvard.edu (isen) wrote:
> > > does anyone have a perl script to make all possible DNA sequence
> > > Nmers (and put in an array preferably) when given N as an input?
> >
> > warn "Untested Code";
> > sub Nmer {
> >   die unless $_[0];
> >   return qw/A C T G/ if $_[0]==1;
> >   return map {$_.'A', $_.'C', $_.'T', $_.'G'} Nmer($_[0]-1);
> > };
>
> This puts everything on the stack -- kinda wasteful of memory, ne?

Well, the poster didn't ask for an efficient solution :)

I figure if you have memory, it's as much of a waste to not use
it as it is to use it.  Does Perl treat stack different
than heap?  I've never paid much attention to where my data
would be going, I that I know haven't suffered from it.  It
seems perl will dynamically allocate as much stack as it needs.

Anyway, mine worked right out of the box, and took few seconds of my time.
I spent a bit of time working on yours, and still haven't gotten
it to work properly.  In my book, that's the biggest test of efficiency,
at least for a program I'm not being paid to write.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB


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

Date: 19 Dec 2002 10:46:54 -0800
From: laffle@aol.com (laffle)
Subject: Internet  SQLstore available
Message-Id: <6213147f.0212191046.7139d87f@posting.google.com>

http://www.sqlstore.com/

Looks good!


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

Date: Thu, 19 Dec 2002 15:52:12 +0000
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: Localising large data structures to a sub
Message-Id: <3E01EB2C.28BBB921@bbsrc.ac.uk>

I've had this situation crop up a couple of times and have bluffed my
way round it rather than figuring out a good answer, but I'm feeling
bold today!

If I have a large data structure which is assembled from data in a file,
which is only needed in one subroutine, how can I best localise it to
that sub.

An example of what I imagine to be bad (but may not be) is this
(untested)....

sub whatever {

  my ($query) = @_;

  my %data;

  open (IN,'data.txt') || die $!;

  while (<IN>){
    my ($key,$value) = split(/\t/);
    $data{$key}=$value;
  }

  return($data{$query});
}

In this scenario, the way I read this is that data.txt will be reread
every time the sub is called, whereas I need some way to populate %data
the first time the sub is called, and then keep the stored value around
for future calls without having to make %data a global variable.

What's the best way to do this?

Cheers

Simon.


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

Date: Thu, 19 Dec 2002 09:37:48 -0700
From: "Rod" <palladium@spinn.net>
Subject: Re: Localising large data structures to a sub
Message-Id: <v03tknasr9at9d@corp.supernews.com>

"Simon Andrews" <simon.andrews@bbsrc.ac.uk> wrote in message
news:3E01EB2C.28BBB921@bbsrc.ac.uk...
> I've had this situation crop up a couple of times and have bluffed my
> way round it rather than figuring out a good answer, but I'm feeling
> bold today!
>
> If I have a large data structure which is assembled from data in a file,
> which is only needed in one subroutine, how can I best localise it to
> that sub.
>

Try the Storable module from CPAN. I think you will like what it can do for
these scenarios.
Rodney




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

Date: 19 Dec 2002 17:43:46 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Localising large data structures to a sub
Message-Id: <u9smwtykdp.fsf@wcl-l.bham.ac.uk>

Simon Andrews <simon.andrews@bbsrc.ac.uk> writes:

> I've had this situation crop up a couple of times...

So, you might guess it's likely to be a FAQ.

> An example of what I imagine to be bad (but may not be) is this
> (untested)....
> 
> sub whatever {
>   my ($query) = @_;
>   my %data;
>   open (IN,'data.txt') || die $!;
>   while (<IN>){
>     my ($key,$value) = split(/\t/);
>     $data{$key}=$value;
>   }
>   return($data{$query});
> }

>                               ...I need some way to populate %data
> the first time the sub is called, and then keep the stored value around
> for future calls without having to make %data a global variable.

Yep, this is FAQ: "How do I create a static variable?"

That said, the answer given in the FAQ is a little unhelpful.

{
  my %data;
  sub whatever {
    my ($query) = @_;
    unless (%data) {
      open (my $in,'data.txt') || die $!;
      local $_;
      while (<$in>){
      my ($key,$value) = split(/\t/);
       $data{$key}=$value;
      }
    }
    return($data{$query});
  }
}

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


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

Date: Thu, 19 Dec 2002 18:28:39 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Localising large data structures to a sub
Message-Id: <x7wum5oobt.fsf@mail.sysarch.com>

>>>>> "BM" == Brian McCauley <nobull@mail.com> writes:


  BM> {
  BM>   my %data;
  BM>   sub whatever {
  BM>     my ($query) = @_;
  BM>     unless (%data) {
  BM>       open (my $in,'data.txt') || die $!;
  BM>       local $_;
  BM>       while (<$in>){
  BM>       my ($key,$value) = split(/\t/);
  BM>        $data{$key}=$value;
  BM>       }
  BM>     }
  BM>     return($data{$query});
  BM>   }
  BM> }

a shorter variant that saves an indent and {}. i like returning early if
possible.  if the file is short enough, then a slurp might be fine.

{
  my %data;
  sub whatever {
    my ($query) = @_;

    return($data{$query}) if %data ;

    open (my $in,'data.txt') || die $!;
    local $/;
    my $text = <$in> ;
    %data = $text = /^([\t]+)\t(.+)/mg ;
    return($data{$query});
}

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 19 Dec 2002 15:14:37 GMT
From: opt cool dude <control153@NOSPAMyahoo.com>
Subject: Re: perl script to capture streaming audio
Message-Id: <Xns92E9689F218A0control153NOSPAMyaho@167.206.3.3>

thanks for your help ... here is the url:

http://www.wjse.com/wmplayer.asp


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

Date: 19 Dec 2002 08:15:52 -0800
From: sharda@hotmail.com (raj)
Subject: Re: Replacing text strings contains more than 1 dot
Message-Id: <ac4b6b9a.0212190815.34e31bbf@posting.google.com>

Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net> wrote in message news:<atscas$6lr$1@korweta.task.gda.pl>...
> In article <d8c847cd.0212190357.34282b4@posting.google.com>, Eric
> wrote:
> > Greetings,
> > 
> > I would like to replace some ip addresses in a text file.
> > 
> > I try:
> > 
> > perl -pi -e 's/111.222.333.444/111.222.333.999/e' filename
> 
> 
> Get rid of the /e and backslash the .s in the regex:
> 
> 
> s/111\.222\.333\.444/111.222.333.999/;
> 
> 
> And check out:
> 
> 
> perldoc perlop
> 
> 
> for why you got incorrect results with /e.
> 
> 
> 
> Cheers,
> Bernard

perl -pi -e 's/oldstring/newstring' filename

HTH.


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

Date: Thu, 19 Dec 2002 14:11:29 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: splitting array, each element holding multiple values into array with single values 
Message-Id: <lskM9.25406$3t6.12880@nwrddc03.gnilink.net>

hugo wrote:
> When the form is forwarded I get the values out as follows:
>
> for ($i = 0; $i < $projectlimit; $i++)  {
>     $P[$i] = join ' ' => $query->param("company_projects$i");
> }
>
> so that I end up with an array, each array element containing a set of
> values.
>
> However, I would like to split the values into another array which,
> presumably, has to be two dimensional. In other words, if my array @P
> contains

I don't understand why you "join" the items if you don't want to them
joined?

jue




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

Date: Thu, 19 Dec 2002 15:06:00 GMT
From: "codeWarrior" <GPatnude@adelphia.net>
Subject: Re: splitting array, each element holding multiple values into array with single values 
Message-Id: <sflM9.33343$VA5.4096147@news1.news.adelphia.net>


"hugo" <hugo@geoinformex.com> wrote in message
news:3E017B4E.7080603@geoinformex.com...
> Hi
>
> I have a problem I don't seem to be able to solve.
>
> I have a cgi script creating a page with a form containing a series of
> text boxes, each box containing a multi-selection list.
>
> When the form is forwarded I get the values out as follows:
>
> for ($i = 0; $i < $projectlimit; $i++)  {
>     $P[$i] = join ' ' => $query->param("company_projects$i");
> }
>
> so that I end up with an array, each array element containing a set of
> values.
>
> However, I would like to split the values into another array which,
> presumably, has to be two dimensional. In other words, if my array @P
> contains
>
> $P[0] = "A B C D";
> $P[1] = "X Y Z";
>
> then my new array should be:
>
> $NP[0][0] = "A";
> $NP[0][1] = "B";
> $NP[0][2] = "C";
> $NP[0][3] = "D";
> $NP[1][0] = "X";
> $NP[1][1] = "Y";
> $NP[1][2] = "Z";
>
> How can I do this?
>
> Any help, particularly a code example would be most welcome.
>
> Thanks
>
> Hugo
>
> --
> Dr Hugo Bouckaert
> Systems and Programming Engineer
>
> GeoInformatics Exploration Australia P/L
> 57 Havelock St
> West Perth, WA 6005
> PO Box 1675, West Perth 6872
>
> Ph:       61 08 9420 7400
> Fax:      61 08 9226 1299
>
> www.geoinformex.com
>
> ------------------------------------------------------------------------
> This email and any attachments may be confidential or legally
> privileged. If you received this message in error or are not the
> intended recipient, you should destroy the e-mail message and any
> attachments or copies, and you are prohibited from retaining,
> distributing, disclosing or using any information contained herein.
> Please inform us of the erroneous delivery by return e-mail. Thank you
> for your cooperation.
>
>
It's even easier that that if you don't try to number all of the form fields
with $i... Just call the same form fields "company_projects" and use CGI to
retrieve them as an array...

@myCGIARRAY = join " ', $query->param("company_projects"); # DROP THE FORM
NUMBERING --- CGI CAN HANDLE ARRAYS...

foreach $Pn (@myCGIARRAY) {

    @Pn = split " ", $P;

    foreach $P (@Pn) {

        push ($P, @P);

    }

}





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

Date: Thu, 19 Dec 2002 18:21:57 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: splitting array, each element holding multiple values into array with single values
Message-Id: <x71y4dq37f.fsf@mail.sysarch.com>

>>>>> "c" == codeWarrior  <GPatnude@adelphia.net> writes:

<snip of ENTIRE quoted email>

at least edit it down some.

  c> It's even easier that that if you don't try to number all of the
  c> form fields with $i... Just call the same form fields
  c> "company_projects" and use CGI to retrieve them as an array...

  c> foreach $Pn (@myCGIARRAY) {

  c>     @Pn = split " ", $P;

where is $P assigned?

don't use mixed case for perl variables.

don't use duplicate names for scalars and arrays.

  c>     foreach $P (@Pn) {

  c>         push ($P, @P);

that is backwards. and again duplicate and confusing names

so we have poor name selection, wrong names in places, and a broken call
to push in only 6 lines of untested code.

some codewarrior. and you bragged about some massive income in
alt.perl. i wonder who hired you for perl hacking?

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: 19 Dec 2002 08:41:05 -0800
From: schuckm@emigrant.com (Mac)
Subject: Stat() function not working.  Kind of...
Message-Id: <3d9b1ac6.0212190841.64b1ca81@posting.google.com>

I'm trying to get all the files in a specific directory and, at this
point, simply retrieving information about them using the stat
function.  Problem is, most of the files have no information about
them and are coming up blank.  I can't make any rhyme or reason as to
why some files are actually coming up with information and most not. 
I've looked at the files' rights, directories' rights, and they all
appear the same.  My development environment is Microsoft (IIS) and
production is a Unix box, but the same problem occurs on both.  Can
anyone lend any insight whatsoever as to why this may be occuring. 
Thanks in advance.  Here's the code:


#!/usr/local/bin/perl5

print ("Content-Type:text/html\n\n");

opendir(DIRHANDLE, "test/") or die "couldn't open directory : $!" ;

while ( defined ($filename = readdir(DIRHANDLE))) {
	($TEST1) = (stat($filename)) [0];
	($TEST2) = (stat($filename)) [7];
	($TEST3) = (stat($filename)) [2];
	($TEST4) = (stat($filename)) [9];	

        print $filename." - ".$TEST1."<BR>";
        print $filename." - ".$TEST2."<BR>";
        print $filename." - ".$TEST3."<BR>";
        print $filename." - ".$TEST4."<BR>";	
	
}
	
closedir(DIRHANDLE);


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

Date: Thu, 19 Dec 2002 12:21:39 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Stat() function not working.  Kind of...
Message-Id: <slrnb043hj.2jh.tadmc@magna.augustmail.com>

Mac <schuckm@emigrant.com> wrote:

> while ( defined ($filename = readdir(DIRHANDLE))) {
> 	($TEST1) = (stat($filename)) [0];


You should read the documentation for the functions that you use.

   perldoc -f readdir

Pay particular attention to the second paragraph...


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


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

Date: Thu, 19 Dec 2002 09:50:13 -0500
From: Lou Moran <lou.moran@gellerandwind.com>
Subject: Sys Adminy Advice Requested
Message-Id: <58m30vk7grokl8c7rmh2oj725hq1ntg723@4ax.com>

I have recently joined a new company of under 100 W2K machines.

There is little scripting being done here.  And I am dutifully
scripting away with my favorite scripting language Perl.  I intend to
script login/logoff and other user related things using Perl after the
new year (and when I get  a better idea of how things work on a Human
level.)  The servers are fairly robust machines:

Considering the low number of users can I simply have users use the
Perl on the server to run their scripts or should I install Perl on
every machine.  In larger settings I would certainly install Perl on
every machine.

Second question:

There is a lot of "documentation" strewn about the network about
various programs and settings and the network itself.  These docs are
in Word and .txt files.  The Word files have screen shots which aren't
all that important.

I would like to convert them into web pages (HTML) but am wondering if
that it the best choice.  Would XML be a better choice?  Things I know
about XML include what the letters stand for and there are modules
written for XML in Perl.



--
There's more than one way to do it, but only some of them work


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

Date: Thu, 19 Dec 2002 14:18:14 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Tracking User's OS type?
Message-Id: <GykM9.25439$3t6.18412@nwrddc03.gnilink.net>

Alan J. Flavell wrote:
> On Dec 19, Jürgen Exner inscribed on the eternal scroll:
>
>> John wrote:
>>> I recently created a website and I am able to do the following:
>>>
>>> Track IP Address, browser, etc.
>>>
>>> However, I can't seem to find how to track what OS the user is
>>> using. Is there a simple line of perl code that will accomplish
>>> this?
>>
>> Please see "perldoc perlvar":
>> $OSNAME
>> $^O     The name of the operating system under which this copy of
>>         Perl was built, as determined during the configuration
>> process.
>
> With respect, I presume that the hon Usenaut already knows what OS is
> running on the server, and is more interested to know what the caller
> is using.  It's unlikely that the caller will consent to running his
> perl code on their client platform for this...?

Well, if the honerable usenaut would have had a question about a web
client/web server environment and he would have been interested in
information about the web client then I'm sure he would have asked in e.g.
webauthoring.cgi, because that question would have had nothing to do with
Perl.

jue




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

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


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