[22152] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4373 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 9 14:05:38 2003

Date: Thu, 9 Jan 2003 11:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 9 Jan 2003     Volume: 10 Number: 4373

Today's topics:
    Re: Activeperl : ppm and GD (Randy Kobes)
    Re: Arrays. What don't I get? <spikey-wan@bigfoot.com>
    Re: Arrays. What don't I get? (Matt Venn)
    Re: Arrays. What don't I get? (Anno Siegel)
    Re: Arrays. What don't I get? <nobull@mail.com>
    Re: Dates in the filename <jon@nospam.org>
    Re: Dates in the filename (Tad McClellan)
    Re: Dates in the filename <nobull@mail.com>
    Re: Dates in the filename (Lack Mr G M)
        How am I using sort wrong? (Joe)
    Re: How am I using sort wrong? <shondell@cis.ohio-state.edu>
        Is there a maximum length for system() or backtick comm <hal@thresholddigital.com>
    Re: pack( "N", inet_aton("client.example.net")) (Lack Mr G M)
    Re: reload not terminating process ctcgag@hotmail.com
    Re: silly question -- please help! (tom)
        simple file variable question <shamrockirishbar.remove.nospam@yahoo.co.uk>
    Re: simple file variable question <nobull@mail.com>
    Re: Taint check question (Helgi Briem)
    Re: Unix Vars declared in system() call -> %ENV (Christopher Hamel)
        Why is map so much faster then a nested for loop? <asimmons@mitre.org>
    Re: Why is map so much faster then a nested for loop? <tassilo.parseval@post.rwth-aachen.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 9 Jan 2003 16:19:21 GMT
From: randy@theoryx5.uwinnipeg.ca (Randy Kobes)
Subject: Re: Activeperl : ppm and GD
Message-Id: <slrnb1r7vk.sk7.randy@theoryx5.uwinnipeg.ca>

On Thu, 09 Jan 2003 15:50:23 +0000, 
  Simon Andrews <simon.andrews@bbsrc.ac.uk> wrote:
>Jan wrote:
>> I had some scripts using the GD and Date modules.  Last I had to
>> reinstall ActivePerl and since then (or since earlier ?) when I start
>> ppm and do a search on GD I get only three modules.  That used to be
>> much more.  Now even the GD module itself doesn't turn up.
>
>If you're using the new 5.8 builds then Activestate have started
>including more modules in the default install, meaning that you may have
>GD there already.  Try running "ppm query GD" on your system and see
>what turns up.

If it's not there, we have a GD-2.06 ppm package, suitable
for ActivePerl 8xx builds, at
    http://theoryx5.uwinnipeg.ca/ppms/
which you can access within the ppm shell by setting the
respository to
  http://theoryx5.uwinnipeg.ca/cgi-bin/ppmserver?urn:/PPMServer58

-- 
best regards,
randy kobes


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

Date: Thu, 9 Jan 2003 16:04:13 -0000
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Re: Arrays. What don't I get?
Message-Id: <avk6j4$iun$1@newshost.mot.com>

"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
news:avjo63$dbb$1@mamenchi.zrz.TU-Berlin.DE...
> > use strict;
> > use warnings;
> > our $one = 1; our $two = 2; our $three = 3; our $four = 4;
>
> Is there any reason why these must be package variables?  Use my()
> instead of our().

I think so. There are an awful lot of variables in my real script, and so I
gave the user the option to save them to a file.
Near the start of my script, I set the variables to their default values
(with our). I then check to see if the file exists, and if so, do it. The
file is a text file like this:

$one = 1;
$two = 2;
etc.

If I use my, then this part of my script doesn't work properly.

> > our $value; our $print;
> > our @values = ($one, $two, $three, $four);
>
> This *copies* the values from $one, $two, ... into @values.  What
> happens to @values has no bearing upon the original variables.

Mmmm. I understand that part.

