[22441] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4662 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 4 18:06:07 2003

Date: Tue, 4 Mar 2003 15:05:11 -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           Tue, 4 Mar 2003     Volume: 10 Number: 4662

Today's topics:
    Re: Array construction with references rather than anon ctcgag@hotmail.com
        Carp <member19587@dbforums.com>
    Re: Carp <andy@misk.co.uk>
    Re: Delete the element with the lowest value? NEED SPEE ctcgag@hotmail.com
        finding files containing string x but not string y (spam-this-at-erc-dot-bc-dot-see-eh)
    Re: finding files containing string x but not string y <mpapec@yahoo.com>
    Re: finding files containing string x but not string y <jamesd@transmeta.com>
    Re: finding files containing string x but not string y <usenet@dwall.fastmail.fm>
    Re: finding files containing string x but not string y <goldbb2@earthlink.net>
    Re: Greedy regexps <noreply@gunnar.cc>
    Re: Greedy regexps <asby@kinderen4kinderen.org>
    Re: Greedy regexps <abigail@abigail.nl>
    Re: Greedy regexps (Tad McClellan)
        insert meta tags into an existing html file <pdhze@yahoo.co>
    Re: insert meta tags into an existing html file <noreply@gunnar.cc>
        memory testing with Perl <tzz@lifelogs.com>
    Re: Playing a .wav file <goldbb2@earthlink.net>
    Re: Playing a .wav file <ian@WINDOZEdigiserv.net>
        please help -- perl newbie question <cluiz@att.net>
    Re: please help -- perl newbie question <noreply@gunnar.cc>
    Re: please help -- perl newbie question (Tad McClellan)
    Re: Problem with Unix pipe within perl script (also pos <goldbb2@earthlink.net>
        Problem with Unix pipe within perl script (also posted  (velvel)
        Rebuilding a Perl dist with fast Intel-compiled Perl <brundlefly76@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 04 Mar 2003 22:27:49 GMT
From: ctcgag@hotmail.com
Subject: Re: Array construction with references rather than anonymous array's, using 'split'?
Message-Id: <20030304172749.522$pb@newsreader.com>

bob@mve.com (Bob Kenney) wrote:
> How can I return a 'split' as an array, which I can then reference,
> from a reference array,

[ split ]

> The Sample of code below works pretty well on
> the majority of my files? However, files that contain 1,000,000+
> vertex (all doubles) things just grind to a halt... Although, not to
> bad on LINUX and SGI64, (obviously) on WIN32 and dealing with doubles
> in these numbers, we hit problems.

Get more memory for your windows machine, or use it for a football.

> I need a Solution biased on references rather than copying data. +

I don't know what this means.  Furthermore, whatever it means, how do
you know that this is what you need?

> This small section is were all my scope for optimisation lies and the
> script has to be fast on all platforms.

Or else what?

> There has to be away around
> the windows problem, short of using it as a football!)

Get more memory for your windows machine.  Or better, change your algorithm
so that it doesn're require everthing in memory at one time.

>
> Any suggestions!
>
> I would ideally like to do something like:
>
> $array[$counter] = \( split( ' ', $line) ); #But this returns a list
> and not an array!!!

In list context it would return a list of references, in the scalar context
it is in it returns...I don't know, a reference to it's last element I
guess. You want the square brackets that you already have rather than the
backslash.

>   while ( $line =<FILE> )
>   {
>     #Split the line and put all data less "spaces" in to an array of
> references
>
>     $array[$counter] = [ split(' ', $line) ];
>
>     $counter++;
>     $line = <FILE>;
>   }

You appear to processing only every other line (you read from the file
both at the top and bottom of the loop.  The data read at the bottom
is being ignored, as it is immediately overwritten at the top).  That
probably isn't what you want to do.

Don't use a counter when you don't need one, just do
push @array, [ split ' ', $line ] instead.

However, your problem on Windows is almost surely memory-related, so
taking out the every-other line bug will make things worse, and avoiding
the counter will not help memory usage.

In decreasing order of preference:

1) Change the algorithm so that it doesn't read everything into memory at
   once. (Store the file name or a file handle in the data structure,
instead.) 2) Get more memory.
3) Use some kind of Tie module to tie to disk, or to tight-pack the
numbers.3 4) Rotate your data structure from 1e6 arrays with 3 members each
   to 3 arrays with 1e6 members each.  (each array has ~80 bytes of
   overhead for me, I don't know how much on Windows.)

my ($zero, $one, $two)= split ' ', $line;
push @{$array[0]}, $zero;  # this is ugly, but you get the point
push @{$array[1]}, $one ;
push @{$array[2]}, $two;

5) Try to get perl to store only the floating point part of the variable,
   and not the string representation also.  This can cut memory from
   ~80 bytes per SV to ~20 bytes by my hand.  Note that this is only good
   if the value is never again used in string context.

