[23883] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6086 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 6 00:05:40 2004

Date: Thu, 5 Feb 2004 21:05:05 -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, 5 Feb 2004     Volume: 10 Number: 6086

Today's topics:
        attachment email script problem <spedwards@qwest.net>
    Re: Clarifications <bmb@ginger.libs.uga.edu>
    Re: Clarifications <kkeller-usenet@wombat.san-francisco.ca.us>
    Re: Counting words <bmb@ginger.libs.uga.edu>
    Re: Counting words (Walter Roberson)
    Re: executing from command line <ceo@nospan.on.net>
    Re: how to find the last "new line" in string <krahnj@acm.org>
    Re: how to find the last "new line" in string (Walter Roberson)
    Re: Optimization request <dwall@fastmail.fm>
    Re: Perl data types <jwkenne@attglobal.net>
    Re: Perl data types <jwkenne@attglobal.net>
    Re: Perl data types <tassilo.parseval@rwth-aachen.de>
    Re: Perl For Amateur Computer Programmers <matthew.garrish@sympatico.ca>
    Re: RDBMS to hold Perl objects? <bobx@linuxmail.org>
        recordset error/perl messages <gartim@comcast.net>
        URGENT: updating array question (Brent Silver)
    Re: URGENT: updating array question (Walter Roberson)
    Re: URGENT: updating array question <noreply@gunnar.cc>
    Re: URGENT: updating array question <noreply@gunnar.cc>
    Re: URGENT: updating array question <tadmc@augustmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 5 Feb 2004 21:20:04 -0700
From: "Shawn" <spedwards@qwest.net>
Subject: attachment email script problem
Message-Id: <ZBEUb.137$Ki4.122871@news.uswest.net>

Hi,

We have been using the below script to auto email some reports from UNIX to
a management group.
Its been in place for sometime and luckily for me it hasn't needed any
maintenance.

The 1st section would include that particular report as the body of the
email and the other 2 reports as attachments.
It goes to people who are on PCs and NCD Unix terminals.  Within the past
week the 1st report which had been the
body of the email turned into a 3rd attachment on the email and there was no
longer a body to the email for the PC
users only.  The people who were on the NCD terminals didn't notice a change
and received the email as normal.

After a short discussion with the system admin, he suggested maybe the
encoding of the email was be manipulated to strip
the body of the email.  This is where I get in over my head.  Because I can
send the email manually through my NCD
with the exact attachments, recipients, etc and it is received as it
normally was with the 1st report in the body of the email.
I'm guessing that maybe I need to change some of the setting in the script
like the type, or encoding to correct the problem.
But, just am not sure what to do???  Any suggestions would be greatly
appreciated!  Thanks!


#!/usr/local/bin/perl5.6
use lib "lib";
use MIME::Lite;
$msg = new MIME::Lite
     From     => 'xxx@xxx.com',
     To       => (join',','glcomm@xxx.com','nfix@xxx.com'),
     Cc       => 'isisgl@xxx.com'),
     Subject  => 'PNP Daily Gain/Loss Results',
     Type     => 'TEXT',
     Path     =>
"/home/pnp/gp22/SCRIPTS_regular/gainloss/reports/GP22_all_pwgl_rept.txt ",
     Encoding => '7bit';
attach $msg
    Type     => 'TEXT',
    Path
=>"/home/pnp/gp22/SCRIPTS_regular/gainloss/reports/GP22_pwgl_user_rept.txt",
    Filename =>"GP22_pwgl_user_rept.txt";
attach $msg
    Type     => 'TEXT',
    Path
=>"/home/pnp/gp22/SCRIPTS_regular/gainloss/reports/pnp_readme.txt",
    Filename =>"pnp_readme.txt";
$msg->send;
exit 0;
}




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

Date: Thu, 5 Feb 2004 21:13:06 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Clarifications
Message-Id: <Pine.A41.4.58.0402052103010.29194@ginger.libs.uga.edu>

On Thu, 5 Feb 2004, edgrsprj wrote:

> "Joe Smith" <Joe.Smith@inwap.com> wrote in message
> news:MDdUb.173729$Rc4.1316159@attbi_s54...
> > edgrsprj wrote:
>
> > It's not a problem with any browser.  It's your source code.
> >
> > 1: open FILENAME =93> c:\textfile.txt=94;  # =93smart quotes=94
> > 2: open FILENAME "> c:/textfile.txt";  # "double quotes" forward slash
> >
> > Any code you post needs to be formatted such that the quote marks
> > are vertical, not slanted left and right like line 1 above.
> > -Joe
>
> Now I see what you mean.  I will have to check on how my word processor i=
s
> generating those quotes.  There is probably some way to ensure that they =
all
> look the same.