> > print "\$one = $one\n\$two = $two\n\$three = $three\n\$four = $four\n";
> > foreach $value (@values) {
> >  $value *= 2;
> > }
> > foreach $print (@values) {
> >  print "$print\n";
> > }
> > print "\$one = $one\n\$two = $two\n\$three = $three\n\$four = $four\n";
>
> If you want to change a bunch of scalars in one go, list them directly:
>
>     $_ *= 2 for $one, $two, $three, $four;
>
> This makes $_ an alias for $one, then $two, etc, so the originals are
> changed.

Cool, that's sort of what I want to do. The problem is I have to do many
operations on my variables, and there are an awful lot of them, so that's
why I was trying to only have to list them all once.

I suppose I should have them split into array groups, store them in the
array, modify them in the array, and access them as $variable_group1[69]. I
haven't done this, because there's so many of them, that I gave them all
meaningful names, so that I wouldn't have to remember which was which.

> If you must collect the variables into a list for some reason, use
> references:
>
>     my @refs = ( \ $one, \ $two, \ $three, \ $four);
>     $$_ *= 2 for @refs;

>
> The first line could also be "my @refs = \ ( $one, $two, $three, $four)",
> but I don't like that.

A quick example is when I have to collect data from my entry boxes.
Currently I have:
sub get_values {
 $host    = $host_entry  -> get;
 $interval  = $interval_entry -> get;
 $timeout  = $timeout_entry -> get;
 $size   = $size_entry  -> get;
 $number   = $number_entry -> get;
 $save   = $save_entry  -> get;
 ......
}

I would like to be able to replace that lot with...

my @variables =  \($host, $interval, $timeout, $size, $number, $save, ...);
 ...
sub get_values {
  foreach $variable (@variables) {
    my $entry = $_."_entry";
    $_ = $entry -> get;
    }
}

Isn't it much nicer than 100+ lines of very repetitive code? Shame it
doesn't work, though ;-)

I modified my example script...

use strict;
use warnings;
our $one = 1; our $two = 2; our $three = 3; our $four = 4;
our $value; our $print;
our @values = (\$one, \$two, \$three, \$four);

print "\$one = $one\n\$two = $two\n\$three = $three\n\$four = $four\n";

# This won't change the variables...
# foreach $value (@values) {
#  $_ *= 2;
# }

# Neither will this...
# $_ *= 2 for (@values);

# But this one works...
$_ *= 2 for ($one, $two, $three, $four);

print "\$one = $one\n\$two = $two\n\$three = $three\n\$four = $four\n";

Am I attempting the impossible, or have I just got my head on backwards?

Thanks.

R.




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

Date: Thu, 9 Jan 2003 17:21:15 +0000
From: news@ttvenn.net (Matt Venn)
Subject: Re: Arrays. What don't I get?
Message-Id: <slrnb1rbsb.lbg.news@flop.localnet>

>I would like to be able to replace that lot with...
>
>my @variables =  \($host, $interval, $timeout, $size, $number, $save, ...);
>...
>sub get_values {
>  foreach $variable (@variables) {
>    my $entry = $_."_entry";
>    $_ = $entry -> get;
>    }
>}

the problem with this is that you are creating $entry using the
reference of the variable, so your finished entry will be like

SCALAR(0x80f3e64)_entry

which as you say, won't work. However your idea will work, you just
need to implement it properly. I think I would suggest representing
your list of variables as a hash. For example:

my $variableDefs = 
{
	one	=> {},
	two	=> {},
};

foreach my $var ( keys %$variableDefs )
{
	print "getting $var\n";
	my $subName = $var . "_entry";
	$variableDefs->{ $var } = $subName->get();
}


Then you could retrieve the values by saying

print $variableDefs->{ one };

Hope that helps,

Matt


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

Date: 9 Jan 2003 17:42:57 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Arrays. What don't I get?
Message-Id: <avkcb1$s0j$1@mamenchi.zrz.TU-Berlin.DE>

Richard S Beckett <spikey-wan@bigfoot.com> wrote in comp.lang.perl.misc:
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:avjo63$dbb$1@mamenchi.zrz.TU-Berlin.DE...
> > > use strict;
> > > use warnings;
> > > our $one = 1; our $two = 2; our $three = 3; our $four = 4;
> >
> > Is there any reason why these must be package variables?  Use my()
> > instead of our().
> 
> I think so. There are an awful lot of variables in my real script, and so I
> gave the user the option to save them to a file.
> Near the start of my script, I set the variables to their default values
> (with our). I then check to see if the file exists, and if so, do it. The
> file is a text file like this:
> 
> $one = 1;
> $two = 2;
> etc.
> 
> If I use my, then this part of my script doesn't work properly.

