[14130] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1539 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 1 18:06:10 1999

Date: Wed, 1 Dec 1999 15:05:40 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <944089539-v9-i1539@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 1 Dec 1999     Volume: 9 Number: 1539

Today's topics:
    Re: -s over a Windows network gives negative file size? <jon@midnightbeach.com>
    Re: command line argument <tony_curtis32@yahoo.com>
    Re: command line argument <dederder@micron.com>
    Re: command line argument <tony_curtis32@yahoo.com>
    Re: command line argument <lr@hpl.hp.com>
        Contract - TX - Dallas - Perl/Internet Developer <info@acclaimsvc.com>
    Re: Creating Mail Attachments <send@no.junk.mail>
    Re: dbm database perl script (revised) <cassell@mail.cor.epa.gov>
    Re: dbm database perl script (revised) <cassell@mail.cor.epa.gov>
    Re: dbm database perl script (revised) (Martien Verbruggen)
    Re: dbm database perl script (revised) (Martien Verbruggen)
    Re: Devoo.com : source code search engine (Randal L. Schwartz)
    Re: Dial Up Connection <cassell@mail.cor.epa.gov>
    Re: executing in-line program on remote machine <cassell@mail.cor.epa.gov>
    Re: Extracting data (Yitzchak Scott-Thoennes)
    Re: grep perl function <lr@hpl.hp.com>
    Re: Help passing arguments to a subroutine <gnielson@charlotte.com>
    Re: help with inserting another html please! <cassell@mail.cor.epa.gov>
        Help with XML::DOM usage.. (Michael F. Loll)
    Re: HELP! Pair Pattern Matching (Abigail)
    Re: How do I see error msgs on Web Page? <red_orc@my-deja.com>
    Re: How do I see error msgs on Web Page? dixonan@my-deja.com
    Re: How do I see error msgs on Web Page? (Tad McClellan)
    Re: How do I see error msgs on Web Page? <gellyfish@gellyfish.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 01 Dec 1999 11:09:41 -0800
From: Jon Shemitz <jon@midnightbeach.com>
Subject: Re: -s over a Windows network gives negative file size?
Message-Id: <38457275.E0D5776A@midnightbeach.com>

Wyzelli wrote:

> > Larry Rosler gets positive file sizes, too. I get negative, with the
> > 'same' Win98 and NT4, SP4 that works for you. I'm running a 'straight
> > tcp/ip' network, these days - no IPX or NetBEUI. Might that be the
> > difference?
> >
> Having removed IPX and Netbios (leaving TCP/IP only) from my Workstation
> I still get only positive numbers...

Thanks for doing the test. I'm using 169.254.xxx.xxx addrs on my LAN -
might *that* be it?

-- 

http://www.midnightbeach.com    - Me, my work, my writing, and
http://www.midnightbeach.com/hs - my homeschool resource pages


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

Date: 01 Dec 1999 19:07:09 +0000
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: command line argument
Message-Id: <wkvh6ih44i.fsf@yahoo.com>

Daniel Derderian <dederder@micron.com> writes:

> How do i put all the command line arguments into a
> single string, keeping the whitespaces as entered
> on the command line?

perldoc -f join
perldoc perlvar   / ARGV

Yielding something like this:

    print join(' ', @ARGV), "\n";

Note that you'll usually only preserve *significant*
spaces from the command-line arguments, depending on
how the parent shell treats spaces.

hth
tony



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

Date: Wed, 01 Dec 1999 13:05:43 -0700
From: Daniel Derderian <dederder@micron.com>
Subject: Re: command line argument
Message-Id: <38457F97.132C2B54@micron.com>

Tony Curtis wrote:

> Daniel Derderian <dederder@micron.com> writes:
>
> > How do i put all the command line arguments into a
> > single string, keeping the whitespaces as entered
> > on the command line?
>
> perldoc -f join
> perldoc perlvar   / ARGV
>
> Yielding something like this:
>
>     print join(' ', @ARGV), "\n";
>
> Note that you'll usually only preserve *significant*
> spaces from the command-line arguments, depending on
> how the parent shell treats spaces.
>
> hth
> tony

