[22963] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5183 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jul 5 18:07:43 2003

Date: Sat, 5 Jul 2003 15:05:09 -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, 5 Jul 2003     Volume: 10 Number: 5183

Today's topics:
        &#1055;&#1086;&#1082;&#1072; (Andrew)
    Re: Alternative to use vars <bik.mido@tiscalinet.it>
    Re: Alternative to use vars <bik.mido@tiscalinet.it>
    Re: Confused with array and references (Tad McClellan)
    Re: Confused with array and references <tassilo.parseval@rwth-aachen.de>
    Re: dynamic sorting (Tad McClellan)
    Re: dynamic sorting <bdonlan@bd-home-comp.no-ip.org>
    Re: dynamic sorting <krahnj@acm.org>
    Re: From floating point to fraction <nospam-abuse@ilyaz.org>
    Re: naming hash using a variable name. <uri@stemsystems.com>
    Re: naming hash using a variable name. <REMOVEsdnCAPS@comcast.net>
    Re: naming hash using a variable name. (Tad McClellan)
    Re: naming hash using a variable name. (Tad McClellan)
    Re: ping Tad <requests@zipperpulls.com>
        Problem with counter CGI script <tstewart66@hotmail.com>
    Re: Problems with perlcc <dennis.hueckelheim@issdh.com>
    Re: Problems with perlcc <tassilo.parseval@rwth-aachen.de>
    Re: Problems with perlcc <bdonlan@bd-home-comp.no-ip.org>
    Re: Problems with perlcc <dennis.hueckelheim@issdh.com>
    Re: reading header? results from another script (Tad McClellan)
    Re: Reading JPEG file <zvone.zagar@siol.net>
    Re: Regexp constructed from command line arguments. <this.is.invalid@yahoo.com>
    Re: Regexp constructed from command line arguments. <this.is.invalid@yahoo.com>
    Re: script for unrestricted permutation (Chris Charley)
    Re: script for unrestricted permutation (Jay Tilton)
    Re: trying to parse XML from an email... (rtl)
    Re: trying to parse XML from an email... <flavell@mail.cern.ch>
    Re: using 'DB_File' versus just plain tie() ? <bik.mido@tiscalinet.it>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 5 Jul 2003 12:26:52 -0700
From: kx@peterlink.ru (Andrew)
Subject: &#1055;&#1086;&#1082;&#1072;
Message-Id: <a87ac51e.0307051126.58676f55@posting.google.com>

&#1044;&#1086; &#1089;&#1074;&#1080;&#1076;&#1072;&#1085;&#1080;&#1103;,
&#1083;&#1102;&#1073;&#1080;&#1090;&#1077;&#1083;&#1080; Perl.


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

Date: Sat, 05 Jul 2003 21:24:48 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Alternative to use vars
Message-Id: <019egvcskmp6ocgmajdt7p4hb9arrdq7de@4ax.com>

On Sat, 5 Jul 2003 10:26:54 +1000, Martien Verbruggen
<mgjv@tradingpost.com.au> wrote:

>This is what the difference between C<our> and C<use vars> is. C<our>
>works on lexical scopes, and C<use vars> works on package scope. 

Hmmm... this seems to be the main issue here. Maybe for a future Perl5
release a (backwards compatible) mechanism might be devised, by means
e.g. of a C<package> modifier, that gives a package an implicit
lexical scope.


Michele
-- 
$\=q.,.,$_=q.print'  ,\g,,( w,a'c'e'h,,map{$_-=qif/g/;chr
}107..q[..117,q)[map+hex,split//,join' ,2B,, w$ECDF078D3'
F9'5F3014$,$,];];$\.=$/,s,q,32,g,s,g,112,g,y,' , q,,eval;


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

Date: Sat, 05 Jul 2003 21:24:49 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Alternative to use vars
Message-Id: <aa6egvkv440j3u8baqeugciu6ut6jrcsh4@4ax.com>

On Fri, 4 Jul 2003 17:34:41 -0500, tadmc@augustmail.com (Tad
McClellan) wrote:

>>   perl -Mstrict -wlne 'our $c++ if /\bfoo$/; END{print $c}' file

>Warnings and strictures are basically just good Software Engineering.
>Good SE hardly makes sense for a one-line program.

OK, I'm not really concerned with writing one-liners that work under
strictures.

It should be clear that mine was just an example, and one, as
precisely stated in the OP, having to do with something that really
helped *me* to understand C<our> and "C<our> vs C<use vars>"...

>Precious few programmers use them on one-liners, the payback is not there.

Including myself indeed!

>If you had wanted it Done Right, you would have put the code in a file!

And in fact I do. However there are some scripts that are not
substantially different in their structure from a one-liner, but OTOH
are complex enough to benefit from the C<use strict>: if not for
other, to allow someone else to use (portions of code from) them in
other programs.

Another point that I wanted to discuss yesterday, but avoided to for
various reasons, has to do with the well known
natural-language-like-features-in-Perl issue: I read MJD's article on
Perl's two mechanisms for local variables. I agree that they are
jointly (IIRC) somewhat "towards the baroque end of the scale", OTOH I
find the word "my" perfectly suited for conveying the psychological
feeling of a local variable.

Also, while I read that C<my> doesn't apply to Perl's predefined
variable for technical reasons (at the time of the original
implementation, AFAIK), it does make sense that it is so, again from
an aesthetic point of view: they're not *mine*, they're *perl's* (the
implementation, thus lowercase!); I can only assign to them, if I like
to, a C<local> value.