Well, that's true.  It wasn't clear that these variables are used
across two files.  There are ways to avoid package variables even
in this case, but let's leave that aside for the moment.  It's a
side issue, though a relevant one.

> > > our $value; our $print;
> > > our @values = ($one, $two, $three, $four);
> >
> > This *copies* the values from $one, $two, ... into @values.  What
> > happens to @values has no bearing upon the original variables.
> 
> Mmmm. I understand that part.
> 
> > > print "\$one = $one\n\$two = $two\n\$three = $three\n\$four = $four\n";
> > > foreach $value (@values) {
> > >  $value *= 2;
> > > }
> > > foreach $print (@values) {
> > >  print "$print\n";
> > > }
> > > print "\$one = $one\n\$two = $two\n\$three = $three\n\$four = $four\n";
> >
> > If you want to change a bunch of scalars in one go, list them directly:
> >
> >     $_ *= 2 for $one, $two, $three, $four;
> >
> > This makes $_ an alias for $one, then $two, etc, so the originals are
> > changed.
> 
> Cool, that's sort of what I want to do. The problem is I have to do many
> operations on my variables, and there are an awful lot of them, so that's
> why I was trying to only have to list them all once.
> 
> I suppose I should have them split into array groups, store them in the
> array, modify them in the array, and access them as $variable_group1[69]. I
> haven't done this, because there's so many of them, that I gave them all
> meaningful names, so that I wouldn't have to remember which was which.

 ...which is a very good reason.  However, this is where hashes come in
in Perl.  Collecting your variables in a hash %var (say) allows you to
have your cake (pass all variables around as a single collective %var)
and eat it too (access single values through meaningful names: $var{ one},
$var{ two}, etc).

> > If you must collect the variables into a list for some reason, use
> > references:
> >
> >     my @refs = ( \ $one, \ $two, \ $three, \ $four);
> >     $$_ *= 2 for @refs;
> 
> >
> > The first line could also be "my @refs = \ ( $one, $two, $three, $four)",
> > but I don't like that.
> 
> A quick example is when I have to collect data from my entry boxes.
> Currently I have:
> sub get_values {
>  $host    = $host_entry  -> get;
>  $interval  = $interval_entry -> get;
>  $timeout  = $timeout_entry -> get;
>  $size   = $size_entry  -> get;
>  $number   = $number_entry -> get;
>  $save   = $save_entry  -> get;
> ......
> }

I don't understand how this illustrates the problem.  This is an entirely
different situation.  It looks like you have a bunch of objects ($host_entry,
$interval_entry, etc) and you are applying the get method to each of them.
This is rather, umm... atypical for an OO approach.  I'd rather expect a
single data object ($entry, say) with a bunch of methods (get_host,
get_interval, etc).  I'm not saying it must be wrong, but the approach
looks strange.

> I would like to be able to replace that lot with...
> 
> my @variables =  \($host, $interval, $timeout, $size, $number, $save, ...);
> ...
> sub get_values {
>   foreach $variable (@variables) {
>     my $entry = $_."_entry";

Hmm... Where does the value in $_ come from?  Did you mean

    my $entry = $variable . '_entry';

Anyway, this won't do what you want.  $entry will contain s string like
"SCALAR(0xf0c0)_entry" and not the object you need to apply the get method.

>     $_ = $entry -> get;
>     }
> }
>
> Isn't it much nicer than 100+ lines of very repetitive code? Shame it
> doesn't work, though ;-)

Much nicer.  I'm also sure you can get something like this to work, if
it only were clear what you actually need.  I believe your first step
must be to find the right data structure(s) for your problem.  A bunch of
single scalar variables has too little structure to be conveniently
handled.  In fact, most programmers would start thinking of something else
when the variable count reaches 10 or so, not to speak of 69 or 100.  A
hash, used as a data record, looks like a good candidate.