push @array, [ map $_+0.0 , split ' ', $line ];
#or
push @{$array[0]}, $zero+0.0;

Micro-optimization to fit into memory sucks.  It feels good to get that
1 million item data structure to fit in memory, but then when it changes
to 1.2 million items, is doesn't fit again.  All you work if for naught,
as there is no micro-optimization left, and you are left to do the
fundamental changes you should have done in the first place.  Plus, your
optimized code is now fragile and nonintuitive, so unless you saved your
non-optimized code, you are worse than at square one.

Xho

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


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

Date: Tue, 04 Mar 2003 22:18:23 +0000
From: pons <member19587@dbforums.com>
Subject: Carp
Message-Id: <2603224.1046816303@dbforums.com>


In my script, I have this line
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
each time I try to do perl -c test.cgi .... it show an
error on above line .... could it be that I using an
old version of CGI.pm module ...
or do I need a better Perl / latest Perl
I am running FreeBSD 4.4 stable


Thanks

--
Posted via http://dbforums.com


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

Date: Tue, 04 Mar 2003 22:50:10 +0000
From: Andrew McGregor <andy@misk.co.uk>
Subject: Re: Carp
Message-Id: <3E652DA2.9040208@misk.co.uk>

pons wrote:
> In my script, I have this line
> use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
> each time I try to do perl -c test.cgi .... it show an
> error on above line .... could it be that I using an

error messages can be indicative to the problem.  what was the error?



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

Date: 04 Mar 2003 23:01:39 GMT
From: ctcgag@hotmail.com
Subject: Re: Delete the element with the lowest value? NEED SPEED!
Message-Id: <20030304180139.871$dD@newsreader.com>

"Freddo" <FreddoSpaceMonkey@hotmail.com> wrote:
> Hi there,
>
> I've been trying to devise a method to delete the lowest value from an
> array (without disturbing the order of the array). For example:
>
> @array contains:
> 5,4,2,1,3
>
> # Code to remove smallest number, preserving order goes here
>
> @array now contains:
> 5,4,2,3
>
> The code I have come up so far is inefficient and I think overly-complex.
> Is there a 'quick' way to do this? I'm stumped if I can find it!

An efficient answer to this is extremely depended on how many times
it must be done to the same array, and what other operations are happening
to the array between calls to this operation.  But if you don't want to
worry about that, then here's a simple way to do it:

# broken for empty @array.  Finds the first of equals.
my $minin=0;
foreach (1..$#array) {
  $minin=$_ if $array[$_]<$array[$minin];
};
splice @array, $minin, 1;

Xho

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


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

Date: 4 Mar 2003 11:18:23 -0800
From: spamthis@erc.bc.ca (spam-this-at-erc-dot-bc-dot-see-eh)
Subject: finding files containing string x but not string y
Message-Id: <379ac2fa.0303041118.522d3f6d@posting.google.com>