And. It's. Still. A. Syntax. Error.

(I don't know why I can't resist jumping in on this thread.  I wonder if
it's a mass hypnosis worm ...)

Brad


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

Date: Thu, 5 Feb 2004 19:32:21 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Clarifications
Message-Id: <5s1vvb.ilv.ln@goaway.wombat.san-francisco.ca.us>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

On 2004-02-06, Brad Baxter <bmb@ginger.libs.uga.edu> wrote:
>
> (I don't know why I can't resist jumping in on this thread.  I wonder if
> it's a mass hypnosis worm ...)

It must be the usenet equivalent of a spectacular car crash, where
passersby feel compelled to stop and stare.

- --keith

- -- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQFAIwrChVcNCxZ5ID8RAjtnAJwIiTduqdBFQ4nK4dLOLp3CXYKF+QCeISdF
iVvUuY5kCzmWaDkB6yosNsc=
=xwj9
-----END PGP SIGNATURE-----


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

Date: Thu, 5 Feb 2004 21:50:47 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Counting words
Message-Id: <Pine.A41.4.58.0402052134460.28924@ginger.libs.uga.edu>

On Wed, 4 Feb 2004, Fran wrote:
> Can anybody please tell me how to count words? If a need to know if an
> input has n words, how do I do it? Thank you

perl -pale '$=+=@F}{*_=*=' input

Regards,

Brad


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

Date: 6 Feb 2004 03:12:01 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: Counting words
Message-Id: <bvv0m1$8qq$1@canopus.cc.umanitoba.ca>

In article <Pine.A41.4.58.0402052134460.28924@ginger.libs.uga.edu>,
Brad Baxter  <bmb@ginger.libs.uga.edu> wrote:
:On Wed, 4 Feb 2004, Fran wrote:
:> Can anybody please tell me how to count words? If a need to know if an
:> input has n words, how do I do it? Thank you

:perl -pale '$=+=@F}{*_=*=' input

That's cruel!
-- 
   IEA408I: GETMAIN cannot provide buffer for WATLIB.


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

Date: Fri, 06 Feb 2004 04:20:59 GMT
From: Chris <ceo@nospan.on.net>
Subject: Re: executing from command line
Message-Id: <LCEUb.19176$xq.8881@newssvr16.news.prodigy.com>

Monkey Man wrote:
> Hey there,
> I have a perl script that i would like to run it on a windows server.  Since
> there is no command line with windows, i want to execute script from a web
> page.  Is that possible?  Or am i just dreaming?
> 

I think Brian McCauley successfully interpretted your question here, and 
now you can, with his help, receive a reasonable answer.

Yes, you can do this with Windows (assuming Brian is right and I think 
he is -- you want to know if you can host a web page that executes a 
command on another machine and writes the results of the commend 
executed on the remote machine to a web page), but just be aware you are 
opening up a (huge) security hole on the remote machine when you do this.

On Windows, you can do this natively in ASP, or you can do it through a 
Perl CGI script.

See these programs for direction here:

CGI: 
http://www.technologease.com/cgi-bin/listing.cgi?config=resume&tmpl=listing&setid=2&progid=3

ASP: 
http://www.technologease.com/cgi-bin/listing.cgi?config=resume&tmpl=listing&setid=5&progid=1

Both are written in Perl.  One is CGI and the other requires the 
PerlScript Classic ASP engine installed.  If you want to (horrors) do 
this in VBScript, then the essential code is:

Sub Shell( strCmd )
    Set WshShell = Server.CreateObject( "WScript.Shell" )
    Set oExec = WshShell.Exec( "%COMSPEC% /c " & strCmd )
    Set oExec = Nothing
    Set WshShell = Noting
End Sub

I'll leave it to you to translate the complete Perl examples I gave you 
above into VBScript using the above fragment if you want since this IS a 
Perl NG and other than providing you with Perl code to do what (I think) 
you want, this has nothing to do with Perl.  (I should be shot for 
posting VB code, probably.)

I would post a disclaimer about you opening up some huge security hole 
using the above code, but since your target is a Windows box, no 
disclaimer will be necessary since Windows is basically Swiss Cheese 
right out of the box as it is...  8-(  But don't blame me if you get 
into trouble with the above code.  I run that code, but locked down 
(which I won't get into here.)

Finally, Windows DOES have a remote command utility called RCMD which 
you can install from the Windows Resource Kit CD...

Chris
-----
Chris Olive
chris -at- --spammers-are-vermin-- technologEase -dot- com
http://www.technologEase.com
(pronounced "technologies")


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

Date: Fri, 06 Feb 2004 01:06:26 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: how to find the last "new line" in string
Message-Id: <4022E838.33F20CBC@acm.org>

hshen wrote:
> 
> If a string contains a few lines, (separated by '\n'), how can I make
> a  regular expression to replace this '\n' by a space?

You don't really need a regular expression.

$string =~ tr/\n/ /;


John
-- 
use Perl;
program
fulfillment


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

Date: 6 Feb 2004 01:51:24 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: how to find the last "new line" in string
Message-Id: <bvurus$6pr$1@canopus.cc.umanitoba.ca>

In article <4022E838.33F20CBC@acm.org>, John W. Krahn <krahnj@acm.org> wrote:
:hshen wrote:

:> If a string contains a few lines, (separated by '\n'), how can I make
:> a  regular expression to replace this '\n' by a space?

:You don't really need a regular expression.

:$string =~ tr/\n/ /;

But the Subject refers to the *last* "new line" in the string;
your proposed solution would change *all* of them.
-- 
   "WHEN QUINED, YIELDS A TORTOISE'S LOVE-SONG"
    WHEN QUINED, YIELDS A TORTOISE'S LOVE-SONG.   (GEB)


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

Date: Fri, 06 Feb 2004 00:40:00 -0000
From: "David K. Wall" <dwall@fastmail.fm>
Subject: Re: Optimization request
Message-Id: <Xns9486C8112D71Adkwwashere@216.168.3.30>

ajs@ajs.com (Aaron Sherman) wrote:

> "David K. Wall" <dwall@fastmail.fm> wrote in message news:
<Xns94866A4E9C8B1dkwwashere@216.168.3.30>...
>> Guru03 <Guru03@despammed.com> wrote:
>> 
>> > For you, it's faster this:
> [...]
>> Use the first one, no need to search the string twice.
> 
> Something to keep in mind is that a) Perl doesn't always work that way
> and b) when you answer someone's question, you might consider
> answering the one they asked.
> 
> He didn't ask "which of these would you use", he asked (in admittedly
> broken english, but still quite comprehensibly) which of them was
> faster.

Sometimes I mistake a poster's intent by reading a question too quickly or too 
carelessly, but not this time. Right or wrong, I *was* replying to the question 
of which was faster. Might I suggest that you read my post too quickly?

-- 
David Wall


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

Date: Thu, 05 Feb 2004 23:43:05 GMT
From: "John W. Kennedy" <jwkenne@attglobal.net>
Subject: Re: Perl data types
Message-Id: <dyAUb.37052$%93.9202188@news4.srv.hcvlny.cv.net>

Tassilo v. Parseval wrote:
> No, not in Java. Due to broken-by-design method dispatch, you will
> constantly be checking the type and then do a typecast. If you have a
> class "Foo" with a method "bar" and you stuff 10 Foo objects into 
> 
>     Object array[10];
> 
> you can't just say 'array[0].bar'.

Assuming that you are an adult, you declared it:
      Foo array[10];
and then you can say:
      array[0].bar();

 > Instead you have to write
> 
>      ((Foo)array[0]).bar();
> 
> This gets worse if 'array' contains Foo and Bar objects and both have a
> "bar" method. Then this becomes:
> 
>     if (array[0] instanceof Foo) {
>         ((Foo)array[0]).bar();
>     } else {
>         ((Bar)array[0]).bar();
>     }
> 
> Thus, it is often required in Java to do the type checking by hand.
> Therefore I never quite understood how SUN can claim that Java has
> polymorphism at all.

No, assuming that you are an adult, you declared
         interface BarInterface {
             void bar();
         }
and you declared both classes Foo and Bar as:
         implements BarInterface
and you declared the array as:
         BarInterface array[10];
and then you can say:
         array[0].bar();

-- 
John W. Kennedy
"But now is a new thing which is very old--
that the rich make themselves richer and not poorer,
which is the true Gospel, for the poor's sake."
   -- Charles Williams.  "Judgement at Chelmsford"


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

Date: Thu, 05 Feb 2004 23:47:33 GMT
From: "John W. Kennedy" <jwkenne@attglobal.net>
Subject: Re: Perl data types
Message-Id: <pCAUb.37148$%93.9230892@news4.srv.hcvlny.cv.net>

Tassilo v. Parseval wrote:
> Too bad that you sometimes have no choice. Just look at some of the
> classes in the Java API (like 'Collection' or so). They all cast their
> objects down to the most generic class 'Object'.

Which is why Java 1.5 includes generic types, so that you can declare a 
collection as:
         Collection<Foo> fooset;

> Take this hierarchy:
> 
>     Class1;
>     Class2 extends Class1;
>     Class3 extends Class2;  // and possibly overrides Class1.method()
> 
> Say, that each of these classes is instantiatable. So I'd naturally
> choose
> 
>     Class1 array[10];
> 
> How exactly would that avoid typecasts? Sure, I can probably have each
> of these three implement an interface and change the type of the array
> to that of the common interface. However, do I want that? Certainly not.
> It means I, the programmer, have to accept such a red-herring in order
> to make polymorphism work as expected and convenient.

Poor baby!

If you're too big a coward to tell your lies about Java in Java 
newsgroups, then keep the Hell off the subject of Java in other groups.

-- 
John W. Kennedy
"But now is a new thing which is very old--
that the rich make themselves richer and not poorer,
which is the true Gospel, for the poor's sake."
   -- Charles Williams.  "Judgement at Chelmsford"


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

Date: 6 Feb 2004 00:53:50 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Perl data types
Message-Id: <bvuoiu$ken$1@nets3.rz.RWTH-Aachen.DE>

Also sprach John W. Kennedy:

> Tassilo v. Parseval wrote:

>> Too bad that you sometimes have no choice. Just look at some of the
>> classes in the Java API (like 'Collection' or so). They all cast their
>> objects down to the most generic class 'Object'.
> 
> Which is why Java 1.5 includes generic types, so that you can declare a 
> collection as:
>          Collection<Foo> fooset;

I am aware of that. Java 1.5 is still beta and so I don't see any reason
why I should withdraw my statement.

>> Take this hierarchy:
>> 
>>     Class1;
>>     Class2 extends Class1;
>>     Class3 extends Class2;  // and possibly overrides Class1.method()
>> 
>> Say, that each of these classes is instantiatable. So I'd naturally
>> choose
>> 
>>     Class1 array[10];
>> 
>> How exactly would that avoid typecasts? Sure, I can probably have each
>> of these three implement an interface and change the type of the array
>> to that of the common interface. However, do I want that? Certainly not.
>> It means I, the programmer, have to accept such a red-herring in order
>> to make polymorphism work as expected and convenient.
> 
> Poor baby!
> 
> If you're too big a coward to tell your lies about Java in Java 
> newsgroups, then keep the Hell off the subject of Java in other groups.

I am not subscribed to any Java newsgroup, so I couldn't see the
discussion evolving from that. I am afraid you have to antagonize me
here in this group (or if you prefer: by mail. I'd be delighted).

Apart from that, everything I wrote in the above paragraph is the truth
for non-beta Javas. Or else show me how to do it without interfaces (I
said that you can use them and that I consider them a red-herring).

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Thu, 5 Feb 2004 18:00:03 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Perl For Amateur Computer Programmers
Message-Id: <RVzUb.12052$bp1.596326@news20.bellglobal.com>


"G Klinedinst" <g_klinedinst@hotmail.com> wrote in message
news:168f035a.0402050844.4381d07c@posting.google.com...
> Iain Chalmers <bigiain@mightymedia.com.au> wrote in message news:
>
> > Err, let me clarify, I think they have "terrible form" for _some_ of the
> > target audience.
>
> Sorry Iain, I wasn't trying to put words in your mouth there. Maybe I
> should have qualified that a little more. Let me try again:
>
> I agree with Iain that some of the docs could use a looking over. In
> my opinion some of the docs seem to have terrible form which makes
> them hard to understand for beginners without previous C or *nix
> experience. It also makes them hard to browse through as an
> experienced programmer due to the fundemental organization of some of
> the documents. It would be worth while to take a look at them and see
> which ones could use some improving, keeping users of all levels and
> experience in mind.
>

I'm actually surprised that no one has put together a better html form of
the documents. perldoc.com is a very good site for searching for
information, but it still suffers from the man pageiness of the
documentation. I understand the usefulness of this ordering and naming for
using the perldoc tool (and for updating), but timtowtdi is equally
applicable to the documentation. Activestate makes a nice bundle of the html
documenation, but there's just something disconcerting about using a menu
where every entry is perlxxxx. (perllol, in particular, has a way of making
me laugh out loud whenever I come across it... : )

And to avoid the inevitable "well stop whining about it and do something"
responses, I may just work on a script to build a more user-friendly html
interface to the existing docs.

Matt




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

Date: Thu, 05 Feb 2004 19:48:47 -0500
From: Robert <bobx@linuxmail.org>
Subject: Re: RDBMS to hold Perl objects?
Message-Id: <EPGdnc6NrZvyeb_d4p2dnA@adelphia.com>

Randal L. Schwartz wrote:
> If you want a free RDBMS, there's plenty.  I recommend DBD::SQLite as
> a serverless solution, or DBD::Pg and PostgreSQL as a proper database.
> Stay away from MySQL for new installations, no point in it anymore.
> 
Simply wrong! Now once PG goes native on Windows THEN I see no point. 
Until then MySQL it is. Firebird is looking really good as well. ;-)

Of course he didn't say a platform so the whole argument is a moot one.


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

Date: Thu, 05 Feb 2004 17:50:02 -0800
From: gary artim <gartim@comcast.net>
Subject: recordset error/perl messages
Message-Id: <pan.2004.02.06.01.49.48.351475@comcast.net>

Hi All,

I have a problem using DBIx::RecordSet. I get correct results but continue
to get these messages on stderr. I looked at Compat.pm and it seems to be
pointing out a problem with my call to Setup. Could anyone (much thanks)
shed some light on my tired eyes? See below...

Gary

code sample:
*set = DBIx::Recordset-> Setup ( {'!DataSource'   =>  "dbi:mysql:database=$opt_db;host=127.0.0.1",
                                        '!Username'     =>  $user,
                                        '!Password'     =>  $password,
                                        '!Table'        =>  $opt_table,
                                        } );


error message:
gen1:/home/mysql_dev # ./dbutil.pl -d t -t abc
returning default for NumericTypes on driver mysql at /usr/lib/perl5/site_perl/5.8.1/DBIx/Compat.pm line 517
        DBIx::Compat::GetItem('mysql','NumericTypes') called at /usr/lib/perl5/site_perl/5.8.1/DBIx/Database.pm line 212
        DBIx::Database::Base::QueryMetaData('DBIx::Recordset=HASH(0x8538138)','abc') called at /usr/lib/perl5/site_perl/5.8.1/DBIx/Recordset.pm line 240
        DBIx::Recordset::SetupDBConnection('DBIx::Recordset=HASH(0x8538138)','dbi:mysql:database=t;host=127.0.0.1','abc','root','sql!my','undef') called at /usr/lib/perl5/site_perl/5.8.1/DBIx/Recordset.pm line 334
        DBIx::Recordset::New('DBIx::Recordset','dbi:mysql:database=t;host=127.0.0.1','abc','root','sql!my','undef') called at /usr/lib/perl5/site_perl/5.8.1/DBIx/Recordset.pm line 432
        DBIx::Recordset::SetupObject('DBIx::Recordset','HASH(0x85381b0)') called at /usr/lib/perl5/site_perl/5.8.1/DBIx/Recordset.pm line 595
        DBIx::Recordset::Setup('DBIx::Recordset','HASH(0x85381b0)') called at ./dbutil.pl line 194
        main::dump_table('dbi:mysql:database=t;host=127.0.0.1','root','sql!my','abc','','') called at ./dbutil.pl line 51
        main::main_routine('t','abc','undef','') called at ./dbutil.pl line 32



my version of perl:
Summary of my perl5 (revision 5.0 version 8 subversion 1) configuration:
  Platform:
    osname=linux, osvers=2.6.0-test3, archname=i586-linux-thread-multi
    uname='linux g8 2.6.0-test3 #1 smp fri nov 14 00:07:01 utc 2003 i686 i686 i386 gnulinux '
    config_args='-ds -e -Dprefix=/usr -Dvendorprefix=/usr -Dinstallusrbinperl -Dusethreads -Di_db -Di_dbm -Di_ndbm -Di_gdbm -Duseshrplib=true -Doptimize=-O2 -march=i586 -mcpu=i686 -fmessage-length=0 -Wall -pipe'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -march=i586 -mcpu=i686 -fmessage-length=0 -Wall -pipe',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -fno-strict-aliasing'
    ccversion='', gccversion='3.3.1 (SuSE Linux)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =''
    libpth=/lib /usr/lib /usr/local/lib
    libs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.3.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5/5.8.1/i586-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared'


Characteristics of this binary (from libperl):
  Compile-time options: MULTIPLICITY USE_ITHREADS USE_LARGE_FILES PERL_IMPLICIT_CONTEXT
  Built under linux
  Compiled at Dec 10 2003 09:22:12
  @INC:
    /usr/lib/perl5/5.8.1/i586-linux-thread-multi
    /usr/lib/perl5/5.8.1
    /usr/lib/perl5/site_perl/5.8.1/i586-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.1
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.1/i586-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.1
    /usr/lib/perl5/vendor_perl
    .




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

Date: 5 Feb 2004 18:09:41 -0800
From: google@scihelp.com (Brent Silver)
Subject: URGENT: updating array question
Message-Id: <519c6ce6.0402051809.22f77fee@posting.google.com>

Hi,

Can someone please help me with this? 

@A =  (1,2,3);
@B=();
 
for($i=0; $i<10; $i++){  #STORE DATA
    $A[0]=$i;
    $B[$i]=\@A;
}       
for($i=0; $i<10; $i++){  #PRINT DATA
    print $B[$i][0] . "\t";
}
 
 
The result looks like:  9 9 9 9...
instead of: 0..1..2...3..4...why?    How can one update the reference
to @A through each loop when storing data?

Thanks.
Brent Silver
www.scihelp.com - Quality Software Solutions for Advanced Research


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

Date: 6 Feb 2004 02:20:43 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: URGENT: updating array question
Message-Id: <bvutlr$7h2$1@canopus.cc.umanitoba.ca>

In article <519c6ce6.0402051809.22f77fee@posting.google.com>,
Brent Silver <google@scihelp.com> wrote:
:Can someone please help me with this? 

:@A =  (1,2,3);
:@B=();

:for($i=0; $i<10; $i++){  #STORE DATA
:    $A[0]=$i;

Okay, so A[0] is smashed on each iteration

:    $B[$i]=\@A;

And B[i] is set to be a pointer to the array A.

:}       
:for($i=0; $i<10; $i++){  #PRINT DATA
:    print $B[$i][0] . "\t";
:}


:The result looks like:  9 9 9 9...
:instead of: 0..1..2...3..4...why?


Each step, you are creating a reference to the -same- array.
So of course when you print them out, they are all the same.

:How can one update the reference
:to @A through each loop when storing data?

Perhaps what you want at each step to create a -new- array and stuff
the reference to that in. If so, then you want

  $B[$i] = [@A];

The [ ] construct generates a new anonymous array and returns
a reference to it.
-- 
millihamlet: the average coherency of prose created by a single monkey
typing randomly on a keyboard. Usenet postings may be rated in mHl.
   -- Walter Roberson


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

Date: Fri, 06 Feb 2004 03:42:03 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: URGENT: updating array question
Message-Id: <bvuuri$11k6bq$1@ID-184292.news.uni-berlin.de>

Brent Silver wrote:
> 
> @A =  (1,2,3);
> @B=();
>  
> for($i=0; $i<10; $i++){  #STORE DATA
>     $A[0]=$i;
>     $B[$i]=\@A;
> }       
> for($i=0; $i<10; $i++){  #PRINT DATA
>     print $B[$i][0] . "\t";
> }
>  
> The result looks like:  9 9 9 9...
> instead of: 0..1..2...3..4...why?

Because $A[0] has the value 9 when you print the @B array.

> How can one update the reference
> to @A through each loop when storing data?

Err.. Do not understand.

If you want it to print 0..9, you can assign *anonymous* array 
references to the @B elements instead, i.e. instead of

     $B[$i]=\@A;

you can do:

     $B[$i] = [ @A ];

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



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

Date: Fri, 06 Feb 2004 03:45:32 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: URGENT: updating array question
Message-Id: <bvuv1t$11k6bq$2@ID-184292.news.uni-berlin.de>

Gunnar Hjalmarsson wrote:
> If you want it to print 0..9, you can assign *anonymous* array 
> references to the @B elements instead, ...

Correction: should have been "references to *anonymous* arrays".

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



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

Date: Thu, 5 Feb 2004 22:08:21 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: URGENT: updating array question
Message-Id: <slrnc264pl.36e.tadmc@magna.augustmail.com>

Brent Silver <google@scihelp.com> wrote:

> Subject: URGENT: updating array question

> Can someone please help me with this? 


I could have, but since your post is urgent and more than a couple
of hours old, you are probably already dead, so I won't bother.


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


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

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


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