[snippage]

Anno


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

Date: 09 Jan 2003 17:56:31 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Arrays. What don't I get?
Message-Id: <u9of6qmckw.fsf@wcl-l.bham.ac.uk>

"Richard S Beckett" <spikey-wan@bigfoot.com> writes:

> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:avjo63$dbb$1@mamenchi.zrz.TU-Berlin.DE...
> > > use strict;
> > > use warnings;
> > > our $one = 1; our $two = 2; our $three = 3; our $four = 4;
> >
> > Is there any reason why these must be package variables?  Use my()
> > instead of our().
> 
> I think so. There are an awful lot of variables in my real script, and so I
> gave the user the option to save them to a file.
> Near the start of my script, I set the variables to their default values
> (with our). I then check to see if the file exists, and if so, do it. The
> file is a text file like this:
> 
> $one = 1;
> $two = 2;
> etc.

In that case I would recommend putting the user config variables in a
separate symbol table rather than poluting main::

> I suppose I should have them split into array groups, store them in the
> array, modify them in the array, and access them as $variable_group1[69]. I
> haven't done this, because there's so many of them, that I gave them all
> meaningful names, so that I wouldn't have to remember which was which.

Subscripts in hashes can be meaningful.

> > If you must collect the variables into a list for some reason, use
> > references:
> >
> >     my @refs = ( \ $one, \ $two, \ $three, \ $four);
> >     $$_ *= 2 for @refs;

Note the double dolar in Anno's code above is _not_ a typo.

> A quick example is when I have to collect data from my entry boxes.
> Currently I have:
> sub get_values {
>  $host    = $host_entry  -> get;
>  $interval  = $interval_entry -> get;
>  $timeout  = $timeout_entry -> get;
>  $size   = $size_entry  -> get;
>  $number   = $number_entry -> get;
>  $save   = $save_entry  -> get;
> ......
> }
> 
> I would like to be able to replace that lot with...
> 
> my @variables =  \($host, $interval, $timeout, $size, $number, $save, ...);
> ...
> sub get_values {
>   foreach $variable (@variables) {
>     my $entry = $_."_entry";
>     $_ = $entry -> get;
>     }
> }
> 
> Isn't it much nicer than 100+ lines of very repetitive code? Shame it
> doesn't work, though ;-)

It would work if you used symbolic references.

You should always think twice before using symbolic references but
they do have their uses.
 
Before you resort to symrefs you need a really strong reason why
putting the configs in hash would not be better.

> I modified my example script...
> 
> use strict;
> use warnings;
> our $one = 1; our $two = 2; our $three = 3; our $four = 4;
> our $value; our $print;
> our @values = (\$one, \$two, \$three, \$four);

There is no reason for @values not to be lexical.

> # This won't change the variables...
> # foreach $value (@values) {
> #  $_ *= 2;
> # }

I'll asume $_ is just a typo.  You forgot to undo those backlashes.
Also there is no reason for $value not to be lexically scoped to the loop.

 foreach my $value (@values) {
   $$value *= 2;
 }

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 09 Jan 2003 12:12:22 -0500
From: Jon Zero <jon@nospam.org>
Subject: Re: Dates in the filename
Message-Id: <C44D7FD35A7C1038.0CC7AAF84C083EF1.FF637AC08C1C2FF3@lp.airnews.net>

On Thu, 09 Jan 2003 11:04:36 -0500, Jürgen Exner wrote:

> Jon Zero wrote:
>> All-
>>    Im not sure how to approach this problem, any help would be great.
>> I have a list of files, and the files are in the following format:
>>
>> MMDDYY-{randomnumber}.jjp
>>
>> I want to delete files older then 11 days based on the MMDDYY in the
>> file names.  What would be the best way to go about doing this?
> 
> The best(!) way would be to persuade the tool that generates those file
> names to use ISO date format: YYYYMMDD. Then all you have to do is a
> simple comparison on the first 8 characters of the file name. And you
> don't have a Y2100 problem, either ;-)
> 
> Now, if this is the easiest way in your org I do not know.
> 
> jue
 