tony,
thanks for your help, but that is exactly my problem......I want to be able to preserve the multiple spaces in the command-line
arguments.
for example if the arguments are
-gp=/12345     23456/
I want to keep the multiple white spaces between the numbers.
thanks again,
dan



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

Date: 01 Dec 1999 21:27:34 +0000
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: command line argument
Message-Id: <wkso1mgxmh.fsf@yahoo.com>

Daniel Derderian <dederder@micron.com> writes:

> Tony Curtis wrote:
> 
> > Daniel Derderian <dederder@micron.com> writes:
> >
> > > How do i put all the command line arguments into a
> > > single string, keeping the whitespaces as entered
> > > on the command line?
>
> thanks for your help, but that is exactly my
> problem......I want to be able to preserve the
> multiple spaces in the command-line arguments.
> for example if the arguments are
> -gp=/12345     23456/

Well, most shells will tokenise the above into 2,
viz. "-gp=/12345" and "23456/" which probably isn't
what you want; you'd have to quote it.

Things outside of your program are generally not
under your control - if you want things passed over
without undue parsing, you'll need to indicate the
use of quoting to the invoker of the program.

tony


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

Date: Wed, 1 Dec 1999 14:25:45 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: command line argument
Message-Id: <MPG.12af40498d21c8b198a2c7@nntp.hpl.hp.com>

In article <wkvh6ih44i.fsf@yahoo.com> on 01 Dec 1999 19:07:09 +0000, 
Tony Curtis <tony_curtis32@yahoo.com> says...
> Daniel Derderian <dederder@micron.com> writes:
> 
> > How do i put all the command line arguments into a
> > single string, keeping the whitespaces as entered
> > on the command line?
> 
> perldoc -f join
> perldoc perlvar   / ARGV
> 
> Yielding something like this:
> 
>     print join(' ', @ARGV), "\n";

Equivalently (unless someone has mucked with $"),

      print "@ARGV\n";

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 1 Dec 1999 15:34:09 -0600
From: "Acclaim Services, Inc." <info@acclaimsvc.com>
Subject: Contract - TX - Dallas - Perl/Internet Developer
Message-Id: <vtg14.101$8H.188@newsfeed.slurp.net>

We are a leading contract firms in the Dallas area currently working on an
assignement for a client with multiple openings for PERL coders with
Internet experience.  Will be developing a Web enabled application.

Phil Fields
214-750-1818 x26
phil@acclaimsvc.com






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

Date: Thu, 2 Dec 1999 09:24:59 +1300
From: "Peter Sundstrom" <send@no.junk.mail>
Subject: Re: Creating Mail Attachments
Message-Id: <944119301.556247@shelley.paradise.net.nz>

There are plenty of perl modules on CPAN that will simplify your task
greatly.  Take a look at MIME::Lite

"Cory Phillips" <cory-p@usa.net> wrote in message
news:38444bcd.15354405@news.jsc.nasa.gov...
> How do I create a mail attachment using Perl?  I just want my mail
> attachment to be plain text.  I have Linux at home and got it to work,
> but it does not work at my computers at the office.
>
> It doesn't show up as an attachment, it just puts all of this word for
> word in the message body.  See results below.
>
> Code
> -----------------------
>     open(MAIL, "|$mailprog -t");
>     print MAIL "To: $recipient\n";
>     print MAIL "From: $webUserName \<$webUserEmail\>\n";
>     print MAIL "Content-Type: Multipart/Mixed;
> boundary=12345abcdef\n";
>     print MAIL "Subject: $subject\n\n";
>     print MAIL "--12345abcdef\n";
>     print MAIL "Content-Type: text/plain; charset=US-ASCII\n";
>     print MAIL "$message\n\n";
>     print MAIL "$webUserName\n\n";
>     print MAIL "--12345abcdef\n";
>     print MAIL "Content-Type: text/plain; name=\"attach.txt\"\n";
>     print MAIL "Content-Transfer-Encoding: 8bit\n";
>     print MAIL "Content-Disposition: attachment;
> filename=\"attach.txt\"\n\n";
>     print MAIL "This is the attachment\n\n";
>     print MAIL "--12345abcdef--\n";
>     close (MAIL);
>
> Results
> -------------------------------
> --12345abcdef
> Content-Type: text/plain; charset="iso-8859-1"
> A new action request has been submitted
> The action number for tracking purposes is 6
> The title is VMDB Path Test
> The IP Address that generated this request is 139.169.234.108
>
>
> Cory
>
> --12345abcdef
> Content-Type: text/plain; name="attach.txt"
> Content-Transfer-Encoding: 8bit
> Content-Disposition: attachment; filename="attach.txt"
>
> This is the attachment
>
> --12345abcdef--
>
>




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

Date: Wed, 01 Dec 1999 11:54:50 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: dbm database perl script (revised)
Message-Id: <38457D0A.BA58E36F@mail.cor.epa.gov>

makau@multimania.com wrote:
[about Abigail]
> Damnit, your posting history @CLPM is simply FrIgHtEnInG!!!
> I think you have set a record of the greatest contributor on this
> newsgroup! =)