Well, again IMO, C<our> fits perfectly this scheme, while C<use vars>
is not, by any means. Hmmm! I even wonder if there's room for C<his>,
C<your>, C<their>...


Michele
-- 
$\=q.,.,$_=q.print'  ,\g,,( w,a'c'e'h,,map{$_-=qif/g/;chr
}107..q[..117,q)[map+hex,split//,join' ,2B,, w$ECDF078D3'
F9'5F3014$,$,];];$\.=$/,s,q,32,g,s,g,112,g,y,' , q,,eval;


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

Date: Sat, 5 Jul 2003 09:33:23 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Confused with array and references
Message-Id: <slrnbgdodj.6no.tadmc@magna.augustmail.com>

Abigail <abigail@abigail.nl> wrote:
> Eric J. Roode (REMOVEsdnCAPS@comcast.net) wrote on MMMDXCV September

> %%      It can be a list:    @a = (5, 6, 7);
> %%      It can be arguments to a function:     myfunc(5, 6, 7);
> %%      It can be an expression with two comma operators:  $x = (5, 6, 7);
> 
> Actually, I'd say the parens in the above expressions all mean the same:
> they are there for precedence,

> In '@a = (5, 6, 7)', it's the fact there's an array on the LHS of the 
> assignment that makes the RHS a list, not the parenthesis. If you have
> '@a = 5', there's still a list on the RHS.


I like to use the below for an example of a "list without parens":

   push @a, 5, 6, 7;


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


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

Date: 5 Jul 2003 18:41:03 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Confused with array and references
Message-Id: <be763v$8q8$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Tad McClellan:

> Abigail <abigail@abigail.nl> wrote:
>> Eric J. Roode (REMOVEsdnCAPS@comcast.net) wrote on MMMDXCV September
> 
>> %%      It can be a list:    @a = (5, 6, 7);
>> %%      It can be arguments to a function:     myfunc(5, 6, 7);
>> %%      It can be an expression with two comma operators:  $x = (5, 6, 7);
>> 
>> Actually, I'd say the parens in the above expressions all mean the same:
>> they are there for precedence,
> 
>> In '@a = (5, 6, 7)', it's the fact there's an array on the LHS of the 
>> assignment that makes the RHS a list, not the parenthesis. If you have
>> '@a = 5', there's still a list on the RHS.
> 
> 
> I like to use the below for an example of a "list without parens":
> 
>    push @a, 5, 6, 7;

Not sure how convincing this is. The fact that perl treats 5, 6, 7 as a
list is a result of the prototype that is attached with push(). Function
arguments always start with being one large list that perl then breaks
into segments according to the function's prototype.

I think that round parens generally do construct lists. However, Perl
allows to omit the parens when they are not needed (just like one can do
away with the $_ with many built-ins). This becomes clearer for those
cases where the parens must be used to enforce list context:

    ($var) = keys %hash;
    # compared to
    $var = keys %hash;

So you sometimes need parens to force something into list context
whereas in the opposite case (when you have the context already), you
don't need them. Therefore it's probably better to tackle and explain
lists from a context-angle.

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, 5 Jul 2003 09:36:06 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: dynamic sorting
Message-Id: <slrnbgdoim.6no.tadmc@magna.augustmail.com>

ARAVIND <arawind@yahoo.com> wrote:

> say i have a variable 
> $temp = "ARAVIND     25     BANGALORE";

> @splitval = split /\d /,$temp;
> then i get
> $splitval[0] = 'ARAVIND     25';


I don't get that.

Your installation of perl may be messed up.


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


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

Date: Sat, 05 Jul 2003 14:45:14 -0400
From: "bd" <bdonlan@bd-home-comp.no-ip.org>
Subject: Re: dynamic sorting
Message-Id: <pan.2003.07.05.18.45.14.5027@bd-home-comp.no-ip.org>

On Sat, 05 Jul 2003 04:11:57 -0700, ARAVIND wrote:

> hello,
> 
> say i have a variable 
> $temp = "ARAVIND     25     BANGALORE";
> I want just ARAVIND and BANGALORE
> if i do 
> @splitval = split /\d /,$temp;
> then i get
> $splitval[0] = 'ARAVIND     25';
> $splitval[1] = 'BANGALORE';
> 
> i can further split it from $splitval[0] and get only ARAVIND.
> but how to make it one shot....spliting.
> 
> Regards,
> Aravind.

Use a regex:
$temp =~ s/^(\W+)\s*\d+\s*(\W+)$/;
@splitval = ($1, $2); # @splitval = ('ARAVIND', 'BANGALORE')

Read perldoc perlre for more info on regexes.

-- 
Freenet distribution not available
According to all the latest reports, there was no truth in any of the
earlier reports.



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

Date: Sat, 05 Jul 2003 20:27:26 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: dynamic sorting
Message-Id: <3F0734B4.A6945985@acm.org>

bd wrote:
> 
> On Sat, 05 Jul 2003 04:11:57 -0700, ARAVIND wrote:
> >
> > say i have a variable
> > $temp = "ARAVIND     25     BANGALORE";
> > I want just ARAVIND and BANGALORE
> 
> Use a regex:
> $temp =~ s/^(\W+)\s*\d+\s*(\W+)$/;

The \W character class will not match either 'ARAVIND' or 'BANGALORE'. 
You probably meant to use the \w character class.


> @splitval = ($1, $2); # @splitval = ('ARAVIND', 'BANGALORE')

You shouldn't use the values of $1 and $2 unless you know the match was
successful.


John
-- 
use Perl;
program
fulfillment


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

Date: Sat, 5 Jul 2003 20:19:08 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: From floating point to fraction
Message-Id: <be7brs$316u$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Mark Jason Dominus
<mjd@plover.com>], who wrote in article <be4ifd$ial$1@plover.com>:
> I think the simplest approach is to use 'continued fractions'.