Thanks for the reply, Its not our orginization that generates the files,
so I cant change them, but im sure with a search and replace I can append
a 20 at the beging and strip it out later.   The real problem Im haveing
is once I have the 8 digit date, how do I tell if it is older then 11
days.

Jon


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

Date: Thu, 9 Jan 2003 11:45:32 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Dates in the filename
Message-Id: <slrnb1rd9s.osb.tadmc@magna.augustmail.com>

Jon Zero <jon@nospam.org> wrote:

> The real problem Im haveing
> is once I have the 8 digit date, how do I tell if it is older then 11
> days.


   perldoc -q date

      How can I compare two dates and find the difference?


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


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

Date: 09 Jan 2003 17:41:12 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Dates in the filename
Message-Id: <u9smw2mdaf.fsf@wcl-l.bham.ac.uk>

Jon Zero <jon@nospam.org> writes:

> The real problem Im haveing is once I have the 8 digit date, how do
> I tell if it is older then 11 days.

See FAQ: "How can I compare two dates and find the difference?"

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 09 Jan 2003 17:37:25 GMT
From: gml4410@ggr.co.uk (Lack Mr G M)
Subject: Re: Dates in the filename
Message-Id: <2003Jan9.173725@ukwit01>

In article <3E0CCC8349DB3069.18797EBD0756632D.E666C002EB19BB0E@lp.airnews.net>, Jon Zero <jon@nospam.org> writes:
|>
|>    Im not sure how to approach this problem, any help would be great.  I
|> have a list of files, and the files are in the following format:
|> 
|> MMDDYY-{randomnumber}.jjp
|> 
|> I want to delete files older then 11 days based on the MMDDYY in the file
|> names.  What would be the best way to go about doing this?


 use Time::Local;

 my $before = time() - (11 * 60*60*24);      # 11 days ago

 foreach $fn (@filenames) {
    my ($m, $d, $y) = ($fn =~ /^(\d\d)(\d\d)(\d\d)-\d+\.jjp$/);
    next unless $m;     # Some non-matching name found...
 # ASSUME FILES NAMED SINCE Y2K!!!
 #
    $y += 2000;         # 00 == 2000
    $m--;               # Months indexed from 0
    my $fdate = timelocal(0, 0, 0, $d, $m, $y);
    next if ($fdate > $before);  # Still too young
    printf "Deleting $fb\n";
    ulink $fn;
 }


   I'll leave you to add the error checking....
 
-- 
--------- Gordon Lack --------------- gml4410@ggr.co.uk  ------------
This message *may* reflect my personal opinion.  It is *not* intended
to reflect those of my employer, or anyone else.


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

Date: 9 Jan 2003 10:20:36 -0800
From: jjulian_97@yahoo.com (Joe)
Subject: How am I using sort wrong?
Message-Id: <88a42151.0301091020.56cac024@posting.google.com>

This seems like it should work according to the FM (this is the entire
script, I'm just trying to see how sort works - I'm still a newb):

@cdata = (5, -10, 3, 12, -2, -14, 16, -16);
@cdata = sort ($a <=> $b) @cdata;
print @cdata,"\n";

but I get this error:

Array found where operator expected at foo line 2, at end of line
        (Missing operator before ?)
syntax error at foo line 2, near ") @cdata"
Execution of foo aborted due to compilation errors.

This is such a simple implementation I really didn't expect to
encounter any problems. What's wrong?


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

Date: 09 Jan 2003 13:24:00 -0500
From: Ryan Shondell <shondell@cis.ohio-state.edu>
Subject: Re: How am I using sort wrong?
Message-Id: <xcw65sykwqn.fsf@psi.cis.ohio-state.edu>

jjulian_97@yahoo.com (Joe) writes:

> This seems like it should work according to the FM (this is the entire
> script, I'm just trying to see how sort works - I'm still a newb):
> 
> @cdata = (5, -10, 3, 12, -2, -14, 16, -16);
> @cdata = sort ($a <=> $b) @cdata;
                ^         ^
You want {} instead of ()...