Actually, Abigail is a valued contributor.  The cases where
Abigail responds with abrupt comments are those where the
poster is off-topic [asking in the wrong newsgroup] or is
asking a FAQ [which the poster should have checked first, as
per newsgroup rules].  In other cases, Abigail can provide
detailed discussions full of well-written code.  As in another
thread just today.  And the Abigailisms that crop up are
a fun way to learn more Perl - if your cerebrum doesn't
implode when you first look at it.

If you don't want to see Abigail's posts any more, do what
Abigail has already done to you.  Put the address in your
killfile and never see Abigail again.
 
> Sent via Deja.com http://www.deja.com/
> Before you buy.

s/buy/think/;

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Wed, 01 Dec 1999 11:56:31 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: dbm database perl script (revised)
Message-Id: <38457D6F.8C2F8932@mail.cor.epa.gov>

Jim wrote:
> 
> here's the bit that displays the table. any help ?

Actually, no.  You need to show us the [trimmed] parts where
you [1] put the data in your dbm, and [2] try to get it back
out.  Not HTML or the parts which do the display.  And please
keep your snippets under 20 lines.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Wed, 01 Dec 1999 22:24:29 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: dbm database perl script (revised)
Message-Id: <xeh14.200$JO3.3602@nsw.nnrp.telstra.net>

[Please, don't cc me again on something you also post, and if you
_must_, at least mention it]
[And your systems seems to have caught that chronology bug that is
going around. Your reply comes before the text you reply to. Please
reverse your clock]

On Wed, 01 Dec 1999 15:41:36 GMT,
	Jim <jim@jimmo.freeuk.com> wrote:
> here's the bit that displays the table. any help ?

[snip]

Not really... This isn't related to a dbm at all, as far as I can see.
You really need to show us the code where the dbm gets filled, as I
thought I explained in my request for code earlier in this thread.

All I can see in your code are accesses to two arrays @title and
@maxwidth that seem to be the core of it all.. And maybe an array of
hashes %flags. Is that bit what you are looking for? If so, I am
sorry, but this code bears no resemblance to the question you
originally posted, which was about email addresses and user names.

Either you show us how the dbm gets built, or you tell us a bit more
clearly what it is you want. If you do that, I'm sure we'll be able to
be of much more assistance.

And maybe instead of saying 'I want to use arrays and hashes etc',
state your problem in more general terms. Maybe your choice of storage
solutions (apart maybe from the dbm) is not the best way to go. 

But it is _pertinent_ that you show us how your dbm file is built. If
we don't know that, there is nothing we can do.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Think of the average person. Half of
Commercial Dynamics Pty. Ltd.   | the people out there are dumber.
NSW, Australia                  | 


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

