[22930] in Perl-Users-Digest
Perl-Users Digest, Issue: 5150 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jun 28 18:05:44 2003
Date: Sat, 28 Jun 2003 15:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 28 Jun 2003 Volume: 10 Number: 5150
Today's topics:
Re: ASP -> Perl Script HELP ..NEWBIE>. <tim@vegeta.ath.cx>
Re: Hash::Utils lock_keys <bwalton@rochester.rr.com>
Re: Hash::Utils lock_keys <tassilo.parseval@rwth-aachen.de>
How do you sort a 2D array with column headers? Dennis@NoSpam.com
Re: How do you sort a 2D array with column headers? (Greg Bacon)
Re: How do you sort a 2D array with column headers? Dennis@NoSpam.com
Re: Module for sorting (while either reading from or wr (Greg Bacon)
Re: Module for sorting (while either reading from or wr (Tad McClellan)
Re: No error for calling undefined sub's? (James Willmore)
Not following "if" <Snygg@gmx.net>
Re: Not following "if" <bdonlan@bd-home-comp.no-ip.org>
Re: Not following "if" <eric-amick@comcast.net>
Re: Not following "if" (James Willmore)
Re: Problem with fork (Greg Bacon)
Re: scalars and namespace (Greg Bacon)
Re: scalars and namespace <cyberjeff@sprintmail.com>
Re: scalars and namespace (Kent Paul Dolan)
Re: scalars and namespace <noreply@gunnar.cc>
Re: Using perl/shell scripts to kill processes more tha <wefles@ameritech.net>
Re: Yet another "undefined reference to `_WinMain@16'" <asu1@c-o-r-n-e-l-l.edu>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 28 Jun 2003 12:31:48 -0700
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: ASP -> Perl Script HELP ..NEWBIE>.
Message-Id: <slrnbfrr9j.9n9.tim@vegeta.ath.cx>
kalusalu graced us by uttering:
> Hello..I was browsing thru the newsgroups ...and was wondering
> if anyone here can be of assistance to me....as I am very very
> new to PERL..and have this ASP SCRIPT..I have to convert...
[ snip VBScript ]
> it outputs the following:
> 34342323423 D:\www-roots\www.example.com.80/wwwroot/
>
> the diskusage the real path the virtual path
>
> I have written this..
>
[ snip "PERL" code ]
You'll want to learn Perl.
> cannot find a function for this det dir name...any ideas..and
> how I convert this ASP SCRIPT ????
Not many of us program in PERL. But if you'd like it converted to
Perl, many of us here would be glad to do it for a fee.
Or if you prefer, you're invited to learn Perl yourself:
http://learn.perl.org/
Cheers,
Tim Hammerquist
--
When the gods wish to punish us, they answer our prayers.
-- Oscar Wilde, "An Ideal Husband"
------------------------------
Date: Sat, 28 Jun 2003 14:55:04 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Hash::Utils lock_keys
Message-Id: <3EFDAC2D.5070400@rochester.rr.com>
Jay Tilton wrote:
...
> lock_keys() just invokes a routine inside perl to mark the hash as
> read-only.
Well, almost -- the values assigned to existing keys may be modified.
Perhaps the correct statement would that the keys themselves are read-only.
--
Bob Walton
------------------------------
Date: 28 Jun 2003 15:28:03 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Hash::Utils lock_keys
Message-Id: <bdkc63$2ln$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Bob Walton:
> Jay Tilton wrote:
>
> ...
>> lock_keys() just invokes a routine inside perl to mark the hash as
>> read-only.
>
>
> Well, almost -- the values assigned to existing keys may be modified.
> Perhaps the correct statement would that the keys themselves are read-only.
That happens automatically. When setting the SVf_READONLY flag on a hash
you get exactly this behaviour. To mark the values as read-only you'd
have to walk through the hash and do a SvREADONLY_on on each of them. I
remember once wanting to make a nested hash fully read-only (that is:
including all the values recursively) and I was slightly taken aback
that it required so much work.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Sat, 28 Jun 2003 14:00:48 -0500
From: Dennis@NoSpam.com
Subject: How do you sort a 2D array with column headers?
Message-Id: <95prfvg1r96onjgq0h3bbevdqre832ecsc@4ax.com>
I have a numerical array consisting of 5000 rows and 30 columns. The first row
consists of 30 ascii column labels for example L1,L2.....L30. I would like to
sort the column with the header L5 in ascending order leaving the header labels
intact on the first row.
I'm familiar with code
@array =sort { $a->[1] <=> $b->[1]} @array;
and I have read the perdoc -f sort.
But the code above doesn't allow me to sort the array by column labels.
How would I do that?
Any help would be appreciated.
Dennis
------------------------------
Date: Sat, 28 Jun 2003 19:55:56 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: How do you sort a 2D array with column headers?
Message-Id: <vfrsmccc7huq46@corp.supernews.com>
In article <95prfvg1r96onjgq0h3bbevdqre832ecsc@4ax.com>,
<Dennis@NoSpam.com> wrote:
: I have a numerical array consisting of 5000 rows and 30 columns. The
: first row consists of 30 ascii column labels for example
: L1,L2.....L30. I would like to sort the column with the header L5 in
: ascending order leaving the header labels intact on the first row.
Assuming @array is an array of rows, you could use something similar
to the code below.
[14:53] ant% cat try
#! /usr/local/bin/perl
use warnings;
use strict;
sub find_column_index {
my $a = shift;
my $col = shift;
my $header = $a->[0];
my $colidx = 0;
for (@$header) {
last if $_ eq $col;
++$colidx;
}
$colidx >= @$header ? () : $colidx;
}
sub sort_by_column {
my $m = shift;
my $col = shift;
return unless ref($m) && @$m && $col;
my $colidx = find_column_index $m, $col;
return unless defined $colidx;
@{$m}[1..$#$m] = sort { $a->[$colidx] <=> $b->[$colidx] }
@{$m}[1..$#$m];
}
my @array = (
[qw/ L1 L2 L3 L4 L5 /],
[9, 8, 7, 6, 5],
[1, 2, 3, 4, 5],
[0, 0, 0, 0, 0],
);
sort_by_column \@array, 'L3';
for (@array) {
printf join(" ", ("%5s") x @$_) . "\n", @$_;
}
[14:53] ant% ./try
L1 L2 L3 L4 L5
0 0 0 0 0
1 2 3 4 5
9 8 7 6 5
Hope this helps,
Greg
--
Government, even in its best state, is but a necessary evil; in its worst
state, an intolerable one. Government, like dress, is the badge of lost
innocence; the palaces of kings are built upon the ruins of the bowers of
paradise. -- Thomas Paine, "Common Sense"
------------------------------
Date: Sat, 28 Jun 2003 15:34:24 -0500
From: Dennis@NoSpam.com
Subject: Re: How do you sort a 2D array with column headers?
Message-Id: <liurfvo9qc5miq038r5f3taoq9b302g8rs@4ax.com>
gbacon@hiwaay.net (Greg Bacon) wrote:
>In article <95prfvg1r96onjgq0h3bbevdqre832ecsc@4ax.com>,
> <Dennis@NoSpam.com> wrote:
>
>: I have a numerical array consisting of 5000 rows and 30 columns. The
>: first row consists of 30 ascii column labels for example
>: L1,L2.....L30. I would like to sort the column with the header L5 in
>: ascending order leaving the header labels intact on the first row.
>
>Assuming @array is an array of rows, you could use something similar
>to the code below.
<snipped code for it's shown in above post>
>Hope this helps,
>Greg
Thank you Greg!
A lot of neat code. Some of the perl syntax is new to me but I'll get to work
with my Perl books and learn. Thanks again.
Dennis
------------------------------
Date: Sat, 28 Jun 2003 14:21:48 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Module for sorting (while either reading from or writing to) a FH?
Message-Id: <vfr93s9q6stg32@corp.supernews.com>
In article <ej0rfvg3vdevforo7hbdb0s9k36k6be3t4@4ax.com>,
Michele Dondi <bik.mido@tiscalinet.it> wrote:
: [...]
:
: Now I know that Perl supports tied filehandles: I wonder if there
: exists a module that automatically ties a filehandle to a sub that,
: for each print() statement, instead of printing the string it would,
: puts it into an array and prints the sorted array as a whole when the
: FH is closed. Dually it should work in a similar way for each read().
Why not hook it up yourself?
[8:35] ant% cat input
foo
bar
baz
quux
blurfl
[8:35] ant% cat try
#! /usr/local/bin/perl
use strict;
use warnings;
open my $sort, "| sort" or die "$0: fork: $!\n";
while (<>) {
print $sort $_;
}
[8:35] ant% ./try input
bar
baz
blurfl
foo
quux
: Please forgive me for the wording, but I couldn't express myself
: better. However I'm referring to something that would allow some code
: like this:
:
: #!/usr/bin/perl
: use strict
: use warnings
: use Sort::FH STDOUT => sub {...}
:
: while (<>) {
: s/^.*:+//;
: print;
: }
:
: In case it just doesn't exist, (i) would it be possible to write one?
: (ii) could it be done in a manner consistent with -i (and -pi,
: and...)?
You could do something similar to the code below. I don't like
having to qualify the sort parameters, though.
[9:19] ant% cat try
#! /usr/local/bin/perl
use strict;
use warnings;
package Sorter;
sub TIEHANDLE {
my $class = shift;
my $sub = shift || sub { $a cmp $b };
my $obj = {
sub => $sub,
lines => [],
};
bless $obj, $class;
}
sub PRINT {
my $obj = shift;
push @{ $obj->{lines} } => @_;
}
sub CLOSE {
my $obj = shift;
return unless @{ $obj->{lines} };
my $sub = $obj->{sub};
print sort $sub @{ $obj->{lines} };
}
sub DESTROY {}
package main;
use vars qw/ *FOO /;
tie *FOO, 'Sorter', sub { $Sorter::b cmp $Sorter::a };
while (<>) {
print FOO;
}
close FOO;
[9:19] ant% cat input
foo
bar
baz
quux
blurfl
[9:19] ant% ./try input
quux
foo
blurfl
baz
bar
The latter looks ugly to me, though.
Hope this helps,
Greg
--
Laws provide against injury from others; but not from ourselves. God
himself will not save men against their wills.
-- Thomas Jefferson
------------------------------
Date: Sat, 28 Jun 2003 10:06:16 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Module for sorting (while either reading from or writing to) a FH?
Message-Id: <slrnbfrbn7.52g.tadmc@magna.augustmail.com>
Michele Dondi <bik.mido@tiscalinet.it> wrote:
> One advantage of Perl's built in sort() over *nix 'sort' utility is
> its flexibility. However, especially in one-liners, when I just need
> to sort my input or output, it is easier to pipe from or to 'sort'.
You might borrow code from the Perl Power Tool's implementation
of sort(1):
http://www.perl.com/language/ppt/src/sort/index.html
> Now I know that Perl supports tied filehandles: I wonder if there
> exists a module that automatically ties a filehandle to a sub that,
> for each print() statement, instead of printing the string it would,
> puts it into an array and prints the sorted array as a whole when the
> FH is closed.
Since the tie code would have to save the whole thing in memory anyway,
why not just save it in memory in the main program?
That is, use:
push @out, $_;
instead of
print $_;
then apply the sort(), perhaps with an imported sort subroutine.
> Dually it should work in a similar way for each read().
You must mean readline() since your code does not use read().
> Please forgive me for the wording, but I couldn't express myself
> better. However I'm referring to something that would allow some code
> like this:
>
> #!/usr/bin/perl
> use strict
> use warnings
> use Sort::FH STDOUT => sub {...}
>
> while (<>) {
> s/^.*:+//;
> print;
> }
You could do that particular job as easily as this in the
main code (untested):
my @out = sort {...} map { s/^.*:+//; $_ } <>;
...
print @out;
or even just:
print sort {...} map { s/^.*:+//; $_ } <>;
I don't see the payback for the time that would be required to
implement tie()ing that would have to buffer the whole thing anyway...
> In case it just doesn't exist, (i) would it be possible to write one?
Possible? Probably yes.
Worth the effort? I'm not seeing it (unless the output is huge and
you want to use disk instead of RAM).
Do you have some reason that I am overlooking?
> (ii) could it be done in a manner consistent with -i (and -pi,
> and...)?
My untested code above will (err, should) work with -i (you wouldn't
need -n or -p since map() will do that looping for you).
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 28 Jun 2003 13:49:26 -0700
From: jwillmore@cyberia.com (James Willmore)
Subject: Re: No error for calling undefined sub's?
Message-Id: <e0160815.0306281249.49a7b115@posting.google.com>
> I am having this problem:
> Since some point in time the script is not complaining about calls of
> any undefined subroutines(e.g. by a typo). It simply exits, like it
> finished running. It didn't use to do that but I can't possibly
> remember what change I made caused this.
> What is likely to be wrong here?
Do you have warnings turned on? Diagnostics? Are you using "strict"?
How about Carp - if this is/was/will be a module, using Carp can be
helpful
How about a plain old .....
perl -c "insert name of script here"
This is used to check the script for syntax errors.
How about when you use "die" - are you giving a descriptive message
about why the script died?
Do you have any "exit"s in the script. If so, are these "exit"s
around the point where the subroutine is called? I sometimes put an
exit statement in a test script to prevent it from running the whole
way through while I'm debugging. Have you, maybe, done the same
thing?
HTH
Jim
------------------------------
Date: Sat, 28 Jun 2003 16:25:02 +0200
From: Stefan Glimne <Snygg@gmx.net>
Subject: Not following "if"
Message-Id: <3efda59e$0$21964$9b4e6d93@newsread4.arcor-online.net>
Hello 2 u all,
I have a really interesting problem that I get when I program my
html-pages with perl.
The problem is that the perl-program doesn't follow the if-statement.
1. I get info from a standard text-file database
2. I store an hash like , $imdblink{$imdbid} = $value , from the
database
3. Then I have a new number $imdbid_new that I want to check if it's in
the $imdblink-hash like ,
if ($imdblink{$imdbid_new}) {
"if it exist then this should happen"
} else {
"if it doesn't exist then this should happen"
}
The problem is that it doesn't exist when the test is done, and that is
a fact. I then store the data for the $imdbid_new within the
else-statement in the same database. And I don't even set the
$imdblink{$imdbid_new}.
The program now says that the $imdblink{$imdbid_new} exist, even if I
don't set it under "point 2"
As I see it the program checks if it doesn't exist and then continues to
the else-statement, but then suddenly get the idea that it did exist,
because I saved it in the database-file, and goes back to the if-stetement.
Is there an explanation to this?
Thanks in advance
/Stefan
Here is the example that does not work:
##############################################
#
# Load Films in FilmDataBase
#
$file = "db\\filmdatabase_comp.txt";
open (INDATA, "$home_dir$file") or die "Can't open $home_dir$file: $!\n";
while ($line = <INDATA>) {
chop $line;
($key,$value) = split(" = ", $line);
$key2 = $filmid . '_' . $key;
$filmdatabase{$key2} = $value;
if ($key eq "imdblink") {
($key,$imdbid) = split('\?', $line);
$imdblink{$imdbid} = $filmid;
}
}
close INDATA;
if ($in{'update'} eq "IMDB") {
($key,$imdbid) = split('\?', $in{'imdblink'});
if ($imdblink{$imdbid}) {
print "File already exist with the name
$filmlista{$imdblink{$imdbid}}<BR>\n";
} else {
... reading and storing data in hashes (but not %imdblink .....
$file = $home_dir;
$file .= "db\\filmdatabase_comp.txt";
$file_tmp = $home_dir;
$file_tmp .= "db\\filmdatabase_comp.tmp";
rename($file, $file_tmp);
open (UTDATA_TMP, "$file_tmp") or die "Can't open
$home_dir$file_tmp: $!\n";
open (UTDATA, ">>$file") or die "Can't open $home_dir$file: $!\n";
while ($line = <UTDATA_TMP>) {
chop $line;
if ($line eq "##########") {
print UTDATA "##########\n";
$line = <UTDATA_TMP>;
chop $line;
($key,$filmid) = split(" = ", $line);
if ((int($filmid) + 1) == int($in{'filmnumber'})) {
print UTDATA "$line\n";
for ($i = 1; $i <= 9; $i++) {
$line = <UTDATA_TMP>;
print UTDATA "$line";
}
print UTDATA "##########\n";
print UTDATA "filmnumber = $filmdatabase{$in{'filmnumber'} .
'_filmnumber'}\n";
print UTDATA "filmname = $filmdatabase{$in{'filmnumber'} .
'_filmname'}\n";
print UTDATA "year = $filmdatabase{$in{'filmnumber'} .
'_year'}\n";
print UTDATA "imdblink = $filmdatabase{$in{'filmnumber'} .
'_imdblink'}\n";
print UTDATA "imdbrating = $filmdatabase{$in{'filmnumber'} .
'_imdbrating'}\n";
print UTDATA "runtime = $filmdatabase{$in{'filmnumber'} .
'_runtime'}\n";
print UTDATA "genre = $filmdatabase{$in{'filmnumber'} .
'_genre'}\n";
print UTDATA "actors = $filmdatabase{$in{'filmnumber'} .
'_actors'}\n";
print UTDATA "directors = $filmdatabase{$in{'filmnumber'} .
'_directors'}\n";
print UTDATA "writers = $filmdatabase{$in{'filmnumber'} .
'_writers'}\n";
} else {
print UTDATA "$line\n";
}
} else {
print UTDATA "$line\n";
}
}
close UTDATA;
close UTDATA_TMP;
# unlink $file_tmp;
}
$in{'update'} = "YES";
}
##############################################
------------------------------
Date: Sat, 28 Jun 2003 11:03:19 -0400
From: "bd" <bdonlan@bd-home-comp.no-ip.org>
Subject: Re: Not following "if"
Message-Id: <pan.2003.06.28.15.03.19.417119@bd-home-comp.no-ip.org>
On Sat, 28 Jun 2003 16:25:02 +0200, Stefan Glimne wrote:
> Hello 2 u all,
>
> I have a really interesting problem that I get when I program my
> html-pages with perl.
> The problem is that the perl-program doesn't follow the if-statement.
>
> 1. I get info from a standard text-file database
> 2. I store an hash like , $imdblink{$imdbid} = $value , from the
> database
> 3. Then I have a new number $imdbid_new that I want to check if it's in
> the $imdblink-hash like ,
> if ($imdblink{$imdbid_new}) {
> "if it exist then this should happen"
> } else {
> "if it doesn't exist then this should happen"
> }
Try using:
if(exists $imdblink{$imdbid_new}) {
This'll work correctly even when you set it to 0, or '', or something. If
it still won't work, then try using Data::Dumper:
use Data::Dumper;
my %hash;
# ...
# Print perl code to recreate the hash
print Dumper \%hash;
--
Freenet distribution not available
Today is a good day for information-gathering. Read someone else's mail file.
------------------------------
Date: Sat, 28 Jun 2003 13:08:59 -0400
From: Eric Amick <eric-amick@comcast.net>
Subject: Re: Not following "if"
Message-Id: <q2irfv8sb8b7sfkklaev39jd6jg0503jtm@4ax.com>
On Sat, 28 Jun 2003 16:25:02 +0200, Stefan Glimne <Snygg@gmx.net> wrote:
> if ($imdblink{$imdbid}) {
> print "File already exist with the name
>$filmlista{$imdblink{$imdbid}}<BR>\n";
> } else {
In most cases, referring to an nonexistent array or hash element causes
it to be created, a process called "autovivification." Most of the time
it's very handy, but it isn't when you just want to check for existence.
The exists() function can check for existence without actually creating
the element; similarly, the defined() function does likewise when
checking if the element has a value other than undef.
--
Eric Amick
Columbia, MD
------------------------------
Date: 28 Jun 2003 13:30:46 -0700
From: jwillmore@cyberia.com (James Willmore)
Subject: Re: Not following "if"
Message-Id: <e0160815.0306281230.77e2768c@posting.google.com>
> 1. I get info from a standard text-file database
> 2. I store an hash like , $imdblink{$imdbid} = $value , from the
> database
> 3. Then I have a new number $imdbid_new that I want to check if it's in
> the $imdblink-hash like ,
> if ($imdblink{$imdbid_new}) {
> "if it exist then this should happen"
> } else {
> "if it doesn't exist then this should happen"
> }
Since you're dealing with a hash, you may want to do something like
....
if(exists $imdblink{$imdbid_new}){
.....
}
This is because, to Perl, you're defining a new key to the hash when
you do something like ...
if ($imdblink{$imdbid_new}) {
.....
}
So, this is where "exists" comes in.
Try that out. If you're not 100% satisfied, I'll give you you're
money back :)
HTH
Jim
------------------------------
Date: Sat, 28 Jun 2003 13:31:42 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Problem with fork
Message-Id: <vfr65u79l5g97e@corp.supernews.com>
In article <19c69beb.0306271317.10255c2b@posting.google.com>,
Krishna <kgundlapalli@hotmail.com> wrote:
: I am using 'fork' to execute a child process (a perl program) in my
: CGI.
Have you read mjd's "Suffering from Buffering?"[*]?
[*] http://perl.plover.com/FAQs/Buffering.html
What version of perl are you using? According to the perlfunc manpage
Beginning with v5.6.0, Perl will attempt to flush all
files opened for output before forking the child
process, but this may not be supported on some
platforms (see the perlport manpage). To be safe,
you may need to set "$|" ($AUTOFLUSH in English) or
call the "autoflush()" method of "IO::Handle" on any
open handles in order to avoid duplicate output.
: When the user submits the page, I am displaying a status page (created
: by a CGI) and forking the my external process. However spawning of
: this external process is redisplaying the the status page below the
: original page (means I am getting a TILED page of my status page).
:
: $pid = fork;
: if ($pid)
: { return 1; }
: else {
: close STDOUT;
: exec "/usr/local/bin/perl /../../push.pl ";
: exit 1;
: }
I can't say given only this little example. Is running push.pl
generating another copy?
Someone else in this thread asked if /../../push.pl is the path you
really meant to use. Does your web server's error log have any relevant
information?
You aren't checking whether the fork failed. Look for an undefined
return:
my $pid = fork;
unless (defined $pid) {
warn "$0: fork failed: $!\n";
}
You might also consider hooking up your parent and child processes as
in the following example:
#! /usr/local/bin/perl
use warnings;
use strict;
print "Content-type: text/plain\n\n";
open STDERR, ">&STDOUT" or print "$0: dup STDOUT: $!\n";
my $pid = open my $kid, "-|";
die "$0: fork: $!\n" unless defined $pid;
if ($pid) {
# parent
while (<$kid>) {
print "kid: $_";
}
}
else {
exec 'lynx', '-dump', 'http://www.perl.org/'
or die "$0: exec: $!\n";
}
# check child's exit status
# try changing lynx to something bogus
$kid = waitpid $pid, 0;
if ($kid == -1) {
print "pid $pid already reaped\n";
}
else {
print "exit status for $pid: $?\n";
}
Hope this helps,
Greg
--
One of the paradoxes of software engineering is that people with bad ideas
and low productivity often think of themselves as supremely capable. They
are the last people whom one can expect to fall in line with a good strategy
developed by someone else. -- Phil Greenspun
------------------------------
Date: Sat, 28 Jun 2003 14:26:08 -0000
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: scalars and namespace
Message-Id: <vfr9c08237lb2@corp.supernews.com>
In article <3EFCBA74.199FFEB@sprintmail.com>,
Jeff Thies <cyberjeff@sprintmail.com> wrote:
: [...]
:
: I can see where I would have been better off using hashes!
Hey, Doc, it hurts when I do my arm like this! :-)
Greg
--
But the opposition to the gold standard in any form--from a growing number
of welfare-state advocates--was prompted by a much subtler insight: the
realization that the gold standard is incompatible with chronic deficit
spending . . . -- Alan Greenspan, "Gold and Economic Freedom"
------------------------------
Date: Sat, 28 Jun 2003 15:15:13 GMT
From: Jeff Thies <cyberjeff@sprintmail.com>
Subject: Re: scalars and namespace
Message-Id: <3EFDB147.1C765132@sprintmail.com>
> > I have all these "config" files with lists of global scalars:
> ...
> > Now I want to import those into a sub and make that list of scalars
> > local to that sub. (I want to do something with the list of scalars in
> > all these "config" files one file at a time) How do I do that?
>
> I guess it depends on what you want to do. I'm kinda unclear on what
> you're trying to accomplish. (What does "local to that sub" mean?)
Yes lexical. I'm sorry this is unclear.
What I'm doing is creating html pages from templates. The scalars (from
the config files, one config file per page) get plugged into the
template. The trouble I have is that the number of scalars in each
config file are different and may have different names.
That means that when I have all these scalars global to the script that
for ex: $scalar_that_exists_in_config1_but_not_config2 will still be
around when I'm processing the page for config2. If I had done this with
a hash, I could've just emptied the old hash out and reassigned it to
the hash in the new config file. If I had made these packages, I could
have just imported the package names. Instead I've stuck myself with
these global scalars.
What I think I'll do is like what Gunnar suggested.
Jeff
>
> - --
> Eric
> $_ = reverse sort qw p ekca lre Js reh ts
> p, $/.r, map $_.$", qw e p h tona e; print
>
> -----BEGIN xxx SIGNATURE-----
> Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
>
> iQA/AwUBPvz4LmPeouIeTNHoEQIx/QCg/NnMzSp54UFFf1O8f2+/j2GsJBQAoIe8
> MEQJ5TdALv8Af1sQstoHApyS
> =fVfd
> -----END PGP SIGNATURE-----
------------------------------
Date: 28 Jun 2003 12:30:48 -0700
From: xanthian@well.com (Kent Paul Dolan)
Subject: Re: scalars and namespace
Message-Id: <a3eaa964.0306281130.576b2f53@posting.google.com>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> Jeff Thies wrote:
> > I have all these "config" files with lists of global scalars:
> >
> > config_1.cfg
> > ###########
> >
> > $scalar1='something';
> > $scalar2='something_else';
> >
> >
> > #########
> >
> > That worked for me in that I could import those scalars like this:
> >
> > require 'path_to/config_1.cfg';
> >
> > Now I want to import those into a sub and make that list of scalars
> > local to that sub. (I want to do something with the list of scalars in
> > all these "config" files one file at a time) How do I do that?
>
> One way:
>
> sub mysub {
> my ($scalar1, $scalar2);
> open FH, 'config_1.cfg' or die "Can't open... $!";
> eval while <FH>;
> close FH;
> [do something]
> }
>
> / Gunnar
Shouldn't you do something in there to prevent the overhead of opening,
interpreting, and closing FH _every_ time mysub is invoked (and thus
have containers _with state_ for the scaler values), or have I
(very likely) missed some subtlety in the original request?
xanthian.
------------------------------
Date: Sat, 28 Jun 2003 23:59:27 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: scalars and namespace
Message-Id: <bdl39m$tqndt$1@ID-184292.news.dfncis.de>
Kent Paul Dolan wrote:
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
>> Jeff Thies wrote:
>>> I have all these "config" files with lists of global scalars:
>>>
>>> config_1.cfg
>>> ###########
>>>
>>> $scalar1='something';
>>> $scalar2='something_else';
<snip>
>>> Now I want to import those into a sub and make that list of
>>> scalars local to that sub. (I want to do something with the
>>> list of scalars in all these "config" files one file at a time)
>>> How do I do that?
>>
>> One way:
>>
>> sub mysub {
>> my ($scalar1, $scalar2);
>> open FH, 'config_1.cfg' or die "Can't open... $!";
>> eval while <FH>;
>> close FH;
>> [do something]
>> }
>
> Shouldn't you do something in there to prevent the overhead of
> opening, interpreting, and closing FH _every_ time mysub is invoked
> (and thus have containers _with state_ for the scaler values), or
> have I (very likely) missed some subtlety in the original request?
You imply that the variables in a config file may be needed at more
than one stage of the process. If there is such a need, you have a
point with respect to efficiency. Personally I don't identify that
need, neither in the original post nor in OP's clarification.
I just provided a plain solution to the question that was asked.
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 28 Jun 2003 16:30:13 GMT
From: "Walt Fles" <wefles@ameritech.net>
Subject: Re: Using perl/shell scripts to kill processes more than x days old
Message-Id: <pojLa.3183$Vx2.1588879@newssvr28.news.prodigy.com>
Your best bet is to go into /proc and disect the data yourself, instead of
relying on what formatting commands ( ie, ps ) gives you.
"Jimmy" <jimmy_mcnamara@hotmail.com> wrote in message
news:e08ac7c8.0306270541.55c20f09@posting.google.com...
> Hi Folks,
>
> OS : Solaris 8
>
> I have a question regarding killing processes on a unix server. I
> would like to run a cron job to kill processes run by certain binaries
> that are more than 2 weeks old. I had a look at using the awk combined
> with the output of ps but this doesn'tgive me what I want as the
> output of ps is limited in what
> it outputs as a start date of the process. Has anyone used perl or
> shell scripting to come up with a nice way of doing this.
>
> Regards,
>
> Jimmy
------------------------------
Date: 28 Jun 2003 14:09:43 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Yet another "undefined reference to `_WinMain@16'" in cygwin
Message-Id: <Xns93A8676006B3Dasu1cornelledu@132.236.56.8>
dejanews@email.com (Sam Denton) wrote in
news:3c863a7a.0306272123.2b827030@posting.google.com:
> I'm getting this message when linking under Cygwin. I've googled the
> message text and found several of "voodoo" fixes (i.e. "This worked
> for me but I don't know why"). I've blindly tried several of them,
> but none of them worked.
I do not _know_ the solution, but have you looked at
http://cygwin.com/faq/faq_toc.html#TOC95
and
http://cygwin.com/cygwin-ug-net/dll.html
I am only asking this because I do not see a `shared' flag anywhere, and it
looks like, from the line
> LD_RUN_PATH="/usr/local/lib" g++ -s -L/usr/local/lib Plotter.o
you are stripping symbols. Again, I am no expert on cygwin, but those look
like problem spots to me. Have you tried asking this question on the cygwin
mailing list?
Sinan.
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 5150
***************************************