> You need to arrange your program to decide
> which one it wants to use.  That's a policy matter that I can't really
> help with. 

One needs to know the error estimate.  When the next fraction is
(within the estimate) of the previous one, one should stop.  [Two
consequent fractions are not only both "best" approximations, they
also bracket the initial value between them.]

But if you can use the LLL algorithm, finding the stuff becomes much
more convenient; this is why I did not use PARI's builtin continuous
fraction routines in my sample solution.  [It is harder to explain LLL
in 3 minutes, though.  ;-(]

> For your example of 0.33333333333333333, the function generates
> 
>         0 / 1
>         1 / 3
> 
> and then stops, which I think is just what you would want.

Nope, it should generate

          33333333333333333/100000000000000000

(or some such) too.  Your calculations where done with too little
precision...

Hope this helps,
Ilya


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

Date: Sat, 05 Jul 2003 14:36:33 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: naming hash using a variable name.
Message-Id: <x7el15niq6.fsf@mail.sysarch.com>

>>>>> "Ph" == Perusion hostmaster <nanae@perusion.com> writes:

  Ph> 	my $tmp1 = $rand[int rand(scalar(@rand))];

nither the int nor the scalar are needed there. rand provides scalar
context to its single argument (single argument means wants a single
value which is what scalar context is). and indexing also provides
integer context (ever heard of the 3.14159th slot of an array) to any
values being used.

	my $tmp1 = $rand[rand @rand];

that is the classic select a random element from an array idiom.

  Ph> 	$hash{$tmp1} = {};

no need to initialize that. autovivification will handle it for you.
>>>>> "Ph" == Perusion hostmaster <nanae@perusion.com> writes:


  Ph> 	for(my $i = 0; $i < @ARGV; $i++) {
  Ph> 		$hash{$tmp1}{$ARGV[$i]} = $i;
  Ph> 	}

ewww.

	@{$hash{$tmp1}}{@ARGV} = 0 .. $#ARGV ;


  Ph> If you insist on the tired Perl 4 way:

no, he doesn't insist upon it. you shouldn't even show how symrefs can
be done. go with your correct instincts and not show it at all.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Sat, 05 Jul 2003 10:11:39 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: naming hash using a variable name.
Message-Id: <Xns93AF71DEF84Bsdn.comcast@206.127.4.25>

arawind@yahoo.com (ARAVIND) wrote in news:1d21ceeb.0307050327.3e140fd1
@posting.google.com:

> I have a variable output from one part of program,
> $tmp1 = I.LUV.U;
> Now,
> I want to create a variable of type hash with a name I.LUV.U
> i.e. the name of hash to be same as $tmp1,
> 
> how can i achieve this?

The correct answer to this question is "Why do you think you need to do 
this?"

It can be done, but it's generally a bad idea.  Better to use a nested 
hash.  

-- 
Eric
$_ =  reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print


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

Date: Sat, 5 Jul 2003 09:39:39 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: naming hash using a variable name.
Message-Id: <slrnbgdopb.6no.tadmc@magna.augustmail.com>

ARAVIND <arawind@yahoo.com> wrote:

> $tmp1 = I.LUV.U;


You should always enable "use strict" when developing Perl code.


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


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

Date: Sat, 5 Jul 2003 09:40:55 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: naming hash using a variable name.
Message-Id: <slrnbgdorn.6no.tadmc@magna.augustmail.com>

ARAVIND <arawind@yahoo.com> wrote:

> i.e. the name of hash to be same as $tmp1,
> 
> how can i achieve this?


Friends don't let friends use symbolic references.

Use a hash and real references instead:

   http://www.plover.com/~mjd/perl/varvarname.html
   http://www.plover.com/~mjd/perl/varvarname2.html
   http://www.plover.com/~mjd/perl/varvarname3.html


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


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

Date: 5 Jul 2003 16:22:40 -0500
From: "noViagraHere" <requests@zipperpulls.com>
Subject: Re: ping Tad
Message-Id: <3f074049$0$81802$45beb828@newscene.com>

Thank you so much for your help but I don't think you understood my
question. Let me try to explain better.

file1.cgi is called from a third party by sending variables to the script,
ie. http://file1.cgi?parameters=list

file1.cgi then stores the transaction variables in mysql and in turn from
within file1.cgi calls http://file2.cgi?parameters=list
file2.cgi will then return simply the word approved or declined in plain
text html.

I need to know how to add code within file1.cgi to determine what
http://file2.cgi?parameters=list returned, approved or declined. I suspect
this is done through reading http headers or something but am new to this
area.

Thnks

Rodney Stover




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

Date: Sat, 05 Jul 2003 14:59:03 -0400
From: T Stewart <tstewart66@hotmail.com>
Subject: Problem with counter CGI script
Message-Id: <ak7egv0nie4sa1f0o9mdnh7tfksooudqdl@4ax.com>


I downloaded a free counter CGI from http://www.htmlgoodies.com/ and
it works fine on my server with one exception.

It has a feature where if someone else is detected using it without
permission, you can create a .LOCK file in the counter directory that
will always cause it to return 0 to the caller.

But I'm finding it will create the .LOCK file after the first call,
causing subsequent calls to return 0.

Here is where it goes to increment the counter:

sub incrementCount {
  if (&lockFile == 1) {
    $count = "0";
    return;
  }
  &incrementTotalReads;
  &unlockFile;
}


In doing so, it checks for the presence of a .LOCK file:

sub lockFile {
  $lockCount = 0;
  while (-f "$counterFile.lock") { 
    if ($lockCount > $lockWait) {
      $count = 0;
      return 1;
    }
    sleep 1; 
    $lockCount++;
  }
  open(LOCK,">$counterFile.lock") || die("Can't open
$counterFile.lock: $!\n");
  return 0;
}

Shouldn't this just check for a LOCK file, not create one?

Thanks in advance,

Tim

//====================================
Full code is below FYI
Obtained free from http://www.htmlgoodies.com/ 
//====================================
#!c:\Perl\bin\perl.exe
$minLen = 7;

#This is absolute path of the directory where the counter files are
stored. Must be global-writeable.
$counterdir = "";

$lockWait = 5;

&ReadParse;
&initialize;
&loadbitmaps;
&incrementCount;
&generateBitmap;
&writeBitmap;
exit(0);

sub writeBitmap {
  print "Content-type: image/x-xbitmap\n\n";
  print "#define count_width ",$len*8,"\n#define count_height 16\n";
  print "static char count_bits[] = {\n";
  for($i = 0; $i < ($#bytes + 1); $i++) {
    print "0x$bytes[$i]";
    if ($i != $#bytes) {
      print ",";
      if (($i+1) % 7 == 0) {
        print "\n" ;
      }
    }
  }
  print "};\n";
}

sub generateBitmap {
  $count = $totalReads;
  @bytes = ();
  $len = length($count) > $minLen ? length($count) : $minLen;
  $outtext = sprintf("%0${len}d",$count);
  for ($i = 0; $i < $len*3; $i++ ) {
    push(@bytes,"ff");
  }
  for ($y=0; $y < 10; $y++) {
    for ($x=0; $x < $len; $x++) {
      push(@bytes,substr($chars{substr($outtext,$x,1)},$y*3,2));
    }
  }
  for ($i = 0; $i < $len*3; $i++ ) {
    push(@bytes,"ff");
  }
}


sub initialize {
  if ($#in < 0) {
    $scriptURL = "http://" . $ENV{'SERVER_NAME'} . ":" .
$ENV{'SERVER_PORT'} . $ENV{'SCRIPT_NAME'};
    print ("Content-type: text/html\n\n");
    print ("<HTML><HEAD><TITLE>Visitor counter</TITLE></HEAD>\n");
    print ("<BODY><h1>counter.xbm</h1>To put a visitor counter like
this \n");
    print ("<IMG SRC=\"$scriptURL?unique_id\">\n");
    print ("on your web page, put an image tag in your HTML document
like:<br>\n");
    print ("&lt;IMG SRC=\"$scriptURL?unique_id\"&gt;<br>\n");
    print ("where \"unique_id\" is a unique identifier for your
counter.<p>\n");
    print ("When creating a new counter you can set the starting value
by adding a count parameter to the URL. So if the counter \"qwerty\"
didn't exist, accessing the URL<br>\n");
    print ("$scriptURL?qwerty&COUNT=1234<br>\n");
    print ("will create a new counter called \"qwerty\" with its
counter set to 1234.<br>The counter can only be set when creating a
new counter.\n");
    print ("<hr></BODY></HTML>\n");
    exit;
  }
  else {
    $countername = $in[0];
    $countername =~ s/\W//g;
    $counterFile = $counterdir . $countername;
    if (!( -f $counterFile )) {
      $start = $in{'COUNT'} -1;
      open(CNTRFILE,">$counterFile");
      print CNTRFILE "$start\n";
      close(CNTRFILE);
    }
  }
}

sub incrementCount {
  if (&lockFile == 1) {
    $count = "0";
    return;
  }
  &incrementTotalReads;
  &unlockFile;
}


sub unlockFile {
  unlink("$counterFile.lock");
}

sub lockFile {
  $lockCount = 0;
  while (-f "$counterFile.lock") { 
    if ($lockCount > $lockWait) {
      $count = 0;
      return 1;
    }
    sleep 1; 
    $lockCount++;
  }
  open(LOCK,">$counterFile.lock") || die("Can't open
$counterFile.lock: $!\n");
  return 0;
}

sub incrementTotalReads {
  if (-e $counterFile) {
    open(COUNT,"$counterFile") || die("Can't open $counterFile:
$!\n");
  }
  $totalReads = <COUNT>;
  chop $totalReads;
  close(COUNT);
  $totalReads++;
  open(COUNT,">$counterFile") || die "$0: can\'t open $counterFile:
$!\n";
  print (COUNT "$totalReads\n");
  close(COUNT);
}

sub loadbitmaps {
  $chars{'0'} = "c3 99 99 99 99 99 99 99 99 c3";
  $chars{'1'} = "cf c7 cf cf cf cf cf cf cf c7";
  $chars{'2'} = "c3 99 9f 9f cf e7 f3 f9 f9 81";
  $chars{'3'} = "c3 99 9f 9f c7 9f 9f 9f 99 c3";
  $chars{'4'} = "cf cf c7 c7 cb cb cd 81 cf 87";
  $chars{'5'} = "81 f9 f9 f9 c1 9f 9f 9f 99 c3";
  $chars{'6'} = "c7 f3 f9 f9 c1 99 99 99 99 c3";
  $chars{'7'} = "81 99 9f 9f cf cf e7 e7 f3 f3";
  $chars{'8'} = "c3 99 99 99 c3 99 99 99 99 c3";
  $chars{'9'} = "c3 99 99 99 99 83 9f 9f cf e3";
}

# Perl Routines to Manipulate CGI input
# Copyright 1993 Steven E. Brenner  
sub ReadParse {
  if (@_) {
    local (*in) = @_;
  }

  local ($i, $loc, $key, $val);

  # Read in text
  if ($ENV{'REQUEST_METHOD'} eq "GET") {
    $in = $ENV{'QUERY_STRING'};
  } elsif ($ENV{'REQUEST_METHOD'} eq "POST") {
    for ($i = 0; $i < $ENV{'CONTENT_LENGTH'}; $i++) {
      $in .= getc;
    }
  } 

  @in = split(/&/,$in);

  foreach $i (0 .. $#in) {
    # Convert plus's to spaces
    $in[$i] =~ s/\+/ /g;

    # Convert %XX from hex numbers to alphanumeric
    $in[$i] =~ s/%(..)/pack("c",hex($1))/ge;

    # Split into key and value.
    $loc = index($in[$i],"=");
    $key = substr($in[$i],0,$loc);
    $val = substr($in[$i],$loc+1);
    $in{$key} .= '\0' if (defined($in{$key})); # \0 is the multiple
separator
    $in{$key} .= $val;
  }

  return 1; 
}



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

Date: Sat, 5 Jul 2003 15:49:36 +0200
From: "Dennis Hueckelheim" <dennis.hueckelheim@issdh.com>
Subject: Re: Problems with perlcc
Message-Id: <be6l3k$1o4hn$1@ID-139877.news.dfncis.de>


"Sisyphus" <kalinabears@hdc.com.au> wrote
>
> I can't really answer any of those questions.
> There are generally problems with perlcc. I believe it's no longer
> maintained.
>
> The best solution is to use the 'pp' utility that comes with the PAR
module
> (available from cpan).
>
> If you really *must* use perlcc then you're probably on your own :-)
>
> Cheers,
> Rob
>
>

No, I don't *must* use perlcc. I only want to compile my sources, because
the program would run faster, wouldn't it? A second reason s, that the other
webmaster's on my server can't read the sources.




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

Date: 5 Jul 2003 18:25:53 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Problems with perlcc
Message-Id: <be757h$81k$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Dennis Hueckelheim:

> No, I don't *must* use perlcc. I only want to compile my sources, because
> the program would run faster, wouldn't it? 

No, it wouldn't. At least as far as run-time is concerned, there is no
measurable difference. Compile-time (that is: the time that is usually
needed to start the perl interpreter and have it compile the script)
will benefit. But this is very seldom a concern for Perl scripts. The
interpreter is pretty fast at compiling Perl code into executable
bytecode.

> A second reason s, that the other
> webmaster's on my server can't read the sources.

There are no satisfactory solutions for this problem AFAIK (if it is
actually a problem). Why shouldn't other webmasters be allowed to see
your scripts?

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, 05 Jul 2003 14:40:38 -0400
From: "bd" <bdonlan@bd-home-comp.no-ip.org>
Subject: Re: Problems with perlcc
Message-Id: <pan.2003.07.05.18.40.36.847146@bd-home-comp.no-ip.org>

On Sat, 05 Jul 2003 15:49:36 +0200, Dennis Hueckelheim wrote:

> 
> "Sisyphus" <kalinabears@hdc.com.au> wrote
>>
>> I can't really answer any of those questions.
>> There are generally problems with perlcc. I believe it's no longer
>> maintained.
>>
>> The best solution is to use the 'pp' utility that comes with the PAR
> module
>> (available from cpan).
>>
>> If you really *must* use perlcc then you're probably on your own :-)
>>
>> Cheers,
>> Rob
>>
>>
> 
> No, I don't *must* use perlcc. I only want to compile my sources, because
> the program would run faster, wouldn't it? A second reason s, that the other
> webmaster's on my server can't read the sources.

If you're using Apache, you can use mod_perl to compile your scripts only
once. As for the source viewing problem, this would be something to take
up with your hosting provider.

-- 
Freenet distribution not available
You'll never be the man your mother was!



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

Date: Sat, 5 Jul 2003 21:14:41 +0200
From: "Dennis Hueckelheim" <dennis.hueckelheim@issdh.com>
Subject: Re: Problems with perlcc
Message-Id: <be7853$1vout$1@ID-139877.news.dfncis.de>


"bd" <bdonlan@bd-home-comp.no-ip.org> wrote
>
> If you're using Apache, you can use mod_perl to compile your scripts only
> once. As for the source viewing problem, this would be something to take
> up with your hosting provider.
>

The problem is, that the people who don't should see the sources have access
as root, so I can't use different rights.




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

Date: Sat, 5 Jul 2003 10:14:10 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: reading header? results from another script
Message-Id: <slrnbgdqq2.6no.tadmc@magna.augustmail.com>

noViagraHere <requests@zipperpulls.com> wrote:

> then pass the parameters to another server calling 'file2.cgi' then


Your Question is Asked Frequently:

   How do I automate an HTML form submission?


> #!/usr/bin/perl


You should ask for all the help you can get.

Programs that take form input should enable taint checking (perlsec.pod).

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



>   print qq~
><html><head>
><title>Result.</title>
> 
> 
> 
></head>
><body MARGINWIDTH="0" MARGINHEIGHT="0" LEFTMARGIN="0" TOPMARGIN="0"
> bgcolor="#ffffff" link="#0000CC" vlink="#0066FF" alink="#0066FF"
> text="#000000">
><br>
>   ~;


You shouldn't mislead yourself like that.

That is, you shouldn't imply that backslash escapes or interpolation
is needed, only to not use either.

   print q~
or
   print '



>         }else{


perlstyle.pod suggests you avoid such "cuddled" elses.


>         if ($from) {
>         print "From_email: $from<br>\n";
>         }else{
>         print "From_email: NULL<br>\n";
>         }


You should indent your code so as to indicate the extent of the blocks.

Another way to do that:

   $from = 'NULL' unless $from;
   print "From_email: $from<br>\n";


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


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

Date: Sat, 05 Jul 2003 22:37:13 +0200
From: Zvone Zagar <zvone.zagar@siol.net>
Subject: Re: Reading JPEG file
Message-Id: <7HGNa.22$2B6.2874@news.siol.net>

A. Sinan Unur wrote:

> Zvone Zagar <zvone.zagar@siol.net> wrote in news:iafNa.2024$78.139057
> @news.siol.net:
> 
>> A. Sinan Unur wrote:
>> 
>>> Zvone Zagar <zvone.zagar@siol.net> wrote in
>>> news:GdKLa.1908$78.104444@news.siol.net:
>>> 
>>>> I would like to read a jpg image, get data (decode) out of it and make
>>>> a postscript file from scratch. I can get width, height, color depth
>>>> but I don't know how to make a hex string needed for postscript.
>>>> Postscript line  should look like: width height depth matrix {<hex
>>>> data>} false 3 colorimage.
> ...
>>> ImageMagick can save image data in raw RGB format. Although I have
>>> never used it, and do not have it installed, I thought pointing that
>>> out might help.
>>> 
>>> Sinan.
>> I appologize for my late answer.
>> The raw RGB format is unfortunately not the proper one.
>> At first my lips smiled, but code generated is not PS digested.
>> I will dig deeper.
> 
> If I understand correctly, you need to get to the raw RGB data somehow (I
> have no idea how one embeds jpegs in postscript), and then insert those
> data in the document as ascii hexadecimal numbers. Is that the case? If
> so, once you get the raw RGB data, you can easily get what you want. So,
> raw RGB would not be the solution to your problem, but the first step in a
> solution.
> 
> I should probably shut up because I am a little fuzzy on what you are
> trying to do. If you can post a link to the specification of the output
> file format (for your particular case) or maybe just explain it a little,
> we might be able to help more.
> 
> Sinan.
> 
Hello
I really appreciate your effort. I set up temporary site at
http:/freeweb.siol.net/an511zvo where some examples will clarify my
intentions (I hope). The Tk script creates a ps file. That is what I want
to make, but not using Tk. I would like to make text (console) application
which creates postscript file.
File (I stripped off unnecessary ps code) raptor2.ps is what I want to get
at. The hex code between curly braces and <> is the hex string which makes
me perplexed. I think that raw RGB data is the first step, too.

Zvone

p.s. My appreciation was not empty words



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

Date: Sat, 05 Jul 2003 22:44:07 +0300
From: ddtl <this.is.invalid@yahoo.com>
Subject: Re: Regexp constructed from command line arguments.
Message-Id: <j06egvour5lbhv8i8377obcu7sfo3clv3h@4ax.com>


>> s/\Q$opts{'s'}\E/\Q$opts{'r'}\E/g;
>
>You are subjecting $opts{s} to quotemeta() you are therefore not
>treating the contents of $opts{s} as a regexp to match but rather as a
>plain string to match.

Now i understand a problem (didn't get book's explanation about 
quotemeta() right) - saying \Q$opts{'s'}\E with "[\d]{2}" will
actually search for "\[d\]\{2\}"

 .
>You are also subjecting $opts{r} to quotemeta().  This makes no sense
>at all - if $opts{r} contained any \W characters they would actually
>appear backslashed in the output.

Yes, that was part of my misunderstanding about quotemeta().

Though still i couldn't get a script to do quite the right thing
(after removing all \Q and \E, of course): if a replacement string 
is "0\1" (file name and searchexp is "00.mp3" and "([\d]{2})"),
a file is renamed to be "0\1.mp3" instead of "000.mp3", though
it works when used literally in code, for example:

$a="00";
$a=~s/([\d]{2})/0\1/g;
print "$a";

Here, i get "000" as an output.

What is another problem here? Apparently, expansion of a variable
containing a replacement string is used "as it is", without treating
metacharacters as such. 

But why it is so - it is not happening with expansion of a variable
containing regexp?

ddtl.




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

Date: Sat, 05 Jul 2003 22:52:43 +0300
From: ddtl <this.is.invalid@yahoo.com>
Subject: Re: Regexp constructed from command line arguments.
Message-Id: <draegv442901u5u28f06va7ul3anms8jg2@4ax.com>


>> 7) $n++;
>
>
>You should probably be letting Perl do the indexing for you by
>using push() instead of doing your own indexing into @entry.
>
>   push @entry, "$entry[1]$entry[0]$entry[2]";  # Look Ma! No $n needed!

Thanks for advice - will take it into account. I am (was long ago,
actually) used to C, and still didn't learn "perl ways" - you couldn't
do it after only 4 days of learning and in your first program :).

ddtl.


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

Date: 5 Jul 2003 11:01:22 -0700
From: charley@pulsenet.com (Chris Charley)
Subject: Re: script for unrestricted permutation
Message-Id: <4f7ed6d.0307051001.70ce5a48@posting.google.com>

weberh@zedat.fu-berlin.de (weberh) wrote in message news:<7003ec4a.0307031056.22785260@posting.google.com>...
> Thanks for the hint.
> I have to admit, that I haven't understood bd's code yet.
> I'll make a hardcopy and study it at home with a cup of tea.  
> 

I solved this permutation by modeling it on an odometer. The number of
wheels to the odometer is the number of groupings (4, for example). A
car odometer wheel is marked from 0 to 9 - base ten. For the odometer
this code creates, the wheels are from 0 to the number of elements in
the array minus 1. (Total numbers on the wheel = number of array
elements to be permuted). Then, to generate the permutations, you
cycle the odometer (like a car) adding 1, getting that permutation,
and continuing until the odometer 'rolls over' and exits at the last
permutation. This 'perm' function does not handle incorrect parameter
lists or error checking and will be unpredictable in that case. Scalar
@elements is the 'base' of the number system of the odometer.

The line of code: 
           push @perms, [ @elements[@odometer] ];
Uses array slices to assign elements to the permutation.

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

my $group = 4;

my @perms = perm($group, "red", "green", "blue");

for my $i (0..$#perms) {
    for my $j (0..$group-1) {
        print "$perms[$i][$j] ";
    }
    print "\n";
}


# function perm($groupings, @elements)

sub perm {
    my $groupings = shift @_;
    my @elements = @_;
    my @odometer = (0) x $groupings;
    my @perms;
    while ( 1 ) {
        push @perms, [ @elements[@odometer] ];
        my $wheel= 0;
        $odometer[$wheel] = ($odometer[$wheel] + 1) % @elements;
        
        while ($odometer[$wheel] == 0 && ++$wheel< @odometer) {
            $odometer[$wheel] = ($odometer[$wheel] + 1) % @elements;
        }
        return @perms if $wheel == @odometer;
    }
}


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

Date: Sat, 05 Jul 2003 21:31:56 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: script for unrestricted permutation
Message-Id: <3f073a46.103382417@news.erols.com>

charley@pulsenet.com (Chris Charley) wrote:

: I solved this permutation by modeling it on an odometer.

Nice analogy.

: #!/usr/bin/perl
: use strict;
: use warnings;
: 
: my $group = 4;
: my @perms = perm($group, "red", "green", "blue");
: 
: for my $i (0..$#perms) {
:     for my $j (0..$group-1) {
:         print "$perms[$i][$j] ";
:     }
:     print "\n";
: }
: sub perm {
:     my $groupings = shift @_;
:     my @elements = @_;
:     my @odometer = (0) x $groupings;
:     my @perms;
:     while ( 1 ) {
:         push @perms, [ @elements[@odometer] ];
:         my $wheel= 0;
:         $odometer[$wheel] = ($odometer[$wheel] + 1) % @elements;
:         
:         while ($odometer[$wheel] == 0 && ++$wheel< @odometer) {
:             $odometer[$wheel] = ($odometer[$wheel] + 1) % @elements;
:         }
:         return @perms if $wheel == @odometer;
:     }
: }

I like the principle, but the implementation feels a little too
fiddly.

How about instead of monitoring $wheel and bailing out when it indexes
a nonexistent @odometer element, just add another element to
@odometer.  Ignore its value in the permutation, but bail out when it
increments.  Program flow simplifies itself a lot.

    print "@$_\n" for perm(4, "red", "green", "blue");
    sub perm {
        my($groupings, @elems) = @_;
        my @odometer = (0) x ($groupings+1);
        my @perms;
        until( $odometer[-1] ) {
            push @perms, [ @elems[ @odometer[0..$groupings-1] ] ];
            for( @odometer ) {
                $_++;
                last if $_ %= @elems;
            }
        }
        return @perms;
    }



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

Date: 5 Jul 2003 07:44:59 -0700
From: rtl@trsolutions.net (rtl)
Subject: Re: trying to parse XML from an email...
Message-Id: <cd8b6435.0307050644.aa9f149@posting.google.com>

inwap@inwap.com (Joe Smith) wrote in message news:<f9sNa.224$603.12107@iad-read.news.verio.net>...
> In article <cd8b6435.0307020749.6dc639bd@posting.google.com>,
> rtl <rtl@trsolutions.net> wrote:
> >I am retrieving an email with XML content.  I strip off the email
> >headings and save only the XML portion to a file.
> 
> You should not blindly strip off all of the email headers, especially
> the ones that state how the rest of the message is encoded.
> Watch out for quoted-printable, uuencode, and BASE64.
> 
> You should use a MIME module to parse the message, locate the
> attachment, decode it in a manner consistent with the attachment's
> headers, and write the decoded data to a file.
> 	-Joe

I've taken everyone's advice and used a MIME module instead of
stripping the headers.  So far it's worked like a charm.  Now, I still
need some more advice.  I am sending the data from the XML back out
as: 1) an email and 2) MySQL inserts.

I am trying to now figure out how to "encode" them properly so the
special symbols (trademark, etc) display properly on the receiving
ends (email, SQL).  I have tried setting the bits => "8" part of the
net::smtp module when sending the mail, but no luck yet.

Any more pointers?  So far your responses have been great.  Thanks
again!


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

Date: Sat, 5 Jul 2003 19:10:44 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: trying to parse XML from an email...
Message-Id: <Pine.LNX.4.53.0307051900330.9892@lxplus097.cern.ch>

On Sat, Jul 5, rtl inscribed on the eternal scroll:

> I've taken everyone's advice and used a MIME module instead of
> stripping the headers.

Quite right, too.

>  So far it's worked like a charm.  Now, I still
> need some more advice.  I am sending the data from the XML back out
> as: 1) an email and 2) MySQL inserts.
>
> I am trying to now figure out how to "encode" them properly so the
> special symbols (trademark, etc) display properly on the receiving
> ends (email, SQL).

If you knew what you wanted, I don't think you'd have the slightest
difficulty in writing Perl code to achieve it.  So you don't seem to
have a Perl problem.

> I have tried setting the bits => "8" part of the
> net::smtp module when sending the mail, but no luck yet.

That sounds almost as bad an error report at "it doesn't work".

I'd have no difficulty in expressing the trademark sign in XML, in
a number of different ways, but unless you understand enough XML I'm
not sure what sense you'd make of the answer.

Once you've got your XML representation sorted out, then MIME-encoding
them for transmission as email is pretty-much the converse of what
you've already done, no?  And indeed you'd do it with an appropriate
MIME module.

> Any more pointers?

If you're not comfortable with handling character codings, then the
safest way to represent non-US-ASCII characters in XML is as &#number;
character references.  It's far from being the most economical
representation, especially if there are a lot of non-US-ASCII
characters of course, but it's pretty safe.  Look up the characters at
the Unicode site - or most of the ones commonly needed are listed at
the end of the HTML4.01 specification.[1]

I'm afraid the corresponding answer in a MySQL context is beyond my
usual working range, so I'll leave that for someone else.

good luck

[1] don't be misled by bogus references that include displayable
characters between 127 and 159 decimal inclusive.


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

Date: Sat, 05 Jul 2003 21:24:53 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: using 'DB_File' versus just plain tie() ?
Message-Id: <0c5dgv0gd3pl6mucam32nj5pn1heii8aep@4ax.com>

On Fri, 4 Jul 2003 17:24:26 +0100, "Paul Marquess"
<paul.marquess@btinternet.com> wrote:

>I'm going to add a note about all of this to the DB_File documentation.

That's a good idea(TM)!


Michele
-- 
$\=q.,.,$_=q.print'  ,\g,,( w,a'c'e'h,,map{$_-=qif/g/;chr
}107..q[..117,q)[map+hex,split//,join' ,2B,, w$ECDF078D3'
F9'5F3014$,$,];];$\.=$/,s,q,32,g,s,g,112,g,y,' , q,,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 5183
***************************************


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