Date: Wed, 01 Dec 1999 22:53:50 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: dbm database perl script (revised)
Message-Id: <2Gh14.306$JO3.3602@nsw.nnrp.telstra.net>

On 01 Dec 1999 06:06:39 -0800,
	Randal L. Schwartz <merlyn@stonehenge.com> wrote:
> >>>>> "Jim" == Jim  <jim@jimmo.freeuk.com> writes:
> 
> Jim> Hi
> Jim> I have a perl script that will write data to a DBM database file.
> Jim> I have no problems with the writing to a database but only the reading
> Jim> from one.
> 
> Argh.  This was also posted in alt.perl, without a crosspost.

You read alt.perl? Hmmm...

Martien

:)
-- 
Martien Verbruggen              | 
Interactive Media Division      | We are born naked, wet and hungry.
Commercial Dynamics Pty. Ltd.   | Then things get worse.
NSW, Australia                  | 


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

Date: 01 Dec 1999 12:11:57 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Devoo.com : source code search engine
Message-Id: <m1ogcamnea.fsf@halfdome.holdit.com>

>>>>> "Alexandre" == Alexandre Naressi <anaressi@rz.uni-leipzig.de> writes:

>> >
>> >Thanks to its increasing popularity, DevCorner becomes DevOo.com.
>> 
>> why would increasing popularity cause you to change to a dumb sounding
>> name?

Alexandre> Indeed, Devoo sounds quite dumb. ;-)

<song style="Devo">
  "Are we not code?  We are De-voo!"
  "Are we not code?  D-e-v-oo!"
</song>

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


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

Date: Wed, 01 Dec 1999 12:38:42 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Dial Up Connection
Message-Id: <38458752.BFE1E642@mail.cor.epa.gov>

dave h wrote:
> 
> Does anyone know if it is possible to write a Perl program to make a
> dial up connection.

Of course it is.

But could you be more specific about the requirements?  Do you
want to dial up a number using a serial port and a modem?  Or
do you have something else in mind?

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Wed, 01 Dec 1999 11:16:34 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: executing in-line program on remote machine
Message-Id: <38457412.6E25146C@mail.cor.epa.gov>

Greg Hersh wrote:
> 
> On a local machine I can execute the following from some shell:
> 
> perl -e 'print "Hello world\n";'
> 
> I can execute the same command on remote host, by issuing the
> following from some shell:
> 
> ssh -r remote-host perl -e \''print "Hello world\n";'\'
> 
> What I can't figure out is how to do the same remote command from
> inside the perl script. Seems like I need yet another layer of quotes,
> butI can't come up with a proper syntax. Any ideas?

Yes.  Don't.

seriously, if you're already in Perl, shelling out to do this
is sub-optimal.  Look at the Net::* modules like Net::Telnet,
Net::FTP, Net::Cmd and see if there's already a module which
does just what you want.  Then you can execute the remote
command without having to spawn a subprocess to spawn a
subprocess to...

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: 1 Dec 1999 08:33:08 -0800
From: sthoenna@efn.org (Yitzchak Scott-Thoennes)
Subject: Re: Extracting data
Message-Id: <ldKR4gzkgqqT092yn@efn.org>

In article <81tu31$ela$1@nnrp1.deja.com>, dave h <dave4000@my-deja.com> wrote:
>The part I need help with is extracting the times!!

Here's one way.

#!perl -w
use strict;
use integer;
use vars qw/$data/;

undef $/;     # file slurp mode--see perldoc perlvar
$data = <DATA>;  # read in the file