I need a way to generate a list of all files in a given directory
(recursively) that contain string "x" but not contain string "y"
recursively.  I don't need exact code, but just some hints that can
point me in the right direction.

Thank you.


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

Date: Tue, 04 Mar 2003 20:36:27 +0100
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: finding files containing string x but not string y
Message-Id: <3dv96vsm7t3vaq9jae52i31dtkq8b2ukum@4ax.com>

X-Ftn-To: spam-this-at-erc-dot-bc-dot-see-eh 

spamthis@erc.bc.ca (spam-this-at-erc-dot-bc-dot-see-eh) wrote:
>I need a way to generate a list of all files in a given directory
>(recursively) that contain string "x" but not contain string "y"
>recursively.  I don't need exact code, but just some hints that can
>point me in the right direction.

this /should/ work but only with files in current directory

$x = qr/yes/;
$y = qr/no/;

#1 short, using glob
print "$_\n" for grep /$x/ and !/$y/, <*>;


#2 verbose
local *DIR;
open(DIR, '.');
for $file(grep /$x/ and !/$y/, readdir(DIR)) {
  print "$file\n";
}
close(DIR);



-- 
Matija


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

Date: Tue, 04 Mar 2003 12:30:27 -0800
From: James Damon <jamesd@transmeta.com>
Subject: Re: finding files containing string x but not string y
Message-Id: <3E650CE3.C9E4D6D@transmeta.com>

Hi,

To get you started you could use find2perl..

find2perl "*.pl" -exec grep "use" {} \; -print

will generate some Perl code that looks for files ending in  ".pl".  You
could then hack this code to
do a more elaborate string comparisson.
You just need to modify doexec... so that it calls an internal
function.... for the doexec part..




> I need a way to generate a list of all files in a given directory
> (recursively) that contain string "x" but not contain string "y"
> recursively.  I don't need exact code, but just some hints that can
> point me in the right direction.
>
> Thank you.



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

Date: Tue, 04 Mar 2003 20:38:47 -0000
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: finding files containing string x but not string y
Message-Id: <Xns93349F2A16B2Fdkwwashere@216.168.3.30>

spam-this-at-erc-dot-bc-dot-see-eh <spamthis@erc.bc.ca> wrote on 04 Mar 
2003:

> I need a way to generate a list of all files in a given directory
> (recursively) that contain string "x" but not contain string "y"
> recursively.  I don't need exact code, but just some hints that can
> point me in the right direction.

use File::Find;
find ( sub { 
        # fill this in... 
        # open file, check for 'x' and 'y'
        # do something if condition is satisfied
    },
    '/path/dir'
);

-- 
David K. Wall - usenet@dwall.fastmail.fm
"Oook."


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

Date: Tue, 04 Mar 2003 16:22:00 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: finding files containing string x but not string y
Message-Id: <3E6518F8.173E4B1F@earthlink.net>

spam-this-at-erc-dot-bc-dot-see-eh wrote:
> 
> I need a way to generate a list of all files in a given directory
> (recursively) that contain string "x" but not contain string "y"
> recursively.  I don't need exact code, but just some hints that can
> point me in the right direction.


use File::Find;
find ( sub { 
       my $found_x = 0;
       open _ or warn($!), return;
       while(<_>) {
          /y/ and return;
          $found_x ||= /x/;
       }
       return unless $found_x;
       # do something
    },
    "/path/to/directory/"
);


-- 
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print


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

Date: Tue, 04 Mar 2003 21:44:46 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Greedy regexps
Message-Id: <b433d5$1r52qm$1@ID-184292.news.dfncis.de>

Bigus wrote:
> I would be interested in knowing what I was doing wrong for
> future ref.

So would I.

This is what 'perlre' says about changing "greediness":
"If you want it to match the minimum number of times possible, follow 
the quantifier with a ``?''."

Abigail wrote:
> The ? modifier doesn't stop the regexp from matching, and it doesn't
> stop the regexp from matching at the earliest point possible.

