[15829] in Perl-Users-Digest
Perl-Users Digest, Issue: 3242 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jun 3 14:05:26 2000
Date: Sat, 3 Jun 2000 11:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <960055511-v9-i3242@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 3 Jun 2000 Volume: 9 Number: 3242
Today's topics:
"system" and output flush <fchen@fas.harvard.edu>
Any function to include a HTML file into the Perl scrip <chus@netvigator.com>
Re: Any function to include a HTML file into the Perl s <kestrelwings@laser.home.com>
Re: CHDIR - I can't get it to work (Gwyn Judd)
Re: CHDIR - I can't get it to work (Bart Lateur)
create Hash from two arrays? <mc@backwoods.org>
Re: create Hash from two arrays? <abe@ztreet.demon.nl>
Re: Email this story to a friend - html to text (Tad McClellan)
Re: error compiling Perl with HP-UX 11 <Reiner_Buehl@hp.com>
Re: error compiling Perl with HP-UX 11 <dan@tuatha.sidhe.org>
Execute perl code in a variable <eidheim@hivolda.no>
Re: Execute perl code in a variable <tony_curtis32@yahoo.com>
Re: How do I update records in a file? (cgi & perl) (Tad McClellan)
Re: How do I update records in a file? (cgi & perl) <nayler@SPAMOFFses.curtin.edu.au>
Re: how do you create scalar vars from a hash? <abe@ztreet.demon.nl>
How to escape "/"? <fchen@fas.harvard.edu>
Re: How to escape "/"? <tony_curtis32@yahoo.com>
Re: How to find out height and width of a PNG graphic <founder@pege.org>
Limits on $ENV{} hash ? (Philip Taylor)
Re: Limits on $ENV{} hash ? <dan@tuatha.sidhe.org>
Not shifting what I want from an array (Craig Kelly)
Re: Not shifting what I want from an array <tony_curtis32@yahoo.com>
Ordering Elements in an Array <Greg@LibertyMarketing.com>
Re: Ordering Elements in an Array <sweeheng@usa.net>
Re: Ordering Elements in an Array <abe@ztreet.demon.nl>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 3 Jun 2000 15:25:36 GMT
From: feng chen <fchen@fas.harvard.edu>
Subject: "system" and output flush
Message-Id: <8hb81g$vo6$2@news.fas.harvard.edu>
Hi, There.
I have a perl script which uses several "system" calls
to run other perl script such as:
system "perl p1.pl ......";
system "perl p2.pl ......";
system "perl p3.pl ......";
The problems I have are that the outputs from those
system calls are interleaved. How to make sure that
the output from p2.pl appears after the output of p1.pl?
Thanks.
Feng
------------------------------
Date: Sun, 4 Jun 2000 00:00:24 +0800
From: "Chu" <chus@netvigator.com>
Subject: Any function to include a HTML file into the Perl script
Message-Id: <8hb9pf$bp53@imsp212.netvigator.com>
Dear all Perl specialist,
In the PHP, you can include a HTML file inside the script.
Can the Perl do that? If can, how?
Best Rgds,
Eddie Chu
chus@netvigator.com
------------------------------
Date: Sat, 03 Jun 2000 17:57:38 GMT
From: "Mike Rhino" <kestrelwings@laser.home.com>
Subject: Re: Any function to include a HTML file into the Perl script
Message-Id: <mGb_4.86479$55.708487@news1.sttls1.wa.home.com>
Chu <chus@netvigator.com> wrote in message
news:8hb9pf$bp53@imsp212.netvigator.com...
> Dear all Perl specialist,
>
> In the PHP, you can include a HTML file inside the script.
>
> Can the Perl do that? If can, how?
>
> Best Rgds,
> Eddie Chu
> chus@netvigator.com
I don't know anything about PHP. Are you talking about something like the
following? The following prints the top of a web page. The meat of the
code prints the rest of the page. Everthing after "<<" becomes the end of
text marker -- in this case END_OF_HTML_HEADER. When it hits that string
again, that's the end of the text string. You can also load a multiline
string into a string. The following example includes some variables like
"$textcolor" and "$tablebackcolor".
sub print_header {
print FOUT <<END_OF_HTML_HEADER;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<style>
a:hover { color : #FF0000; }
</style>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">
<META NAME="GENERATOR" Content="V">
<TITLE>Directory of $picdir</TITLE>
</HEAD>
<BODY TEXT="$textcolor" topmargin="0" leftmargin="0" marginwidth="0"
marginheight="0" BGCOLOR="$pagebackcolor">
<FORM ACTION="default.cgi" METHOD="POST"
ENCTYPE="application/x-www-form-urlencoded">
<P>
<TABLE BORDER="0" CELLPADDING="3" CELLSPACING="0" WIDTH="$tablewidth"
BGCOLOR="$tablebackcolor">
<TR>
<TD COLSPAN="$maxcols"><P ALIGN="CENTER"><B><FONT SIZE="5"
COLOR="#FFFF88">Directory of $picdir</FONT></B></TD>
</TR>
<TR>
END_OF_HTML_HEADER
}
------------------------------
Date: Sat, 03 Jun 2000 13:17:27 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: CHDIR - I can't get it to work
Message-Id: <slrn8jklrk.35f.tjla@thislove.dyndns.org>
I was shocked! How could Kenny <kenny@kenny.co.uk>
say such a terrible thing:
>The reason I put in the line I did rather than a DIE statement was simply
>because I was using the command for the first time in a test program,
>therefore I just was mucking about. The directory name I used definitely
>exists because it came back with the statement "It worked" and I checked the
>directory exists as well. However, I don't see how permissions could be a
>reason it would not work. What permission needs to be set?
Well to change to a directory you need to have execute permissions. Did
you try the version I gave you? WHat did it say? The reason I ask is
that the die() wasn't strictly speaking the interesting bit but it used
the $! variable (which holds the string describing the last system call
error). If that works okay then maybe you need to look at the thing your
glob is matching against. The "*.*" pattern will match any file with a
"." in it's name. Maybe none of the files have "."'s?
--
Gwyn Judd (tjla@guvfybir.qlaqaf.bet)
My return address is rot13'ed
People who claim they don't let little things bother them have never
slept in a room with a single mosquito.
-- Unknown
------------------------------
Date: Sat, 03 Jun 2000 13:43:58 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: CHDIR - I can't get it to work
Message-Id: <393b09fb.1313366@news.skynet.be>
Kenny wrote:
>The e-mail address I quoted is certainly not correct, if I put in my real
>e-mail address I would get thousands of SPAM mail. You're not trying to
>tell me people actually put in their real addresses here, are you? If you
>do, how do you stop the spam?
I do use y real email address. I don't get thousands of spam messages. I
get a few a day, at most. Actually, it looks like at present, I get more
spam messages sent through some mailng lists, than sent directly to me.
I don't know why I don't get more. It used to be a lot worse. Maybe my
ISP filters a lot of spam out of my mail. Some ISP's do. I don't know...
maybe the spammers have just given up? Maybe nobody loves me? I didn't
even get a copy of the I LOVE YOU email virus! Sniff...
Anyway, one way to get rid of a lot of spam, is through an email filter.
Many email clients have that possibility. Just move all mails not
addressed to you personally (your address not in To: or CC: field) to
the trash. That would include mailing lists... which you have to filter
out first.
--
Bart.
------------------------------
Date: Sat, 03 Jun 2000 13:26:10 -0400
From: MC <mc@backwoods.org>
Subject: create Hash from two arrays?
Message-Id: <39393FB2.91F6D93F@backwoods.org>
I need to create a hash from two arrays, one containing the keys, the other
containing the data.
I have the following code, but is there a simpler/faster way....
my (@keys, @data, %hash);
... code which populates @keys and @data from a file ...
for ($f=0;$f<=$#keys;$f++) { $hash{$keys[$f]} = $data[$f] };
any suggestions anyone ?
MC
--
---------------------------------------------------------------------
My email address(s) are my private property. They are NOT to be used
or recorded for ANY reason without my explicit permission. Disregard
of this statement is in violation of federal privacy & copyright law.
---------------------------------------------------------------------
The new Decade/Century/Millennium doesnt start until the year 2001 !!
Lets make the year 2000, the last year of the Millennium, a good one!
--------------------------------------------+------------------------
|
<-- THIS SPACE FOR RENT --> | Question Reality
advertise~backwoods.org |
|
Time is nature's way of keeping | If at first you don't
everything from happening at once | succeed... REBOOT!
|
--------------------------------------------+------------------------
------------------------------
Date: Sat, 03 Jun 2000 20:17:05 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: create Hash from two arrays?
Message-Id: <jpiijs84lh3cn8okhk62luv0fudgolml38@4ax.com>
On Sat, 03 Jun 2000 13:26:10 -0400, MC <mc@backwoods.org> wrote:
> I need to create a hash from two arrays, one containing the keys, the other
> containing the data.
>
> I have the following code, but is there a simpler/faster way....
>
> my (@keys, @data, %hash);
>
> ... code which populates @keys and @data from a file ...
>
> for ($f=0;$f<=$#keys;$f++) { $hash{$keys[$f]} = $data[$f] };
my %hash; #you'd done that already
@hash{ @keys } = @values;
--
Good luck,
Abe
------------------------------
Date: Sat, 3 Jun 2000 07:49:56 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Email this story to a friend - html to text
Message-Id: <slrn8jhvnk.ts.tadmc@maxim.metronet.com>
On Sat, 03 Jun 2000 03:08:42 GMT, Tony Lanier <rlanier@nc.rr.com> wrote:
>If you're on UNIX (any flavor, I suppose), you'd have to set your $PERL5LIB
^^^^^^^
You _can_, not _have to_.
There are other ways.
>environment variable to point to this new directory. If you're on Windows
>(or whatever), I'm not sure, but I would think its probably similar to what
>I just said. Hope this helps.
>
>
><rk27@my-deja.com> wrote in message news:8h93np$6j7$1@nnrp1.deja.com...
>>
>>
>> But how do I installed these modules.
Perl FAQ, part 8:
"How do I keep my own module/library directory?"
"How do I add the directory my program lives in to the
module/library search path?"
"How do I add a directory to my include path at runtime?"
>> I am on an NT.
Everbody has problems :-)
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 03 Jun 2000 21:31:30 +0400
From: Reiner Buehl <Reiner_Buehl@hp.com>
Subject: Re: error compiling Perl with HP-UX 11
Message-Id: <a2gijs0pt78f5otm6g55s5hfu54k1phue0@4ax.com>
On 31 May 2000 14:55:47 GMT, sicherman@lucent.com (G. L. Sicherman) wrote:
>2. Omit -O or replace it by +O1. Feasible but sacrifices efficiency.
>
>3. Use gcc. Same comment as 2.
What makes you think, gcc is less efficient? Did you do any tests?
A lot of Opensource code is written to use the specifics of gcc.
Best Regards,
Reiner.
------------------------------
Date: Sat, 03 Jun 2000 18:03:03 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: error compiling Perl with HP-UX 11
Message-Id: <rLb_4.100804$hT2.410435@news1.rdc1.ct.home.com>
Reiner Buehl <Reiner_Buehl@hp.com> wrote:
> On 31 May 2000 14:55:47 GMT, sicherman@lucent.com (G. L. Sicherman) wrote:
>>2. Omit -O or replace it by +O1. Feasible but sacrifices efficiency.
>>
>>3. Use gcc. Same comment as 2.
> What makes you think, gcc is less efficient? Did you do any tests?
If you're on a non-intel machine, generally gcc isn't the best choice for
speed. It's generally beaten by the CPU manufacturer or OS vendor's
compiler. (Dec C is significantly better on Alphas, Sun's compiler usually
beats it on Sparc machines, and I expect it's not as good for MIPS systems
or HP's PA-RISC machines, though I have no direct experience with either
of them)
> A lot of Opensource code is written to use the specifics of gcc.
So? The compiler's still not as good. (And we'll ignore the fact that C is
usually the wrong language for whatever you're doing, but that's a
separate issue) Regardless, we're talking perl specifically and it isn't
written to the specifics of GCC. Using any ANSI C compiler will get you
going, and using your vendor's latest compiler will generally get you
better performance than GCC, assuming that GCC isn't what they provide.
Dan
------------------------------
Date: Sat, 03 Jun 2000 19:29:00 +0200
From: Ole Christian Eidheim <eidheim@hivolda.no>
Subject: Execute perl code in a variable
Message-Id: <3939405C.62C527A2@hivolda.no>
I want to execute code that resides in a variable. The code is fetched
into the variable from a database. How do I execute this code and still
have access to the resources in my script(the script that runs the code
in the variable).
So far I have used `perl -e $code_from_database`. But doing this don't
give the code in $code_from_database access to variables declared in my
script that runs the command listed above. Also using this command
starts another instance of perl which takes time and resources.
Another question:
In C you have #define statements. Is there a similiar data type in perl?
Thanks,
Ole Christian Eidheim
------------------------------
Date: 03 Jun 2000 12:39:52 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Execute perl code in a variable
Message-Id: <87snuuvf2v.fsf@limey.hpcc.uh.edu>
>> On Sat, 03 Jun 2000 19:29:00 +0200,
>> Ole Christian Eidheim <eidheim@hivolda.no> said:
> I want to execute code that resides in a variable. The
> code is fetched into the variable from a database. How
> do I execute this code and still have access to the
> resources in my script(the script that runs the code in
> the variable).
perldoc -f eval
> Another question: In C you have #define statements. Is
> there a similiar data type in perl?
Well, #define doesn't have anything to do with data types,
it's simply a textual replacement with macros. It's
(almost) invisible to the C compiler.
"perldoc perldata" is probably the place to start,
followed by "perldoc perldsc".
An example of what you're trying to do might help as well,
there are probably well-known ways (probably modules) of
achieving what to you want to do.
hth
t
--
"Trying is the first step towards failure"
Homer Simpson
------------------------------
Date: Sat, 3 Jun 2000 07:55:34 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: How do I update records in a file? (cgi & perl)
Message-Id: <slrn8ji026.ts.tadmc@maxim.metronet.com>
On Sat, 3 Jun 2000 18:52:35 +0800, Thaddeus
<nayler@SPAMOFFses.curtin.edu.au> wrote:
>
>People need to be able to update the second field via cgi and see the
^^^^^^^
>results.
So you have taint checking (-T) turned on and you carefully
check what the crackers (err, users) have entered into the form?
>I'm fine with opening, printing, appending, and overwriting records, but how
>do I get to a certain part of a certain record and update that in
>particular? Since this is web-based, different people can update the same
>record at any one time -
You will need file locking to avoid corrupting the data file too.
>How would I do this?
-------------------------------
#!/usr/bin/perl -w
use strict;
while (<DATA>) {
print "before: $_";
my @fields = split /\|/;
$fields[1] = 'a new value';
print ' after: ', join('|', @fields), "\n";
}
__DATA__
1|2|person|description
2|8|person|description
3|25|person|description
4|0|person|description
-------------------------------
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 4 Jun 2000 00:20:03 +0800
From: "Thaddeus" <nayler@SPAMOFFses.curtin.edu.au>
Subject: Re: How do I update records in a file? (cgi & perl)
Message-Id: <8hbb86$3jb$1@ftp.curtin.edu.au>
> -------------------------------
> #!/usr/bin/perl -w
> use strict;
>
> while (<DATA>) {
> print "before: $_";
> my @fields = split /\|/;
>
> $fields[1] = 'a new value';
>
> print ' after: ', join('|', @fields), "\n";
> }
>
Ok, great, how do i actually update this file when it is open for reading?
eg:
open (DATA, "<$filename");
while (<DATA>)
{
@record=split/\|/;
$record[1]++;
join('|', @record); **gives a warning - pointless use of join **
*the file is open and i want to update the record*
}
This seems better but it also doesnt work:
open (DATA, "<$filename");
@records=<DATA>;
foreach $record (@records)
{
($field1,$field2,$field3)=split(/\|/, $record);
if ($field3 eq "personname")
{
close (DATA)
$field2++
$record[$count]="$field1|$field2|$field3";
open (DATA, "<$filename");
@records=sort {$b <=> $a} @records;
close (DATA);
}
}
I also need to sort the record by the value of the second field (highest ->
lowest) as you can see I was trying to do.
Feel free to point out syntax errors, but i didnt copy/paste so its not
exact.
Sorry if its simple, but its not clear to me just now how to do it.
Thad.
------------------------------
Date: Sat, 03 Jun 2000 19:33:20 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: how do you create scalar vars from a hash?
Message-Id: <i3eijs4lni7k3506pt4t012d4urvjncmc7@4ax.com>
On Sat, 03 Jun 2000 10:55:12 GMT, arneh@NOSPAMistar.ca (Arne Hermann)
wrote:
> On Wed, 31 May 2000 22:45:25 -0700, Larry Rosler <lr@hpl.hp.com>
> wrote:
>
> >In article <3935beb4.14673748@news.direct.ca>, arneh@NOSPAMistar.ca
> >says...
> >...
> >> On Mon, 29 May 2000 17:22:31 -0700, Larry Rosler <lr@hpl.hp.com>
> >> wrote:
> >...
> >> >In article <3932c114.62322141@news.direct.ca>, arneh@NOSPAMistar.ca
> >> >says...
> >...
...
> >> $PARMS{'foo'} = "FOO";
^^^^^
> >> $$PARMS{'foo'} = $PARMS{'foo'};
> >
> > $PARMS{'foo'} = "foo";
^^^^^
> > ${$PARMS{'foo'}} = $PARMS{'foo'};
> >
> >You can leave out all those single quotes, and use single quotes for the
> >simple constant:
> >
> > $PARMS{foo} = 'foo';
> > ${$PARMS{foo}} = $PARMS{foo};
> >
> >> print "foo is $foo\n"; #does not print FOO, prints null
> >> $$_ = $PARMS{$_} for keys %PARMS;
> >> print "foo is $foo\n"; #prints FOO
> >> exit;
...
> >> And, of course, your thoughts on why the $$PARMS
> >> assignment doesn't work!
> >
> >I answered that above. It is a question of binding precedence, and Perl
> >variable names are case sensitive. $FOO isn't the same as $foo.
>
> Um, I know that var names are case sensitive (duh!) - I never
> referenced $FOO anywhere but only $foo (where did you see $FOO??) .
You seem to misunderstand what happened:
Your assignment:
$PARMS{foo} = 'FOO';
Larry's assignment:
$PARMS{foo} = 'foo';
if you do: ${ $PARMS{foo} } = $PARMS{foo}; #which is kinda silly anyway
it will translate in your case to:
${ 'FOO' } = $PARMS{foo}; #assign to $FOO
and in Larry's case to:
${ 'foo' } = $PARMS{foo}; #assign to $foo
> And you didn't really anwer the question - the question was, why does
> the assignment I tried not work? Why does one have to use
> ${ $PARMS{foo}} = ... but $$_ works in your example?? I would have
> thought (incorrectly, obviously) that $$PARMS{foo} = ... would have
> worked.
As explained, you want a variable with the same name as the hash-key to
hold the same value as the one in the hash associated with that key.
$PARMS{title} = 'This is a title';
should be transformed to:
$title = 'This is a title';
hence Larry's loop:
${ $_ } = $PARMS{$_} for keys %PARMS;
>
> Oh, and BTW, saying $PARMS{foo}='FOO' and $PARMS{'foo'} = "FOO" are
> essentially equivelent and to say mine is wrong just seems like
> needless quibling.
He was only saying that you could do it with less keyclicks :-)
(And he preferes a different quoting-style.)
>
> And in this particular case (ie my config file example) I think that
> most would agree that this "violation" of the strict pragma is ok;
Well I'm not most then. What do you do when somebody passes one of the
Perl globals in the %PARMS hash?
--
Good luck,
Abe
------------------------------
Date: 3 Jun 2000 15:18:42 GMT
From: feng chen <fchen@fas.harvard.edu>
Subject: How to escape "/"?
Message-Id: <8hb7ki$vo6$1@news.fas.harvard.edu>
Hi, There.
How to escape "/"?
For example, if I have a string "/usr/bin/" and I want to change
it to "\usr\bin\". I am doing it this way:
$ch = "/";
$string =~ s/$ch/\\/;
Are there any elegant ways?
Thanks.
Feng Chen
------------------------------
Date: 03 Jun 2000 10:34:03 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: How to escape "/"?
Message-Id: <87ya4mvkwk.fsf@limey.hpcc.uh.edu>
>> On 3 Jun 2000 15:18:42 GMT,
>> feng chen <fchen@fas.harvard.edu> said:
> Hi, There. How to escape "/"? For example, if I have a
> string "/usr/bin/" and I want to change it to
> "\usr\bin\". I am doing it this way: $ch = "/"; $string
> =~ s/$ch/\\/;
> Are there any elegant ways?
perldoc -f tr
If you use a s/// operator, note that you don't have to
use / as the marker, e.g.
s(/)(\\)g;
You need the 'g' modifier to replace all occurrences,
"perldoc perlre".
However, perl is quite happy to use / in paths, even if
you're using Windows. It does the "right thing"(tm).
hth
t
--
"Trying is the first step towards failure"
Homer Simpson
------------------------------
Date: Sat, 3 Jun 2000 15:05:04 +0200
From: "Mösl Roland" <founder@pege.org>
Subject: Re: How to find out height and width of a PNG graphic
Message-Id: <39390780$0$41652@SSP1NO17.highway.telekom.at>
"Glenn Randers-Pehrson" <randeg@alum.rpi.edu> wrote in message
news:8hau60$dln$1@nnrp1.deja.com...
> In article <3937a74c$0$83464@SSP1NO17.highway.telekom.at>,
> "Mösl Roland" <founder@pege.org> wrote:
> > I am far far away from being perfect in Perl,
> > but I am using Perl as my standard programing
> > language now.
> >
> > I extracted from other scripts how to find out
> > height and width of a GIF or a JPG graphic,
> > but I did not find it until now for a PNG.
> >
> > But I want to change all my sites to PNG
> > because of this idiotic patent threat with GIF
>
> Good plan!
>
> If you cannot find a ready-made PERL script to find the PNG
I used the modul from the other response
and extracted the part for PNG graphics.
And after all was done, I found out that
PNG does not support animated graphics :-(
--
Mösl Roland http://www.pege.org
Clear targets for a confused civilization
http://www.BeingFound.com
web design and seminars
+43 699 17343674
------------------------------
Date: Sat, 03 Jun 2000 14:07:42 GMT
From: phil.taylor@bigfoot.com (Philip Taylor)
Subject: Limits on $ENV{} hash ?
Message-Id: <39390fb6.8387199@news.demon.co.uk>
I have been using the $ENV hash to set system wide parameters such as
file names and other system constants. For some reason some of the
values being set during the initialisation of my program are not being
set. I have about set about 30 $ENV parameters abd it's seems to be
the ones set last which are not acccessible from the program.
Is there a limit on the size of $ENV content or on the number of
entries possible?
If there is a limit, how do I create a global variable with the same
scope?
Any help appreciated
Phil
------------------------------
Date: Sat, 03 Jun 2000 17:54:39 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: Limits on $ENV{} hash ?
Message-Id: <zDb_4.100802$hT2.410435@news1.rdc1.ct.home.com>
Philip Taylor <phil.taylor@bigfoot.com> wrote:
> I have been using the $ENV hash to set system wide parameters such as
> file names and other system constants. For some reason some of the
> values being set during the initialisation of my program are not being
> set. I have about set about 30 $ENV parameters abd it's seems to be
> the ones set last which are not acccessible from the program.
What OS, and where aren't the elements of %ENV not being seen? In your
program? In children your process spawns? In the shell after your program
exits?
More details here would be good.
> Is there a limit on the size of $ENV content or on the number of
> entries possible?
Depends on your OS. Generally the limit per entry is big (though keep it
under 255 bytes for full cross-platform prtability) and the total number
of elements is also big and depends on the system and amount of free
memory. A quick check (print scalar keys %ENV) on one of my systems tops
out at more than 2000 entries in %ENV at program start, though that's
quite system dependent. I expect Windows might have a problem with great
heaps of them, and it'll likely slow things down a tad on both windows and
Unix systems if you have a bazillion of them.
> If there is a limit, how do I create a global variable with the same
> scope?
If you're trying to treat the %ENV hash like any other global variable in
perl, then don't--%ENV has magic and there are repercussions from its use
beyond your program. Just create another global with "use vars". (Or just
use it if you don't have strict on)
If you actually need extra variables in your environment for the duration
of your program (remember %ENV entries are only visible to your program
and any children it spawns unless you're running VMS) then use %ENV and
maybe see if assignments to it throw any errors. (Got -w enabled?)
Dan
------------------------------
Date: Sat, 03 Jun 2000 16:17:00 GMT
From: cekelly@dvol.com (Craig Kelly)
Subject: Not shifting what I want from an array
Message-Id: <39392b0a.17405196@news.dvol.com>
I am a novice using ActiveStates' Build 520 on WinNT 4.0
After reading a text file into an array, I want to shift
off each line of header stuff until I come to a line with
the word "LINE" in it. The snippet below removes an arbitrary
(too few) number of lines then exits the loop. Not what I
expected. Worse, it behaves differently with different files
that only vary by a coupla characters (never where it stops).
Can anyone spare a clue? I've appended an example input file.
use strict;
my @lines;
my $key = "LINE";
@lines = <>;
foreach (@lines)
{
last if ($_ =~ m/$key/);
shift (@lines);
}
# do stuff with what's left
============== Example file (72-char lines) ===========
START METRIC DESOUT
HEADER HEADERINFO 26
GENERAL MOTORS UG V15.0
DATA FORMAT IS - LWH
FIXTURE NAME: DATE: 15MY00
YEAR/VEHICLE/STYLE:
TOOL NUMBER: REV.
------------------------------------------------------------------------
ASM/DETAIL PART NAME PART FILE NO.
STG/REL
CODE
LVL
------------------------------------------------------------------------
------------------------------------------------------------------------
PROGRAM PHASE: ALPHA( ) BETA( ) PROTO( ) PROD( )
DATA TYPE: NOMINAL
VEHICLE SIDE OF CHECK: LH( ) RH( )
DATA DESC: KPC( ) PMP( ) PTO( ) REF( ) FIX( ) SPL( ) VIS( ) MST( )
ENGINEER:
MATH DATA CONTACT:
PROGRAMMER:
CHECKER:
DEBUGGER:
OUTPUT TO: B&S( ) DEA( ) LK( ) ZEISS( ) TARUS( ) DMIS( ) OTHER( )
DATA/PROGRAM USAGE:
------------------------------------------------------------------------
DWG STATUS REVISION HISTORY
AUTH/
DATE STG REL CHG PDI EWO
------------------------------------------------------------------------
------------------------------------------------------------------------
LINE B9RHTFD001 1 1 1
2529.99 776.03 834.39 0.00000-0.21530 0.97655
LINE B9RFTFD002 1 1 1
2537.63 776.14 835.96-0.99857-0.05205-0.01183
LINE B9RFTDO003 1 1 1
2522.44 775.27 835.76 0.99825 0.05769 0.01311
LINE D9LXYHU002 2 2 1
5317.50 -270.00 868.00 1.00000 0.00000 0.00021
5317.50 -270.00 868.00 0.00000-1.00000 0.00000
LINE B9LFSHU003 1 1 1
5305.80 -489.01 746.00 1.00000 0.00000 0.00000
* TERMINATE
Craig Kelly <cekelly@dvol.com>
-------------------------------
"Hey, I'm just this guy, see?"
-Zaphod Beeblebrox
-------------------------------
------------------------------
Date: 03 Jun 2000 11:57:12 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Not shifting what I want from an array
Message-Id: <87vgzqvh1z.fsf@limey.hpcc.uh.edu>
>> On Sat, 03 Jun 2000 16:17:00 GMT,
>> cekelly@dvol.com (Craig Kelly) said:
> I am a novice using ActiveStates' Build 520 on WinNT 4.0
> After reading a text file into an array, I want to shift
> off each line of header stuff until I come to a line
> with the word "LINE" in it.
Why read the whole thing in first and then get rid of
bits? It's simpler to read the file until you get to your
boundary marker and then grab the rest of the file.
> my $key = "LINE";
Literal string is better off with single quotes (saves
interpolation pass).
> last if ($_ =~ m/$key/);
$_ is implied my m// anyway, and since $key never
changes...
last if m/$key/o;
(perldoc perlre)
Here's my interpretation:
use strict;
my $key = 'LINE';
my @lines;
# scan input until we see the key
while (<DATA>) {
last if /^$key/o; # ^ anchors to start-of-line
}
# should add logic to check that LINE was actually found before EOF
# save the key
chomp; push @lines, $_;
# save the rest of the input
while (<DATA>) {
chomp; push @lines, $_;
}
# let's have a look at it
use Data::Dumper;
print Dumper(\@lines);
__DATA__
START METRIC DESOUT
HEADER HEADERINFO 26
GENERAL MOTORS UG V15.0
DATA FORMAT IS - LWH
FIXTURE NAME: DATE: 15MY00
YEAR/VEHICLE/STYLE:
TOOL NUMBER: REV.
------------------------------------------------------------------------
ASM/DETAIL PART NAME PART FILE NO.
STG/REL
CODE
LVL
------------------------------------------------------------------------
------------------------------------------------------------------------
PROGRAM PHASE: ALPHA( ) BETA( ) PROTO( ) PROD( )
DATA TYPE: NOMINAL
VEHICLE SIDE OF CHECK: LH( ) RH( )
DATA DESC: KPC( ) PMP( ) PTO( ) REF( ) FIX( ) SPL( ) VIS( ) MST( )
ENGINEER:
MATH DATA CONTACT:
PROGRAMMER:
CHECKER:
DEBUGGER:
OUTPUT TO: B&S( ) DEA( ) LK( ) ZEISS( ) TARUS( ) DMIS( ) OTHER( )
DATA/PROGRAM USAGE:
------------------------------------------------------------------------
DWG STATUS REVISION HISTORY
AUTH/
DATE STG REL CHG PDI EWO
------------------------------------------------------------------------
------------------------------------------------------------------------
LINE B9RHTFD001 1 1 1
2529.99 776.03 834.39 0.00000-0.21530 0.97655
LINE B9RFTFD002 1 1 1
2537.63 776.14 835.96-0.99857-0.05205-0.01183
LINE B9RFTDO003 1 1 1
2522.44 775.27 835.76 0.99825 0.05769 0.01311
LINE D9LXYHU002 2 2 1
5317.50 -270.00 868.00 1.00000 0.00000 0.00021
5317.50 -270.00 868.00 0.00000-1.00000 0.00000
LINE B9LFSHU003 1 1 1
5305.80 -489.01 746.00 1.00000 0.00000 0.00000
* TERMINATE
However, you might want to think about whether you need to
read all of the LINE lines into memory at one go and then
process them. Could they be processed as they come in?
(I suspect the "* TERMINATE" is significant too, which
would be trivial to incorporate into the scan.)
hth
t
--
"Trying is the first step towards failure"
Homer Simpson
------------------------------
Date: Sat, 03 Jun 2000 15:00:58 GMT
From: "Gregory D. Fox" <Greg@LibertyMarketing.com>
Subject: Ordering Elements in an Array
Message-Id: <K49_4.67849$MZ2.725343@news1.wwck1.ri.home.com>
Hi All,
I need help.
I would like to have the @items array in a particular order.
Right now the array looks like this:
@items =CJ1 CJ2 FU1 FU2 0 3 21 1
I would like this:
@items =CJ1 0 CJ2 3 FU1 21 FU2 1
Below is the code. Any help is greatly appreciated.
----- BEGIN CODE -----
#!/bin/perl -w
use diagnostics;
use CGI qw (:standard);
use CGI::Carp qw(fatalsToBrowser);
use strict;
BEGIN {
print CGI::header();
open (STDERR, '>error.log');
}
my(@items,@itemcodes,@units,$key);
@itemcodes = qw/CJ1 CJ2 FU1 FU2/;
@units = qw/0 3 21 1/;
foreach $key (@itemcodes, @units) {
push @items, $key;
}
print "<H2>Here are the results</H2>";
print qq{
<p>
\@items =@items
};
exit;
--
Gregory D. Fox
Greg@LibertyMarketing.com
<>< <>< <>< <>< <>< ><> ><> ><> ><> ><>
Liberty Computer Solutions/Liberty Marketing
Web Site Hosting and Design
<>< <>< <>< <>< <>< ><> ><> ><> ><> ><>
(401) 823-5252/Fax: (401) 828-7057
<>< <>< <>< <>< <>< ><> ><> ><> ><> ><>
Visit our website at: www.libertymarketing.com
<>< <>< <>< <>< <>< ><> ><> ><> ><> ><>
------------------------------
Date: Sat, 3 Jun 2000 23:34:00 +0800
From: "Swee Heng" <sweeheng@usa.net>
Subject: Re: Ordering Elements in an Array
Message-Id: <8hb879$73u$1@mawar.singnet.com.sg>
> I would like to have the @items array in a particular order.
>
> Right now the array looks like this:
> @items =CJ1 CJ2 FU1 FU2 0 3 21 1
>
> I would like this:
>
> @items =CJ1 0 CJ2 3 FU1 21 FU2 1
Try this:
@one = qw(a b c d e);
@two = qw(1 2 3 4 5);
push @items, (shift @one, shift @two) while @one;
print "@items\n";
------------------------------
Date: Sat, 03 Jun 2000 20:08:41 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Ordering Elements in an Array
Message-Id: <2phijsorhr27fkqtl4k9793p7qt3mdrv23@4ax.com>
On Sat, 03 Jun 2000 15:00:58 GMT, "Gregory D. Fox"
<Greg@LibertyMarketing.com> wrote:
> Hi All,
...
> I would like to have the @items array in a particular order.
>
> Right now the array looks like this:
> @items =CJ1 CJ2 FU1 FU2 0 3 21 1
>
> I would like this:
>
> @items =CJ1 0 CJ2 3 FU1 21 FU2 1
my @items = qw(CJ1 CJ2 FU1 FU2 0 3 21 1);
my $max = int (@items / 2);
splice @items, 2*$_ + 1, 0, splice @items, $_ + $max, 1
for (0..$max-1);
>
> Below is the code. Any help is greatly appreciated.
...
> my(@items,@itemcodes,@units,$key);
> @itemcodes = qw/CJ1 CJ2 FU1 FU2/;
> @units = qw/0 3 21 1/;
That looks different from your first question.
my @items = @itemcodes;
splice @items, 2*$_ + 1, 0, $units[$_] for (0..$#itemcodes);
--
Good luck,
Abe
------------------------------
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 3242
**************************************