# now go through one record at a time, parsing and validating
while ($data=~m'\G       # start this match immediately after the previous one
             name:\ +(.*)\n
             time\ in:\ +((?:[01]\d)|(?:2[0-3])):([0-5]\d)\.([0-5]\d)\n
             time\ out:\ +((?:[01]\d)|(?:2[0-3])):([0-5]\d)\.([0-5]\d)\n
             payee\ no:\ +(.*)\n
               'gcx) {
   my ($name, $timein, $timeout, $payee) = ($1, "$2:$3:$4", "$5:$6:$7", $8);
   my $timediff = (($5-$2)*60+$6-$3)*60+$7-$4;
   $timediff += 86400 if $timediff < 0;  # fixup if they worked through midnight

   printf "Name: %s\nIn: %s\nOut: %s\nSeconds worked: %d\nPayee: %s\n",
          $name, $timein, $timeout, $timediff, $payee;
}
# make sure we successfully parsed the whole thing
die "Bad data!" if !defined pos $data || pos $data != length $data;
__DATA__
name: Mr smith
time in:  09:10.54
time out: 11:13.21
payee no: 0001
name: Mr Bloggs
time in:  11:10.54
time out: 14:13.21
payee no: 0011


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

Date: Wed, 1 Dec 1999 11:38:03 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: grep perl function
Message-Id: <MPG.12af18f1828b845298a2c3@nntp.hpl.hp.com>

In article <823dit0v0t@enews4.newsguy.com> on Wed, 1 Dec 1999 09:53:33 -
0500, Richard Hunkler <rhunkler@isrv.com> says...
> I think I know what the following does:
> 
>    foreach (values %hash1) {
>         grep($hash2{$_}++, @$_);
>    }
> 
> It creates a hash, %hash2, where its keys are the values of %hash1 and the
> values for each of its keys are 1. What I need to know is how it does this?
> What I really need is a more extensive reference to the grep function? All
> the references I find give an example and explanation of grep when the first
> argument is either an expr or a {block}. Any help would be appreciated.

Well, in this case, the first argument to grep *is* an expression.  But 
the use of grep to apply this expression to each of the members of the 
succeeding list is rather deranged.  The purpose of grep is to filter 
the list against the expression and produce either a new list or a count 
of matches.

The proper coding of this snippet just uses another for[each] loop:

     foreach (values %hash1) {
          $hash2{$_}++ foreach @$_;
     }

If the shifting semantics of $_ in the inner loop are too confusing, it 
might be written this way:

     foreach my $value (values %hash1) {
          $hash2{$_}++ foreach @$value;
     }

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 01 Dec 1999 16:37:31 -0500
From: Gary Nielson <gnielson@charlotte.com>
Subject: Re: Help passing arguments to a subroutine
Message-Id: <3845951A.ABD03A93@charlotte.com>

Thanks. I've got it working, even with "use strict" so I am feeling kind of macho right now.
:) But I am also quickly being humbled by the next task I am trying to wrestle with. I am
not looking for code here, just advice on how best to write this part.

Basically, as written now, the script will produce photos and descriptions down a column,
all generated with templates. I want to accomplish two things:

1) After every three photos, add a </TR><TR> so that a new row will be created and three
photos will apear across each row.

2) After a pre-determined number of rows, do something like:

Photos 10-20  Photos 20-30  Photos 30-33

all hyperlinks of course, so I need to create a counter that in advance counts hope many
photos there are to
display, keeps count and on each page keeps track of how many are displayed so far, how many
to display on that page and how many more pages to display of x defined number of photos.

Can you all help point me in the right direction for thinking this through correctly and how
to start sketching out the code I need to create?

Thanks. Please email reply as well.

Gary

Jeff Zucker wrote:

> [posted and mailed]
>
> Gary Nielson wrote:
>
> > My head hurts. I am making progress but it is really painful.
>
> It's darkest before the dawn.  Take a deep breath.  Pour yourself a cup
> of your favorite beverage. Repeat 10 times: "Perl is fun".
>
> >     57         print my $template;
>
> "my" should only be used when you first introduce a variable in a given
> scope; it does not belong in the print statement; it causes Perl to
> forget any previous definitions of $template.  Try this simple example:
>
> my $x = 'hi';
> print my $x;
>
> It prints nothing because the second "my"  negates the first one.
> Remove the second my and this prints "hi" like it should.
>
> >      72                                  $template =~ s/\$SECTION/$contents[1]/g;
> >      73                                  $template =~ s/\$IMAGE/$link\/$contents[0]/g;
> >      74                                  $template =~ s/\$DESCRIPTION/$contents[2]/g;
> >
> > Use of uninitialized value at wallpaper.beta.cgi line 72.
> > Use of uninitialized value at wallpaper.beta.cgi line 74.
>
> Notice that your line 73 did not get a warning but your lines 72 and 74
> did: this means that $contents[0] is initialized but that $contents[1]
> and $contents[2] are not.
>
> > I have tried to initialize all values:
> >
> >      45 my @contents = "";
>
> Aha, so you told Perl that the array @contents was a single string (i.e.
> that $contents[0] is an empty string and that $contents[1] and
> $contents[2] don't exist).  That is why you got those error messages.
> Remove that line and replace it with something that fills the entire
> array @contents with values.
>
> > I do not understand how hashes will help me.
>
> Well perhaps it's too much for you right now.  Stick with your array if
> you are more comfortable with it.  If you want me to explain the hash
> thing, I will, but it sounds like you would prefer to just get what you
> have working for now.  Here's the smallest bit I can think of that
> behaves like what you seem to want:
>
> #!/usr/local/bin/perl -w
> use strict;
> my @contents = ('hello','new','world');
> my $template = '$x--$y--$z';
> $template =~ s/\$x/$contents[0]/g;
> $template =~ s/\$y/$contents[1]/g;
> $template =~ s/\$z/$contents[2]/g;
> print $template; # prints "hello--new--world";
>
> --
> Jeff



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

Date: Wed, 01 Dec 1999 11:21:59 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: help with inserting another html please!
Message-Id: <38457557.3DC2D487@mail.cor.epa.gov>

Bowmah wrote:
> 
> I have permission from another site to insert their html on my site.
> They will update their material daily so I don't want to copy and
> paste on a daily basis. Is there a perl script which will let me
> include their page somewhere as part of my page?
> 
> I am not a programmer and any help would be greatly appreciated!

Perl answer:       You can do this yourself with LWP::simple.

Helpful answer:    Go to comp.infosystems.www.authoring.cgi
                   because this isn't a Perl problem and the
                   answer is more in their purview.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: 1 Dec 1999 21:06:59 GMT
From: mloll@wam.umd.edu (Michael F. Loll)
Subject: Help with XML::DOM usage..
Message-Id: <8242li$j3f$1@dailyplanet.wam.umd.edu>
Keywords: xml dom XML XML::DOM node

First off, if you respond please CC: mloll@wam.umd.edu since I sometimes
can't get time to read newsgroups.  Also, just fyi - this is not a school
project.  This is actually work related.

Ok, I am using XML::DOM to parse a very simple XML file. Basically, my
task is this:

* load the file into the parser
* locate where I should put a new node in
* create new node w/ proper data, put into xml structure, save file

The first two (2) tasks are simple.  It is the third that is giving me
trouble.

I am using perl -w and 'use strict' both of which tell me nothing.  I'll
include the code below ... and how you wehre I get the error.  I did not
include the entire perl script, only the relevant parts (there is no
problem with the rest of the code).

The XML structure is as follows...

-- begin XML file --
<JOBS>
  <JOB ID="NT-000-R3">
    <TITLE>Technician</TITLE>
  </JOB>
  <JOB ID="NT-000-R5">
    <TITLE>Technician #2</TITLE>
  </JOB> 
</JOBS>
-- end XML file --

--begin script--
use strict;

# XML processing
use XML::DOM;

# create parser
my $parser = new XML::DOM::Parser;

# load document
my $job_file = "c:/job.xml";
my $doc = $parser->parsefile($job_file) or
  die "unable to parse document $job_file: $!";

# get all job elements within XML doc
my $jobs = $doc->getElementsByTagName('JOB');

my $found = 0;
my $i = 0;
my $job_position_code = "NT-001-R4";
my $job_title = "a new title";

while( !$found && $i < $jobs->getLength-1 ){
  # get current job
  my $job = $jobs->item($i);
  # find place to insert new node
  if( $job->getAttribute("ID") ge $job_position_code || 
      $job->getAttribute("ID") eq $job_position_code ){

  # I thought this would clone the structure (minus the data)
  # of the node .. basically I want a node that I can copy new data into
  # but keeping the structure of the <JOB> element of the XML doc.
  my $new_node = $job->cloneNode(1);
  $found = 1;
  
  # set ID attribute
  $new_node->setAttribute("ID", $job_position_code);

  # this next line generates the error!
$new_node->getElementsByTagName('TITLE')->item(0)->getFirstChild->setData($job_title);

  # insert node before this current node
  $jobs->insertBefore($new_node, $job);

}

# save changes to file
$doc->printToFile($job_file);

--end of script--

Perl gives me the following error:

-- begin error --
Can't call method "setData"on an undefined value at getXml.pl line 122
-- end error --

Ignore the line number, sicne I shortened the file for this post.  The
error occurs when I try to set the TITLE element's data.

Am I misusing cloneNode() ?  The call to SetAttribute() works fine I
guess, since perl does not complain .. it looks as if perl is complaining
because the element TITLE has no children nodes (i.e. no palce to store
its data??)...???

Any ideas?  Is there an easy why to create a node and insert it into the
XML structure?  I am using Windows98 w/ ActiveState's port of perl version
5.005_03 .

If you respond to my post, please CC mloll@wam.umd.edu.

Thank you.

--
Mike Loll      		mloll@wam.umd.edu
"Opportunities multiply as they are seized."
	-- Sun Tzu, The Art of War


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

Date: 1 Dec 1999 14:29:18 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: HELP! Pair Pattern Matching
Message-Id: <slrn84b1en.m2v.abigail@alexandra.delanet.com>

Tad McClellan (tadmc@metronet.com) wrote on MMCCLXXXIII September
MCMXCIII in <URL:news:slrn84a3to.2v.tadmc@magna.metronet.com>:
** On Wed, 01 Dec 1999 13:23:02 GMT, dave h <dave4000@my-deja.com> wrote:
** 
** >the only ones I need are the Start/Stop pairs.
** >How can I ONLY get these values, not any extra Start or stop values in
** >between?
** 
** -----------------------------------
** #!/usr/bin/perl -w
** use strict;
** 
** my $start;
** 
** while (<DATA>) {
**    $start = $_ if /Start$/;  # overwrite if repeated
**    if ( /Stop$/ ) {          # found a pair, do some processing
**       print $start;
**       print $_;
**    }
** }

That would trigger on *any* Stop found, including "extra" ones.

   my $start;
   while (<DATA>) {
       $start = $_ if /Start$/;
       if (/Stop$/ && $start) {
           # Do something.
           undef $start;
       }
   }

(This however doesn't work if your pairs can nest. It 'start/start/stop/stop'
 a set of 2 nested pairs, or just one pair and two "extra" values? The
 problem isn't clear on that)


Abigail
-- 
perl -e '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
         / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / 
         % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %;
         BEGIN {% % = ($ _ = " " => print "Just Another Perl Hacker\n")}'


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Wed, 01 Dec 1999 19:04:23 GMT
From: Rodney Engdahl <red_orc@my-deja.com>
Subject: Re: How do I see error msgs on Web Page?
Message-Id: <823rfj$pcm$1@nnrp1.deja.com>

In article <823ko2$k7t$1@nnrp1.deja.com>,
  dixonan@my-deja.com wrote:
> I am running a Perl script on my ISP's NT Web Server.
>
> When the script aborts I don't see any messages, so far I've been
> guessing at what is causing the problem. I've read that "CGI::Carp qw
> (fatals to browser); should be used, but I don't know where or how to
> use it.
>

alternatively, and until you get CGI::Carp working, you could simply
print to the browser at intervals until it fails . . . :^)

> Also, how do I access PerlDoc and the FAQ's when Perl is on my ISP's
> machine?

www.cpan.org has this stuff on tap . . .

>
> Thanks
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 01 Dec 1999 19:43:05 GMT
From: dixonan@my-deja.com
Subject: Re: How do I see error msgs on Web Page?
Message-Id: <823to8$r73$1@nnrp1.deja.com>

Thanks for responding to my cry for help...

I've entered messages and I know the line causing my program to abort
but the command looks right, it even works 1/2 the time.  So now I need
to know the exact error.

Can you tell me how I go about getting CGI::Carp running?

Thanks

P.S.  I've checked out www.cpan.org and it's a great help!

In article <823rfj$pcm$1@nnrp1.deja.com>,
  Rodney Engdahl <red_orc@my-deja.com> wrote:
> In article <823ko2$k7t$1@nnrp1.deja.com>,
>   dixonan@my-deja.com wrote:
> > I am running a Perl script on my ISP's NT Web Server.
> >
> > When the script aborts I don't see any messages, so far I've been
> > guessing at what is causing the problem. I've read that "CGI::Carp
qw
> > (fatals to browser); should be used, but I don't know where or how
to
> > use it.
> >
>
> alternatively, and until you get CGI::Carp working, you could simply
> print to the browser at intervals until it fails . . . :^)
>
> > Also, how do I access PerlDoc and the FAQ's when Perl is on my ISP's
> > machine?
>
> www.cpan.org has this stuff on tap . . .
>
> >
> > Thanks
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
> >
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 1 Dec 1999 09:15:35 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: How do I see error msgs on Web Page?
Message-Id: <slrn84abc7.he.tadmc@magna.metronet.com>

On Wed, 01 Dec 1999 17:09:27 GMT, dixonan@my-deja.com <dixonan@my-deja.com> wrote:

>Also, how do I access PerlDoc and the FAQ's when Perl is on my ISP's
>machine?


   Perl is free.

   You can download and install it on your local machine.

   Or, you can check the FAQs online (though that is time consuming
   and inefficient), by going to www.perl.com and clicking on,
   what else?, "FAQs"   :-)



   If you are doing CGI stuff, then you might also want to
   download and install a free web server (e.g. apache) so
   that you can fully test your CGI programs without even
   needing to connect to your ISP.