Hmm.. Considering the above quote, I would have thought otherwise.

Can somebody possibly explain what the ? modifier actually does? 
Irrespective of various opinions on the appropriate in parsing HTML 
through a regexp, this seems to be a regexp question of general interest.

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Tue, 4 Mar 2003 23:00:12 +0100
From: "Asby" <asby@kinderen4kinderen.org>
Subject: Re: Greedy regexps
Message-Id: <3e6521f1$0$49117$e4fe514c@news.xs4all.nl>

"Bigus" <somewhere@nowhere.com> wrote in message
news:b427pu$vf2@newton.cc.rl.ac.uk...
> Hi
>
> I am parsing some HTML code in the following manner:
>
>     $html =~ s/\n//g;
>     $html =~ s/.*<!--search-begin-->(.*)<!--search-end-->.*/$1/i;
>     $html =~ s/(^\s+|\s+$)//g;
>     $html =~ s/\s+/ /g;
>     $html =~ s/<td.+?class=\"*head1.*?>(.*?)<\/td>/###$1###/gi;

Besides the fact that you "could" use a HTML parser, you also uses to much
 .*
Don't feed a regexp engine with .* if you don't have to.
Try something like:

$html =~ s!<td[^>]+class="?head1"?>([^<]+)</td>!###$1###!gi;


--
ttfn,

Asby
$_="qdjb3H kqdP qdgsnmA srtJ";y/a-y3/b-za/;print scalar reverse




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

Date: 04 Mar 2003 22:14:57 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Greedy regexps
Message-Id: <slrnb6a9b0.93e.abigail@alexandra.abigail.nl>

Gunnar Hjalmarsson (noreply@gunnar.cc) wrote on MMMCDLXXII September
MCMXCIII in <URL:news:b433d5$1r52qm$1@ID-184292.news.dfncis.de>:
''  Bigus wrote:
'' > I would be interested in knowing what I was doing wrong for
'' > future ref.
''  
''  So would I.
''  
''  This is what 'perlre' says about changing "greediness":
''  "If you want it to match the minimum number of times possible, follow 
''  the quantifier with a ``?''."
''  
''  Abigail wrote:
'' > The ? modifier doesn't stop the regexp from matching, and it doesn't
'' > stop the regexp from matching at the earliest point possible.
''  
''  Hmm.. Considering the above quote, I would have thought otherwise.

How so? I don't see me in disagreement with perlre.

''  Can somebody possibly explain what the ? modifier actually does? 

The modifier makes that if the regex has the possibility of matching
the subexpression it's applied to is as small as possible. 

It will *NOT* effect matching or not matching. It will *NOT* effect
where earlier subpatterns match. It will *NOT* effect later subpatterns
(except that they might be tried earlier in the string).

? has mostly local effect - the local effect can ripple outwards, but
it doesn't change any global effects.



Abigail
-- 
perl -e '$a = q 94a75737420616e6f74686572205065726c204861636b65720a9 and
         ${qq$\x5F$} = q 97265646f9 and s g..g;
         qq e\x63\x68\x72\x20\x30\x78$&eggee;
         {eval if $a =~ s e..eqq qprint chr 0x$& and \x71\x20\x71\x71qeexcess}'


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

Date: Tue, 4 Mar 2003 16:18:05 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Greedy regexps
Message-Id: <slrnb6a9gt.1us.tadmc@magna.augustmail.com>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> Bigus wrote:
>> I would be interested in knowing what I was doing wrong for
>> future ref.
> 
> So would I.
> 
> This is what 'perlre' says about changing "greediness":
> "If you want it to match the minimum number of times possible, follow 
> the quantifier with a ``?''."


You snipped too much. Before that it says:

   By default, a quantified subpattern is "greedy", that is, it will match as
   many times as possible (given a particular starting location) while still
   allowing the rest of the pattern to match.

The "particular starting location" and "allowing the rest of the 
pattern to match" parts are applicable to the sentence that you
quoted as well.