@cdata = sort {$a <=> $b} @cdata;

Check out perldoc -f sort for more info.

-- 
Ryan Shondell <shondell@cis.ohio-state.edu>


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

Date: Thu, 09 Jan 2003 18:48:56 GMT
From: Hal Vaughan <hal@thresholddigital.com>
Subject: Is there a maximum length for system() or backtick commands?
Message-Id: <sujT9.623832$WL3.193403@rwcrnsc54>

I've been testing Bash for maximum command line lengths (and trying to find 
a limit in the man page) and can't find any.

I'm looking at building up a string like this:

$command = "lp ";

foreach (@file) {
        $command = $command.$_." ";
}

And then doing either:

system($command);

or this:

$output = `$command`;


Is there a maximum length I can make $command without problems?  I can 
easily see sending 400 (or even 500) files to the printer this way.  I'd 
rather do it in one command (for various reasons), then breaking it down by 
limiting each command to only a certain number of files.

Thanks!

Hal


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

Date: Thu, 09 Jan 2003 16:21:32 GMT
From: gml4410@ggr.co.uk (Lack Mr G M)
Subject: Re: pack( "N", inet_aton("client.example.net"))
Message-Id: <2003Jan9.162132@ukwit01>

In article <d3a9d3a6.0301090741.43c2bb45@posting.google.com>, msbob@hotmail.com (M. S. Bob) writes:
|>
|> I am have problems writing a pack statement that uses the output of
|> inet_aton().

   The output from inet_aton isn't a number - it's an 4-byte string. 
The 'C'x8 you are trying to use is expecting 8 separate integer args
which it will treat as 8 single chars.  You've got 2 args of 4 chars
each:

|> $buffer = pack( 'a64'. ('C'x8) .'NN', 

$buffer = pack( 'a64' . 'a4a4' . 'NN', 


-- 
--------- Gordon Lack --------------- gml4410@ggr.co.uk  ------------
This message *may* reflect my personal opinion.  It is *not* intended
to reflect those of my employer, or anyone else.


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

Date: 09 Jan 2003 16:37:33 GMT
From: ctcgag@hotmail.com
Subject: Re: reload not terminating process
Message-Id: <20030109113733.912$AT@newsreader.com>

Marshall Dudley <mdudley@execonn.com> wrote:
> I have a perl program that takes about 2 seconds to complete.  I have
> noticed occassionally all the available servers will become busy and top
> reports that this program is running 30 or so intances. When I do a
> server-status, I find that they are all being requested by the same ip.
> Thus it appears that the user has hit reload 30 or more times in a short
> period, causing the program to execute each time.

Or that thirty people on the same server (or behind the same
firewall) are going to your web page, or that someone is using
a Perl script with LWP to slam your page, or using some other language
with someother web agent.  I think it's rather unlikely someone
would bounce on the reload button at 15 Hz.

>
> I was under the impression that if you hit the reload or stop on a
> browser, it is suppose to send a kill to the process so this doesn't
> happen.

The scripts this happen to do tend to die...sometimes...eventually.

But first you have to determine that this is what is actually happening.
Maybe all 30 connections are still listening.

> I am not sure quite where to look to resolve this issue, in the
> program, unix, apache, or is there anything that can be done at all?

I think the first place I'd look is at the IP address that is sending
30 requests in 2 seconds.  Whose is it?  The quickest (and dirtiest)
solution would probably be to change the script to check the IP address
($ENV{'REMOTE_ADDR'}) and quit with a shame_on_you message if it is the
offending one.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB


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

Date: 9 Jan 2003 09:10:10 -0800
From: theiman@comcast.net (tom)
Subject: Re: silly question -- please help!
Message-Id: <47f04bf1.0301090910.24af3902@posting.google.com>

Hi Dr. Siegel,

Thank you for responding!! I really appreciate it!!

Sincerely,

Tom


anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<avjmpp$7kc$2@mamenchi.zrz.TU-Berlin.DE>...
> tom <theiman@comcast.net> wrote in comp.lang.perl.misc:
> > Hi,
> > 
> > I have lots of files with the following structure:
> > 
> > Wnt8	Krl	SoxB1	Krox	Otx	Eve
> > -0.069	0.028	-0.025	-0.011	0.0171	-0.022
> > -0.066	-0.011	-0.035	0.002	-0.001	0.007
> > -0.064	0.0171	-0.040	0.030	0.025	0.009
> > etc...
> > 
> > and I need to convert each one to the following format for use with
> > somebody else's program:
> > 
> > Wnt8 -0.069
> > Krl 0.028
> > SoxB1 -0.025
> > Krox -0.011
> > Otx 0.017
> > Eve -0.022
> > Wnt8 -0.066
> > Krl -0.011
> > SoxB1 -0.035
> > Krox 0.002
> > Otx -0.001
> > Eve 0.007
> > etc...
> > 
> > Any ideas on how to do this in Perl? I'm drawing a big blank.. I'd
> > really appreciate it!!! Thank you!!
> 
>     my @titles = split /\s+/, <DATA>;
>     while ( <DATA> ) {
>         my @fields = split;
>         print "$_ ", shift @fields, "\n" for @titles;
>     }
> 
> Anno


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

Date: Thu, 9 Jan 2003 18:17:51 +0100
From: "Walter Mitty" <shamrockirishbar.remove.nospam@yahoo.co.uk>
Subject: simple file variable question
Message-Id: <avkas0$smj$02$1@news.t-online.com>

(I hope!)

I have downloaded a perl script which I have embedded in a page as a
hyperlink to the script file. This script references a data file using a
perl variable name. When I test it though, if the perl script is executed
from a page in a different directory it doesn't find the data file it needs
(both perl script and data file are in my root web directory). How to I
specifiy the filename to be absolutely in my root directory?

e.g
$tmp_words_file = "email"

assumes the file to be in current pages directory. I don't want "../email"
or anything relative as the page depth might change. I have tried
http://root/datafile but this doesn't work.

--
http://www.shamrockirishbar.com




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

Date: 09 Jan 2003 17:40:53 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: simple file variable question
Message-Id: <u9vg0ymday.fsf@wcl-l.bham.ac.uk>

"Walter Mitty" <shamrockirishbar.remove.nospam@yahoo.co.uk> writes:

> (I hope!)
> 
> I have downloaded a perl script which I have embedded in a page as a
> hyperlink to the script file. This script references a data file using a
> perl variable name. When I test it though, if the perl script is executed
> from a page in a different directory it doesn't find the data file it needs
> (both perl script and data file are in my root web directory). How to I
> specifiy the filename to be absolutely in my root directory?

You represent an abolute filename "/something/like/this".  This, of
course, has nothing to do with Perl.

Of you want to find the absolute path of your document root then this
information is available under CGI in $ENV{DOCUMENT_ROOT}.  This, of
course, has nothing to do with Perl.
 
If you want the directory from which the script was loaded this can be
derived from $ENV{SCRIPT_FILENAME}.  This, of course, has nothing to do
with Perl.

Of course, inside your server document hierachy is a pathologically
bad place to keep data files unless you actually _want_ them to be
downloadable.  This, of course, has nothing to do with Perl.

BTW: Did I mention that none this has anything to do with Perl.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 09 Jan 2003 16:26:44 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Taint check question
Message-Id: <3e1da1ff.480013262@news.cis.dfn.de>

On Thu, 09 Jan 2003 15:52:36 +0100, henrik nilsson
<md0nilhe@mdstud.DIESPAMchalmers.se> wrote:

>Now I at least know I won't have bother too much about PATH.
>My taint check error messages must be related to someting else.

It also appears that you are very unclear on what
it means that data is tainted, why you need to check
user input for taintedness and how to untaint data.

A search in the Frequently Asked Questions:

   perldoc -q taint 

will lead you to read the Perl Security Guidelines

  perldoc perlsec

which includes the chapter:

  "Laundering and Detecting Tainted Data"

which will tell you all you need to know on this
subject.  Get back to use if there is something
there that you don't understand.
-- 
Regards, Helgi Briem
helgi AT decode DOT is


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

Date: 9 Jan 2003 11:01:07 -0800
From: hamelcd@hotmail.com (Christopher Hamel)
Subject: Re: Unix Vars declared in system() call -> %ENV
Message-Id: <4f60d5b3.0301091101.516f86c3@posting.google.com>

"J rgen Exner" <jurgenex@hotmail.com> wrote in message news:<EpgT9.33875$xb.28129@nwrddc02.gnilink.net>...
> 
> Which part of the FAQ "perldoc -q environment" is unclear and need
> improvement?
> 
> jue

None.  It was, in fact perfectly clear.  I actually tried

  perldoc -q environmental

And got nothing.  I see now the error was similar to the use of
"irregardless."

In my [not-so-strong] defense, our Unix sysadmin calls them
"environmental" variables.

Thanks for the responses.
Chris


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

Date: Thu, 9 Jan 2003 13:15:30 -0500
From: "Aaron Simmons" <asimmons@mitre.org>
Subject: Why is map so much faster then a nested for loop?
Message-Id: <avke6e$d86$1@newslocal.mitre.org>

I recently optimized some of my code by using a map instead of a nested for
loop.  This one change took the code that used to take 53 seconds to iterate
over 95,000 rows down to 4 seconds.

Original Code:
for ($i=0; $i<@{$rows->[0]}; $i++) {
    $row = +{}; # Create new anonymous hash

    for ($j=0; $j<$RS->Fields->Count; $j++) {
        $row->{$fields[$j]} = $rows->[$j]->[$i];
    }

    push @{$rs}, $row;
}

Replacement Code:
for ($i=0; $i<@{$rows->[0]}; $i++) {
    push @{$rs}, { map {($fields[$_], $rows->[$_]->[$i])}
0..$RS->Fields->Count };
}


Why and how is this so much faster?

--
Aaron Simmons
G066-Software Systems Eng, Lead
(703) 883-3394
AaronSimm1 (AIM)







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

Date: 9 Jan 2003 18:56:44 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Why is map so much faster then a nested for loop?
Message-Id: <avkglc$mgk$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Aaron Simmons:

> I recently optimized some of my code by using a map instead of a nested for
> loop.  This one change took the code that used to take 53 seconds to iterate
> over 95,000 rows down to 4 seconds.
> 
> Original Code:
> for ($i=0; $i<@{$rows->[0]}; $i++) {
>     $row = +{}; # Create new anonymous hash
> 
>     for ($j=0; $j<$RS->Fields->Count; $j++) {
>         $row->{$fields[$j]} = $rows->[$j]->[$i];
>     }
> 
>     push @{$rs}, $row;
> }
> 
> Replacement Code:
> for ($i=0; $i<@{$rows->[0]}; $i++) {
>     push @{$rs}, { map {($fields[$_], $rows->[$_]->[$i])}
> 0..$RS->Fields->Count };
> }
> 
> 
> Why and how is this so much faster?A

I would assume that the performance difference between these two is
caused by two lines.

Slow:

    for ($j=0; $j < $RS->Fields->Count; $j++) {
                    ^^^^^^^^^^^^^^^^^^
Unless perl is smart enough to turn this into a constant expression
(which I doubt because it might change during the loop) this means that
for each iteration you call the method Fields() on $RS and the Count()
method on the return value of $RS->Fields. Method calls in Perl are
unfortunately quite slow so the above line thus becomes a rather costly
operation.

    { map {($fields[$_], $rows->[$_]->[$i])} 0..$RS->Fields->Count;

is obviously faster because you do the methods calls only once for each
iteration of the outer for-loop.

How fast is the following modification of your original code:

    my $max = $RS->Fields->Count - 1;
    for my $i (0 .. @{ $rows->[0] } - 1) {
        my $row = {}; # Create new anonymous hash
        $row->{$fields[$_]} = $rows->[$_]->[$i] for 0 .. $max;
        push @$rs, $row;
    }
    
A side note: You don't appear to be using strictures in your code since
all your variables were globals. Yet you should make yourself familiar
with the strict-pragma (see 'perldoc strict') and properly scope your
variables to the smallest possible scope using my().

Tassilo
-- 
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;


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

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


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