-- 
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 1 Dec 1999 21:16:06 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: How do I see error msgs on Web Page?
Message-Id: <82436m$fmh$1@gellyfish.btinternet.com>

On Wed, 01 Dec 1999 19:43:05 GMT dixonan@my-deja.com wrote:
> In article <823rfj$pcm$1@nnrp1.deja.com>,
>   Rodney Engdahl <red_orc@my-deja.com> wrote:
>> In article <823ko2$k7t$1@nnrp1.deja.com>,
>>   dixonan@my-deja.com wrote:
>> > I am running a Perl script on my ISP's NT Web Server.
>> >
>> > When the script aborts I don't see any messages, so far I've been
>> > guessing at what is causing the problem. I've read that "CGI::Carp
> qw
>> > (fatals to browser); should be used, but I don't know where or how
> to
>> > use it.
>> >
>>
>> alternatively, and until you get CGI::Carp working, you could simply
>> print to the browser at intervals until it fails . . . :^)
>>
>> > Also, how do I access PerlDoc and the FAQ's when Perl is on my ISP's
>> > machine?
>>
>> www.cpan.org has this stuff on tap . . .
>>
>> >
> 
> I've entered messages and I know the line causing my program to abort
> but the command looks right, it even works 1/2 the time.  So now I need
> to know the exact error.
> 
> Can you tell me how I go about getting CGI::Carp running?
> 

If CGI::Carp doesnt work (it is part of recent Perl installations) then
you need to ask your ISP to upgrade to a version of Perl that includes
it.

In the meantime you might try putting something like :

BEGIN
{
   $SIG{__WARN__} = $SIG{__DIE__} = sub {
                                         print "Content-type: text/plain\n\n";
                                         print @_;
                                        };
}

near the top of your program.  But dont use this as an excuse not to 
complain until your ISP upgrades.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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

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


------------------------------
End of Perl-Users Digest V9 Issue 1539
**************************************


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