> Abigail wrote:
>> The ? modifier doesn't stop the regexp from matching, and it doesn't
>> stop the regexp from matching at the earliest point possible.
> 
> Hmm.. Considering the above quote, I would have thought otherwise.
> 
> Can somebody possibly explain what the ? modifier actually does? 


Patterns always match at the first opportunity.

"Greediness" only matters when there is more than one way to match
at that position. Match the longest if greedy, the shortest if
non-greedy.


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


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

Date: Tue, 04 Mar 2003 21:00:32 GMT
From: piet <pdhze@yahoo.co>
Subject: insert meta tags into an existing html file
Message-Id: <Usenet.qppaqegm@localhost>

How do I insert new meta tags into an existing local html file?
txs
piet



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

Date: Tue, 04 Mar 2003 22:05:18 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: insert meta tags into an existing html file
Message-Id: <b434jo$1rf95k$1@ID-184292.news.dfncis.de>

piet wrote:
> How do I insert new meta tags into an existing local html file?

How about using a text editor? ;-)

If that's not the answer you had expected, you may want to give some 
more details. For instance: In what way is your question related to Perl?

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Tue, 04 Mar 2003 16:41:08 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: memory testing with Perl
Message-Id: <4nllzu6c97.fsf@lockgroove.bwh.harvard.edu>

Has anyone written a memory tester using Perl?  I don't mean something
fancy, just to create an array of N elements and then verify the
contents.  The key feature is that I'd like to know when the script
has reached, let's say, 512MB of memory usage.  I've assumed so far
that every element is just a little larger than its contents and added
the contents up (ignoring the interpreter size, so I'm guaranteed to
use at least that much memory), but I was wondering if there's a
better way.

Thanks
Ted


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

Date: Tue, 04 Mar 2003 16:17:50 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Playing a .wav file
Message-Id: <3E6517FE.6D233145@earthlink.net>

"Ian.H [dS]" wrote:
> 
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
> 
> Afternoon all =)
> 
> Does anyone know of a method/function that'll enable a wav file to be
> played on a certain event?

On unix, simply copy the file into /dev/audio.

On windows, use Win32::Sound.

For something more portable, use Audio::Data and Audio::Play, but this
only plays .au files.

There are other Audio:: modules on CPAN which may suit your needs
better.

> I experimented and used a system() call with just the wav file as an
> arg, but this opened the default media player.

Sounds like you're on windows...  Defnitely Win32::Sound.

> The script will be run through a client app on a system, not Web
> based. I've tried searching google and came up with no leads.

-- 
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print


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

Date: Tue, 04 Mar 2003 22:41:07 GMT
From: "Ian.H [dS]" <ian@WINDOZEdigiserv.net>
Subject: Re: Playing a .wav file
Message-Id: <nkaa6vk7vf1nuuknt81bdlpp2f7goki85b@4ax.com>
Keywords: Remove WINDOZE to reply

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

In a fit of excitement on Tue, 04 Mar 2003 16:17:50 -0500, Benjamin
Goldberg <goldbb2@earthlink.net> managed to scribble:

> "Ian.H [dS]" wrote:
> > 
> > -----BEGIN xxx SIGNED MESSAGE-----
> > Hash: SHA1
> > 
> > Afternoon all =)
> > 
> > Does anyone know of a method/function that'll enable a wav file
> > to be played on a certain event?
> 
> On unix, simply copy the file into /dev/audio.


Well, that was an easy solution... and people say UNIX is complicated
=)


> 
> On windows, use Win32::Sound.
> 
> For something more portable, use Audio::Data and Audio::Play, but
> this only plays .au files.
> 
> There are other Audio:: modules on CPAN which may suit your needs
> better.


The Win32::Sound looks like a likely candidate. The script's to run
within an IRC client. It has a system speaker 'beep' for messages,
but sometimes, it disappears under the sound of music etc, so my
thoughts was to play a wav sound of some description (user
configurable) so that the volume can be controlled through an
amp/speakers.


