[17374] in Perl-Users-Digest
Perl-Users Digest, Issue: 4796 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 2 18:05:47 2000
Date: Thu, 2 Nov 2000 15:05:18 -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: <973206318-v9-i4796@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 2 Nov 2000 Volume: 9 Number: 4796
Today's topics:
1+(-1)=? can be 0 or 2, depending on context (Helmut Richter)
Re: 1+(-1)=? can be 0 or 2, depending on context <joe+usenet@sunstarsys.com>
Re: 1+(-1)=? can be 0 or 2, depending on context <ren.maddox@tivoli.com>
Re: 1+(-1)=? can be 0 or 2, depending on context <joe+usenet@sunstarsys.com>
Re: @ARGV and Absolute URL (BUCK NAKED1)
Re: @ARGV and Absolute URL (Tad McClellan)
Re: @ARGV and Absolute URL (BUCK NAKED1)
Re: @ARGV and Absolute URL (Tad McClellan)
Re: @ARGV and Absolute URL (Richard J. Rauenzahn)
Re: asp <gellyfish@gellyfish.com>
Re: Beginner help with code <michael.segulja@sgi-lsi.com>
Re: Calling a perl script from another domain drtsq@my-deja.com
Communicating with a child process (Sean McAfee)
Comparison - Execution of scripts <dwill@sigecom.net>
Compile Error <bob@fdm4.com>
Do I need eval? jack.dunnigan@ec.gc.ca
Re: Do I need eval? (John J. Trammell)
Re: Do I need eval? jack.dunnigan@ec.gc.ca
Re: Do I need eval? (John J. Trammell)
Re: Do I need eval? (John J. Trammell)
Re: Do I need eval? (Tad McClellan)
does anyone know if this will work? wildhorses@my-deja.com
Re: does anyone know if this will work? (Tad McClellan)
Re: Double fork trick: why does grandkid avoid becoming (Mark-Jason Dominus)
Duplicate lInes in File count and del routine jkipp@mbna.com
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 2 Nov 2000 20:08:41 GMT
From: Helmut.Richter@lrz-muenchen.de (Helmut Richter)
Subject: 1+(-1)=? can be 0 or 2, depending on context
Message-Id: <8tshk9$k47$1@wsc10.lrz-muenchen.de>
I am sorry to be unable to present my problem with a shorter program
than the one below which is already a short excerpt of a much longer
one.
The program parses a linear expression without parentheses. If the
expression is 'i-i' (the first example), it inserts the missing
coefficients so that in effect '1i-1i' is parsed. This happens at the
line which is marked by the comment.
The result is that the minus sign found is concatenated with the thus
defined 1 to become -1. *This* -1 has the odd behaviour that it yields
2 when added to a value of 1.
If the expression is '1i-1i' (second example), this insertion of
missing coefficients does not take place, instead the coefficients are
found in the input string. Again, the minus sign is concatenated with
the 1 (but this one found in the input) to become -1. *This* -1 has
the correct behaviour that it yields 0 when added to a value of 1.
The output of the entire program is:
+++++old: coeff{i}=
+++++coe=+1, coeff{i}=1
+++++old: coeff{i}=1
+++++coe=-1, coeff{i}=2
+++++old: coeff{i}=
+++++coe=+1, coeff{i}=1
+++++old: coeff{i}=1
+++++coe=-1, coeff{i}=0
The problem can be patched by replacing the statement '$coe=1' by
'$coe="1"' but I am reluctant to rely on it because I do not
understand why the first one is wrong. Moreover, the attempt failed to
reproduce a similar problem with an example that contained only the
few lines - irrespective of how the 1 was defined in those artificial
examples. Only the real-life example has this problem.
The interpreter is 'perl, v5.6.0 built for sun4-solaris'.
Any assistance is most warmly welcomed. Thank you.
Helmut Richter
Now here is the program:
#! /client/bin/perl
@irg = &parse_linear ('i-i');
@irg = &parse_linear ('1i-1i');
sub parse_linear {
my ($x) = $_[0];
my (@res);
my (@pos, %coeff, $term, $ipos, $const, $i, $op, $coe, $var);
# parses a linear expression in variables, returns an array containing (coeff, var, ...)
if ($x !~ /^[+-]/) {
$x = "+$x";
};
return ('undef') if $x !~ /^([+-]\d*[A-Za-z]?)+$/;
$x =~ s/([+-])/,$1/g;
$x = substr ($x, 1);
@res = split (/,/, $x);
$ipos = 0;
$const = 0;
foreach $term (@res) {
$term =~ /^([+-])(\d*)([A-Za-z]?)$/;
$op = $1;
$coe = $2;
$var = $3;
return ('undef') if "$coe$var" eq '';
if ($coe eq '') {
# now the following statement causes the problem, but why?
$coe = 1;
};
$coe = "$op$coe";
if ($var eq '') {
$const += $coe;
} else {
if (! defined $coeff{$var}) {
$pos[$ipos++] = $var;
};
print "+++++old: coeff{$var}=$coeff{$var}\n";
$coeff{$var} += $coe;
print "+++++coe=$coe, coeff{$var}=$coeff{$var}\n";
};
};
$pos[$ipos++] = '';
$coeff{''} = $const;
undef @res;
for ($i=0; $i<$ipos; $i++) {
$var = $pos[$i];
if ($coeff{$var}) {
push (@res, $coeff{$var}, $var);
};
};
return (@res);
}
------------------------------
Date: 02 Nov 2000 15:43:51 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: 1+(-1)=? can be 0 or 2, depending on context
Message-Id: <m31ywuxfy0.fsf@mumonkan.sunstarsys.com>
Helmut.Richter@lrz-muenchen.de (Helmut Richter) writes:
> #! /client/bin/perl
>
It usually makes you debugging chores much easier of you acquire
the habit of always enabling warning flags. One way is like so:
#! /client/bin/perl -w
($^W is a global I actually like :)
I'm pretty sure that will help you track down what's happening here.
If you keep a couple of perl versions floating around, in cases
like these it can be enlightening to see the different outputs of
each version.
YMMV.
--
Joe Schaefer
------------------------------
Date: 02 Nov 2000 14:24:21 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: 1+(-1)=? can be 0 or 2, depending on context
Message-Id: <m3hf5q2kcq.fsf@dhcp11-177.support.tivoli.com>
Helmut.Richter@lrz-muenchen.de (Helmut Richter) writes:
> The output of the entire program is:
>
> +++++old: coeff{i}=
> +++++coe=+1, coeff{i}=1
> +++++old: coeff{i}=1
> +++++coe=-1, coeff{i}=2
> +++++old: coeff{i}=
> +++++coe=+1, coeff{i}=1
> +++++old: coeff{i}=1
> +++++coe=-1, coeff{i}=0
Not for me. I get:
+++++old: coeff{i}=
+++++coe=+1, coeff{i}=1
+++++old: coeff{i}=1
+++++coe=-1, coeff{i}=0
+++++old: coeff{i}=
+++++coe=+1, coeff{i}=1
+++++old: coeff{i}=1
+++++coe=-1, coeff{i}=0
BTW, I recommend that you enable warnings and strict. It looks like
you probably have at least strict enabled in your real code, but you
didn't include it in this code. As important as these tools are in
your real code, they are even more important when posting code here.
It gets everyone started on the right foot as they know they are not
going to find silly errors that Perl could have already found.
In this case, you do get a couple of warnings, but they are just
regarding your debug messages. And, of course, you'll need a "my" on
@irg.
I have no idea why you and I get different output. It may seem silly,
but try cut-and-pasting from your own article to make sure you still
get the same behavior.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 02 Nov 2000 16:38:14 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: 1+(-1)=? can be 0 or 2, depending on context
Message-Id: <m3wvemvyux.fsf@mumonkan.sunstarsys.com>
Ren Maddox <ren.maddox@tivoli.com> writes:
> Helmut.Richter@lrz-muenchen.de (Helmut Richter) writes:
>
> > The output of the entire program is:
[...]
> Not for me. I get:
>
> +++++old: coeff{i}=
> +++++coe=+1, coeff{i}=1
> +++++old: coeff{i}=1
> +++++coe=-1, coeff{i}=0
> +++++old: coeff{i}=
> +++++coe=+1, coeff{i}=1
> +++++old: coeff{i}=1
> +++++coe=-1, coeff{i}=0
>
Out of pure curiosity, what version of perl produced such an output?
> I have no idea why you and I get different output. It may seem silly,
> but try cut-and-pasting from your own article to make sure you still
> get the same behavior.
Sheesh !
--
Joe Schaefer
------------------------------
Date: Thu, 2 Nov 2000 13:14:40 -0600 (CST)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: @ARGV and Absolute URL
Message-Id: <18391-3A01BD20-49@storefull-247.iap.bryant.webtv.net>
Here is the part of my script where I'm having a problem. Why doesn't
$ARGV[0} work?
use LWP::Simple;
use MIDI;
getstore("http://downtowndisco.hypermart.net/mid/a-f/fifth_of_beethoven.mid",
$file );
my $o = MIDI::Opus->new( { 'from_file' => "$ARGV[0]" } );
my @tracks = $o->tracks;
print "$ARGV[0] Midi has ", scalar(@tracks), " tracks\n";
Thanks,
Dennis
------------------------------
Date: Thu, 2 Nov 2000 13:47:40 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: @ARGV and Absolute URL
Message-Id: <slrn903dmc.f7u.tadmc@magna.metronet.com>
On Thu, 2 Nov 2000 11:59:38 -0600 (CST), BUCK NAKED1
<dennis100@webtv.net> wrote:
>Thanks Tad. I obviously need to learn about @ARGV, $ARGV and $ARGV[0].
So can we assume that you have already read about them
in perlvar.pod then, right?
@ARGV contains the command line arguments.
$ARGV[0] is indexing the first element in @ARGV, that is,
the first command line argument.
"$ARGV" and "$ARGV[0]" are not related at all despite their
names "looking like" each other. They come from separate namespaces.
>I
>don't know why they are used, or how to use them. I thought $ARGV was
>just a filename or scalar,
It is.
perlvar describes how $ARGV gets set and how to interpret its contents.
>but I'm obviously wrong because something
>like
>
>$ARGV = getstore("http.webhost.com", $file)
>
>doesn't work.
The docs don't say what will happen when _you_ put something
in $ARGV. They only say what _perl_ will put in there, and
when it will put something there.
You should treat the $ARGV variable as "read only".
>Do you put $file in getstore(as above), OR should $file be
>replaced withthe absolute URL where the file is to be kept for
>reading??? I've read perltutopen, and didn't find much there.
You seem to be very confused. I think you are equating "file"
and "what you get when you request a URL on the WWW".
They are not the same thing by a very long shot.
You use open() to read files. Files are on the machine
where your Perl program is running.
You use a module to "read" URLs, such as LWP::Simple. The data
you get may come from a file on the web server that you are
making the request of (most likely this is NOT the machine
where your Perl program is running).
The data may not come from any file anywhere! "URL" does not
imply "file". I hear there is a popular programming language
used to create "dynamic" web pages :-)
In that case "what you get from a URL" is the output of a
program, not a file.
>I'll read
>the doc you suggested.
Oh great. Now you made me spend time on helping you, when you
have ignored the help I've already offered.
You have taken away too much time from the other posters.
I won't be seeing your posts for a while. Sorry.
>It'd be great though, if someone could tell me how to read in the
>contents of an absolute URL that's not on my server with $ARGV[0], for
>processing. :)
Here it is:
die "no args given\n" unless @ARGV;
use LWP::Simple;
my $webpage = get $ARGV[0];
print "here is the webpage I got from $ARGV[0]:\n$webpage\n";
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 2 Nov 2000 14:44:25 -0600 (CST)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: @ARGV and Absolute URL
Message-Id: <3229-3A01D229-10@storefull-246.iap.bryant.webtv.net>
Hi Tad,
I'm sorry you feel that you time was wasted, and that I have taken too
much time from other posters, yet...
I appreciate your help and want to Thank You. FWIW, I had already
studied pervar before seeing your suggestion, but didn't realize it
during my last reply. This is one group where I always first study the
docs and any other info I can find
BEFORE asking a question. THEN, if I still don't "get it" or don't know
"where to find it", I post here for help. Isn't that the way it's
supposed to be done?
Regards,
Dennis
------------------------------
Date: Thu, 2 Nov 2000 15:59:13 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: @ARGV and Absolute URL
Message-Id: <slrn903ld1.fus.tadmc@magna.metronet.com>
On Thu, 2 Nov 2000 14:44:25 -0600 (CST), BUCK NAKED1
<dennis100@webtv.net> wrote:
>Hi Tad,
>
>I'm sorry you feel that you time was wasted, and that I have taken too
>much time from other posters, yet...
It's OK.
Your articles will become visible again in a week or two anyway.
[ I spent time explaining ARGV variables that I didn't need
to spend. I gotta give the other posters a turn for awhile.
]
>I appreciate your help and want to Thank You.
You're welcome.
<FWIW, I had already
>studied pervar before seeing your suggestion, but didn't realize it
>during my last reply.
Oh. You can see how I concluded otherwise?
>This is one group where I always first study the
>docs and any other info I can find
>BEFORE asking a question.
You may even end up being hotlisted then, being in the
minority (for these here parts) and all :-)
>THEN, if I still don't "get it" or don't know
>"where to find it", I post here for help. Isn't that the way it's
>supposed to be done?
Yep. It just didn't appear that that was what had happened.
It's a minor thing. Forget about it.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 2 Nov 2000 22:20:47 GMT
From: nospam@hairball.cup.hp.com (Richard J. Rauenzahn)
Subject: Re: @ARGV and Absolute URL
Message-Id: <973203645.501323@hpvablab.cup.hp.com>
dennis100@webtv.net (BUCK NAKED1) writes:
>Here is the part of my script where I'm having a problem. Why doesn't
>$ARGV[0} work?
What exactly are you expecting @ARGV to do?
>use LWP::Simple;
>use MIDI;
>getstore("http://downtowndisco.hypermart.net/mid/a-f/fifth_of_beethoven.mid",
>$file );
>my $o = MIDI::Opus->new( { 'from_file' => "$ARGV[0]" } );
>my @tracks = $o->tracks;
>print "$ARGV[0] Midi has ", scalar(@tracks), " tracks\n";
What do you expect $ARGV[0] to contain and why?
Rich
--
Rich Rauenzahn ----------+xrrauenza@cup.hp.comx+ Hewlett-Packard Company
Technical Consultant | I speak for me, | 19055 Pruneridge Ave.
Development Alliances Lab| *not* HP | MS 46TU2
ESPD / E-Serv. Partner Division +--------------+---- Cupertino, CA 95014
------------------------------
Date: 2 Nov 2000 07:12:50 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: asp
Message-Id: <8tr45i$7eo$1@orpheus.gellyfish.com>
On 1 Nov 2000 10:54:01 GMT Pinchao Lu wrote:
>
sd[
We need question.
/J\
--
Jonathan Stowe |
<http://www.gellyfish.com> | This space for rent
|
------------------------------
Date: Thu, 02 Nov 2000 22:05:18 GMT
From: Michael Segulja <michael.segulja@sgi-lsi.com>
Subject: Re: Beginner help with code
Message-Id: <8tsoen$sss$1@nnrp1.deja.com>
Thanks so much for the help. That cuts out a lot of work. One thing
I'm wondering about... This returns exactly what I need, but I guess
since it is returning the array, it just outputs each artist on the
smae line separated by a space. Ultimately, I want to output each
artist into a table vertically on a web page so that I can make it
formatted and look nice and neat. i.e. [artist 1]
I guess what I need to do find each row one at a time and output it,
then go and get the second row and output it, etc. I guess I might
need to use some sort of fetchrow_array but I can't figure out what. I
can get it to output one at a time line by line, but it comes out
looking like this: hash[043kd82jsu].
Thanks,
Michael
In article <8ts80o$d3g$1@nnrp1.deja.com>,
Dick Latshaw <latsharj@my-deja.com> wrote:
> In article <8ts1dt$6qv$1@nnrp1.deja.com>,
> Michael Segulja <michael.segulja@sgi-lsi.com> wrote:
>
> > I query the main table (mp3main) on artist. This returns a list of
> > all the artists if I print this out to STDOUT. However, they are
> > listed multiple times, so I then want to take those artists and
> > insert them into a temporary table with a UNIQUE INDEX so duplicates
> > will not be inserted.
>
> > my $statement = "SELECT artist FROM mp3main";
> Try 'SELECT DISTINCT artist FROM mp3main'
>
> --
> Regards,
> Dick
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 02 Nov 2000 22:21:06 GMT
From: drtsq@my-deja.com
Subject: Re: Calling a perl script from another domain
Message-Id: <8tspc8$trm$1@nnrp1.deja.com>
Yes you can.
from perlfaq9 - Networking
"How do I fetch an HTML file?"
# simplest version
use LWP::Simple;
$content = get($URL);
where $URL is the URL and whatever params you are passing, for example
"HTTP://www.foobar-doodad.com.au/cgi-bin/example.pl?mode=lost&faq=net"
then your $content will contain your output.
In article <5BbM5.13364$SF5.292438@ozemail.com.au>,
"Andrew" <andrew_long@andrews-models.com.au> wrote:
>
> Wondering whether it is possible to call a perl script in the cgi-bin
from
> another domain - I've experimented but had no success so far.
>
> Reason for doing that is we have a CPU intensive script and we want
to share
> the load among a number of machines
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 02 Nov 2000 21:00:30 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Communicating with a child process
Message-Id: <OBkM5.8671$O5.196474@news.itd.umich.edu>
This seems like it should be an elementary problem in IPC, but I just can't
seem to come up with a (simple) solution. Argh!
In essence, my problem is this. I fork a child process to act as a filter
by prepending all of its input lines with the line number:
defined(my $pid = open PIPE, '|-') or die "Can't fork: $!\n";
if ($pid == 0) {
my $line = 0;
while (<STDIN>) {
print ++$line, " ", $_;
}
exit;
}
print PIPE "foo\nbar\nbaz\n"; # print lines "1 foo", "2 bar", and "3 baz"
Now I want to change the code so that I can reset the line counter in
the child process from the parent process:
print PIPE "foo\nbar\nbaz\n"; # prints "1 foo", "2 bar", "3 baz"
# (do something)
print PIPE "baz\nbletch\nquux\n"; # prints "1 baz", "2 bletch", "3 quux"
Is this possible? If so, how? Every approach I've tried rapidly becomes
more complicated than my original solution (using a tied filehandle).
--
Sean McAfee mcafee@umich.edu
print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!
------------------------------
Date: Thu, 2 Nov 2000 14:47:40 -0600
From: "David Williams" <dwill@sigecom.net>
Subject: Comparison - Execution of scripts
Message-Id: <mdkM5.224$GI4.182@newsfeed.slurp.net>
I am new to Perl, have worked with JavaScript some, VBScript some. I am
curious as to which scripting language provides the fastest response for the
user. Does anyone have a link to this information or your own opinion?
------------------------------
Date: Thu, 02 Nov 2000 20:28:16 GMT
From: "Bob Q" <bob@fdm4.com>
Subject: Compile Error
Message-Id: <A7kM5.421159$1h3.11466527@news20.bellglobal.com>
Installng Perl 5.6.0
IBM AIX 4.3.#
running make
Any suggestions ,
Thanks in advance.
`sh cflags libperl.a pp_sys.o` pp_sys.c
CCCMD =
cc -DPERL_CORE -c -D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOU
RCE -qmaxmem=16384 -fno-strict-aliasing -I/usr/local/include -q32 -D_LARGE_F
ILES
-qlonglong -O
cc: unrecognized option `-qmaxmem=16384'
cc: unrecognized option `-q32'
cc: unrecognized option `-qlonglong'
pp_sys.c: In function `Perl_pp_gmtime':
pp_sys.c:4079: warning: assignment makes pointer from integer without a cast
pp_sys.c:4081: warning: assignment makes pointer from integer without a cast
pp_sys.c:4090: dereferencing pointer to incomplete type
pp_sys.c:4091: dereferencing pointer to incomplete type
pp_sys.c:4092: dereferencing pointer to incomplete type
pp_sys.c:4093: dereferencing pointer to incomplete type
pp_sys.c:4094: dereferencing pointer to incomplete type
pp_sys.c:4095: dereferencing pointer to incomplete type
pp_sys.c:4096: dereferencing pointer to incomplete type
pp_sys.c:4100: dereferencing pointer to incomplete type
pp_sys.c:4101: dereferencing pointer to incomplete type
pp_sys.c:4102: dereferencing pointer to incomplete type
pp_sys.c:4103: dereferencing pointer to incomplete type
pp_sys.c:4104: dereferencing pointer to incomplete type
pp_sys.c:4105: dereferencing pointer to incomplete type
pp_sys.c:4106: dereferencing pointer to incomplete type
pp_sys.c:4107: dereferencing pointer to incomplete type
pp_sys.c:4108: dereferencing pointer to incomplete type
make: The error code from the last command is 1.
Stop.
#
------------------------------
Date: Thu, 02 Nov 2000 20:00:16 GMT
From: jack.dunnigan@ec.gc.ca
Subject: Do I need eval?
Message-Id: <8tsh4a$m36$1@nnrp1.deja.com>
I have an array for which some of the elements hold a keyword and a
directory structure like so..
eq/ one element of the array might be..
Reception_Group_Definition = /users/goesadm/db/pdg/somefile
another might be..
Band4_Product = /disk1/goes_im/products/anotherfile
Is there an elegant way to grep the array and somehow 'eval' to set a
variable of the same keyword in my perlscript.
i.e. I want my script to somehow do this..
$Reception_Group_Definition="/users/goesadm/db/pdg/somefile";
$Band4_Product = "/disk1/goes_im/products/anotherfile";
preferably using a one-liner within a loop..
something like
foreach (qw/keywords to search/){
#please help with one liner for here
}
Jack
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 2 Nov 2000 20:18:59 GMT
From: trammell@nitz.hep.umn.edu (John J. Trammell)
Subject: Re: Do I need eval?
Message-Id: <slrn902om5.nbb.trammell@nitz.hep.umn.edu>
On Thu, 02 Nov 2000 20:00:16 GMT, jack.dunnigan@ec.gc.ca
<jack.dunnigan@ec.gc.ca> wrote:
>I have an array for which some of the elements hold a keyword and a
>directory structure like so..
>
>eq/ one element of the array might be..
>Reception_Group_Definition = /users/goesadm/db/pdg/somefile
>
>another might be..
>Band4_Product = /disk1/goes_im/products/anotherfile
>
>Is there an elegant way to grep the array and somehow 'eval' to set a
>variable of the same keyword in my perlscript.
It is possible, but it is the wrong approach. See
http://www.plover.com/~mjd/perl/varvarname.html
for a concise explanation, and the "right" answer.
--
John J. Trammell
johntrammell@yahoo.com
------------------------------
Date: Thu, 02 Nov 2000 21:04:11 GMT
From: jack.dunnigan@ec.gc.ca
Subject: Re: Do I need eval?
Message-Id: <8tsks4$pee$1@nnrp1.deja.com>
In article <slrn902om5.nbb.trammell@nitz.hep.umn.edu>,
trammell@nitz.hep.umn.edu (John J. Trammell) wrote:
> On Thu, 02 Nov 2000 20:00:16 GMT, jack.dunnigan@ec.gc.ca
> <jack.dunnigan@ec.gc.ca> wrote:
> >I have an array for which some of the elements hold a keyword and a
> >directory structure like so..
> >
> >eq/ one element of the array might be..
> >Reception_Group_Definition = /users/goesadm/db/pdg/somefile
> >
> >another might be..
> >Band4_Product = /disk1/goes_im/products/anotherfile
> >
> >Is there an elegant way to grep the array and somehow 'eval' to set a
> >variable of the same keyword in my perlscript.
>
> It is possible, but it is the wrong approach. See
>
> http://www.plover.com/~mjd/perl/varvarname.html
>
> for a concise explanation, and the "right" answer.
Understood. So how would one just parse the directory (in one line) so I
can store it to a hash?
...I'm thinking of something like this..
$hash{uniquekeyname} = (split("=",(grep/$_/,@array)))[1];
but it doesn't seem to work.
Jack
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 2 Nov 2000 22:12:15 GMT
From: trammell@nitz.hep.umn.edu (John J. Trammell)
Subject: Re: Do I need eval?
Message-Id: <slrn902vai.oks.trammell@nitz.hep.umn.edu>
On Thu, 02 Nov 2000 21:04:11 GMT, jack.dunnigan@ec.gc.ca
<jack.dunnigan@ec.gc.ca> wrote:
>In article <slrn902om5.nbb.trammell@nitz.hep.umn.edu>,
> trammell@nitz.hep.umn.edu (John J. Trammell) wrote:
>> On Thu, 02 Nov 2000 20:00:16 GMT, jack.dunnigan@ec.gc.ca
>> <jack.dunnigan@ec.gc.ca> wrote:
>> >I have an array for which some of the elements hold a keyword and a
>> >directory structure like so..
>> >
>> >eq/ one element of the array might be..
>> >Reception_Group_Definition = /users/goesadm/db/pdg/somefile
>> >
>> >another might be..
>> >Band4_Product = /disk1/goes_im/products/anotherfile
>> >
[snip]
>
>Understood. So how would one just parse the directory (in one line) so I
>can store it to a hash?
>
>...I'm thinking of something like this..
>$hash{uniquekeyname} = (split("=",(grep/$_/,@array)))[1];
How about
my %hash;
foreach my $line (@array)
{
chomp $line;
my ($k,$v) = ($line =~ /(.*) = (.*)/); # may need work
$hash{$k} = $v;
}
One could cobble something together w/ map() but I think this
scans better.
--
John J. Trammell
johntrammell@yahoo.com
------------------------------
Date: 2 Nov 2000 22:17:17 GMT
From: trammell@nitz.hep.umn.edu (John J. Trammell)
Subject: Re: Do I need eval?
Message-Id: <slrn902vk0.p7a.trammell@nitz.hep.umn.edu>
On 2 Nov 2000 22:12:15 GMT, John J. Trammell <trammell@nitz.hep.umn.edu> wrote:
>On Thu, 02 Nov 2000 21:04:11 GMT, jack.dunnigan@ec.gc.ca
><jack.dunnigan@ec.gc.ca> wrote:
>>In article <slrn902om5.nbb.trammell@nitz.hep.umn.edu>,
>> trammell@nitz.hep.umn.edu (John J. Trammell) wrote:
>>> On Thu, 02 Nov 2000 20:00:16 GMT, jack.dunnigan@ec.gc.ca
>>> <jack.dunnigan@ec.gc.ca> wrote:
>>> >I have an array for which some of the elements hold a keyword and a
>>> >directory structure like so..
>>> >
>>> >eq/ one element of the array might be..
>>> >Reception_Group_Definition = /users/goesadm/db/pdg/somefile
>>> >
>>> >another might be..
>>> >Band4_Product = /disk1/goes_im/products/anotherfile
>>> >
>[snip]
>>
>>Understood. So how would one just parse the directory (in one line) so I
>>can store it to a hash?
[snip]
Whoops -- one line, huh?
my %hash = map { split /=/ } @array; # regex may need tweaking
--
John J. Trammell
johntrammell@yahoo.com
------------------------------
Date: Thu, 2 Nov 2000 16:14:47 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Do I need eval?
Message-Id: <slrn903ma7.fus.tadmc@magna.metronet.com>
On Thu, 02 Nov 2000 21:04:11 GMT, jack.dunnigan@ec.gc.ca
<jack.dunnigan@ec.gc.ca> wrote:
>In article <slrn902om5.nbb.trammell@nitz.hep.umn.edu>,
> trammell@nitz.hep.umn.edu (John J. Trammell) wrote:
>> On Thu, 02 Nov 2000 20:00:16 GMT, jack.dunnigan@ec.gc.ca
>> <jack.dunnigan@ec.gc.ca> wrote:
[ snip wants to use a symref ]
>Understood. So how would one just parse the directory (in one line) so I
^^^^^^^^^^^
>can store it to a hash?
That is a silly restriction that can not add any significant value,
so I'm going to ignore it :-)
Do you have a sensible justification for restricting it to
only one-line solutions?
----------------------
#!/usr/bin/perl -w
use strict;
my %hash;
while ( <DATA> ) {
chomp;
my($key, $value) = split /\s*=\s*/;
$hash{$key} = $value;
}
foreach (sort keys %hash) {
print "$_ ==> $hash{$_}\n";
}
__DATA__
Reception_Group_Definition = /users/goesadm/db/pdg/somefile
Band4_Product = /disk1/goes_im/products/anotherfile
----------------------
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 02 Nov 2000 19:25:58 GMT
From: wildhorses@my-deja.com
Subject: does anyone know if this will work?
Message-Id: <8tsf3p$jvt$1@nnrp1.deja.com>
We want to test to see if our data base is working or not. Does this
($Conn->Open( "username", "password", "databasename" )) return true or
false if used as posted below?
<%@ LANGUAGE = PerlScript %>
<%
$Conn = $Server->CreateObject("ADODB.Connection");
if ($Conn->Open( "username", "password", "databasename" )){
$Response->Write("SUCCESS");
}
else{
$Response->Write("UNSUCCESSFUL");
}
$Conn->Disconnect();
%>
<html>
<meta name="Microsoft Border" content="none, default">
<body>
</body>
</html>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 2 Nov 2000 15:40:20 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: does anyone know if this will work?
Message-Id: <slrn903k9k.fon.tadmc@magna.metronet.com>
On Thu, 02 Nov 2000 19:25:58 GMT, wildhorses@my-deja.com
<wildhorses@my-deja.com> wrote:
><%@ LANGUAGE = PerlScript %>
PerlScript is not Perl.
This is a newsgroup for Perl.
Please try to find a newsgroup or mailing list about the
PerlScript language for asking PerlScript questions.
Thank you.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 02 Nov 2000 20:11:24 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Double fork trick: why does grandkid avoid becoming a zombie?
Message-Id: <3a01ca6b.224$2d3@news.op.net>
In article <3A01927E.CAE3552A@unix.amherst.edu>,
Laird Nelson <ljnelson@unix.amherst.edu> wrote:
>The grandchild of the original spawning process--the grandchild's path
>of execution is inside the second "unless" block--apparently does not
>become a zombie because its parent process ID somehow magically becomes
>that of the init process. My question is, how? why? Nothing in fork(2)
>that I can see (note: that I can see :-)) implies that a forked child's
>child will somehow magically get assigned to the init process as a
>child.
Right, because of course that is not the case. Otherwise, your Perl
program would have been adopted by init, because it is the child of
the shell you ran it from, and the shell is the child of /bin/login.
What you are missing is that when a process *exits*, its orphaned
children are adopted by init. If you look in _exit(2), it will
probably say something to this effect. For example, on my system:
_exit terminates the calling process immediately. . . . any
children of the process are inherited by process 1, init. . . .
In the double-fork trick, the main process forks a child, which forks
a grandchild. The child exits, and the orphaned grandchild is adopted
by init. The dead child can be cleaned up immediately.
Now the next question is: "Why does being adopted by init prevent a
process form becoming a zombie?" And the answer is that the code for
init looks something like this:
while (1) { wait() }
# except the real init is written in C, not in Perl.
It is in an infinite loop waiting for one of its adopted children to
die; when one does, init cleans up the corpse immediately. In fact,
that's the primary function of init.
Hope this helps.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Thu, 02 Nov 2000 22:24:53 GMT
From: jkipp@mbna.com
Subject: Duplicate lInes in File count and del routine
Message-Id: <8tspj9$tut$1@nnrp1.deja.com>
Myself and another admin are workin on the following script ( I will
only post the routines I have the question on). The part of the script
That I am dealing with here parses a file generated by another script.
The file will have lines with one IP address on each line. It then
makes a new file after it is done doing stuff to the file fed to it.
here is the sub that takes the file and passes to another routine :
---------------
elsif (defined($opts{f} && $opts{l})) {
my $file = $opts{f};
my $log = $opts{l};
pfile_log(\$file, \$log);
--------------
the file is passed to another routine that parses the file and and pairs
the IP adr with a hostname
---------------
sub pfile_log {
my ($file, $log) = @_;
open(FILE, "$$file") or die "Can't open $$file:$!" if -e $$file;
my @file = <FILE>;
close FILE or die "Can't close $$file:$!";
open(LOG, ">$$log") or die "Can't open $$log for writing:$!";
foreach (@file) {
chomp;
if (/( \d{1,3} \. \d{1,3} \. \d{1,3} \. \d{1,3} )/gx){
my $name = gethostbyaddr(inet_aton($1), AF_INET);
print LOG "$name => ",$1, "\n";
} else {
next;
}
next;
}
-----------------
Here is what we need it to now do.
Read each line in the result log file(ip/hostname combo) if we find a
dup line start counter at 2 and delete the dup line
if find again add 1 to count
delete the dup line
do until EOF
print non dup lines just as "Ip -> Host"
print dup lines "ip -> host" x "times"
--------------------
Any suggestions will be greatly appreciated. Email directly or posts if
this is not clear.
Thanks
Jim
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
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 4796
**************************************