> 
> > I experimented and used a system() call with just the wav file as
> > an arg, but this opened the default media player.
> 
> Sounds like you're on windows...  Defnitely Win32::Sound.


This box runs Win2k.. other box run FreeBSD =)

Thanks Ben for your suggestions.



Regards,

  Ian

-----BEGIN xxx SIGNATURE-----
Version: PGP 8.0

iQA/AwUBPmUrgWfqtj251CDhEQLEggCbBP2NA3pU+JGLtSmhV8XfPPD5A5kAoI0k
lmp4t5cHEounUpzbib60RfGq
=aCti
-----END PGP SIGNATURE-----

-- 
Ian.H  [Design & Development]
digiServ Network - Web solutions
www.digiserv.net  |  irc.digiserv.net  |  forum.digiserv.net
Scripting, Web design, development & hosting.


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

Date: Tue, 04 Mar 2003 20:45:19 GMT
From: "cluiz" <cluiz@att.net>
Subject: please help -- perl newbie question
Message-Id: <zf89a.600$1v.52309@bgtnsc04-news.ops.worldnet.att.net>

sorry to bother everyone, this is probably very simple, but i'm new to perl.

i'm running this counter script named gcv15.pl in my /cgi-bin on a windows
2000 server, calling it from an .shtml file in my root directory using a ssi
<!--exec cgi="/cgi-bin/gcv15.pl" -->

i'm hoping someone can tell me why it is reading the "count.log" file in my
data directory, incrementing it, writing the new count back to "count.log"
but the code the script is supposed to print out (<img tags> for counter
gifs) isn't appearing in my .shtml page -- all my html is there, but where
the <!--exec cgi="/cgi-bin/gcv15.pl" --> was is just blank.

i know my permissions are correct, and obviously the script is executing,
but it just won't print the html.

i appreciate any help.

#!/usr/bin/perl
$Count_Log = "../data/count.log";
$Width = "10";
$Height = "17";
$Border = "0";
$IP_Logging = "0";
$IP_Log = "ips.log";
$Extension = ".gif";
$Location = "../images/counter/";
if ($IP_Logging eq "1") {
open(IPLOG,"$IP_Log"); @ips = <IPLOG>; close(IPLOG);

foreach $ip (@ips) { chomp($ip);
if ($ip eq "$ENV{REMOTE_ADDR}") { $match = 1;
open(COUNTLOG,"$Count_Log"); $count = <COUNTLOG>; close(COUNTLOG);
@numbers1 = split(//, $count);

 foreach $number (@numbers1) { print qq~
 <img src="$Location$number$Extension" width="$Width" height="$Height"
border="$Border">
 ~; }

exit; }
}

if (! $match) {
open(IPLOG,">>$IP_Log"); print IPLOG "$ENV{REMOTE_ADDR}\n"; close(IPLOG);
open(COUNTLOG,"$Count_Log"); $count = <COUNTLOG>; close(COUNTLOG);
$nextnumber = ($count) + (1);

open(COUNTLOG1,">$Count_Log"); print COUNTLOG1 "$nextnumber";
close(COUNTLOG1);
@numbers = split(//, $nextnumber);

 foreach $nextnumber(@numbers) { print qq~
 <img src="$Location$nextnumber$Extension" width="$Width" height="$Height"
border="$Border">
 ~; }

exit; }
}

open(COUNTLOG,"$Count_Log"); $count = <COUNTLOG>; close(COUNTLOG);
$nextnumber = ($count) + (1);

open(COUNTLOG1,">$Count_Log"); print COUNTLOG1 "$nextnumber";
close(COUNTLOG1);

@numbers = split(//, $nextnumber);
foreach $number (@numbers) { print qq~
<img src="$Location$number$Extension" width="$Width" height="$Height"
border="$Border">
~; exit; }




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

Date: Tue, 04 Mar 2003 22:00:06 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: please help -- perl newbie question
Message-Id: <b4349v$1rgvmf$1@ID-184292.news.dfncis.de>

cluiz wrote:
> i'm hoping someone can tell me why it is reading the "count.log" file in my
> data directory, incrementing it, writing the new count back to "count.log"
> but the code the script is supposed to print out (<img tags> for counter
> gifs) isn't appearing in my .shtml page -- all my html is there, but where
> the <!--exec cgi="/cgi-bin/gcv15.pl" --> was is just blank.

I'd try adding a HTTP header before the first print statement:

     print "Content-type: text/html\n\n";

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Tue, 4 Mar 2003 16:39:36 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: please help -- perl newbie question
Message-Id: <slrnb6aap8.1us.tadmc@magna.augustmail.com>

cluiz <cluiz@att.net> wrote:

> Subject: please help -- perl newbie question


Please put the subject of your article in the Subject of your article.

The subject you've chosen is information-free.


> sorry to bother everyone, this is probably very simple, but i'm new to perl.


Have you seen the Posting Guidelines that are posted here frequently?


> i'm running this counter script named gcv15.pl in my /cgi-bin on a windows
> 2000 server, calling it from an .shtml file in my root directory using a ssi
><!--exec cgi="/cgi-bin/gcv15.pl" -->
> 
> i'm hoping someone can tell me why it is reading the "count.log" file in my
> data directory, incrementing it, writing the new count back to "count.log"
> but the code the script is supposed to print out (<img tags> for counter
> gifs) isn't appearing in my .shtml page -- all my html is there, but where
> the <!--exec cgi="/cgi-bin/gcv15.pl" --> was is just blank.
> 
> i know my permissions are correct, and obviously the script is executing,
> but it just won't print the html.
> 
> i appreciate any help.
> 
> #!/usr/bin/perl


Then you should ask for all of the machine help you can get
before bothering humans with it.

   #!/usr/bin/perl
   use strict;
   use warnings;


> $Count_Log = "../data/count.log";


You should not rely on having any particular working directory.

Either use an absolute path, or chdir() to a known directory
before using relative paths.


> $Width = "10";
> $Height = "17";
> $Border = "0";
> $IP_Logging = "0";


Quotes are for strings, not for numbers:

   $Width = 10;

> open(IPLOG,"$IP_Log");
             ^       ^
             ^       ^ a useless use of double quotes


You should always, yes *always*, check the return value from open():

   open(IPLOG, $IP_Log) or die "could not open '$IP_Log'  $!";  

You may want to do something other than die()ing, but the point
is to check and see if you actually got what you asked for
(an opened filehandle).


> foreach $ip (@ips) { chomp($ip);


You can chomp the whole array ahead of time:

   chomp @ips;



> if (! $match) {


You can say "unless" instead of "if not" if you like:

   unless ( $match ) {


> open(COUNTLOG,"$Count_Log"); $count = <COUNTLOG>; close(COUNTLOG);


You have a race condition there.

You will need to implement file locking if you don't want the
count to become corrupted.

Have you checked the Perl FAQ?

   I still don't get locking.  I just want to increment the 
   number in the file.  How can I do this?


> $nextnumber = ($count) + (1);


Two useless uses of parenthesis. Do you get paid by the character?

   $nextnumber = $count + 1;


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


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

Date: Tue, 04 Mar 2003 16:04:06 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Problem with Unix pipe within perl script (also posted in  comp.unix.programmer)
Message-Id: <3E6514C6.AE2AC701@earthlink.net>

velvel wrote:
> 
> A Unix pipe "|" within a shell command in a perl script is not
> executing when I invoke the perl script from korn shell script in one
> environment, while it is fine in another.

This is a shell problem, not a perl problem.

If you were to write your program using any language other than perl,
the problem would persist.

   http://groups.google.com/groups?q=group%3Acomp.unix

-- 
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print


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

Date: 4 Mar 2003 11:57:27 -0800
From: velvels@hotmail.com (velvel)
Subject: Problem with Unix pipe within perl script (also posted in comp.unix.programmer)
Message-Id: <c07924ea.0303041157.2c1272b5@posting.google.com>

A Unix pipe "|" within a shell command in a perl script is not
executing when I invoke the perl script from korn shell script in one
environment, while it is fine in another.
Both are on Solaris 8 and the perl version 5.005_03 built for
sun4-solaris

I am trying to isolate the specific reaosn why the pipe works in one
box (1) and does not in the other (2).
(Note that perl is in /usr/local/bin/ dir in box 1 whereas it is in
/usr/bin/ dir in box 2.)


To demonstrate, I have made a simplistic set of scripts - a shell
script named "test_control.sh" and a perl script named "run_test.pl",
and here are the results of execution:

***********************************************************************
In box 1 (successful execution), 

$which perl
/usr/local/bin/perl

$perl -v

This is perl, version 5.005_03 built for sun4-solaris

$ more test_control.sh
#!/bin/ksh -x
 . $HOME/.profile
cd "`dirname $0`"
echo "STARTING call to perl `date`\n" > logs/test_control.log
run_test.pl toolc_de.dmp >> logs/test_control.log
echo "Returned from PERL. " `date`
exit 99


$ more run_test.pl
#!/usr/local/bin/perl
print " first\n";
print `echo "hello"`;
print " second\n";
print `echo "hello" | wc`;
print " third\n";
exit (99) ;

After execution of test_control.sh, output of log file is:

$more logs/test_control.log
STARTING call to perl Tue Mar  4 12:46:22 EST 2003

 first
hello
 second
       1       1       6
 third


***********************************************************************
In box 2 (pipe not executing), 

$which perl
/usr/bin/perl

$perl -v

This is perl, version 5.005_03 built for sun4-solaris

$ more test_control.sh
#!/bin/ksh -x
 . $HOME/.profile
cd "`dirname $0`"
echo "STARTING call to perl `date`\n" > logs/test_control.log
run_test.pl toolc_de.dmp >> logs/test_control.log
echo "Returned from PERL. " `date`
exit 99


$ more run_test.pl
#!/usr/bin/perl
print " first\n";
print `echo "hello"`;
print " second\n";
print `echo "hello" | wc`;
print " third\n";
exit (99) ;

After execution of test_control.sh, output of log file is:
$more logs/test_control.log
STARTING call to perl Tue Mar  4 12:46:22 EST 2003

 first
hello
 second
 third


*****************************************************************


Could a perl/unix guru give me tips on what else I can look for to
determine the reason for failure in box 2 ?

Thanks


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

Date: Tue, 04 Mar 2003 21:21:34 GMT
From: "Seth Brundle" <brundlefly76@hotmail.com>
Subject: Rebuilding a Perl dist with fast Intel-compiled Perl
Message-Id: <yN89a.70468$Ik.3070859@typhoon.sonic.net>

I keep my entire production perl package in /home/perl - i keep the
binaries, libraries, I even make a dist directory for all the module tgz's
I've installed so I know what I have put in there. I like everything in the
same place, and maintainable outside of a directory which requires root
access.

Anyways, I recently bought a P4 3.06 and benchmarked an Intel Compiler
7.0-compiled version of perl using perlbench - it was 21% faster then the
gcc-compiled version (!!!!)

Obviously I want to start using this Perl instead, I mean, damn, this is
equivilent to upgrading to a 3.7GHz processor for Perl use.

Can I just target my make install into my current production distribution
directory and overwrite the old one? Will it still have access to my
(dynamically-linked) third-party module installs? (actually, I will probably
want to rebuild my modules anyway so that C modules are compiled with the
new compiler also). I am kinda wary, as I've never tinkered with another
compiler.




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

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


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